OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.48k stars 6.5k forks source link

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

Open usrivastava92 opened 4 months ago

usrivastava92 commented 4 months ago

Bug Report Checklist

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

Philzen commented 4 months ago

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.

madorb commented 1 month ago

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