Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Figure out how to create API documentation #11

Open
yalgorithm777 opened this issue Oct 20, 2021 · 2 comments
Open

Figure out how to create API documentation #11

yalgorithm777 opened this issue Oct 20, 2021 · 2 comments
Labels
documentation Improvements or additions to documentation help wanted Extra attention is needed

Comments

@yalgorithm777
Copy link
Collaborator

We need to figure out how to create API documentation pages. For example, check http://flasgger.pythonanywhere.com/

@yalgorithm777 yalgorithm777 added documentation Improvements or additions to documentation help wanted Extra attention is needed labels Oct 20, 2021
@Loooffy
Copy link

Loooffy commented Oct 27, 2021

I'm recently working on a nest.js project, and am impressed by the way it use decorator to define clarified OpenApi spec within the source code.

There are packages which could help us achieve the similar 'smell' for Flask. They are flask-restful and flask-apispec. I found them on this post.

The source code of the provided example below shows the trick.

First, a pair of req/res Schema define the spec of interfaces such as data type, default value etc., and then implemented using use_kwargs, marshal_with decorators by the API handler.

This declarative pattern enable us to define the implementation and spec of an API at the same place.

# 1. Define the pair of req/res Schema of the API

class AwesomeResponseSchema(Schema):
    message = fields.Str(default='Success')

class AwesomeRequestSchema(Schema):
    api_type = fields.String(required=True, description="API type of awesome API")
# 2. Implement them with use_kwargs, marshal_with decorators right above the handler

class AwesomeAPI(MethodResource, Resource):
    @doc(description='My First GET Awesome API.', tags=['Awesome'])
    @use_kwargs(AwesomeRequestSchema, location=('json'))
    @marshal_with(AwesomeResponseSchema)  # marshalling
    def post(self, **kwargs):
        '''
        Get method represents a GET API method
        '''
        return {'message': 'My First Awesome API'}

With these simple gadgets, we can get a basic Swagger UI like this.
image

@arati-1
Copy link

arati-1 commented Oct 30, 2021

Hello,

I am arati, a technical writer interested to contribute for your REST API documentation.

I saw that you need help with your API documentation. May be I can help you with that.

I saw your readme.md and saw API calls section, is that the only Api call you need documentation for, or there is more?

Let me know if you need help and how I can get started. I can write the documentation in markdown file and share it with you for the Get the unique user token from the system API. If you feel that is what your are looking for then I can collaborate.

Regards,
Arati

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants