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

Problem after using ver 7 with generated types for mapping of discriminator #1737

Open
1 task
nenadfspartans opened this issue Jun 28, 2024 · 2 comments
Open
1 task
Labels
bug Something isn't working openapi-ts Relevant to the openapi-typescript library

Comments

@nenadfspartans
Copy link

Description

This was working before ver 7 and it creates working code for my usecase.

This is what creates problem for me:

This is request body that can accept one of these options.

schema:
              oneOf:
                - $ref: '#/components/schemas/Model1'
                - $ref: '#/components/schemas/Model2'
              discriminator:
                propertyName: template
                mapping:
                  model1: '#/components/schemas/Model1'
                  model2: '#/components/schemas/Model2'

Here we define descriminator, redocly populates last 2 rows of mapping, it was not problem with 6.7.0

Document:
      type: object
      properties:
        template:
          $ref: '#/components/schemas/TemplateField'
      discriminator:
        propertyName: template
        mapping:
          model2: '#/components/schemas/Model2'
          model1: '#/components/schemas/Model1'
          Model1: '#/components/schemas/Model1'
          Model2: '#/components/schemas/Model2'

Generated code with v6.7.0, perfectly fine for my needs.

 Model1: {
      template: "model1";
    } & Omit<components["schemas"]["Document"], "template"> & {
      data: {
        page: number;
        batch: {
          sku: string;
          name: string;
        };
        totalPages: number;
        images: components["schemas"]["ImageUrlObject"][];
      };
    };

Generated code with v7.0.0

Model1: Omit<components["schemas"]["Document"], "template"> & {
            data: {
                page: number;
                batch: {
                    sku: string;
                    name: string;
                };
                totalPages: number;
                images: components["schemas"]["ImageUrlObject"][];
            };
        } & {
            /**
             * @description discriminator enum property added by openapi-typescript
             * @enum {string}
             */
            template: "model1";
        } & {
            /**
             * @description discriminator enum property added by openapi-typescript
             * @enum {string}
             */
            template: "model2" | "Model1";
        };

Thanks!

Checklist

@nenadfspartans nenadfspartans added bug Something isn't working openapi-ts Relevant to the openapi-typescript library labels Jun 28, 2024
@mzronek
Copy link
Contributor

mzronek commented Jun 28, 2024

Your bug report is not complete. Please provide a minimum example with all necessary schemas. In your case the models are missing.

@nenadfspartans
Copy link
Author

probably duplicate of #1700

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working openapi-ts Relevant to the openapi-typescript library
Projects
None yet
Development

No branches or pull requests

2 participants