Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lts-beratung/json-to-openapi
A small cli application to convert json schemas to openapi schemas
https://github.com/lts-beratung/json-to-openapi
cli json json-schema openapi openapi-spec openapi-specification schema swagger
Last synced: about 1 month ago
JSON representation
A small cli application to convert json schemas to openapi schemas
- Host: GitHub
- URL: https://github.com/lts-beratung/json-to-openapi
- Owner: lts-beratung
- License: mit
- Created: 2019-01-28T11:22:20.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-04-01T08:39:02.000Z (over 5 years ago)
- Last Synced: 2024-11-14T13:57:02.914Z (about 1 month ago)
- Topics: cli, json, json-schema, openapi, openapi-spec, openapi-specification, schema, swagger
- Language: JavaScript
- Homepage:
- Size: 12.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# json-to-openapi [![install size](https://flat.badgen.net/packagephobia/install/json-to-openapi)](https://packagephobia.now.sh/result?p=json-to-openapi) [![Build Status](https://flat.badgen.net/travis/vikepic/json-to-openapi)](https://travis-ci.org/vikepic/json-to-openapi) [![XO code style](https://flat.badgen.net/xo/status/json-to-openapi)](https://github.com/xojs/xo)
> A small cli application to convert json schemas to openapi schemas.
Using both [json-schema-ref-parser](https://www.npmjs.com/package/json-schema-ref-parser) and [json-schema-to-openapi schema](https://github.com/wework/json-schema-to-openapi-schema).
## Features
Please read the documentation for [json-schema-ref-parser](https://www.npmjs.com/package/json-schema-ref-parser) and [json-schema-to-openapi schema](https://github.com/wework/json-schema-to-openapi-schema#features) to get a complete list of all the features available.
## Install
```
$ npm install --global json-to-openapi
``````
$ json-to-openapi --helpUsage
json-to-openapi filenameExamples
$ json-to-openapi schema.json
// > Converts the json schema stored under schema.json to an openapi schema.
```## Examples
Basic use case where one wants to convert a json schema stored under schema.json to an openapi schema:
```
// schema.json
{
"$schema": "http://json-schema.org/draft-06/schema#",
"description": "A customer schema",
"type": "object",
"required": [
"id"
],
"properties": {
"id": {
"type": "string",
"description": "Customer ID"
},
"firstName": {
"type": "string",
"description": "First name of a customer"
},
"lastName": {
"type": "string",
"description": "Last name of a customer"
}
}
}
```After conversion with `json-to-openapi schema.json`:
```
{
"description": "A customer schema",
"type": "object",
"required": [
"id"
],
"properties": {
"id": {
"type": "string",
"description": "Customer ID"
},
"firstName": {
"type": "string",
"description": "First name of a customer"
},
"lastName": {
"type": "string",
"description": "Last name of a customer"
}
}
}
```It also dereferences `$ref` keywords, thanks to [json-schema-ref-parser](https://www.npmjs.com/package/json-schema-ref-parser). An example of how would that work can be found below:
```
// schema.json
{
// ...
"properties": {
// ...
"emails": {
"type": "array",
"description": "All emails of the customer",
"items": {
"$ref": "#/definitions/email"
}
}
},
"definitions": {
"email": {
"type": "object",
"additionalProperties": false,
"properties": {
"id": {
"type": "string",
"description": "Identifier of the email"
},
"mail": {
"type": "string",
"description": "Mail address"
}
}
}
}
}
```After the conversion:
```
{
// ...
"properties": {
// ...
"emails": {
"type": "array",
"description": "All emails of the customer",
"items": {
"type": "object",
"additionalProperties": false,
"properties": {
"id": {
"type": "string",
"description": "Identifier of the email"
},
"mail": {
"type": "string",
"description": "Mail address"
}
}
}
}
},
"definitions": {
"email": {
// ...
}
}
}
```## See also
* [json-schema-ref-parser](https://www.npmjs.com/package/json-schema-ref-parser)
* [json-schema-to-openapi schema](https://github.com/wework/json-schema-to-openapi-schema)## License
MIT © [vikepic](https://vikepic.github.io)