springwolf-core
springwolf-core copied to clipboard
Add support for Kotlin Serialization
Springwolf doesn't support the generation of AsyncAPI components when used with Kotlin
Example:
@Serializable
data class Period(
@SerialName("start_date")
val startDate: String,
@SerialName("period_end")
val endDate: String,
)
The outcome looks like:
Period:
required:
- endDate
- startDate
type: object
properties:
endDate:
type: string
startDate:
type: string
Ignoring the @SerialName
annotation.
Hi @ctasada ,
springwolf uses swagger to get the property names.
Even though I use kotlin myself, adding support for one 'external' annotations opens the door to add support for many more annotations. Besides, iterating through the class hierarchy to identify all annotations and patch the properties names can be tricky.
Multiple alternatives come to mind:
- Get support for the
@SerialName
annotation in swagger itself. - Create some kind of meta-annotation/code-generation/compiler plugin that adds for each
@SerialName
annotation the swagger@JsonProperty
/@Schema
annotation.
Do you have a simple solution in mind?
Agree, I was thinking about maybe something like a Swagger ModelConverter that supports the annotation.
I found this old ticket in SpringDoc which we may use as reference: https://github.com/springdoc/springdoc-openapi/issues/1226
Awesome, Springwolf does support the ModelConverter
mechanism. Just create a bean in the spring context (example: MonetaryAmountConverter
within the add-ons package)
The class in the linked GH comment has quite high complexity and I am unsure about creating a Springwolf plugin at this point, which will require maintenance. Adding it to Springwolf raises the expectation that the full implementation is tested and works as expected - including resolving issues.
Still, you can add the class to your project.
I am open to re-consider adding it to springwolf, if more people request it.
Thank you @ctasada for the contribution. It is released now.
As discussed, we mark it as beta for now. Feel free to update the documentation - as this becomes stable - to share the effort you put into it to better support Kotlin.
https://github.com/springwolf/springwolf.github.io/blob/master/docs