apispec-chalice
Chalice plugin for the apispec (fka Swagger) generation library.
Installation
From PyPi:
$ pip install apispec-chalice
Example RESTful Application
from apispec import APISpec
from chalice import Chalice
from marshmallow import Schema, fields
import apispec_chalice
# Create an APISpec
spec = APISpec(
title='Swagger Petstore',
version='1.0.0',
plugins=[
'apispec_chalice',
'apispec.ext.marshmallow',
],
)
# Optional marshmallow support
class CategorySchema(Schema):
id = fields.Int()
name = fields.Str(required=True)
class PetSchema(Schema):
category = fields.Nested(CategorySchema, many=True)
name = fields.Str()
class ErrorSchema(Schema):
status_code = fields.Int(required=True)
message = fields.Str()
app = Chalice(__name__)
@app.route('/pets', methods=['GET', 'POST'])
def pets(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'])
def pet(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 paths
spec.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 Spec
spec.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':{
#
# }
#}
License
MIT licensed. See the bundled LICENSE file for more details.
Metadata
Release files for apispec-chalice 0.2.2
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 | |
|---|---|---|---|---|
| apispec-chalice-0.2.2.tar.gz | 3.8 kB | Without provenance | Details |
Release files / apispec-chalice-0.2.2.tar.gz
| Download URL | apispec-chalice-0.2.2.tar.gz |
|---|---|
| Size | 3.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
68984d90cfeacec85cb64c1beae6a48175c67603d9b4ffae148013f1bba802cb
|
|
BLAKE2b-256 checksum How to use checksums |
b83a02950de570c74145e824aa574944350a0b8eb277d46f43d2d4511094943b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for apispec-chalice 0.2.2
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.