Skip to content

Conversation

@anshchaturvedi
Copy link
Contributor

@anshchaturvedi anshchaturvedi commented Jul 23, 2024

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 A type with different I types. For example, a value intended as a boolean at runtime might be passed into the API as a boolean (true or false), a string ("true" or "false"), or even a number (0 or 1). Currently, dev-portal displays 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 a boolean (typed as t.boolean), we should simplify this by presenting only the primitive boolean type.

Solution:
We propose the following criteria for consolidating union schemas into a single primitive type:

  1. The input (I) type is a union.
  2. The runtime (A) type is a primitive type (specifically, string, number, or boolean).
  3. The A type exists literally within the I type.

To support this, we need to address two aspects that are not currently available:

  1. Identifying Primitive Types:
    Add a primitive property to the schema type to identify primitive io-ts codecs.

  2. Determining Intermediate Types:
    Add a decodedType property (name can be revised) to the schema type. This will specify the runtime type of codecs like BooleanFromString or NumberFromString, enabling us to determine if a union containing these codecs can be consolidated into a single primitive type.

Ticket: DX-614

@anshchaturvedi anshchaturvedi force-pushed the DX-614-consolidation-of-unions branch from ce0bc6a to c35e63c Compare July 23, 2024 16:42
@anshchaturvedi anshchaturvedi force-pushed the DX-614-consolidation-of-unions branch 2 times, most recently from 33370f3 to 310b0f8 Compare July 23, 2024 21:28
@anshchaturvedi anshchaturvedi marked this pull request as ready for review July 23, 2024 21:31
@anshchaturvedi anshchaturvedi requested review from a team as code owners July 23, 2024 21:31
@anshchaturvedi anshchaturvedi force-pushed the DX-614-consolidation-of-unions branch from 310b0f8 to 8d610ad Compare July 23, 2024 21:33
>;

export type Schema = BaseSchema & HasComment & SchemaMetadata;
type ExtendedSchemaMetadata = SchemaMetadata & {
Copy link
Contributor

@ad-world ad-world Jul 24, 2024

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!

@bitgopatmcl bitgopatmcl merged commit 9d4fa83 into master Jul 24, 2024
@bitgopatmcl bitgopatmcl deleted the DX-614-consolidation-of-unions branch July 24, 2024 17:31
@github-actions
Copy link

🎉 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 📦🚀

@github-actions
Copy link

github-actions bot commented Aug 5, 2024

🎉 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 📦🚀

@github-actions
Copy link

github-actions bot commented Aug 5, 2024

🎉 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 📦🚀

@github-actions
Copy link

github-actions bot commented Aug 5, 2024

🎉 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 📦🚀

@github-actions
Copy link

github-actions bot commented Aug 5, 2024

🎉 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 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants