使用OpenAPI Maven插件生成API文档

5

我正在尝试为使用OpenAPI 3 yaml生成的Spring REST应用程序生成API文档端点(例如/v3/api-docs)。

我注意到Maven插件有一个generateApiDocumentation标志,但我不确定它的作用是什么。

不幸的是,SpringFox还不支持OpenAPI 3——而且似乎没有必要使用基于反射的生成器,因为我想要做的只是将初始yaml公开为json。

2个回答

0

https://springdoc.org/faq.html

如何正确设置Swagger UI以使用提供的spec.yml文件?

使用此属性,将禁用所有springdoc-openapi自动配置bean:

springdoc.api-docs.enabled=false

然后启用最小的Bean配置,通过添加此Bean:

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

然后配置您自定义UI YAML文件的路径。

springdoc.swagger-ui.url=/my-api-docs.yaml

在这种情况下,您应该将'my-api-docs.yaml'文件放到'src/main/resources/static/'文件夹中!

0

我不确定我是否理解了你的问题,但可以尝试查看这篇文章:https://www.baeldung.com/spring-rest-openapi-documentation

此外,您还可以查看文档https://github.com/springdoc/springdoc-openapi

基本上,您只需要添加此Maven依赖项即可

<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-ui</artifactId>
    <version>1.2.32</version>
</dependency>

之后,当您启动服务时,可以通过以下路径检查您的主机:/swagger-ui.html

http//localhost:8080/swagger-ui.html

我希望我能帮助你。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接