Skip to content

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
Collaborator

@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

3 participants