第 54 章 使用 OpenAPI 支持扩展 JAX-RS 端点

摘要

CXF OpenApiFeature(org.apache.cxf.jaxrs.openapi.openApiFeature)允许您通过扩展公布的 JAX-RS 服务端点来生成 OpenAPI 文档。

Spring Boot 和 Karaf 实现同时支持 OpenApiFeature。

54.1. OpenApiFeature 选项

您可以在 OpenApiFeature 中使用以下选项:

表 54.1. OpenApiFeature 操作

名称描述默认

configLocation

OpenAPI 配置位置

null

contactEmail

联系电子邮件+

null

contactName

联系名称+

null

contactUrl

联系链接+

null

customizer

自定义器类实例

null

description

description+

null

filterClass

一个安全过滤器++

null

ignoredRoutes

扫描所有资源时排除特定路径(请参阅 scanAllResources)++

null

许可证

许可证+

null

licenseUrl

许可证 URL+

null

prettyPrint

当生成 openapi.json 时,正确打印 JSON 文档++

true

propertiesLocation

属性文件位置

/swagger.properties

readAllResources

通读所有操作(没有 @Operation++)

true

resourceClasses

必须扫描++ 的资源类列表

null

resourcePackages

一个软件包名称列表,其中必须扫描资源++

null

runAsFilter

以过滤器的形式运行该功能

false

扫描

自动扫描所有 JAX-RS 资源

true

scanKnownConfigLocations

扫描已知的 OpenAPI 配置位置(classpath 或文件系统),它们是:

openapi-configuration.yaml
openapi-configuration.json
openapi.yaml
openapi.json

true

scannerClass

JAX-RS API 扫描程序类的名称,用于范围应用、资源软件包、资源类和类路径扫描,请参阅 Resource Scanning 部分

null

securityDefinitions

安全定义列表+

null

supportSwaggerUi

启用/关闭 SwaggerUI 支持

null(== true)

swaggerUiConfig

Swagger UI 配置

null

swaggerUiMavenGroupAndArtifact

用于查点 SwaggerUI 的 Maven 工件

null

swaggerUiVersion

SwaggerUI 的版本

null

termsOfServiceUrl

服务 URL 条款+

null

title

标题+

null

useContextBasedConfig

如果设置,则会为每个 OpenApiContext 实例生成唯一的上下文 Id(请参阅 使用多个服务器端点)。另外,您可能想要将扫描属性设置为 false。

false

version

版本+

null

+ 选项在 OpenAPI 类中定义

++ 选项在 SwaggerConfiguration 类中定义