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

Path parameter is not overrided #39

Closed
liutuo opened this issue Jan 9, 2018 · 5 comments
Closed

Path parameter is not overrided #39

liutuo opened this issue Jan 9, 2018 · 5 comments
Labels
dependencies Dependencies

Comments

@liutuo
Copy link

liutuo commented Jan 9, 2018

In the viewset, I add swagger_auto_schema decorator to destroy(self, request, pk=None) method, to override the id path parameter and add descriptions. But in the swagger UI, both of them are showing as path parameters.

@swagger_auto_schema(manual_parameters=[ openapi.Parameter('id', openapi.IN_PATH, description="Instrument Id to be removed from watchlist, if exist", type=openapi.TYPE_STRING, required=True), ])
image

@axnsan12
Copy link
Owner

axnsan12 commented Jan 9, 2018

Hello!

This is indeed strange, but it seems to be a bug in ReDoc - I opened an issue there: Redocly/redoc#400

Meanwhile, you could use swagger-ui, which does handle it correctly.

You could also add a description to the help_text of the corresponding model field instead of overriding the parameter.

@holycheater
Copy link

What seems to be happening that autogenerated path param is placed into path key and path parameters we override are placed in operation (get/post/etc), so we have two

sample yaml:

paths:
  /customer/{customer_id}:
    get:
      operationId: customer_read
      description: Get customer info and balance
      parameters:
        - name: customer_id
          in: path
          description: Customer ID
          required: true
          type: integer
      responses:
        '200':
          description: ''
          schema:
            $ref: '#/definitions/Customer'
      consumes:
        - application/json
      tags:
        - customer
    parameters:
      - name: customer_id
        in: path
        required: true
        type: string

@axnsan12
Copy link
Owner

Yes, that is correct. And the OpenAPI spec says that in this case, the operation (get/post/etc.) parameter wins and overrides the PathItem-level one. It is ReDoc that fails to honor that behavior, which should probably get fixed sometime in the future (see issue linked above).

Meanwhile, as I said, swagger-ui handles it correctly. Or, if you just need to change the description, you can change the help_text on the model field, which will be passed into the path parameter automatically.

axnsan12 added a commit that referenced this issue Jan 23, 2018
@axnsan12
Copy link
Owner

Fixed in ReDoc 1.20.0

@samirhinojosa
Copy link

Hello!!! I'm new to all this... Currently, I'm trying to eliminate the id path parameter cause I have it in the body through Schema like show you below

request_category_put = openapi.Schema(type=openapi.TYPE_OBJECT, required=['id','name'],
    properties={
        'id': openapi.Schema(type=openapi.TYPE_INTEGER, 
                title='Id', readOnly=True,
                description='Id of the category'),
        'name': openapi.Schema(type=openapi.TYPE_STRING, 
                title='Category', maxLength=200, minLength=1,
                description='Name of the category')
    },
    example={
        'id' : 1,
        'name' : 'Business',
    }
)

    @swagger_auto_schema(
        manual_parameters=[authorization],
        request_body=request_category_put,
        responses = {
            '200' : response_category,
            '400': 'Bad Request',
            '404': 'Not found'
        },        
        security=[security_endpoint],
        operation_id='Update category',
        operation_description='Update a specific category.',
    )
    def put(self, request, pk, format=None):
        category = get_object_or_404(Category, pk=pk)
        serializer = CategorySerializer(category, data=request.data)
        if serializer.is_valid():
            serializer.save(modified_by=self.request.user)
            return Response(serializer.data, status=status.HTTP_200_OK)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

But swagger-ui shows the id in parameters. When I add the field in manual_parameters, only change the attributes of this... but the field still is there

image

PaulWay pushed a commit to PaulWay/drf-yasg that referenced this issue Oct 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Dependencies
Projects
None yet
Development

No branches or pull requests

4 participants