OpenAPITools / OpenAPITools/openapi-generator
[BUG][kotlin-spring][gson] Setting serializationLibrary in gson uses Jackson
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the pom.xml configuration and the kotlin-spring generator's handling of the serializationLibrary option, using the supplied OpenAPI schema and the openapi-generator-maven-plugin entry point. Run mvn generate-sources and inspect the generated model annotations; done means the gson setting produces Gson annotations and the documented default matches the generator behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, kotlin, spring
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100