[BUG][kotlin-spring][gson] Setting serializationLibrary in gson uses Jackson
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:
- Setting
serializationLibraryto gson is seemingly ignored - The default value for
serializationLibraryis documented as beingmoshi(see https://openapi-generator.tech/docs/generators/kotlin-spring and search forserializationLibrary)
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
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
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.
Same issue with generator = "kotlin-spring" library = "kotlinx_serialization"
"serializationLibrary" to "kotlinx_serialization", is ignored and instead Jackson impl is generated
Is this property still being ignored? I've tried it just via the gradle plugin, and it still seems to generate via jackson