-
-
Notifications
You must be signed in to change notification settings - Fork 514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Description missing in generated spec when field type is a byte array #2275
Comments
When I tried the following using springdoc 2.0.4, the expected value was returned.
"Response": {
"type": "object",
"properties": {
"content": {
"type": "array",
"description": "foo",
"items": {
"type": "string",
"description": "foo",
"format": "byte"
}
},
"content2": {
"type": "array",
"description": "foo2",
"items": {
"type": "string",
"format": "byte"
}
},
"content3": {
"type": "string",
"description": "foo",
"format": "byte"
}
}
} Can you tell me a concrete code example? |
If I generate a spec from the Record class as you have written it, Springdoc 2.0.4 generates for me the following description (with all the issues I already tried to explain in my original report). Most values in the annotations seem to be ignored: "Response": {
"type": "object",
"properties": {
"content": {
"type": "string",
"format": "byte"
},
"content2": {
"type": "string",
"format": "byte"
},
"content3": {
"type": "string",
"format": "byte"
}
}
}, If I use Springdoc 2.0.2, I get the same output as you claim to get with Springdoc 2.0.4, but this is not the 'expected value'. I can try to explain again it in more detail: The generated specification for the field
Trying to generate code again from this specification will give you a field of type The generated specification for the field The generated specification for the field I am not sure if any other dependencies may be relevant. We are using Spring Boot 3.1.0 if that helps narrowing down the problem. |
I have tried to check if any other dependency in our project is relevant for the behaviour I see and the culprit is Spring Cloud: <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-kubernetes-client-config</artifactId>
<version>3.0.3</version>
</dependency> Without Spring Cloud, Springdoc >=2.0.4 shows the same erroneous behaviour as Springdoc 2.0.2. With Spring Cloud, Springdoc >=2.0.4 produces correct type and format attributes for the byte array field, but ignores most other attributes of the |
Attached here is an MVP allowing to easily test with different versions of Springdoc together with or without a dependency on Spring Cloud. |
@jarnbjo |
|
@uc4w6c I would really appreciate if you tried to understand the issue. In Springdoc <=2.0.2, SpringDocKotlinConfiguration does not invoke In Springdoc >=2.04, SpringDocKotlinConfiguration invokes And now, instead of fixing the issue, you just close the bug? Setting springdoc.enable-kotlin=false and disabling Kotlin does not fix the problem. And for those who are now actually using Kotlin and therefore can't disable it with springdoc.enable-kotlin=false, the generated spec is still false. |
@jarnbjo
By setting
If you have a problem with byte[] returning a Also, if we were to fix that problem, it would be necessary to add a description after swagger-core generated the component. If you still want to fix it, I would appreciate it if you could create a PR. |
I think this issue should be reopened. The workaround Since swagger-api/swagger-core#3944 is now fixed, it should be possible to fix this issue by simply removing the line I was able to restore the correct behavior locally by calling The affected field: @Schema(
description = "The file's byte content encoded as Base64.",
accessMode = Schema.AccessMode.WRITE_ONLY,
example = "IDwhRE9DVFlQRSBodG1sPjxodG1sPjxoZWFkPjx0aXRsZT5TdGVsbGVuYW56ZWlnZTwvdGl0bGU+PC9oZWFkPjxib2R5PjwvYm9keT48L2h0bWw+",
)
val dataBase64: ByteArray, The default generated schema as of springdoc-openapi 2.6.0: The generated schema after calling Afaict, this Kotlin-specific override of |
This is fixed in 2.7.0. |
With springdoc-openapi-starter-common:2.0.4 and newer, generating an OpenAPI spec from a value object containing a byte array field, e.g:
will generate an OpenAPI specification, in which the description of the field is missing:
If I generate the specification from the same model class with version 2.0.2, the following spec comes out:
Here, the description is present, although the data type is incorrectly specified. There have been a lot of bugs reported against both Springdoc as well as Swagger with the data type issue. Probably something went wrong with the bugfix. It is BTW also no more possible to overwrite the type and format fields with the corresponding values in the Schema annotation. The required value in the Schema annotation seem however still to be evaluated.
I am honestly not sure which project (Springdoc or Swagger) might be responsible for this issue, but I assume that it actually is some issue in Springdoc. The reason is:
When using Springdoc 2.0.2, it is at least possible to specify the correct type and format in the Schema annotation:
... in which case the correct spec is generated:
The text was updated successfully, but these errors were encountered: