Package: apispec-chalice
Chaliceplugin for theapispec(fka Swagger) generation library.InstallationFrom PyPi:$ pip install apispec-chaliceExample RESTful ApplicationfromapispecimportAPISpecfromchaliceimportChalicefrommarshmallowimportSchema,fieldsimportapispec_chalice# Create an APISpecspec=APISpec(title='Swagger Petstore',version='1.0.0',plugins=['apispec_chalice','apispec.ext.marshmallow',],)# Optional marshmallow supportclassCategorySchema(Schema):id=fields.Int()name=fields.Str(required=True)classPetSchema(Schema):category=fields.Nested(CategorySchema,many=True)name=fields.Str()classErrorSchema(Schema):status_code=fields.Int(required=True)message=fields.Str()app=Chalice(__name__)@app.route('/pets',methods=['GET','POST'])defpets(gist_id):'''
    ---
    get:
        responses:
            200:
                schema:
                    type: array
                    items: PetSchema
            404:
                schema: ErrorSchema
    post:
        responses:
            201:
                headers:
                    Location:
                        description: 'URI of new pet'
                        type: string
            400:
                schema: ErrorSchema
    '''pass@app.route('/pets/{pet_name}',methods=['GET','PUT','DELETE'])defpet(gist_id):'''
    ---
    get:
        responses:
            200:
                schema: PetSchema
            404:
                schema: ErrorSchema
    delete:
        responses:
            204:
                description: 'deleted pet'
            404:
                schema: ErrorSchema
    put:
        responses:
            204:
                description: 'deleted pet'
            400:
                schema: ErrorSchema
    '''pass# Register entities and pathsspec.definition('Category',schema=CategorySchema)spec.definition('Pet',schema=PetSchema)spec.definition('Error',schema=ErrorSchema)spec.add_path(app=app,view=pets)spec.add_path(app=app,view=pet)Generated OpenAPI Specspec.to_dict()#{#   'info':{#      'title':'Swagger Petstore',#      'version':'1.0.0'#   },#   'paths':{#      '/pets':{#         'get':{#            'responses':{#               '200':{#                  'schema':{#                     'type':'array',#                     'items':{#                        '$ref':'#/definitions/Pet'#                     }#                  }#               },#               '404':{#                  'schema':{#                     '$ref':'#/definitions/Error'#                  }#               }#            }#         },#         'post':{#            'responses':{#               '201':{#                  'headers':{#                     'Location':{#                        'description':'URI of new pet',#                        'type':'string'#                     }#                  }#               },#               '400':{#                  'schema':{#                     '$ref':'#/definitions/Error'#                  }#               }#            }#         }#      },#      '/pets/{pet_name}':{#         'get':{#            'responses':{#               '200':{#                  'schema':{#                     '$ref':'#/definitions/Pet'#                  }#               },#               '404':{#                  'schema':{#                     '$ref':'#/definitions/Error'#                  }#               }#            }#         },#         'delete':{#            'responses':{#               '204':{#                  'description':'deleted pet'#               },#               '404':{#                  'schema':{#                     '$ref':'#/definitions/Error'#                  }#               }#            }#         },#         'put':{#            'responses':{#               '204':{#                  'description':'deleted pet'#               },#               '400':{#                  'schema':{#                     '$ref':'#/definitions/Error'#                  }#               }#            }#         }#      }#   },#   'tags':[##   ],#   'swagger':'2.0',#   'definitions':{#      'Category':{#         'type':'object',#         'properties':{#            'name':{#               'type':'string'#            },#            'id':{#               'type':'integer',#               'format':'int32'#            }#         },#         'required':[#            'name'#         ]#      },#      'Pet':{#         'type':'object',#         'properties':{#            'name':{#               'type':'string'#            },#            'category':{#               'type':'array',#               'items':{#                  '$ref':'#/definitions/Category'#               }#            }#         }#      },#      'Error':{#         'type':'object',#         'properties':{#            'message':{#               'type':'string'#            },#            'status_code':{#               'type':'integer',#               'format':'int32'#            }#         },#         'required':[#            'status_code'#         ]#      }#   },#   'parameters':{##   }#}LicenseMIT licensed. See the bundledLICENSEfile for more details.