OpenAPITools / OpenAPITools/openapi-generator
[BUG][KOTLIN-SPRING] Required properties are always listed first
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
With the generator kotlin-spring required properties of a model are always listed first, regardless of the configuration using sortModelPropertiesByRequiredFlag and sortParamsByRequiredFlag. The expected output is, that the order defined in the OpenAPI file is used for constructor parameters, when both of these properties are set to false.
openapi-generator version
6.5.0, also tested with latest docker image
OpenAPI declaration file content or url
openapi.yaml:
openapi: 3.0.1
info:
title: OpenAPI example
version: 0.0.1
paths: { }
components:
schemas:
TestObject:
type: object
required:
- fieldA
- fieldC
properties:
fieldA:
type: string
nullable: false
fieldB:
type: string
nullable: true
fieldC:
type: string
nullable: false
config.json:
{
"sortModelPropertiesByRequiredFlag": false,
"sortParamsByRequiredFlag": false
}
Generation Details
docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli generate -g kotlin-spring -i /local/openapi.yaml -c /local/config.json -o /local/out
Expected output
data class TestObject(
@Schema(example = "null", required = true, description = "")
@get:JsonProperty("fieldA", required = true) val fieldA: kotlin.String,
@Schema(example = "null", description = "")
@get:JsonProperty("fieldB") val fieldB: kotlin.String? = null,
@Schema(example = "null", required = true, description = "")
@get:JsonProperty("fieldC", required = true) val fieldC: kotlin.String
) {
}
Actual output
data class TestObject(
@Schema(example = "null", required = true, description = "")
@get:JsonProperty("fieldA", required = true) val fieldA: kotlin.String,
@Schema(example = "null", required = true, description = "")
@get:JsonProperty("fieldC", required = true) val fieldC: kotlin.String,
@Schema(example = "null", description = "")
@get:JsonProperty("fieldB") val fieldB: kotlin.String? = null
) {
}
Steps to reproduce
Listed above.
Related issues/PRs
None found.
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
Reproduce the issue with the provided openapi.yaml and config.json using the kotlin-spring generator and the documented Docker command. Compare the generated TestObject constructor with the expected output. Done means both sortModelPropertiesByRequiredFlag and sortParamsByRequiredFlag set to false preserve the OpenAPI property order.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, kotlin, spring
- Domain
- backend-api-design, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100