apispec icon indicating copy to clipboard operation
apispec copied to clipboard

Docs via Python code

Open dandreevv opened this issue 4 years ago • 8 comments

The aiohttp-apispec tool uses a wrapper to create the presentation documentation.

@docs(
    summary="Test method summary",
    description="Test method description",
    responses={
        200: {
            "schema": ResponseSchema,
            "description": "Success response",
        },
    },
)
async def index(request):
    return web.json_response({"msg": "done", "data": {}})

Is there any reason why you didn't do the same? Seems to me it's simpler and gives less errors.

dandreevv avatar Oct 13 '21 10:10 dandreevv

This is similar to FastAPI's approach as well. As FastAPI integrates it deeper into the framework, it's not a standalone decorator, instead it is part of the router definition for a route:

https://fastapi.tiangolo.com/advanced/additional-responses/?h=openapi#additional-response-with-model

kkirsche avatar Jan 31 '23 14:01 kkirsche

apispec does not do that but layers above can do it.

FastAPI is a layer above, at the same level than flask-smorest (which I maintain). flask-smorest does its best at writing doc automatically from in/out schemas, docstrings,...

lafrech avatar Jan 31 '23 14:01 lafrech

@lafrech Is that saying that APISpec is unwilling to do it?

Yes, FastAPI is a layer above, but the original request is 1:1 in line with the act of documenting the responses that APISpec is already asking of users in the docstrings. As I understand it, this is asking for helpers which reduce error rates around this process, not an integration.

This adds value by being able to leverage items such as ParamSpec and other type hints to verify and/or validate that the documented responses are accurate

kkirsche avatar Jan 31 '23 15:01 kkirsche

Hi, author of openapify here 👋 I couldn't put up with manually keeping the documentation up-to-date with the code, so I created a framework agnostic library with built-in JSON Schema generation. It’s now based on decorators but I have plans to develop metadata extractors to integrate more closely with web-frameworks.

Fatal1ty avatar Apr 11 '23 17:04 Fatal1ty

I wouldn't be opposed to the @doc decorator proposed in OP. Would someone be willing to give it a stab?

You may want to have a look at flask-smorest. It has a feature that parses the docstring for summary and description.

And the other elements are inferred from the marshmallow schemas passed to load arguments and dump the response.

https://flask-smorest.readthedocs.io/en/latest/quickstart.html

lafrech avatar Apr 12 '23 07:04 lafrech