我正在导入一个包含使用 openapi-codegen 生成的 RestResources 的 jar 文件。
@Controller
@RequestMapping({"${openapi.someproject.base-path:/v1}"}) // <-- ${openapi.someproject.base-path:/v1} should be replaced by /v1
public class ApiApiController implements ApiApi {
private final ApiApiDelegate delegate;
public ApiApiController(@Autowired(required = false) ApiApiDelegate delegate) {
this.delegate = (ApiApiDelegate)Optional.ofNullable(delegate).orElse(new ApiApiDelegate() {
});
}
public ApiApiDelegate getDelegate() {
return this.delegate;
}
}
部署我的应用程序时,会看到一个名为“${openapi.someproject.base-path:/v1}”的端点。如何将其配置为“/v1”。
我尝试将以下内容放在使用项目的 application.yml 中:
openapi:
someproject:
base-path: ""
使用 openapi-generator-maven-plugin 生成导入的 jar,如下所示:
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>back-end-swagger</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/swagger/api.yml</inputSpec>
<generatorName>spring</generatorName>
<apiPackage>com.test.api</apiPackage>
<modelPackage>com.test.api.model</modelPackage> <supportingFilesToGenerate>ApiUtil.java</supportingFilesToGenerate>
<validateSpec>true</validateSpec>
<configOptions>
<delegatePattern>true</delegatePattern>
</configOptions>
</configuration>
</execution>
api.yml 文件如下所示:
swagger: "2.0"
info:
version: "1.0.0"
title: "someproject"
host: "somehost.io"
basePath: "/v1"
tags:
- name: "endpoint"
schemes:
- "https"
- "http"
paths:
/api/test:
get:
produces:
- "application/json"
responses:
200:
description: OK