简体   繁体   English

如何将 openapi.yaml 规范公开到 rest spring boot 中

[英]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 .我已经在外部安装了 swagger-ui,我只是想将该 swagger-ui(开源)实例从 openapi.yaml 连接到 localhost:8000/doc/api (.yaml)。 any thoughts?有什么想法吗? PS : i tried to use PS:我尝试使用

 @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 :第一个配置:外部​​ OPENAPI 定义

The properties springdoc.swagger-ui.urls.*, are suitable to configure external url ( http://myhoost.com/v3/api-docs )属性 springdoc.swagger-ui.urls.*, 适合配置外部 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.不要忘记还需要启用 CORS。

Second configuration: Internal OPENAPI Definition with static file :第二个配置:带有静态文件的内部 OPENAPI 定义

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.如果您想使用包含您的 openAPI 定义的静态文件,那么只需声明:文件名可以是您想要的任何内容,从您的声明与 yaml 或 json OpenAPI 规范一致的那一刻起。

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

Then the file openapi.yaml, should be located in: src/main/resources/static No additional configuration is needed.然后文件openapi.yaml,应该位于:src/main/resources/static 不需要额外配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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