I use openapi-generator-maven-plugin with a JSON which contains a scheme that references itself (Newtonsoft.Json.Linq.JToken). I specify that I cannot modify the JSON input.
At launch, I have StackOverflowError like this :
Exception in thread "main" java.lang.StackOverflowError
at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:446)
at java.lang.StringBuilder.append(StringBuilder.java:136)
at org.openapitools.codegen.DefaultCodegen.getPrimitiveType(DefaultCodegen.java:2370)
at org.openapitools.codegen.DefaultCodegen.getSingleSchemaType(DefaultCodegen.java:2353)
at org.openapitools.codegen.DefaultCodegen.getSchemaType(DefaultCodegen.java:2244)
at org.openapitools.codegen.languages.AbstractJavaCodegen.getSchemaType(AbstractJavaCodegen.java:1392)
at org.openapitools.codegen.languages.AbstractJavaCodegen.getTypeDeclaration(AbstractJavaCodegen.java:959)
at org.openapitools.codegen.languages.AbstractJavaCodegen.getTypeDeclaration(AbstractJavaCodegen.java:959)
at org.openapitools.codegen.languages.AbstractJavaCodegen.getTypeDeclaration(AbstractJavaCodegen.java:959)
...
Here’s the schema :
"Newtonsoft.Json.Linq.JToken": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Newtonsoft.Json.Linq.JToken"
}, "nullable": true
}
In my pom.xml, the implementation of the plugin :
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>5.3.1</version>
<executions>
<execution>
<id>json-production</id>
<goals>
<goal>generate</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<configHelp>false</configHelp>
<generateApiTests>false</generateApiTests>
<generateModelTests>false</generateModelTests>
<generateApis>false</generateApis>
<configOptions>
<useSpringBoot3>true</useSpringBoot3>
<openApiNullable>false</openApiNullable>
<interfaceOnly>true</interfaceOnly>
</configOptions>
<inputSpec>
${project.basedir}/src/main/resources/schema/openapi.json
</inputSpec>
<generatorName>spring</generatorName>
<apiPackage>com.api</apiPackage>
<modelPackage>com.dto</modelPackage>
<output>${basedir}/target/generated</output>
<globalProperties>
<skipFormModel>false</skipFormModel>
</globalProperties>
</configuration>
</execution>
</executions>
</plugin>
When I replace (for tests), the reference by “type”:”string” like bellow, it works, but I can’t work with this.
"Newtonsoft.Json.Linq.JToken": {
"type": "array",
"items": {
"type": "string"
}, "nullable": true
}
I also tried to change configOptions in the pom, but I found nothing
Jean-Charles Planquais is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1