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

Self-generated API file with hard-coded "types" #611

Open
kmirojo opened this issue Apr 4, 2024 · 1 comment
Open

Self-generated API file with hard-coded "types" #611

kmirojo opened this issue Apr 4, 2024 · 1 comment

Comments

@kmirojo
Copy link
Contributor

kmirojo commented Apr 4, 2024

Hi everyone,
I'm generating an API typescript file from an Open API .yml file, but something is happening.
My .yml file looks like this:

components:
  schemas:
    ItemPropertiesBase:
      type: object
      properties:
        type:
          type: string

    ItemProperties:
      allOf:
        - $ref: '#/components/schemas/ItemPropertiesBase'
        - type: object
          properties:
            prop1:
              type: boolean
            prop2:
              type: number
            prop3:
              type: number

but when I generate the code, the type prop from the ItemPropertiesBase is hard-coded, even though I only assigned a type, but not a value:

export type ItemPropertiesBase = {
    "type": string;
};

export type ItemProperties = {
    "type": "ItemProperties"; 
} & ItemPropertiesBase & {
    prop1: boolean;
    prop2: number;
    prop3: number;
};

The issue with this is that I need the type to be a string, but not a specific value, because otherwise typescript won't allow me to have a different type,
Is there a way to change this?

@Xiphe
Copy link
Collaborator

Xiphe commented Apr 22, 2024

Hi @kmirojo

Seems as if you're running into compatibility issues with our "discriminating schemas" (see #422). Do you use a discriminator in one of your real-world types?

And can you please confirm, the expected outcome would be something along the lines of

export type ItemPropertiesBase = {
    "type": string;
};

export type ItemProperties = ItemPropertiesBase & {
    prop1: boolean;
    prop2: number;
    prop3: number;
};

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

No branches or pull requests

2 participants