gpt4 book ai didi

maven - 如何使用 openapi-generator-maven-plugin 生成 OpenApi 客户端?

转载 作者:行者123 更新时间:2023-12-05 04:49:25 25 4
gpt4 key购买 nike

我有一个 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 未生成。

directory

日志

[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

研究

我发现了一个相关问题:10048 , 但它不包含解决方案。

问题

如何配置插件来生成所有必要的类?

最佳答案

generateSupportingFiles 应该是 true

关于maven - 如何使用 openapi-generator-maven-plugin 生成 OpenApi 客户端?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67592893/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com