Skip to content
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

Add support for Kotlin Serialization #589

Closed
ctasada opened this issue Feb 6, 2024 · 4 comments
Closed

Add support for Kotlin Serialization #589

ctasada opened this issue Feb 6, 2024 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@ctasada
Copy link
Collaborator

ctasada commented Feb 6, 2024

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.

@ctasada ctasada added the enhancement New feature or request label Feb 6, 2024
@timonback
Copy link
Member

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:

  1. Get support for the @SerialName annotation in swagger itself.
  2. 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?

@ctasada
Copy link
Collaborator Author

ctasada commented Feb 9, 2024

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: springdoc/springdoc-openapi#1226

@timonback
Copy link
Member

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.

@timonback
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants