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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to have multiple endpoints in swagger only? #1157

Open
talhaazeemmughal opened this issue Jan 25, 2024 · 4 comments
Open

Is it possible to have multiple endpoints in swagger only? #1157

talhaazeemmughal opened this issue Jan 25, 2024 · 4 comments

Comments

@talhaazeemmughal
Copy link

talhaazeemmughal commented Jan 25, 2024

Describe the Issue
It's not a bug but a question: (I apologise I was unable to find any other way to discuss this 馃槄 )
I have a get endpoint, let's say: /user/
but I call this with different query params based on different scenarios but there is a single function-based view where they land and the logic is defined there to handle them accordingly. Is it possible to have different endpoints in swagger using @extend_schema? I tried defining two of them with methods get but it merged both of them into one.

@tfranzel
Copy link
Owner

Hi, you have a legitimate ask here. However, I don't think this is possible with OpenAPI. It just does not have the dynamic capabilities you need for this kind of thing.

You can do it on a request / response level with PolymorphicProxySerializer, but not on the operation level with different params for different cases.

@talhaazeemmughal
Copy link
Author

@tfranzel Thank you for your quick reply. I have one more question if you can answer that as well.
I have a delete API where I have one query param that is ID and one variable xyz in the request body. can i add them both in the delete API. if yes then how?

@talhaazeemmughal
Copy link
Author

talhaazeemmughal commented Jan 25, 2024

@extend_schema(
        methods=['DELETE'],
        summary='Deletes a Record',
        description='deletes a record using the id',
        request=RecordDeleteSerializer,
        responses={204: None, 400: {'error': 'error'}, 404: {'error': 'error'}})

Serializer:

class RecordDeleteSerializer(serializers.Serializer):
    xyz = serializers.CharField()

I tried this but it didn't show the request there

@tfranzel
Copy link
Owner

HTTP standard strongly discourages bodies on DELETE requests. You could say it is undefined behavior. They are furthermore invalid in OpenAPI 3.0.x. That constraint was loosened with 3.1, but we have not implemented it yet.

We have a couple of issues on that topic, that you can find through the search.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants