sanic-org / sanic-openapi

Easily document your Sanic API with a UI
https://sanic-openapi.readthedocs.io/
MIT License
505 stars 108 forks source link

Swagger specification OAS2.0 dont allow same "operationId" specified … #251

Closed dacasals closed 2 years ago

dacasals commented 2 years ago

…in the route paths specifications.

When you use Sanic HTTPMethodView and define multiple methods in the views, multiple operationId with same string are created. This commit include extra method string to generate different operationId's.


    class ViewConfigStaticRetrieversUsage(HTTPMethodView):
    @doc.produces(
        StaticRetrieversModel,
        description="Static retriever usage status",
        content_type="application/json",
    )
    async def get(self, request):
        ...

    @doc.consumes(StaticRetrieverStatusModel, location="body")
    @doc.produces(
        StaticRetrieversModel,
        description="Static retriever usage status updated",
        content_type="application/json",
    )
    async def put(self, request):
        ...

The swagger result is:

/config/static_providers": {
        "put": {
          "operationId": "Config.ViewConfigStaticRetrieversUsage",
          "consumes": [
            "application/json"
          ],
          ...
        },
        "get": {
          "operationId": "Config.ViewConfigStaticRetrieversUsage",
          "consumes": [
            "application/json"
          ],
          ...
      },`
ahopkins commented 2 years ago

Thanks for the PR! DO you still need OAS2? You cannot upgrade to OAS3?

dacasals commented 2 years ago

Thanks for the PR! DO you still need OAS2? You cannot upgrade to OAS3?

Thanks to you!, looks like i am a little outdated, i tried a fast migration few moth ago, when OAS3 was in beta and it did not go well. But it is because I have a hack function that generates the sanic_openapi models from Pydantic models that I need to refactor.

ahopkins commented 2 years ago

You should look into Sanic Extensions. It should allow you to use pydantic models. IIRC there may still be a bug on the validation, but I want to get that fixed soon. And, if you're only using to build docs right now it should work.

ahopkins commented 2 years ago

I'll get this released soon

dacasals commented 2 years ago

You should look into Sanic Extensions. It should allow you to use pydantic models. IIRC there may still be a bug on the validation, but I want to get that fixed soon. And, if you're only using to build docs right now it should work.

Thanks, i will try with Sanic Extensions, I am interested in the doc but also in the generated swagger specification because I want to generate the SDK using the swagger.json with the openapi-generator. That's way i am trying to solve some issues with the OAS2.