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

Add support for swagger-ui-property 'urls.primaryName'. #574

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ public class SwaggerUiConfigProperties {

private Direction groupsOrder = Direction.ASC;

private String urlsPrimaryName;

public void addGroup(String group) {
SwaggerUrl swaggerUrl = new SwaggerUrl(group);
urls.add(swaggerUrl);
Expand Down Expand Up @@ -204,6 +206,7 @@ public Map<String, Object> getConfigParameters() {
SpringDocPropertiesUtils.put("oauth2RedirectUrl", oauth2RedirectUrl, params);
SpringDocPropertiesUtils.put("url", url, params);
put("urls", urls, params);
SpringDocPropertiesUtils.put("urls.primaryName", urlsPrimaryName, params);
return params;
}

Expand Down Expand Up @@ -407,6 +410,14 @@ public boolean isAscending() {
}
}

public String getUrlsPrimaryName() {
return urlsPrimaryName;
}

public void setUrlsPrimaryName(String urlsPrimaryName) {
this.urlsPrimaryName = urlsPrimaryName;
}

static class SwaggerUrl {
private String url;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@TestPropertySource(properties = "springdoc.swagger-ui.groups-order=DESC")
@TestPropertySource(properties = {"springdoc.swagger-ui.groups-order=DESC", "springdoc.swagger-ui.urlsPrimaryName=pets"})
public class SpringDocApp4Test extends AbstractSpringDocTest {

@Test
Expand All @@ -40,6 +40,7 @@ public void swagger_config_for_multiple_groups() throws Exception {
.andExpect(jsonPath("urls[0].url", equalTo("/v3/api-docs/stores")))
.andExpect(jsonPath("urls[0].name", equalTo("stores")))
.andExpect(jsonPath("urls[1].url", equalTo("/v3/api-docs/pets")))
.andExpect(jsonPath("urls[1].name", equalTo("pets")));
.andExpect(jsonPath("urls[1].name", equalTo("pets")))
.andExpect(jsonPath("$['urls.primaryName']", equalTo("pets")));
}
}