0

I need help to overwrite swagger generator to handle API endpoints with query parameter to be documented in swashbuckle

I have found a link where in Drastic Method explained how to overwrite swagger generator

For example: I have two same route defined endpoints:

  • POST /api/customer (route template -> /api/customer)
  • POST /api/customer?f={f}&l={l} (route template -> /api/customer)

Problem with default swagger generator is that it gives conflicts with same endpoints. I tried ResolveConflictingActions method from swashbuckle but didn't help that much.

Need help with actual working code which overwrites swagger generator in swashbuckle and document endpoints with query parameters like this image

1 Answer 1

1

The error you are getting from Swashbuckle is correct, you are trying to create multiple operations for the same route, the query parameters do not make the path unique. This is a violation of the Swagger spec. From the OpenAPI Spec...

For each path, you define operations (HTTP methods) that can be used to access that path. OpenAPI 3.0 supports get, post, put, patch, delete, head, options, and trace. A single path can support multiple operations, for example, GET /users to get a list of users and POST /users to add a new user. OpenAPI defines a unique operation as a combination of a path and an HTTP method. This means that two GET or two POST methods for the same path are not allowed – even if they have different parameters (parameters have no effect on uniqueness).

You should create a single path with the query parameters being optional. You will have the same API in the end with a compliant swagger definition.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.