This project can generate a swagger.json
from a Flask API.
$ pip install flask-openapi
Generate a `swagger.json` handler from a Flask app
License: MIT License
http://swagger.io/specification/#parameterObject
Currently the only support type of input parameters is body
. It should be possible to consume all types of documented parameters.
Query parameters should be supported. From within a handler it should be possible to use processed parameters.
Since the parameters are mostly implemented by a JSON schema, their definition can be expressed using one. This can be either a JSON schema or **kwargs
passed as a JSON schema.
Thoughts explained by a usage example:
app = Flask(__name__)
oauth = OAuth(app)
@app.route('/')
@oauth.query_param('type', 'BeverageType')
@oauth.query_param('names', collection_format=CollectionFormat.pipes, type='string')
def handler():
assert isinstance(oauth.parameters.type, str)
assert isinstance(oauth.parameters.names, list)
assert isinstance(CollectionFormat, enum.Enum)
assert CollectionFormat.pipes == '|'
client = app.test_client()
client.get('/?type=beer&names=Hertog%20Jan|Palm')
http://swagger.io/specification/#schemaObject
At the moment, there is an OpenAPISchemaValidator
which extends Draft4Validator
. This validator should be extended so it supports the full schemaObject definition.
default
— Fill in the default value, and validate the default against the schema.discriminator
— I shouldn't be creating issues on a saturday morning… ☕readOnly
— Should eventually be used to validate a response, but should not be accepted in the request.xml
— Not needed for schema validation.externalDocs
— Not needed for schema validation.example
— Not needed for schema validation.Incoming primitive types / formats should be converted to Python types according to the schema.
Common Name | type | format | Python type | Comments |
---|---|---|---|---|
integer | integer | int32 | int | signed 32 bits |
long | integer | int64 | int | signed 64 bits |
float | number | float | float | |
double | number | double | decimal.Decimal | |
string | string | str | ||
byte | string | byte | base64 encoded characters | |
binary | string | binary | any sequence of octets | |
boolean | boolean | bool | ||
date | string | date | datetime.date | As defined by full-date - RFC3339 |
dateTime | string | date-time | datetime.datetime | As defined by date-time - RFC3339 |
password | string | password | str | Used to hint UIs the input needs to be obscured. |
Keep as-is or decode? Keep as str
or convert to bytes
? Or BytesIO
?
Convert to a timezone aware object or convert to UTC?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.