feat: map kotlinx-datetime classes to date-time#47
feat: map kotlinx-datetime classes to date-time#47slanos wants to merge 3 commits intotabilzad:masterfrom
Conversation
tabilzad
left a comment
There was a problem hiding this comment.
A couple of things to think about.
- Kotlin data related serializers are configured to produce a general ISO-8601 while the OpenAPI
date-timespec assumes RFC-3339 which is a specific subset of ISO-8601. https://ijmacd.github.io/rfc3339-iso8601. - Support for custom serializers
- KtorFieldDescription annotation already allows to override or set the format explicitly, so in case the, now default, behavior of using
date-timeis not desired - it can be overridden. But we should probably think if it'd be helpful to override the default globally instead of annotating every property.
- KtorFieldDescription annotation already allows to override or set the format explicitly, so in case the, now default, behavior of using
| OpenApiSpec.SchemaType( | ||
| type = kotlinType.toString().toSwaggerType() | ||
| ) | ||
| } else if (kotlinType?.lookupTagIfAny?.name?.asString() == "Instant" || |
There was a problem hiding this comment.
Instead of comparing simple names, we should compare fully qualified package path with the name. So let's define the corresponding fq names in ClassIds.kt similar to others. Then we could just compare kotlinType.classId
There was a problem hiding this comment.
also we're adding this explicit check here for when the whole response body in just an instant or date but the same case for request body is not handled.
There was a problem hiding this comment.
Ahh I can add a test that validates request body works the same as well, good call.
| fqClassName == "kotlinx.datetime.LocalDateTime" || | ||
| fqClassName == "java.time.Instant" | ||
| } | ||
|
|
There was a problem hiding this comment.
Same for all of the above, re: use classId's
There was a problem hiding this comment.
also you could probably re-use this method in the resolveToOpenSpecFormat for consistency.
There was a problem hiding this comment.
There is also java.time.LocalDateTime
There was a problem hiding this comment.
I think there should actually be seperate mappings, but im not sure what the specs map to.. anyway LocalDate is a date object, and Instant is a datetime object, which are both strings with different string formats per the spec: https://swagger.io/docs/specification/v3_0/data-models/data-types/#strings
This is to address what I brought up here: #46
The only issue I foresee is with
LocalDateTimeas it doesn't include a timezone by default 🤷I've added tests that verify the generated output matches this:
So that we don't include unnecessary kotlinx-datetime stuff in our openapi specs 😄