Git Product home page Git Product logo

flask-openapi's Introduction

Flask-OpenAPI

https://coveralls.io/repos/github/remcohaszing/flask-openapi/badge.svg?branch=master https://readthedocs.org/projects/flask-openapi/badge/?version=latest

This project can generate a swagger.json from a Flask API.

Installation

$ pip install flask-openapi

flask-openapi's People

Contributors

remcohaszing avatar

Stargazers

Stepan Zastupov avatar Eric Plaster avatar Mathijs avatar

Watchers

Eric Plaster avatar  avatar James Cloos avatar  avatar

flask-openapi's Issues

Implement parameters for request handlers (operations)

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
  • header
  • path
  • formData
  • body

Query parameters should be supported. From within a handler it should be possible to use processed parameters.

  • collectionFormat — For query and formData.
  • standard schema options

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')

Support full Schema object

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.
byte / binary

Keep as-is or decode? Keep as str or convert to bytes? Or BytesIO?

date / datetime

Convert to a timezone aware object or convert to UTC?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.