首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用OpenApi生成器-maven-插件生成openapi客户端?

如何使用OpenApi生成器-maven-插件生成openapi客户端?
EN

Stack Overflow用户
提问于 2021-05-18 19:34:20
回答 1查看 11K关注 0票数 3

我有一个OpenAPI (版本2)规范文件,我想用openapi-generator-maven-plugin生成一个客户机。不幸的是,它不能生成所有必要的类,因此不能编译生成的源。

POM

代码语言:javascript
运行
复制
<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

代码语言:javascript
运行
复制
{
    "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

日志

代码语言:javascript
运行
复制
[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,但它不包含解决方案。

问题

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

EN

回答 1

Stack Overflow用户

发布于 2021-09-17 17:48:51

generateSupportingFiles应该是true

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67592893

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档