jmcarp / jmcarp/flask-apispec

Documenting path parameters

Open
#137 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
652
Forks
151
PR merge metrics
No merged PRs in 30d

Description

How can I document path parameters? I expected the following to work:

````python
from apispec import APISpec
from apispec.ext.marshmallow import MarshmallowPlugin
from flask import Flask, Blueprint
from flask_apispec import FlaskApiSpec, MethodResource, doc

app = Flask(__name__)
api_blueprint = Blueprint('api', __name__, url_prefix='/api/')

app.config.update({
'APISPEC_SPEC': APISpec(
'Pets pets pets',
'0.0.1',
'2.0',
[MarshmallowPlugin()]
)
})

class PetResource(MethodResource):
@doc(
parameters=[
{
'name': 'pet_id',
'in': 'path',
'description': 'The ID of the pet',
'required': True,
'type': 'string',
'example': '0c3ca635-2d58-4548-ad59-027fe4983e2c'
}
]
)
def get(self, **kwargs):
return None

pet_view = PetResource.as_view(PetResource.__name__)
api_blueprint.add_url_rule('/pet/', view_func=pet_view)

app.register_blueprint(api_blueprint)

docs = FlaskApiSpec(app)
docs.register(PetResource, endpoint=PetResource.__name__, blueprint=api_blueprint.name)

app.run(debug=True)
````

but this produces the following swagger:
````json
{
"definitions": {},
"info": {
"title": "Pets pets pets",
"version": "0.0.1"
},
"parameters": {},
"paths": {
"/api/pet/{pet_id}": {
"get": {
"parameters": [
{
"in": "path",
"name": "pet_id",
"required": true,
"type": "string"
}
],
"responses": {}
}
}
},
"responses": {},
"securityDefinitions": {},
"swagger": "2.0",
"tags": []
}
````
As seen I would like to be able to provide a description and an example value.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at the @doc parameters passed to PetResource.get and the FlaskApiSpec registration that produces /api/pet/{pet_id}; compare the generated Swagger parameter object with the supplied description and example. Done means the generated path parameter retains both fields.

Written by the indexing model from the issue text.

Assessment

Tech stack
flask, python
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.