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

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

Open mwilliams-tyro opened this issue 4 years ago • 4 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)?
  • [ ] 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?
  • [ ] [Optional] Sponsorship to speed up the bug fix or feature request (example)
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 avatar May 17 '21 03:05 mwilliams-tyro

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

mwilliams-tyro avatar Jul 15 '21 07:07 mwilliams-tyro

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.

greenarr0w avatar Aug 09 '21 12:08 greenarr0w

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

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

kumaraish avatar Jul 03 '23 15:07 kumaraish

Is this property still being ignored? I've tried it just via the gradle plugin, and it still seems to generate via jackson

Jarvvski avatar Nov 24 '25 22:11 Jarvvski