Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using openapi.yaml in springdoc

I can customize OpenAPI from code.
Can I do same over openapi.yaml like swagger-petstore
I create simple springboot project with one @RestController.
I create openapi.yaml and copy it to /src/main/resources/.
But I see default values on open swagger-ui page.

like image 417
Yura Shinkarev Avatar asked Mar 21 '26 01:03

Yura Shinkarev


1 Answers

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

  1. Turn off auto-generation in the project property file springdoc.api-docs.enabled=false
  2. Put your yaml file in src/main/resources/static such as src/main/resources/static/myApiFile.yaml
  3. Set the swagger-ui url for the file springdoc.swagger-ui.url=/myApiFile.yaml
  4. 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();
  }
}
like image 96
antonkronaj Avatar answered Mar 24 '26 01:03

antonkronaj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!