-
Notifications
You must be signed in to change notification settings - Fork 22
feat: allow unions to consolidate into single primitive types #842
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
Conversation
ce0bc6a to
c35e63c
Compare
33370f3 to
310b0f8
Compare
310b0f8 to
8d610ad
Compare
| >; | ||
|
|
||
| export type Schema = BaseSchema & HasComment & SchemaMetadata; | ||
| type ExtendedSchemaMetadata = SchemaMetadata & { |
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.
nit: maybe rename this SchemaUtil or something else descriptive that doesn't include Metadata since we use the term metadata to describe the OpenAPI tags in this file, where as these fields are used for something else!
|
🎉 This PR is included in version @api-ts/openapi-generator@4.23.0 🎉 The release is available on npm package (@latest dist-tag) Your semantic-release bot 📦🚀 |
|
🎉 This PR is included in version @api-ts/express-wrapper@1.0.28 🎉 The release is available on npm package (@latest dist-tag) Your semantic-release bot 📦🚀 |
|
🎉 This PR is included in version @api-ts/typed-express-router@1.1.8 🎉 The release is available on npm package (@latest dist-tag) Your semantic-release bot 📦🚀 |
|
🎉 This PR is included in version @api-ts/superagent-wrapper@1.2.3 🎉 The release is available on npm package (@latest dist-tag) Your semantic-release bot 📦🚀 |
|
🎉 This PR is included in version @api-ts/io-ts-http@3.1.0 🎉 The release is available on npm package (@latest dist-tag) Your semantic-release bot 📦🚀 |
This PR aims to introduce a union-consolidation step, where we can simplify union schemas if they meet certain conditions.
Motivation:
We have encountered multiple codecs that type the same
Atype with differentItypes. For example, a value intended as abooleanat runtime might be passed into the API as aboolean(trueorfalse), astring("true"or"false"), or even anumber(0or1). Currently,dev-portaldisplays all these options as valid ways to pass a boolean to the API. However, this can be overwhelming and unnecessary for clients. If the API ultimately expects aboolean(typed ast.boolean), we should simplify this by presenting only the primitivebooleantype.Solution:
We propose the following criteria for consolidating union schemas into a single primitive type:
I) type is a union.A) type is a primitive type (specifically,string,number, orboolean).Atype exists literally within theItype.To support this, we need to address two aspects that are not currently available:
Identifying Primitive Types:
Add a
primitiveproperty to theschematype to identify primitiveio-tscodecs.Determining Intermediate Types:
Add a
decodedTypeproperty (name can be revised) to theschematype. This will specify the runtime type of codecs likeBooleanFromStringorNumberFromString, enabling us to determine if a union containing these codecs can be consolidated into a single primitive type.Ticket: DX-614