Reputation: 1108
So I am using a openApi code generator. (All this goes for Swagger codegen too, same error)
I have created a maven project in eclipse, and I have a POM which looks like this...
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test.api.openapi</groupId>
<artifactId>test-openapi-codegen</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>test-openapi-codegen</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>4.3.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/openAPI.yaml</inputSpec>
<generatorName>java</generatorName>
<apiPackage>com.test.openapi.codegen.demo.api</apiPackage>
<modelPackage>com.test.openapi.codegen.demo.model</modelPackage>
<invokerPackage>com.test.openapi.codegen.demo</invokerPackage>
<configOptions>
<sourceFolder>src/java/</sourceFolder>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>4.3.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
So this POM is taking a YAML file to generate the JAVA code, YAML file act as a architecture/structure file for the code that is to be generated.
Here is a link : [https://openapi-generator.tech/docs/plugins/][1] --> The Plugin that I used is mentioned in the link.
So when I am doing a mvn clean compile, the code is being generated in the output folder mentioned in tag -> src/java/generated-code -> like this. also a POM is being generated for that generated code, but with the above command "mvn clean compile" I am getting below error, saying that A LOT" of packages are missing. READ NEXT TWO LINES.
HERE IS A CATCH, I CHECKED THE POM THAT WAS GENERATED AND DEPENDENCIES WERE RIGHLTY PRESENT IN THE POM AND I TESTED IT AS WELL USING "MVN COMPILE" AND BUILD WAS SUCCESSFUL FOR THAT POM
Changes detected - recompiling the module!
[INFO] Compiling 43 source files to T:\Perforce\testStream\openapi-codegen\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] T:/Perforce/testStream/openapi-codegen/target/generated-sources/openapi/src/java/com/test/openapi/codegen/demo/model/ProvisioningBatch.java:[18,23] package com.google.gson does not exist
What am I doing wrong? I have described in the best possible way.
Upvotes: 2
Views: 4188
Reputation: 1108
I fixed the problem by adding the missing dependencies, but I do not thinks its the best approach, better use a cli jar for the need.
Download jar from maven central, openapi-codegen-cli.jar and its a runnable jar and use the arguments as per req.
It will generate a code from the YAML, and then you can use the generated POM to mvn clean install or anything you want
Upvotes: 1