Ensure enum classes toString() returns kotlin.String#16247
Merged
wing328 merged 1 commit intoOpenAPITools:masterfrom Aug 9, 2023
Merged
Ensure enum classes toString() returns kotlin.String#16247wing328 merged 1 commit intoOpenAPITools:masterfrom
wing328 merged 1 commit intoOpenAPITools:masterfrom
Conversation
When creating an enum where a valid value is `String`, the override of toString() will be the wrong type. Simply using `*kotlin*.String` will allow using `String` as a value in an enum.
androa
added a commit
to navikt/dp-saksbehandling
that referenced
this pull request
Aug 4, 2023
Member
|
@androa thanks for the PR. Can you please share a spec to reproduce the issue? |
Contributor
Author
|
Sure, this will reproduce the issue. openapi: 3.0.3
info:
title: Answer Type POC
version: 1.0.0
paths:
/answer-type:
get:
summary: Get Answer Type
responses:
'200':
description: Successful response with Answer Type
content:
application/json:
schema:
$ref: '#/components/schemas/AnswerType'
components:
schemas:
AnswerType:
type: string
enum:
- String
- LocalDate
- Int
- Boolean
- DoubleWhat happens is the generated code will look like this: enum class SvartypeDTO(val value: kotlin.String) {
@JsonProperty(value = "String")
String("String"),
// ...
override fun toString(): String = valueSince |
Member
|
@androa thanks for the explanation. The fix looks good. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When creating an enum where a valid value is
String, the override of toString() will be the wrong type and compilation fails with:Using
kotlin.Stringinstead of justStringas the return value will allow usingStringas a value in an enum.@jimschubert
PR checklist
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.For Windows users, please run the script in Git BASH.
master(6.3.0) (minor release - breaking changes with fallbacks),7.0.x(breaking changes without fallbacks)