Skip to content

Swagger UI endpoint expand/collapse issue #5032

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
nayanishdamania opened this issue Nov 16, 2018 · 20 comments
Closed

Swagger UI endpoint expand/collapse issue #5032

nayanishdamania opened this issue Nov 16, 2018 · 20 comments

Comments

@nayanishdamania
Copy link

Q&A (please complete the following information)

  • OS: Windows
  • Browser: Chrome
  • Version: 70.0.3538.102
  • Method of installation: NuGet Package
  • Swagger-UI version: 3.19.5
  • Swagger/OpenAPI version: Swagger 2.0

Content & configuration

Swagger-UI configuration options:

app.UseSwaggerUI(c =>
 {
     c.SwaggerEndpoint("/swagger/v1/swagger.json", "Fifo API");
 });
?yourQueryStringConfig

Describe the bug you're encountering

I am using Swagger UI in AspDotNetCore WebApi Application

When Trying expand the API endpoint drop down from UI, It will be expand all the endpoint with same name & different parameter instead of expanding that specific one.

To reproduce...

Steps to reproduce the behavior:

  1. Go to http:/localhost/swagger/
  2. Click on API Endpoint drop down (Make sure you have two endpoint with same name and different parameter)
  3. Now if you look it will expand all endpoint drop down with same & different parameters
  4. Same issue with collapse also.

Expected behavior

It should be expand only one API endpoint drop down which is got clicked

Screenshots

1. When page got loaded.
image

2. I have clicked on 3rd endpoint but all are expanded with same and different parameters
image

Additional context or thoughts

@shockey
Copy link
Contributor

shockey commented Nov 16, 2018

@nayanishdamania, can you provide your Swagger/OpenAPI document (at /swagger/v1/swagger.json)?

It'll be difficult to solve this without having a look at it - if it's non-public, feel free to email it to me at [email protected].

@hkosova
Copy link
Contributor

hkosova commented Nov 16, 2018

It looks like several operations have the same operationId. Duplicate operationIds are not allowed by the OpenAPI Specification.

@nayanishdamania check the relevant annotations in your source code to make sure the operation IDs are unique, or open a ticket with the library you use to generate the spec.

@shockey
Copy link
Contributor

shockey commented Nov 26, 2018

Closing due to inactivity.

This is simply to keep our issue tracker clean - feel free to comment if there are any further thoughts or concerns, and we'll be happy to reopen this issue.

@shockey shockey closed this as completed Nov 26, 2018
@intenzive
Copy link

intenzive commented Apr 12, 2019

I am still having the same issue with Swagger UI (Swashbuckle.AspNetCore 4.0.1).

Here is the OpenAPI document ( some code omitted which is not relevant to the issue )

OpenAPI doc

So clicking either on path "/api/Attributes" or "/api/Attributes/{id}" will expand both of them. The annotations are respectively [HttpGet] and [HttpGet("{id}")]

@hkosova
Copy link
Contributor

hkosova commented Apr 17, 2019

@intenzive your OpenAPI doc is not valid - if you paste it into https://editor.swagger.io it will tell you where the errors are.

@intenzive
Copy link

@hkosova as I said I have omitted some from the json. Just didn't want to show it public. If you send me an email I can send you the original OpenAPI doc.

@mariuszkerl
Copy link

Have the same issue, @intenzive did you solve it?

@intenzive
Copy link

@mariuszkerl, unfortunately no. The problem comes from methods having same names with same http verbs but with different input parameters. Still looking for solution.

@intenzive
Copy link

For everyone still having problems here like me and @mariuszkerl, changing the route name of one of the methods with same name will solve the issue.

@mdzeko
Copy link

mdzeko commented May 29, 2019

It appears that having different route name for two controllers with same HTTP methods also leads to this behavior. @intenzive or @mariuszkerl - confirm?

@intenzive
Copy link

@mdzeko, just tested and I am not able to simulate the described behavior so I am not confirming.
Changing the route name is still a workaround for the main thread.

@mdzeko
Copy link

mdzeko commented Jun 24, 2019

@intenzive found out that even if you have different route names but the same method name (c# in my case) then it leads to this behavior. Making sure method names differ across the app as well as route names fixes it for me.
I suppose that you knew this and one can derive that from all the comments, but I just wanted to state it as clear as possible (for other readers).

@shockey
Copy link
Contributor

shockey commented Jun 24, 2019

@mdzeko indeed. Many OpenAPI document generators (like Swashbuckle) use method names to create operationId values, which OpenAPI requires uniqueness for.

Swagger UI, in turn, uses operationIds internally to track which operations are open and closed (operating on the assumption that they are, indeed unique). If you have two or more operations with the same operationId, you'll see them expand and collapse together, as described.

@vsix27
Copy link

vsix27 commented Oct 22, 2019

i found that this is happening when you have duplicate method names (say Get() and Get(string s)) - they should be unique... if you replace to Get2(string s) - it should not happen

@Andromed75
Copy link

Andromed75 commented Feb 12, 2021

Okay i dont know if some of you guys still have this problem, but i had kind of the same problem i a manage to fixed it.
An error was made on my project, tags were added in the swagger config file

@Bean
public Docket api() {
	return new Docket(DocumentationType.SWAGGER_2)
			.select()
			.apis(RequestHandlerSelectors.basePackage("com.xxx.yyy"))
			.paths(PathSelectors.any())
			.build()
			.tags(new Tag(XX_CONTROLLER, "Public operations"))
			.tags(new Tag(YY_CONTROLLER, "Admin operations"))
			.tags(new Tag(ZZ_CONTROLLER, "Endpoint for operation ... etc"))
			.securityContexts(Lists.newArrayList(securityContext))
			.securitySchemes(Lists.newArrayList(apiKey));
}

But in the controller class we forgot to add the tag as below

@Api(value = Controller.BASE_RESOURCE_PATH, tags = { SwaggerConfig.XX_CONTROLLER })

Endpoints were still accessible but we couldn't toggle the menu.

Hope it will help some of you.

@AzikDeveloper
Copy link

same here. solved it?

@rcadirvele
Copy link

Try use different operation id for each method, similar to below.

image

@kunaldo07
Copy link

I want to set only one API drop down to be expanded at a time. Anyone knows how to do it?

@abhinav011085
Copy link

You can user the @ApiOperation annotation from swagger in each of your versioned APIs for solving this issue like given below.

@ApiOperation({operationId: 'any-other-title-than-v1'})

@rohit-gulati-fourkites
Copy link

I want to set only one API drop down to be expanded at a time. Anyone knows how to do it?

@kunaldo07 Were you able to do this?

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

No branches or pull requests