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

Support for Kotlin Uuid #98

Open
perracodex opened this issue Sep 15, 2024 · 2 comments
Open

Support for Kotlin Uuid #98

perracodex opened this issue Sep 15, 2024 · 2 comments

Comments

@perracodex
Copy link

Kotlin 2.0.20 has introduced Uuid support in the standard library.
In addition, kotlinx.serialization also has been updated in version 1.7.2 to handle the Uuid type.

Issue:
When using the Uuid type with Tegral OpenAPI, it generates the next output:

"id": {
  "mostSignificantBits": 0,
  "leastSignificantBits": 0
}

Instead, of the expected:

id:   
  type: "string"   
  format: "uuid"

Sample usage:

"id" pathParameter {
        description = "Path parameter"
        schema<Uuid>()
 }
@utybo
Copy link
Owner

utybo commented Sep 15, 2024

Tegral OpenAPI uses Swagger Core under the hood, which in turn uses Jackson. Since Kotlin's UUID is not supported at all in Jackson (it's not even supported in the Kotlin-specific module apparently), I think the best way to do this is:

  • Create a custom serializer for Kotlin's UUID (likely to be very similar to Jackson's handling for Java's UUID)
  • Add it in the mapper used internally by Swagger Core. Not 100% sure how this is done but it shouldn't be too bad.

@perracodex
Copy link
Author

perracodex commented Sep 17, 2024

Does the Tegral OpenAPI have access to the final generated OpenApi file? If so, before serving it, it could do a workaround by searching in the schema for Uuid and changing it before it is served. As this is part of the schema, it would have to replace it only once.

So:

    Uuid:
      type: "object"
      properties:
        mostSignificantBits:
          type: "integer"
          format: "int64"
        leastSignificantBits:
          type: "integer"
          format: "int64"

should be replaced by:

    Uuid:
      type: "string"
      format: "uuid"

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

No branches or pull requests

2 participants