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.81k stars 6.58k forks source link

[BUG][kotlin-spring][gson] Setting serializationLibrary in gson uses Jackson #9498

Open mwilliams-tyro opened 3 years ago

mwilliams-tyro commented 3 years ago

Bug Report Checklist

Description

When using the kotlin-spring generator in the openapi-generator-maven-plugin and setting the serializationLibrary property to gson, the JSON serialization annotations used in the generated model classes are Jackson annotations. This is causing issues as we need to have the property name in Pascal case due to a contract with a 3rd party system, so are reliant on the JSON property name annotations (@SerializedName in the case of gson).

There are possibly 2 bugs at play here:

  1. Setting serializationLibrary to gson is seemingly ignored
  2. The default value for serializationLibrary is documented as being moshi (see https://openapi-generator.tech/docs/generators/kotlin-spring and search for serializationLibrary)
openapi-generator version

openapi-generator-maven-plugin:5.1.0

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  title: Open API generator test harness
  description: Test harness for Open API generator
  version: '1.0.0'
paths: {}
components:
  schemas:
    DTO:
      type: object
      properties:
        PascalCaseProp:
          type: string
          minLength: 1
          maxLength: 255
Generation Details

Plugin configured in pom.xml:

            <plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <version>5.1.0</version>
                <configuration>
                    <generatorName>java</generatorName>
                    <generateModels>true</generateModels>
                    <generateSupportingFiles>false</generateSupportingFiles>
                    <configOptions>
                        <modelPackage>mw.test.dto</modelPackage>
                        <serializationLibrary>gson</serializationLibrary>
                    </configOptions>
                </configuration>
                <executions>
                    <execution>
                        <id>dto-test</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>${project.basedir}/src/main/resources/openapi/dtos.yaml</inputSpec>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
Steps to reproduce

Run mvn generate-sources

mwilliams-tyro commented 3 years ago

With the update to 5.2.0 and the latest kotlin-spring templates this has now also broken required field bean validation as the native NotNull annotation has been removed entirely and all the non null handling has been moved inside the jackson specific annotation

greenarr0w commented 3 years ago

I have exactly the same problem. I guess serializationLibrary is always ignored. In our company we are not allowed to use jackson so we have to use another serialization library.

kumaraish commented 1 year ago

Same issue with generator = "kotlin-spring" library = "kotlinx_serialization"

"serializationLibrary" to "kotlinx_serialization", is ignored and instead Jackson impl is generated