-
Notifications
You must be signed in to change notification settings - Fork 8
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
feat: map kotlinx-datetime classes to date-time #47
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of things to think about.
- Kotlin data related serializers are configured to produce a general ISO-8601 while the OpenAPI
date-time
spec 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-time
is 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
@@ -383,6 +383,12 @@ internal class ExpressionsVisitorK2( | |||
OpenApiSpec.SchemaType( | |||
type = kotlinType.toString().toSwaggerType() | |||
) | |||
} else if (kotlinType?.lookupTagIfAny?.name?.asString() == "Instant" || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for all of the above, re: use classId's
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also you could probably re-use this method in the resolveToOpenSpecFormat
for consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is also java.time.LocalDateTime
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
LocalDateTime
as 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 😄