It would nice to be able to generate models from the Typing for Swagger/OpenAPI instead of the empty model currently used.
Could you elaborate a little more on how you see this working? Some example code/swagger docs would be helpful. Thanks!
Sure! Let's take a simple case:
class MyModel(NamedTuple):
hello: str
@app.route("/")
def index() -> MyModel:
return MyModel("world")
This could generate the following OpenAPI:
paths:
/:
get:
responses:
200:
description: "successful operation"
schema:
$ref: "#/definitions/MyModel"
definitions:
MyModel:
type: "object"
properties:
hello:
type: "string"
We should also use the same principle for the params and the body (if possible, but it would be harder since we don't have it as a param).
Maybe something easier for a first step would be to support the documentation as a docstring like what https://github.com/rochacbruno/flasgger does. We already support summary. We should also document this since I didn't see anything related to it.
Ah I see, that's pretty interesting. Thanks for the suggestion, marking as a feature request.
Is this already covered by something like https://pypi.org/project/apispec-chalice/ ?
@dragon788, no, that forces you to write a separate set of docs. To quote FastAPI's docs:
The way it works is that you write the definition of the schema using YAML format inside the docstring of each function handling a route.
But then, we have again the problem of having a micro-syntax, inside of a Python string (a big YAML).
The editor can't help much with that. And if we modify parameters or Marshmallow schemas and forget to also modify that YAML docstring, the generated schema would be obsolete.
Most helpful comment
Sure! Let's take a simple case:
This could generate the following OpenAPI:
We should also use the same principle for the params and the body (if possible, but it would be harder since we don't have it as a param).
Maybe something easier for a first step would be to support the documentation as a docstring like what https://github.com/rochacbruno/flasgger does. We already support summary. We should also document this since I didn't see anything related to it.