Kotlin Spring Generator: add type information to schema annotation#22109
Kotlin Spring Generator: add type information to schema annotation#22109rd-max-hartmann wants to merge 2 commits intoOpenAPITools:masterfrom
Conversation
|
https://github.com/OpenAPITools/openapi-generator/actions/runs/18435804244/job/52531980060?pr=22109 please follow step 3 in the PR checklist to update the samples cc @karismann (2019/03) @Zomzog (2019/04) @andrewemery (2019/10) @4brunu (2019/11) @yutaka0m (2020/03) @stefankoppier (2022/06) @e5l (2024/10) |
done |
|
Are you sure that |
@Mattias-Sehlstedt good point, but how can I implement this schema/array If-condition in the template? |
|
I believe It could for example be done if we were to place So lets say we have the current template with Breaking out parts of the annotation creation into a separate mustache template would also go a long way in making it more readable, since now I find it quite hard to follow exactly what it does. |
@Mattias-Sehlstedt it's too hard for me right now :-) I am not very familar with the template language. Could you please help me or is there a better way like creating an issue or a feature request? |
|
I can see if I can produce a solution. I am a bit curious about the background. How come we have a specification, we generate a server definition for that, and then we use springdoc-openapi to introspect the generated server to get a specification, and then we expose that specification? How come we do not simply expose the initial specification used to generate the server? Or do we have some controllers that are generated, and some that are not? Edit: you can find a suggested solution here. Please try it out and see if it works for your use case. |
@Mattias-Sehlstedt you are right, it's also possible to use the created spec directly in Swagger. Otherwise this setup comes from the OpenAPIGenerator that generates the SpringDocConfiguration. IMO the generated code is not correct and SpringDoc generates incorrect data-type mapping from it:
All these properties are boolean props in the spec |

This PR fixes the problem that the open api generator does not set the type of the Schema annotation at all:
schema = Schema(type="integer", defaultValue = "0")
It's a problem, because we are using Open Api Code Generation in combination with Spring-Doc and Spring-Doc needs so type information of the schema to configure the Swagger UI correctly. Maybe other frameworks and tools rely also on it. This PR fixes only the kotlin-spring generator.