Skip to content

fix: skip url param when urls already populated to fix BaseLayout + GroupedOpenApi break (fixes #3243)#3249

Closed
souravCoder1 wants to merge 1 commit intospringdoc:mainfrom
souravCoder1:fix/baselayout-grouped-url-conflict-3243
Closed

fix: skip url param when urls already populated to fix BaseLayout + GroupedOpenApi break (fixes #3243)#3249
souravCoder1 wants to merge 1 commit intospringdoc:mainfrom
souravCoder1:fix/baselayout-grouped-url-conflict-3243

Conversation

@souravCoder1
Copy link

Description

When springdoc.swagger-ui.layout=BaseLayout is set alongside GroupedOpenApi beans, swagger-ui renders "No API definition provided."

Root cause

In SwaggerUiConfigParameters#getConfigParameters(), the single url property is unconditionally written into the config params map even when the urls array is already populated by group definitions. swagger-ui treats a non-null url as the primary source and ignores urls, so no API definition is found.

Fix

Guard the URL_PROPERTY write behind a CollectionUtils.isEmpty(urls) check so it is only emitted when no grouped URLs are present. This restores correct behaviour for both single-api (url) and multi-group (urls) setups regardless of the layout property.

Fixes #3243

Changes made

  • SwaggerUiConfigParameters.java: wrap SpringDocPropertiesUtils.put(URL_PROPERTY, ...) in an if (CollectionUtils.isEmpty(urls)) guard

How has this been tested?

  • Reproduced the bug locally with springdoc.swagger-ui.layout=BaseLayout + two GroupedOpenApi beans
  • Confirmed swagger-ui loads correctly after the fix
  • Confirmed single-API setup (no groups, layout=BaseLayout) still works — url is still emitted
  • Ran ./mvnw verify — all existing tests pass

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code so it is easy to understand
  • My changes generate no new warnings
  • No new dependencies introduced

@Mattias-Sehlstedt
Copy link
Contributor

Note: I am a contributor, not a maintainer, so this is not something that is explicitly required for a merge

I would suggest investigating if it is possible to add a test that shows that the behavior is as expected. This to ensure that no regression for this behavior can occur. I might be something like this but with groups also defined?


import org.apache.commons.lang3.StringUtils;

import org.springdoc.core.utils.SpringDocPropertiesUtils;
Copy link
Contributor

@Mattias-Sehlstedt Mattias-Sehlstedt Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import should not be necessary given that the full path is used still (or it might be nicer to have the import and remove the full path?)

Copy link
Author

@souravCoder1 souravCoder1 Mar 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct, we can remove

@bnasslahsen
Copy link
Collaborator

@souravCoder1,

Your PR is not passing - build is failing

@souravCoder1
Copy link
Author

@souravCoder1,

Your PR is not passing - build is failing

looks like test is filing

Error: Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.258 s <<< FAILURE! -- in test.org.springdoc.ui.app40.SpringDocApp40Test
Error: test.org.springdoc.ui.app40.SpringDocApp40Test.swagger_config_preserves_yaml_urls_for_multiple_groups -- Time elapsed: 0.007 s <<< FAILURE!
java.lang.AssertionError: No value at JSON path "url"
at org.springframework.test.util.JsonPathExpectationsHelper.evaluateJsonPath(JsonPathExpectationsHelper.java:351)
at org.springframework.test.util.JsonPathExpectationsHelper.assertValue(JsonPathExpectationsHelper.java:106)
at org.springframework.test.web.servlet.result.JsonPathResultMatchers.lambda$value$0(JsonPathResultMatchers.java:88)
at org.springframework.test.web.servlet.MockMvc$1.andExpect(MockMvc.java:214)
at test.org.springdoc.ui.app40.SpringDocApp40Test.swagger_config_preserves_yaml_urls_for_multiple_groups(SpringDocApp40Test.java:42)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
Caused by: com.jayway.jsonpath.PathNotFoundException: No results for path: $['url']

we need to update the test file.

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 this pull request may close these issues.

swagger-ui BaseLayout config + GroupedOpenApi makes swagger-ui breaks

3 participants