简体   繁体   中英

how to expose an openapi.yaml specification into rest spring boot

i have already swagger-ui installed externally, i just wanted to connect that swagger-ui (open source) instance to localhost:8000/doc/api (.yaml) from openapi.yaml . any thoughts? PS : i tried to use

 @Bean
public OpenAPI customOpenAPI() {
    return new OpenAPI()
            .components(new Components().addSecuritySchemes("basicScheme",
                    new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("basic")))
            .info(new Info().title("SpringShop API").version("0.1")
                    .license(new License().name("Apache 2.0").url("http://springdoc.org")))
            .externalDocs(new ExternalDocumentation()
                    .url("restapi/doc/openapi.yaml"));
}

    @Bean
    public SpringDocConfiguration springDocConfiguration(){
        return new SpringDocConfiguration();
    }
    @Bean
    public SpringDocConfigProperties springDocConfigProperties() {
        return new SpringDocConfigProperties();
    }

but i did not find anything useful. thanks.

    application.properties:
    springdoc.api-docs.enabled=false
springdoc.swagger-ui.url=openapi.yaml
springdoc.swagger-ui.path=/doc/api/ui.html

dependecies:
<dependency>
        <groupId>org.springdoc</groupId>
        <artifactId>springdoc-openapi-ui</artifactId>
        <version>1.4.4</version>
    </dependency>

First configuration: External OPENAPI Definition :

The properties springdoc.swagger-ui.urls.*, are suitable to configure external url ( http://myhoost.com/v3/api-docs )

For example if you want to agreagte all the endpoints of other services, inside one single application. Don't forget that CORS needs to be enabled as well.

Second configuration: Internal OPENAPI Definition with static file :

If you want to use a static file that contains your openAPI definition, then simply declare: The file name can be anything you want, from the moment your declaration is consistent yaml or json OpenAPI Spec.

springdoc.swagger-ui.url=/openapi.yaml

Then the file openapi.yaml, should be located in: src/main/resources/static No additional configuration is needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM