gpt4 book ai didi

java - Open Api Generator 插件不适用于 Maven

转载 作者:行者123 更新时间:2023-12-05 07:06:08 27 4
gpt4 key购买 nike

我正在尝试使用 openapi 生成器生成 Apis,就在我运行 mvn compile 时似乎没有找到任何像 jacks httprequest 这样的依赖项,所以,我添加了详细信息我添加了插件:

<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<!-- RELEASE_VERSION -->
<version>4.3.1</version>
<!-- /RELEASE_VERSION -->
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/player.yml</inputSpec>
<generatorName>java</generatorName>
<configOptions>
<sourceFolder>src/gen/java/main</sourceFolder>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>

使用这个文件 player.yml:

openapi: 3.0.1
info:
title: Swagger Petstore
description: 'This is a sample server Petstore server. You can find out more about Swagger
at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For
this sample, you can use the api key `special-key` to test the authorization filters.'
termsOfService: http://swagger.io/terms/
contact:
email: apiteam@swagger.io
license:
name: Apache 2.0
url: http://www.apache.org/licenses/LICENSE-2.0.html
version: 1.0.0
externalDocs:
description: Find out more about Swagger
url: http://swagger.io
servers:
- url: https://petstore.swagger.io/v2
- url: http://petstore.swagger.io/v2
tags:
- name: pet
description: Everything about your Pets
externalDocs:
description: Find out more
url: http://swagger.io
- name: store
description: Access to Petstore orders
- name: user
description: Operations about user
externalDocs:
description: Find out more about our store
url: http://swagger.io
paths:
/cssl/player/{uuid}:
get:
tags:
- store
summary: Find purchase order by ID
description: For valid response try integer IDs with value >= 1 and <= 10. Other
values will generated exceptions
operationId: getOrderById
parameters:
- name: uuid
in: path
description: ID of pet that needs to be fetched
required: true
schema:
maximum: 10.0
minimum: 1.0
type: integer
format: int64
responses:
200:
description: successful operation
content:
application/xml:
schema:
$ref: '#/components/schemas/Player'
application/json:
schema:
$ref: '#/components/schemas/Player'
400:
description: Invalid ID supplied
content: {}
404:
description: Order not found
content: {}
delete:
tags:
- store
summary: Delete purchase order by ID
description: For valid response try integer IDs with positive integer value. Negative
or non-integer values will generate API errors
operationId: deleteOrder
parameters:
- name: uuid
in: path
description: ID of the order that needs to be deleted
required: true
schema:
minimum: 1.0
type: integer
format: int64
responses:
400:
description: Invalid ID supplied
content: {}
404:
description: Order not found
content: {}
components:
schemas:
Player:
type: object
properties:
uuid:
type: integer
format: int64
slName:
type: integer
format: int64
slLastname:
type: integer
format: int32

就在我尝试编译时,它没有找到依赖项,并给出如下错误:

   [DEBUG] incrementalBuildHelper#beforeRebuildExecution
[INFO] Compiling 33 source files to /home/francescolombardi/IdeaProjects/core-comunicator/target/classes
[DEBUG] incrementalBuildHelper#afterRebuildExecution
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/francescolombardi/IdeaProjects/core-comunicator/target/generated-sources/openapi/src/gen/java/main/org/openapitools/client/ApiClient.java:[17,29] package okhttp3.internal.http does not exist
[ERROR] /home/francescolombardi/IdeaProjects/core-comunicator/target/generated-sources/openapi/src/gen/java/main/org/openapitools/client/ApiClient.java:[18,28] package okhttp3.internal.tls does not exist
[ERROR] /home/francescolombardi/IdeaProjects/core-comunicator/target/generated-sources/openapi/src/gen/java/main/org/openapitools/client/ApiClient.java:[19,23] package okhttp3.logging does not exist
[ERROR] /home/francescolombardi/IdeaProjects/core-comunicator/target/generated-sources/openapi/src/gen/java/main/org/openapitools/client/ApiClient.java:[20,46] package okhttp3.logging.HttpLoggingInterceptor does not exist
[ERROR] /home/francescolombardi/IdeaProjects/core-comunicator/target/generated-sources/openapi/src/gen/java/main/org/openapitools/client/ApiClient.java:[21,12] package okio does not exist
[ERROR] /home/francescolombardi/IdeaProjects/core-comunicator/target/generated-sources/openapi/src/gen/java/main/org/openapitools/client/ApiClient.java:[22,12] package okio does not exist
[ERROR] /home/francescolombardi/IdeaProjects/core-comunicator/target/generated-sources/openapi/src/gen/java/main/org/openapitools/client/ApiClient.java:[74,13] cannot find symbol
symbol: class OkHttpClient
location: class org.openapitools.client.ApiClient

我的 pom 是:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.0-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.cssl</groupId>
<artifactId>core-comunicator</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>core-comunicator</name>
<description>Demo project for Spring Boot</description>

<properties>
<java.version>14</java.version>
<openapi-generator-version>4.3.1</openapi-generator-version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>


<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->


<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.4.18.Final</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.14</version>

</dependency>

<dependency>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>4.3.1</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
<scope>provided</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.openapitools/openapi-generator -->
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator</artifactId>
<version>4.3.1</version>
</dependency>



</dependencies>

<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<build>

<plugins>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<!-- RELEASE_VERSION -->
<version>4.3.1</version>
<!-- /RELEASE_VERSION -->
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/player.yml</inputSpec>
<generatorName>java</generatorName>
<configOptions>
<sourceFolder>src/gen/java/main</sourceFolder>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<pluginRepositories>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</pluginRepository>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>

</project>

最佳答案

我发现了问题,我无法继承开放 API 插件的有效 pom.xml 的依赖项,我不得不手动添加依赖项,有人对此解决方法有更好的建议

关于java - Open Api Generator 插件不适用于 Maven,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62603923/

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