"Json to Swagger" conversor
Python utility created to convert JSON to Swagger definitions structure, based on entities concept.
Dependencies
- Python 3.6+
- Libraries:
- swagger-parser
- pyyaml
- pattern
Note: Before run, execute:
$ pip install -r requirements.txt
Usage
Running:
$ python main.py <json-file-path> <RootEntityName> [swagger-file-path] [-v]
json-file-path- path of json file to convertRootEntityName- name of root swagger definitions entityswagger-file-path- path of swagger file. If the file has content, it will be merged with json converted content-v- verbose mode
example.json
{
"id": "ffe74d36-4f76-4ca6-9dd1-8d5c9b16b056",
"name": "JSON example",
"description": "Just a simple JSON file to convert into swagger definition",
"someObject": {
"someInteger": 0,
"someNumber": 0.1,
"someBoolean": true,
"someNull": null,
"someString": "Example string content"
},
"items": [
{
"name": "Item",
"subItem": {
"subItemsOfSubItem": [
{
"foo": "bar"
}
]
}
}
]
}
example.swagger.yaml
definitions:
Root:
type: object
title: Root
description: Root Entity
properties:
id:
type: string
example: ffe74d36-4f76-4ca6-9dd1-8d5c9b16b056
name:
type: string
example: JSON example
description:
type: string
example: Just a simple JSON file to convert into swagger definition
someObject:
$ref: '#/definitions/SomeObject'
items:
type: array
items:
$ref: '#/definitions/Item'
SomeObject:
type: object
title: Some Object
description: Some Object Entity
properties:
someInteger:
type: integer
example: 0
someNumber:
type: number
example: 0.1
someBoolean:
type: boolean
example: true
someNull:
type: string
example: null
someString:
type: string
example: Example string content
Item:
type: object
title: Item
description: Item Entity
properties:
name:
type: string
example: Item
subItem:
$ref: '#/definitions/SubItem'
SubItem:
type: object
title: Sub Item
description: Sub Item Entity
properties:
subItemsOfSubItem:
type: array
items:
$ref: '#/definitions/SubItemsOfSubItem'
SubItemsOfSubItem:
type: object
title: Sub Items Of Sub Item
description: Sub Items Of Sub Item Entity
properties:
foo:
type: string
example: bar
Attention: Properties with same name will be merged
Example
In the JSON structure bellow, it has the "items" property in two objects:
{
"items": [
{
"name": "Item",
"subItem": {
"items": [
{
"foo": "bar"
}
]
}
}
]
}
The result will merge the two "items" properties into "Item" entity:
definitions:
RootEntity:
type: object
title: Root
description: Root Entity
properties:
items:
type: array
items:
$ref: '#/definitions/Item'
Item:
type: object
title: Item
description: Item Entity
properties:
name:
type: string
example: Item
subItem:
$ref: '#/definitions/SubItem'
foo:
type: string
example: bar
SubItem:
type: object
title: Sub Item
description: Sub Item Entity
properties:
items:
type: array
items:
$ref: '#/definitions/Item'
Metadata
Release files for json-to-swagger 0.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| json-to-swagger-0.0.5.tar.gz | 3.9 kB | Without provenance | Details for json-to-swagger-0.0.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| json_to_swagger-0.0.5-py3-none-any.whl | Python 3 | none | any | Details for json_to_swagger-0.0.5-py3-none-any.whl |
Total release size: 20.4 kB
Release files / json-to-swagger-0.0.5.tar.gz
| Download URL | json-to-swagger-0.0.5.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4f52bb9ca4c9217ac5ea85efb3c6b72c1dd22acde008384da8ace685892bb000
|
|
BLAKE2b-256 checksum How to use checksums |
f30e810c9cd7ba722d486f530c7b760ae29aabff4d39b76fb97ea2051a655789
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.2
|
Release files / json_to_swagger-0.0.5-py3-none-any.whl
| Download URL | json_to_swagger-0.0.5-py3-none-any.whl |
|---|---|
| Size | 16.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0463e5e67d84d3ac3308bbfb3ba5e88580ee9339b12aacf080d2d774be54f0a1
|
|
BLAKE2b-256 checksum How to use checksums |
d17cfc3a69ae6a45467e4cf742f646458999c42e2e697caf5c44ed167ba7b50a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.2
|
Security for json-to-swagger 0.0.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.