This is available from the FAQ page in the spring-doc documentation. See What is a proper way to set up Swagger UI to use provided spec.yml? and How can use custom json/yml file instead of generated one ? of the same page.
Example from the FAQ page
- Turn off auto-generation in the project property file
springdoc.api-docs.enabled=false - Put your yaml file in
src/main/resources/staticsuch assrc/main/resources/static/myApiFile.yaml - Set the swagger-ui url for the file
springdoc.swagger-ui.url=/myApiFile.yaml - Enable the minimal beans configuration
import org.springdoc.core.SpringDocConfigProperties;
import org.springdoc.core.SpringDocConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class SpringDocsConfiguration {
@Bean
SpringDocConfiguration springDocConfiguration() {
return new SpringDocConfiguration();
}
@Bean
public SpringDocConfigProperties springDocConfigProperties() {
return new SpringDocConfigProperties();
}
}
Answer from antonkronaj on Stack OverflowVideos
This is available from the FAQ page in the spring-doc documentation. See What is a proper way to set up Swagger UI to use provided spec.yml? and How can use custom json/yml file instead of generated one ? of the same page.
Example from the FAQ page
- Turn off auto-generation in the project property file
springdoc.api-docs.enabled=false - Put your yaml file in
src/main/resources/staticsuch assrc/main/resources/static/myApiFile.yaml - Set the swagger-ui url for the file
springdoc.swagger-ui.url=/myApiFile.yaml - Enable the minimal beans configuration
import org.springdoc.core.SpringDocConfigProperties;
import org.springdoc.core.SpringDocConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class SpringDocsConfiguration {
@Bean
SpringDocConfiguration springDocConfiguration() {
return new SpringDocConfiguration();
}
@Bean
public SpringDocConfigProperties springDocConfigProperties() {
return new SpringDocConfigProperties();
}
}
This answer is excellent and lead me to the right direction. I applied all steps but the code section had a difference with the link provided. In the link provided the code suggested contains also an ObjectMapperProvider which is absent in that answer.
Also once the changes are applied the endpoint to verify the modification that worked for me was http://localhost:8080/swagger-ui/index.html
Hope this helps clarify, but all the information is already there. Thanks.
import org.springdoc.core.SpringDocConfigProperties;
import org.springdoc.core.SpringDocConfiguration;
import org.springdoc.core.providers.ObjectMapperProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* Provides the capabilities to display the apiDoc in a preconfigured endpoint based on the following information of open-api
* https://springdoc.org/faq.html#_what_is_a_proper_way_to_set_up_swagger_ui_to_use_provided_spec_yml
* This apiDoc can be consulted through the endpoint: http://localhost:8080/swagger-ui/index.html
*/
@Configuration
public class SpringDocsConfiguration {
@Bean
SpringDocConfiguration springDocConfiguration() {
return new SpringDocConfiguration();
}
@Bean
public SpringDocConfigProperties springDocConfigProperties() {
return new SpringDocConfigProperties();
}
@Bean
ObjectMapperProvider objectMapperProvider(SpringDocConfigProperties springDocConfigProperties){
return new ObjectMapperProvider(springDocConfigProperties);
}
}