Closed serandel closed 3 months ago
@serandel,
Not reproducible. Feel free to provide a Minimal, Reproducible Example - with HelloController that reproduces the problem.
This ticket will be closed, but can be reopened if your provide the reproducible sample.
Hi, @bnasslahsen , reopening this issue with a PoC in a repo, as asked.
https://github.com/serandel/springdoc-bug-poc
While doing this I realized the problem does not happen when we use Jackson to serialize the types, but just when changing to KotlinX Serialization. If you look at my repo, the first commit works, and then the second doesn't.
(Well, asking for the issue to be reopened, of course. :D)
{
"openapi": "3.0.1",
"info": {
"title": "Foo API",
"version": "v1"
},
"servers": [
{
"url": "http://localhost:8080",
"description": "Generated server url"
}
],
"tags": [
{
"name": "Foo",
"description": "Foo operations"
}
],
"paths": {
"/foo/": {
"post": {
"tags": [
"Foo"
],
"summary": "Post a foo",
"operationId": "postFoo",
"parameters": [
{
"name": "foo",
"in": "query",
"required": true,
"schema": {
"$ref": "#/components/schemas/Foo"
}
}
],
"responses": {
"204": {
"description": "Foo posted"
}
}
}
}
},
"components": {
"schemas": {
"Foo": {
"type": "object",
"properties": {
"id": {
"type": "string",
"format": "uuid"
},
"bar-kCuQ4ew": {
"type": "string"
}
}
}
}
}
}
with bar-kCuQ4ew
being the problem here.
@serandel,
There is an important Note in the docs you are missing: https://springdoc.org/#kotlin-support
If you add, that should work better:
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
Yes, I had missed that indeed. Good catch! Thanks a lot!
Now I just have to ask... would it be feasible and reasonable to ask, as a feature request, to not depend on Jackson and also work with KotlinX Serialization?
@serandel,
If you are having better proposal than jackson-module-kotlin
and willing to submit a PR, we can have look to it!
Describe the bug
Springdoc is putting a random (?) suffix to the end of my fields when they're a Kotlin value class.
This is my DTO for this example:
Please, bear in mind that the other properties should also be value classes. I don't have it this way yet because I was researching this issue.
The problem is that when a schema is generated through
the
country
field is documented as being calledcountry-GvCqL24
, which is just wrong.I've tested that KotlinX Serialization (which we're using instead of Jackson) is correctly defining the field name as
country
in the Json objects.To Reproduce Steps to reproduce the behavior:
Expected behavior
The field should be named as the field is in the enclosing object, in this case: "country". That it is a value class for better domain modelling in my Kotlin service should be irrelevant. (The type is already being translated to
string
, which is right, it's only the name what's being garbled.)Screenshots
Here we can see the wrong name being generated.
Additional context
This is a sample object when serialized from my controller: