我有一个OpenAPI (版本2)规范文件,我想用openapi-generator-maven-plugin
生成一个客户机。不幸的是,它不能生成所有必要的类,因此不能编译生成的源。
POM
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>5.1.0</version>
<executions>
<execution>
<id>generate-client</id>
<goals>
<goal>generate</goal>
</goals>
<phase>process-resources</phase>
<configuration>
<inputSpec>${project.basedir}/src/main/openapi/api.json</inputSpec>
<generatorName>java</generatorName>
<generateApiDocumentation>false</generateApiDocumentation>
<generateApiTests>false</generateApiTests>
<generateSupportingFiles>false</generateSupportingFiles>
<configOptions>
<sourceFolder>/</sourceFolder>
</configOptions>
<library>resttemplate</library>
</configuration>
</execution>
</executions>
</plugin>
OpenAPI
{
"swagger": "2.0",
"info": {
"title": "Test"
},
"host": "localhost:8080",
"basePath": "/",
"tags": [
{
"name": "test-controller"
}
],
"paths": {
"/test": {
"get": {
"tags": [
"test-controller"
],
"operationId": "test",
"responses": {
"200": {
"description": "OK"
}
}
}
}
}
}
生成源
在目录target/generated-sources/openapi
中,只生成子包api
的文件TestControllerApi
。不生成类org.openapitools.client.ApiClient
。
日志
[INFO] --- openapi-generator-maven-plugin:5.1.0:generate (generate-client) @ test ---
[INFO] Generating with dryRun=false
[INFO] No .openapi-generator-ignore file found.
[INFO] OpenAPI Generator: java (client)
[INFO] Generator 'java' is considered stable.
[INFO] Environment variable JAVA_POST_PROCESS_FILE not defined so the Java code may not be properly formatted. To define it, try 'export JAVA_POST_PROCESS_FILE="/usr/local/bin/clang-format -i"' (Linux/Mac)
[INFO] NOTE: To enable file post-processing, 'enablePostProcessFile' must be set to `true` (--enable-post-process-file for CLI).
[INFO] Processing operation test
[WARNING] 'scheme' not defined in the spec (2.0). Default to [http] for server URL [http://localhost:8080/]
[WARNING] 'scheme' not defined in the spec (2.0). Default to [http] for server URL [http://localhost:8080/]
[ERROR] Missing required field info version. Default appVersion set to 1.0.0
[ERROR] Missing required field info version. Default version set to 1.0.0
[WARNING] 'scheme' not defined in the spec (2.0). Default to [http] for server URL [http://localhost:8080/]
[INFO] writing file D:\tmp\workspace\test\target\generated-sources\openapi\org\openapitools\client\api\TestControllerApi.java
[INFO] Skipped D:\tmp\workspace\test\target\generated-sources\openapi\src\test\java\org\openapitools\client\api\TestControllerApiTest.java (Skipped by apiTests options supplied by user.)
[INFO] Skipped D:\tmp\workspace\test\target\generated-sources\openapi\docs\TestControllerApi.md (Skipped by apiDocs options supplied by user.)
[WARNING] 'scheme' not defined in the spec (2.0). Default to [http] for server URL [http://localhost:8080/]
[INFO] Skipping generation of supporting files.
[...]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ test ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 51 source files to D:\tmp\workspace\test\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /D:/tmp/workspace/test/target/generated-sources/openapi/org/openapitools/client/api/TestControllerApi.java:[3,31] cannot find symbol
symbol: class ApiClient
location: package org.openapitools.client
Research
我发现了一个相关的问题:10048,但它不包含解决方案。
问题
如何配置插件以生成所有必要的类?
发布于 2021-09-17 17:48:51
generateSupportingFiles
应该是true
。
https://stackoverflow.com/questions/67592893
复制相似问题