Skip to content

Not distinction between different parameter conditions on the same path in swagger json. #2691

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

Closed
Jelicho opened this issue Aug 29, 2024 · 1 comment

Comments

@Jelicho
Copy link

Jelicho commented Aug 29, 2024

Describe the bug

Not distinction between different parameter conditions on the same path in swagger json.

To Reproduce

Simple example project
https://github.com/Jelicho/springdoc-openapi-parameter-condition-example

As in the example below, two separate APIs are provided with different parameter conditions on the same path.
The response format is also different. However, in swagger json and ui, they are configured and exposed as one.

  • path : /api/example/{exampleNo}
  • parameter condition : application=service1, application=service2
  • Response : ExampleDataForService1Dto, ExampleDataForService2Dto
@Operation(
	operationId = "exampleForService1",
	description = "Returns Example data for service1 application."
)
@GetMapping(value = "/{exampleNo}", params = "application=service1")
public ExampleDataForService1Dto exampleForService1(
	@PathVariable String exampleNo
) {
	return ExampleDataForService1Dto.builder()
		.exampleNo(exampleNo)
		.exampleName("exampleName")
		.build();
}

@Operation(
	operationId = "exampleForService2",
	description = "Returns Example data for service2 application."
)
@GetMapping(value = "/{exampleNo}", params = "application=service2")
public ExampleDataForService2Dto exampleForService2(
	@PathVariable String exampleNo
) {
	return ExampleDataForService2Dto.builder()
		.exampleNo(exampleNo)
		.exampleAddress("exampleAddress")
		.build();
}
image
swagger json
// http://localhost:8080/v3/api-docs

{
  "openapi": "3.0.1",
  "info": {
    "title": "OpenAPI definition",
    "version": "v0"
  },
  "servers": [
    {
      "url": "http://localhost:8080",
      "description": "Generated server url"
    }
  ],
  "paths": {
    "/api/example/{exampleNo}": {
      "get": {
        "tags": [
          "Example"
        ],
        "description": "Returns Example data for service1 application.",
        "operationId": "exampleForService1_1",
        "parameters": [
          
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "*/*": {
                "schema": {
                  "$ref": "#/components/schemas/ExampleDataForService2Dto"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ExampleDataForService2Dto": {
        "type": "object",
        "properties": {
          "exampleNo": {
            "type": "string"
          },
          "exampleAddress": {
            "type": "string"
          }
        }
      }
    }
  }
}

Expected behavior

The results of my custom configuration are as follows.
I would like it to be exposed separately according to parameter conditions as shown below.

image
swagger json
// http://localhost:8080/v3/api-docs

{
  "openapi": "3.0.1",
  "info": {
    "title": "example API",
    "version": "1.0"
  },
  "servers": [
    {
      "url": "http://localhost:8080",
      "description": "Generated server url"
    }
  ],
  "paths": {
    "/api/example/{exampleNo}?application=service2": {
      "get": {
        "tags": [
          "Example"
        ],
        "description": "Returns Example data for service2 application.",
        "operationId": "exampleForService2",
        "parameters": [
          
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "*/*": {
                "schema": {
                  "$ref": "#/components/schemas/ExampleDataForService2Dto"
                }
              }
            }
          }
        }
      }
    },
    "/api/example/{exampleNo}?application=service1": {
      "get": {
        "tags": [
          "Example"
        ],
        "description": "Returns Example data for service1 application.",
        "operationId": "exampleForService1",
        "parameters": [
          
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "*/*": {
                "schema": {
                  "$ref": "#/components/schemas/ExampleDataForService1Dto"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ExampleDataForService2Dto": {
        "type": "object",
        "properties": {
          "exampleNo": {
            "type": "string"
          },
          "exampleAddress": {
            "type": "string"
          }
        }
      },
      "ExampleDataForService1Dto": {
        "type": "object",
        "properties": {
          "exampleNo": {
            "type": "string"
          },
          "exampleName": {
            "type": "string"
          }
        }
      }
    }
  }
}

Additional context

Even if it is not supported by default, it would be nice if an option was provided that allows it to be exposed separately according to parameter conditions through on/off.

@bnasslahsen
Copy link
Collaborator

@Jelicho,

Your expected behavior is invalid.
You will get one endpoint shown.

OpenAPI defines a unique operation as a combination of a path and an HTTP method:

  • This means that two GET methods for the same path are not allowed – even if they have different parameters (parameters have no effect on uniqueness)

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

Successfully merging a pull request may close this issue.

2 participants