Open thokaab opened 5 years ago
Here is a workaround until this is fixed: Using maven-dependency-plugin, unpack the jar , copy open api yaml to a local directory, point generator to the local directory. The generator will be happy now.
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>unpack</id>
<phase>generate-sources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>your-group-id</groupId>
<artifactId>your-artifact-id</artifactId>
<version>your-version</version>
<type>jar</type>
<overWrite>false</overWrite>
<includes>**/*.yaml</includes>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/classes/</outputDirectory>
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>5.0.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>
${project.build.directory}/classes/openapi.yaml
</inputSpec>
<generatorName>spring</generatorName>
<apiPackage>com.example.gen</apiPackage>
<modelPackage>com.example.gen.model</modelPackage>
<configOptions>
<interfaceOnly>true</interfaceOnly>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
...
Is this issue fixed? Can I generate directly from the file in a jar file?
It works for me. We have artifacts only as dependencies of the openapi-generator-maven-plugin
. So it is fixed it worked also in version 3 of this plugin. There is no reason to use maven-dependency-plugin
.
@Saljack Could you please provide an example of specifying inputSpec from maven dependency?
@ILyaCyclone Here you are:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>your-artificat-with-openapi</artifactId>
<version>your-version</version>
</dependency>
<!-- You can add multiple dependencies -->
</dependencies>
<executions>
<execution>
<id>openapi</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<!-- The path of OpenAPI in your file. The origin path in project is /src/main/resources/... -->
<inputSpec>openapi/openapi.yaml</inputSpec>
<!-- Another configuration -->
</configuration>
</execution>
<!-- You can add multiple executions-->
<executions>
</plugin>
Is it possible to do it with gradle? Doesn't work for me currently, the plugin complains that it cannot find the inputSpec file, searching for it in project root.
Edit: succeeded with the suggested workaround (unpacked the JAR with the OpenAPI specification), just wondered if, being still relatively new to gradle, I'm missing something and the workaround can be avoided.
Description
When migrated from swagger-codegen-maven-plugin to openapi-generator-maven-plugin we are no longer able to generate Java code from an OpenAPI specification located in a Maven JAR-dependency. The specification file is first found, then at a later stage it's no longer found.
Please note that the codegen is successful with the exact same configuration if I put the
api.yml
in the local project and point<inputSpec>
to the local file, e.g.Hence:
Detailed Description
When building verbose I can see that the generator first prints my YML-file (api.yml) as JSON (OK):
Then writing model files (schemas), e.g.
Then Model Info is printed (OK):
Then Supporting file info is printed (OK):
Then writing supporting files:
So far everything looks ok and the YML-file has obviously been found by the plugin. But directly after the supporting files have been generated I get a
FileNotFoundException
:The maven plugin is located at
C:\code\example-impl\functions\pom.xml
I runmvn clean install
fromC:\code\example-impl\
which has a parentpom.xml
to thefunctions\pom.xml
(functions
is a module). One thing I noticed is that the error message above looks for the file atC:\code\example-impl\api.yml
, i.e. the folder of the POM I'm running. If I runmvn clean install
on the module POMC:\code\example-impl\functions\pom.xml
then it's the same error, but it now fails with:The file is inside the JAR-dependency, not on any of the project paths.
My plugin definition:
openapi-generator version
3.3.4
OpenAPI declaration file content or url
N/A
Steps to reproduce
See description.
Related issues/PRs
None found.
Suggest a fix