Open Api Generator plugin does not work with Maven
Asked Answered
Z

1

6

I am trying to generate Apis with openapi generator just when i run mvn compile seems like doesn't find any depenncy like jacks httprequest and so, i add the details down i added the plugin:

<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>

with this file 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: [email protected]
  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

just when i try to compile it doesn't find the dependencies givings errors like:

   [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

my pom is:

<?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>
Zoniazoning answered 26/6, 2020 at 22:54 Comment(1)
related: github.com/OpenAPITools/openapi-generator/issues/5690Ellisellison
Z
1

I found out the problem, I can't heritage the dependecy of effective pom.xml of open API plugin, I had to add manually the dependecy, someone has better suggestion for this workaround

Zoniazoning answered 27/6, 2020 at 15:55 Comment(1)
As stated here: If you use plugin, then you have to care about all dependencies on your own. On the other hand plugin has generated all needed dependencies for you. This what I get when I run mvn clean install for yours sample. That generated pom.xml has all necessary dependencies. The generated pom file is under target/generated-sources/openapi (depending on your config). In my case I had to provide one additional dependency on my own, then everything compiled nicely.Mantooth

© 2022 - 2024 — McMap. All rights reserved.