问题描述
我正在使用 swagger ui 并且我试图将 pom.xml 中的一些属性读入 yaml 文件(例如版本、artifactId),但我收到此错误:
我的 openapi.yaml 文件的头部。我需要在标题中使用 artifactId。
openapi: 3.0.3
info:
title: @artifactId@
我需要用 pom.xml 做些什么吗?导出文件?或者还有其他方法可以从 pom.xml 中检索数据?
解决方法
可以使用maven提供的资源过滤功能。 link to doc
将您的 openapi.yaml 文件更改为:
openapi: 3.0.3
info:
title: ${artifactId}
并将以下部分添加到您的 pom.xml。 (假设你的 openapi.yaml 在资源目录下)
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
Maven 构建将创建一个 openapi.yaml 文件,并在目标目录中使用替换的 artifactId。