Generate request parameters from the Swagger json
Project description
Swagger2JSON
Generate request parameters from the Swagger json
Installation
pip install swagger2json
Usage
import swagger2json
import json
swagger= Swagger(json_url='https://petstore.swagger.io/v2/swagger.json')
swagger.parse()
for items in swagger.result:
print(json.dumps(items, sort_keys=True, indent=4, separators=(',', ': ')).encode('utf-8').decode('unicode_escape'))
Examples
python setup.py test
Result
{
"description": "",
"if_params_in_url": false,
"method": "post",
"name": "pet",
"parameters": {
"body": "{
"category": {
"id": 1,
"name": "string"
},
"id": 1,
"name": "string",
"photoUrls": [
"string"
],
"status": "string",
"tags": [
{
"id": 1,
"name": "string"
}
]
}"
},
"path": "/pet",
"summary": "Add a new pet to the store",
"tag": "Pet",
"type": [
"application/json",
"application/xml"
]
}
{
"description": "",
"if_params_in_url": false,
"method": "put",
"name": "pet",
"parameters": {
"body": "{
"category": {
"id": 1,
"name": "string"
},
"id": 1,
"name": "string",
"photoUrls": [
"string"
],
"status": "string",
"tags": [
{
"id": 1,
"name": "string"
}
]
}"
},
"path": "/pet",
"summary": "Update an existing pet",
"tag": "Pet",
"type": [
"application/json",
"application/xml"
]
}
{
"description": "Multiple status values can be provided with comma separated strings",
"if_params_in_url": false,
"method": "get",
"name": "find_by_status",
"parameters": {
"query": "{
"status": []
}"
},
"path": "/pet/findByStatus",
"summary": "Finds Pets by status",
"tag": "Pet",
"type": null
}
{
"description": "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.",
"if_params_in_url": false,
"method": "get",
"name": "find_by_tags",
"parameters": {
"query": "{
"tags": []
}"
},
"path": "/pet/findByTags",
"summary": "Finds Pets by tags",
"tag": "Pet",
"type": null
}
{
"description": "Returns a single pet",
"if_params_in_url": true,
"method": "get",
"name": "pet",
"parameters": {
"path": "{
"petId": 1
}"
},
"path": "/pet/{petId}",
"summary": "Find pet by ID",
"tag": "Pet",
"type": null
}
{
"description": "",
"if_params_in_url": true,
"method": "post",
"name": "pet",
"parameters": {
"formData": "{
"name": "string",
"status": "string"
}",
"path": "{
"petId": 1
}"
},
"path": "/pet/{petId}",
"summary": "Updates a pet in the store with form data",
"tag": "Pet",
"type": [
"application/x-www-form-urlencoded"
]
}
{
"description": "",
"if_params_in_url": true,
"method": "delete",
"name": "pet",
"parameters": {
"header": "{
"api_key": "string"
}",
"path": "{
"petId": 1
}"
},
"path": "/pet/{petId}",
"summary": "Deletes a pet",
"tag": "Pet",
"type": null
}
{
"description": "",
"if_params_in_url": true,
"method": "post",
"name": "upload_image",
"parameters": {
"formData": "{
"additionalMetadata": "string",
"file": "string"
}",
"path": "{
"petId": 1
}"
},
"path": "/pet/{petId}/uploadImage",
"summary": "uploads an image",
"tag": "Pet",
"type": [
"multipart/form-data"
]
}
{
"description": "Returns a map of status codes to quantities",
"if_params_in_url": false,
"method": "get",
"name": "inventory",
"parameters": {},
"path": "/store/inventory",
"summary": "Returns pet inventories by status",
"tag": "Store",
"type": null
}
{
"description": "",
"if_params_in_url": false,
"method": "post",
"name": "order",
"parameters": {
"body": "{
"complete": True,
"id": 1,
"petId": 1,
"quantity": 1,
"shipDate": "string",
"status": "string"
}"
},
"path": "/store/order",
"summary": "Place an order for a pet",
"tag": "Store",
"type": null
}
{
"description": "For valid response try integer IDs with value >= 1 and <= 10. Other values will generated exceptions",
"if_params_in_url": true,
"method": "get",
"name": "order",
"parameters": {
"path": "{
"orderId": 1
}"
},
"path": "/store/order/{orderId}",
"summary": "Find purchase order by ID",
"tag": "Store",
"type": null
}
{
"description": "For valid response try integer IDs with positive integer value. Negative or non-integer values will generate API errors",
"if_params_in_url": true,
"method": "delete",
"name": "order",
"parameters": {
"path": "{
"orderId": 1
}"
},
"path": "/store/order/{orderId}",
"summary": "Delete purchase order by ID",
"tag": "Store",
"type": null
}
{
"description": "This can only be done by the logged in user.",
"if_params_in_url": false,
"method": "post",
"name": "user",
"parameters": {
"body": "{
"email": "string",
"firstName": "string",
"id": 1,
"lastName": "string",
"password": "string",
"phone": "string",
"userStatus": 1,
"username": "string"
}"
},
"path": "/user",
"summary": "Create user",
"tag": "User",
"type": null
}
{
"description": "",
"if_params_in_url": false,
"method": "post",
"name": "create_with_array",
"parameters": {
"body": "[
{
"email": "string",
"firstName": "string",
"id": 1,
"lastName": "string",
"password": "string",
"phone": "string",
"userStatus": 1,
"username": "string"
}
]"
},
"path": "/user/createWithArray",
"summary": "Creates list of users with given input array",
"tag": "User",
"type": null
}
{
"description": "",
"if_params_in_url": false,
"method": "post",
"name": "create_with_list",
"parameters": {
"body": "[
{
"email": "string",
"firstName": "string",
"id": 1,
"lastName": "string",
"password": "string",
"phone": "string",
"userStatus": 1,
"username": "string"
}
]"
},
"path": "/user/createWithList",
"summary": "Creates list of users with given input array",
"tag": "User",
"type": null
}
{
"description": "",
"if_params_in_url": false,
"method": "get",
"name": "login",
"parameters": {
"query": "{
"password": "string",
"username": "string"
}"
},
"path": "/user/login",
"summary": "Logs user into the system",
"tag": "User",
"type": null
}
{
"description": "",
"if_params_in_url": false,
"method": "get",
"name": "logout",
"parameters": {},
"path": "/user/logout",
"summary": "Logs out current logged in user session",
"tag": "User",
"type": null
}
{
"description": "",
"if_params_in_url": true,
"method": "get",
"name": "user",
"parameters": {
"path": "{
"username": "string"
}"
},
"path": "/user/{username}",
"summary": "Get user by user name",
"tag": "User",
"type": null
}
{
"description": "This can only be done by the logged in user.",
"if_params_in_url": true,
"method": "put",
"name": "user",
"parameters": {
"body": "{
"email": "string",
"firstName": "string",
"id": 1,
"lastName": "string",
"password": "string",
"phone": "string",
"userStatus": 1,
"username": "string"
}",
"path": "{
"username": "string"
}"
},
"path": "/user/{username}",
"summary": "Updated user",
"tag": "User",
"type": null
}
{
"description": "This can only be done by the logged in user.",
"if_params_in_url": true,
"method": "delete",
"name": "user",
"parameters": {
"path": "{
"username": "string"
}"
},
"path": "/user/{username}",
"summary": "Delete user",
"tag": "User",
"type": null
}
Running the tests
python setup.py test
Acknowledgments
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
swagger2json-0.1.1.tar.gz
(6.4 kB
view details)
File details
Details for the file swagger2json-0.1.1.tar.gz
.
File metadata
- Download URL: swagger2json-0.1.1.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fdf81c6b4f66bb43a8838d44a7ef12caeb9ed13e9567cb364f0064e73cb093bc |
|
MD5 | 9718f5b5f264deb6aa66b77fe227828b |
|
BLAKE2b-256 | 578a23326aa9b7d110321c16d1abd82968ee3462feac6354846f5f9a89a9a8ea |