openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[BUG] [JAVA] serializationLibrary option not working and AbstractOpenApiSchema missing when generating only models

Open usrivastava92 opened this issue 1 year ago • 3 comments

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:
  1. 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.
  2. 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:

  1. The code generated has AbstractOpenApiSchema class missing when generating only models. Code can be found here
  2. The code uses Gson as serialization library inspire of providing serializationLibrary=jackson as 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:

  1. The code generated has AbstractOpenApiSchema class missing when generating only models. Code can be found here
  2. The code uses Gson as serialization library inspire of providing serializationLibrary=jackson as 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
  1. Clone https://github.com/usrivastava92/openapi-codegen
  2. Run cd java && gradle openApiGenerate command inside the repo to replicated the issue
Screenshot 2024-06-02 at 7 57 14 PM Screenshot 2024-06-02 at 7 57 19 PM Screenshot 2024-06-02 at 7 57 29 PM
Related issues/PRs

N/A

usrivastava92 avatar Jun 02 '24 14:06 usrivastava92

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.

Philzen avatar Jun 04 '24 15:06 Philzen

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",
        ),
    )

madorb avatar Aug 30 '24 03:08 madorb

@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?

rajha-korithrien avatar May 30 '25 16:05 rajha-korithrien