-
-
Notifications
You must be signed in to change notification settings - Fork 72
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
Give format precendence over type property #831
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 9702e76:
|
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.
@stijnvanhulle RFC
// 7.3.1. Dates, Times, and Duration | ||
case 'date-time': | ||
case 'date': | ||
case 'time': |
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.
actually, im not sure if time
should really be cast a Date
. Maybe number
instead?
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.
We have dateType
which can now be a date or a string so maybe we can also add number if that would be needed for other users.
return factory.createTypeReferenceNode(factory.createIdentifier('Date')) | ||
} | ||
case 'uuid': | ||
// TODO how to work with this? use https://www.npmjs.com/package/uuid for it? |
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.
Currently, uuid
would be ignored like all the others, although it would made sense to make it an uuid
, but this would require a custom task or a dependency uuid
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.
In the end, it will be a string
, Typescript does not have a type uuid so I don't think we need to change something here for the ts plugin.
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.
The thing is, the cases added here are directly from the openapi spec. That's why I added them here, too.
But I'll remove unsupported cases if you like.
Imo, being able to map to a specific type is very convinient. But kubb itself should add as little runtime dependencies as possible. Hence, uuid support via @types/uuid
and uuid
would be a great use case for a kubb plugin? Is that already possible with plugins, then I might give them a try.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #831 +/- ##
==========================================
+ Coverage 75.97% 76.10% +0.13%
==========================================
Files 135 135
Lines 12690 12739 +49
Branches 1392 1412 +20
==========================================
+ Hits 9641 9695 +54
+ Misses 3038 3033 -5
Partials 11 11 ☔ View full report in Codecov by Sentry. |
How to work with format: uuid?
Should the format only be used for schema.type === "string", or shall it stay above those?
is this a minor or a breaking change? Without activation flag, I would argue for breaking.
Should this PR also trickle into downstream packages like zod or swr?
|
I'm also interesting in correct generation to properties:
file:
type: string
format: binary @stijnvanhulle What I can use as workaround for now? |
Moved to #935 |
Equal to #777 but rebased on current kubb main branch.
Observation
The JSON schema spec suggests that the
format
keyword has a higher specificity than thetype
keyword, sinceformat
it provides information about the contents of the schema at hand.Prior this PR, the
format
property would only be used by kubb iff thetype
property is not known. However, this prevents theformat
property to be used in most cases (except fordate
, anddate-time
).For example
a plain file upload
leads to a
although a
Blob
oderFormData
would be more helpful in many cases.Goals
This PR enables
format
to "overrule"type
and therefore generalizes the ad hoc approach that was begundate
anddate-time
format parsing.Open questions:
However, some changes are still open for discussion, since they might involve inclusion of further dependencies (e.g. uuid validation).
format: uuid
?format
only be used forschema.type === "string"
, or shall it stay above those?