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.url property #2189

Merged
merged 1 commit into from Apr 16, 2023

Conversation

smou
Copy link

@smou smou commented Mar 31, 2023

As setting the url via application.properties is not supported with the current release (2.0.4) i had to implement a Workaround until this PR get merged and release.

With this change it will be possible to set the api-docs url in the config without activating QueryConfig to be able to load the api-docs directly on loading the swagger ui.

HotFix/Workaroung:

springdoc: swagger-ui: disable-swagger-default-url: true

@Bean @Primary @ConditionalOnMissingBean @Lazy(false) SwaggerIndexTransformer indexPageTransformer(SwaggerUiConfigProperties swaggerUiConfig, SwaggerUiOAuthProperties swaggerUiOAuthProperties, SwaggerUiConfigParameters swaggerUiConfigParameters, SwaggerWelcomeCommon swaggerWelcomeCommon, ObjectMapperProvider objectMapperProvider) { return new FixingSwaggerIndexTransformer(swaggerUiConfig, swaggerUiOAuthProperties, swaggerUiConfigParameters, swaggerWelcomeCommon, objectMapperProvider); }

`
public class FixingSwaggerIndexTransformer extends SwaggerIndexPageTransformer {
/**
* Instantiates a new Swagger index transformer.
*
* @param swaggerUiConfig the swagger ui config
* @param swaggerUiOAuthProperties the swagger ui o auth properties
* @param swaggerUiConfigParameters the swagger ui config parameters
* @param swaggerWelcomeCommon the swagger welcome common
* @param objectMapperProvider the object mapper provider
*/
public FixingSwaggerIndexTransformer(SwaggerUiConfigProperties swaggerUiConfig, SwaggerUiOAuthProperties swaggerUiOAuthProperties,
SwaggerUiConfigParameters swaggerUiConfigParameters, SwaggerWelcomeCommon swaggerWelcomeCommon, ObjectMapperProvider objectMapperProvider) {
super(swaggerUiConfig, swaggerUiOAuthProperties, swaggerUiConfigParameters, swaggerWelcomeCommon, objectMapperProvider);
}

@Override
protected String overwriteSwaggerDefaultUrl(String html) {
    return html.replace(Constants.SWAGGER_UI_DEFAULT_URL, swaggerUiConfig.getUrl());
}

}
`

@bnasslahsen
Copy link
Contributor

@smou,

Can you add the unit test for your PR ?

@smou smou force-pushed the 2.0.4/add-setting-swagger-ui-url branch from c5e09d8 to f8aa2e4 Compare April 2, 2023 11:41
@smou
Copy link
Author

smou commented Apr 2, 2023

@bnasslahsen
sure. Added a unit test for the new method

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.

None yet

2 participants