Skip to content
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

in union types use the given variant name if available #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

anisometropie
Copy link

In a discriminated union, use the provided variant name instead of the schema`s name. use the Schema’s name only if it’s not provided.

For example, here the variant name standard is given, and is used instead of the schema’s name StandardAllowance (which was previously used, and would result in invalid, empty type (because the string has to match discriminated union with

    Allowance:
      oneOf:
        - $ref: "#/components/schemas/EngineeringAllowance"
        - $ref: "#/components/schemas/StandardAllowance"
      discriminator:
        propertyName: allowance_type
    StandardAllowance:
      properties:
        allowance_type:
          type: string
          enum: ["standard"]

This now creates a valid discriminated union. The allowance_type field in the variants matches with the allowance_type in the discriminated unions :

export type EngineeringAllowance = {
  allowance_type?: 'engineering';
  distribution?: 'MARECO' | 'LINEAR';
  capacity_speed_limit?: number;
} & RangeAllowance;
export type StandardAllowance = {
  allowance_type?: 'standard';
  default_value?: AllowanceValue;
  ranges?: RangeAllowance[];
  distribution?: 'MARECO' | 'LINEAR';
  capacity_speed_limit?: number;
};
export type Allowance =
  | ({
      allowance_type: 'engineering';
    } & EngineeringAllowance)
  | ({
      allowance_type: 'standard';
    } & StandardAllowance);

fixes: reduxjs/redux-toolkit#3369

@anisometropie
Copy link
Author

Hello @msutkowski, could you review this ?

@evanjmg
Copy link

evanjmg commented Jan 2, 2024

Any update on this?

@phryneas
Copy link

phryneas commented Jan 2, 2024

This repo is just a clone, if you want to ask for features you have to do that upstream.
I believe this might already have been handled there?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants