[BUG] [JAVA] serializationLibrary option not working and AbstractOpenApiSchema missing when generating only models
Bug Report Checklist
- [X] Have you provided a full/minimal spec to reproduce the issue?
- [X] Have you validated the input using an OpenAPI validator (example)?
- [X] Have you tested with the latest master to confirm the issue still exists?
- [X] Have you searched for related issues/PRs?
- [X] What's the actual output vs expected output? Expected output:
- OpenAPI Generator should generate a code that can successfully be compiled. i.e. it should generate all classes and interfaces required to successfully build the project, even if generator is generating only model classes.
- OpenAPI Generator should respect the config options mentioned on the website i.e. it should use Jackson as serialiser library if the option is provided.
Actual output:
- The code generated has
AbstractOpenApiSchemaclass missing when generating only models. Code can be found here - The code uses Gson as serialization library inspire of providing
serializationLibrary=jacksonas configOptions. Code can be found here
- [ ] [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
I am trying to generate only models using openapi-codegen. I am using Java generator using Gradle plugin and generated source has following issues:
- The code generated has
AbstractOpenApiSchemaclass missing when generating only models. Code can be found here - The code uses Gson as serialization library inspire of providing
serializationLibrary=jacksonas configOptions. Code can be found here
openapi-generator version
Gradle plugin -> id("org.openapi.generator") version "7.6.0"
CLI Version -> openapi-generator-cli 7.6.0
OpenAPI declaration file content or url
https://github.com/usrivastava92/openapi-codegen/blob/8e1e2a889600d3ccdab8153900ad39d0f66f6195/openapi.json
Steps to reproduce
- Clone https://github.com/usrivastava92/openapi-codegen
- Run
cd java && gradle openApiGeneratecommand inside the repo to replicated the issue
Related issues/PRs
N/A
Regarding your first issue: as you haven't specified any library it defaults to okhttp-gson, which – as the name suggests – currently only supports GSON (a request to add Jackson has been pending for a while, see #1648).
I would strongly agree that it would be helpful if the generator gave feedback on this immediately instead of generating something unexpected, but that's a different issue (i've therefore opened #18852).
Apart from that, it works as expected, so maybe you can change the issue title to only refer to the second issue – which i agree is sort of critical, i'll have a look at it.
Running into this as well. Model only generation is generating like:
public class SearchResponseContentInner extends AbstractOpenApiSchema {
where AbstractOpenApiSchema does not exist.
It also tries to import non-existent class com.mypackage.JSON
so it appears model-only generation is just fundamentally broken atm.
enablePostProcessFile.set(false)
validateSpec.set(true)
library.set("native")
generateModelDocumentation.set(false)
generateModelTests.set(false)
generateApiTests.set(false)
globalProperties.set(
mapOf(
"apis" to "false",
"invokers" to "false",
"models" to "",
),
)
configOptions.set(
mapOf(
// Needed due to regression https://github.com/OpenAPITools/openapi-generator/issues/19142
"supportUrlQuery" to "false",
"dateLibrary" to "java8",
"serializationLibrary" to "jackson",
"useBeanValidation" to "true",
"performBeanValidation" to "true",
"useJakartaEe" to "true",
"sourceFolder" to ".",
"annotationLibrary" to "none",
"hideGenerationTimestamp" to "true",
),
)
@Philzen Is your PR for #18856 going anywhere? I am using the jersey3 library with model only generation and also encounter generated java classes that extend AbstractOpenApiSchema but such a class is not generated. My config in pom.xml is:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>${openapi-codegen.version}</version>
<executions>
<execution>
<id>generate java types from openapi</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/kubevirt.io-openapi.yaml</inputSpec>
<output>${project.basedir}</output>
<modelPackage>test.kubevirt.api</modelPackage>
<generatorName>java</generatorName>
<generateSupportingFiles>false</generateSupportingFiles>
<skipValidateSpec>true</skipValidateSpec>
<generateApiDocumentation>false</generateApiDocumentation>
<generateModelDocumentation>false</generateModelDocumentation>
<generateModelTests>false</generateModelTests>
<library>jersey3</library>
</configuration>
</execution>
</executions>
</plugin>
I see that your PR will pull in AbstractOpenApiSchema.mustache which should fix the problem I think. Is there a reason your PR never got merged?