ppbug-example 1.1.6
Converting swagger documents into Python models

# Python-Swagger
## 概述

把Swagger文档转换成Python模型

## 使用说明
- 接口说明
    - swagger.parse(url)
        - 通过远程swagger配置文件转换文档为Python模块
        - 示例
        ```python
        from python_swagger import swagger

        url = 'https://petstore.swagger.io/v2/swagger.json'
        apiList = swagger.parse(url)

        print(apiList)
        ```
        - 输出结果
        ```javascript
        [
            {
                "api": "22517969ee5244be9574d039e829175a",
                "name": "uploadFile",
                "scheme": "https",
                "host": "petstore.swagger.io",
                "path": "/pet/{petId}/uploadImage",
                "method": "post",
                "url": "https://petstore.swagger.io/pet/{petId}/uploadImage",
                "headers": {
                    "Content-Type": "multipart/form-data"
                },
                "pathParams": {
                    "petId": 0
                },
                "query": {},
                "body": {},
                "formData": {
                    "additionalMetadata": "string",
                    "file": "a.txt"
                }
            },
            {
                "api": "9933e80dce5e47e9bed6e6c7b645a48f",
                "name": "addPet",
                "scheme": "https",
                "host": "petstore.swagger.io",
                "path": "/pet",
                "method": "post",
                "url": "https://petstore.swagger.io/pet",
                "headers": {
                    "Content-Type": "application/json;application/xml"
                },
                "pathParams": {},
                "query": {},
                "body": {
                    "id": 0,
                    "category": {
                        "id": 0,
                        "name": "string"
                    },
                    "name": "doggie",
                    "photoUrls": [],
                    "tags": [],
                    "status": "string"
                },
                "formData": {}
            },
            {
                "api": "e7853ed616a84cc2bf1608d4133ef899",
                "name": "updatePet",
                "scheme": "https",
                "host": "petstore.swagger.io",
                "path": "/pet",
                "method": "put",
                "url": "https://petstore.swagger.io/pet",
                "headers": {
                    "Content-Type": "application/json;application/xml"
                },
                "pathParams": {},
                "query": {},
                "body": {
                    "id": 0,
                    "category": {
                        "id": 0,
                        "name": "string"
                    },
                    "name": "doggie",
                    "photoUrls": [],
                    "tags": [],
                    "status": "string"
                },
                "formData": {}
            },
            {
                "api": "f42d5daa2ec949018018873345bdae46",
                "name": "findPetsByStatus",
                "scheme": "https",
                "host": "petstore.swagger.io",
                "path": "/pet/findByStatus",
                "method": "get",
                "url": "https://petstore.swagger.io/pet/findByStatus",
                "headers": {
                    "Content-Type": ""
                },
                "pathParams": {},
                "query": {
                    "status": []
                },
                "body": {},
                "formData": {}
            },
            {
                "api": "5df156c786d0409abb85b2df90c0d8a4",
                "name": "findPetsByTags",
                "scheme": "https",
                "host": "petstore.swagger.io",
                "path": "/pet/findByTags",
                "method": "get",
                "url": "https://petstore.swagger.io/pet/findByTags",
                "headers": {
                    "Content-Type": ""
                },
                "pathParams": {},
                "query": {
                    "tags": []
                },
                "body": {},
                "formData": {}
            },
            {
                "api": "21597ef2369444a8b06c6c7ff0df2260",
                "name": "getPetById",
                "scheme": "https",
                "host": "petstore.swagger.io",
                "path": "/pet/{petId}",
                "method": "get",
                "url": "https://petstore.swagger.io/pet/{petId}",
                "headers": {
                    "Content-Type": ""
                },
                "pathParams": {
                    "petId": 0
                },
                "query": {},
                "body": {},
                "formData": {}
            },
            {
                "api": "a2ec9fc4bbe74e5dbe1f2d4915c02902",
                "name": "updatePetWithForm",
                "scheme": "https",
                "host": "petstore.swagger.io",
                "path": "/pet/{petId}",
                "method": "post",
                "url": "https://petstore.swagger.io/pet/{petId}",
                "headers": {
                    "Content-Type": "application/x-www-form-urlencoded"
                },
                "pathParams": {
                    "petId": 0
                },
                "query": {},
                "body": {},
                "formData": {
                    "name": "string",
                    "status": "string"
                }
            },
            {
                "api": "492d2f1d34a34b4ab6f0bb9707a9a7f7",
                "name": "deletePet",
                "scheme": "https",
                "host": "petstore.swagger.io",
                "path": "/pet/{petId}",
                "method": "delete",
                "url": "https://petstore.swagger.io/pet/{petId}",
                "headers": {
                    "Content-Type": "",
                    "api_key": "string"
                },
                "pathParams": {
                    "petId": 0
                },
                "query": {},
                "body": {},
                "formData": {}
            },
            {
                "api": "829df28c3f72411c8562cfc659131756",
                "name": "getInventory",
                "scheme": "https",
                "host": "petstore.swagger.io",
                "path": "/store/inventory",
                "method": "get",
                "url": "https://petstore.swagger.io/store/inventory",
                "headers": {
                    "Content-Type": ""
                },
                "pathParams": {},
                "query": {},
                "body": {},
                "formData": {}
            },
            {
                "api": "70102877a15240cc9891bb76b1249f58",
                "name": "placeOrder",
                "scheme": "https",
                "host": "petstore.swagger.io",
                "path": "/store/order",
                "method": "post",
                "url": "https://petstore.swagger.io/store/order",
                "headers": {
                    "Content-Type": "application/json"
                },
                "pathParams": {},
                "query": {},
                "body": {
                    "id": 0,
                    "petId": 0,
                    "quantity": 0,
                    "shipDate": "2021-05-01 12:30:15",
                    "status": "string",
                    "complete": true
                },
                "formData": {}
            },
            {
                "api": "25453004525145ca89671236744816ed",
                "name": "getOrderById",
                "scheme": "https",
                "host": "petstore.swagger.io",
                "path": "/store/order/{orderId}",
                "method": "get",
                "url": "https://petstore.swagger.io/store/order/{orderId}",
                "headers": {
                    "Content-Type": ""
                },
                "pathParams": {
                    "orderId": 0
                },
                "query": {},
                "body": {},
                "formData": {}
            },
            {
                "api": "3cab3048fa754f77a25d7666141731b7",
                "name": "deleteOrder",
                "scheme": "https",
                "host": "petstore.swagger.io",
                "path": "/store/order/{orderId}",
                "method": "delete",
                "url": "https://petstore.swagger.io/store/order/{orderId}",
                "headers": {
                    "Content-Type": ""
                },
                "pathParams": {
                    "orderId": 0
                },
                "query": {},
                "body": {},
                "formData": {}
            },
            {
                "api": "9e348304f8fe4693b20a81e595d80dd0",
                "name": "createUsersWithListInput",
                "scheme": "https",
                "host": "petstore.swagger.io",
                "path": "/user/createWithList",
                "method": "post",
                "url": "https://petstore.swagger.io/user/createWithList",
                "headers": {
                    "Content-Type": "application/json"
                },
                "pathParams": {},
                "query": {},
                "body": {},
                "formData": {}
            },
            {
                "api": "98eb240bd27146e3af1bfb9dc0411475",
                "name": "getUserByName",
                "scheme": "https",
                "host": "petstore.swagger.io",
                "path": "/user/{username}",
                "method": "get",
                "url": "https://petstore.swagger.io/user/{username}",
                "headers": {
                    "Content-Type": ""
                },
                "pathParams": {
                    "username": "string"
                },
                "query": {},
                "body": {},
                "formData": {}
            },
            {
                "api": "7f9dce54d70249b6a8efbd8feb0056b0",
                "name": "updateUser",
                "scheme": "https",
                "host": "petstore.swagger.io",
                "path": "/user/{username}",
                "method": "put",
                "url": "https://petstore.swagger.io/user/{username}",
                "headers": {
                    "Content-Type": "application/json"
                },
                "pathParams": {
                    "username": "string"
                },
                "query": {},
                "body": {
                    "id": 0,
                    "username": "string",
                    "firstName": "string",
                    "lastName": "string",
                    "email": "string",
                    "password": "string",
                    "phone": "string",
                    "userStatus": 0
                },
                "formData": {}
            },
            {
                "api": "2dd731eddd464286913b1ac0bbdf6da0",
                "name": "deleteUser",
                "scheme": "https",
                "host": "petstore.swagger.io",
                "path": "/user/{username}",
                "method": "delete",
                "url": "https://petstore.swagger.io/user/{username}",
                "headers": {
                    "Content-Type": ""
                },
                "pathParams": {
                    "username": "string"
                },
                "query": {},
                "body": {},
                "formData": {}
            },
            {
                "api": "373e78e2471b42658159321f40a6557a",
                "name": "loginUser",
                "scheme": "https",
                "host": "petstore.swagger.io",
                "path": "/user/login",
                "method": "get",
                "url": "https://petstore.swagger.io/user/login",
                "headers": {
                    "Content-Type": ""
                },
                "pathParams": {},
                "query": {
                    "username": "string",
                    "password": "string"
                },
                "body": {},
                "formData": {}
            },
            {
                "api": "727fb1f3cd884d839496c8b0f6adcde6",
                "name": "logoutUser",
                "scheme": "https",
                "host": "petstore.swagger.io",
                "path": "/user/logout",
                "method": "get",
                "url": "https://petstore.swagger.io/user/logout",
                "headers": {
                    "Content-Type": ""
                },
                "pathParams": {},
                "query": {},
                "body": {},
                "formData": {}
            },
            {
                "api": "7cb53f162ad74f4faa4d5b0f671e8305",
                "name": "createUsersWithArrayInput",
                "scheme": "https",
                "host": "petstore.swagger.io",
                "path": "/user/createWithArray",
                "method": "post",
                "url": "https://petstore.swagger.io/user/createWithArray",
                "headers": {
                    "Content-Type": "application/json"
                },
                "pathParams": {},
                "query": {},
                "body": {},
                "formData": {}
            },
            {
                "api": "e01e2696c7ea436e980524b95f2c339f",
                "name": "createUser",
                "scheme": "https",
                "host": "petstore.swagger.io",
                "path": "/user",
                "method": "post",
                "url": "https://petstore.swagger.io/user",
                "headers": {
                    "Content-Type": "application/json"
                },
                "pathParams": {},
                "query": {},
                "body": {
                    "id": 0,
                    "username": "string",
                    "firstName": "string",
                    "lastName": "string",
                    "email": "string",
                    "password": "string",
                    "phone": "string",
                    "userStatus": 0
                },
                "formData": {}
            }
        ]
        ```
   - APIEncoder
       - JSON解码器，导出转换结果时非常有用
       - 示例
       ```python
        import json
        
        from python_swagger import APIEncoder,swagger

        url = 'https://petstore.swagger.io/v2/swagger.json'

        apiList = swagger.parse(url)

        with open('test.json',mode='w',encoding='utf8') as f:
            f.write(json.dumps(apiList,ensure_ascii=False,cls=APIEncoder))
       ```
       - test.json输出结果
       ```
       和swagger.parse(url)示例一致
       ```