Reputation: 43
So this is codegen101 for me and I have been trying to use swagger plugin and keep getting error. Is it a known issue, I have tried serval versions for the plugin thinking it might be a known issue in one of them but no success at all.It should be pretty straight forward exercise. I am not sure what I am missing. Can someone point out please
<build>
<plugins>
<plugin>
<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>3.0.18</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/service-api.yaml</inputSpec>
<language>java</language>
<output>${project.build.directory}/generated-sources/</output>
<generateSupportingFiles>false</generateSupportingFiles>
<apiPackage>com.openapi101.api</apiPackage>
<modelPackage>com.openapi101.models</modelPackage>
<configOptions>
<interfaceOnly>true</interfaceOnly>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
error
[ERROR]
java.lang.RuntimeException: Could not generate model 'Book'
at io.swagger.codegen.v3.DefaultGenerator.generateModels (DefaultGenerator.java:451)
at io.swagger.codegen.v3.DefaultGenerator.generate (DefaultGenerator.java:779)
at io.swagger.codegen.v3.maven.plugin.CodeGenMojo.execute (CodeGenMojo.java:547)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:78)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:567)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: com.github.jknack.handlebars.HandlebarsException: /handlebars/JavaSpring/pojo.mustache:2:6: java.lang.reflect.InaccessibleObjectException: Unable to make public boolean java.util.Collections$EmptyMap.isEmpty() accessible: module java.base does not "opens java.util" to unnamed module @4bc33720
/handlebars/JavaSpring/pojo.mustache:2:6
at java.lang.reflect.AccessibleObject.checkCanSetAccessible (AccessibleObject.java:357)
Edit : used the new version - 3.0.27 . Still did not work
here is the yaml file
openapi: 3.0.0
info:
version: 0.0.1
title: Library Service
description: The library service
tags:
- name: "Library"
paths:
/library/books:
get:
summary: This is summary
tags:
- "Library"
description: This is a description
operationId: getAllBooksInLibrary
responses:
"200":
description: This means its ok
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Book'
components:
schemas:
Book:
description: This is the book model
type: object
properties:
name:
description: The name of book
type: string
bookAuthor:
description: name of author
type: string
Upvotes: 3
Views: 2721
Reputation: 38
I had the same issue. The solution is to simply use Java 8 to run it. This allowed me to run the generation without problems
Upvotes: 2