Tuesday, 19 November 2019

Sanic OpenAPI Swagger docs generation throws attribute paths operationId is repeated

I am using sanic to build a simple API. I have two end points defined:

from sanic import Blueprint, response
from sanic_openapi import doc

bp = Blueprint('default', url_prefix="", version=2, strict_slashes=True)


@bp.get("")
@doc.summary('Default GET endpoint for API v2')
async def route_get(request):
    resp = {"message": "New API - GET", "version": 2.0}
    return response.json(resp)


@bp.post("")
@doc.summary('Default POST endpoint for API v2')
async def route_post(request):
    resp = {"message": "New API - POST", "version": 2.0}
    return response.json(resp)

The generated swagger documents fails validation, with the following message

Error:

"attribute paths.'/v2/'(post).operationId is repeated",

I am expecting to have several routes that have multiple HTTP verbs going to the same path:

GET /v2/product
POST /v2/product 

DELETE /v2/product/{id}
PUT /v2/product/{id}

I've tested with these endpoints too, and I get two errors about operationId being repeated. One is for the /v2/product path and one is for /v2/product/{id}

How can I solve this error?



from Sanic OpenAPI Swagger docs generation throws attribute paths operationId is repeated

No comments:

Post a Comment