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

[BUG] OASv3 schema generation fails when model used in @OneOf has kind property #2413

Closed
1 task
denis-maiorov-brightsec opened this issue Aug 21, 2023 · 4 comments · Fixed by #2424
Closed
1 task

Comments

@denis-maiorov-brightsec
Copy link

denis-maiorov-brightsec commented Aug 21, 2023

Information

  • Version: 7.34.3 — 7.34.6
  • Packages: @tsed/schema

Recent fix causes @OneOf to throw runtime error on swagger schema generation when one of the model properties name is kind

Example

export enum Discriminator {
  ONE = 'one',
  TWO = 'two',
}

export abstract class BaseModel {
  @Enum(Discriminator.ONE, Discriminator.TWO)
  @DiscriminatorKey()
  public type!: Discriminator.ONE | Discriminator.TWO;
}

@DiscriminatorValue(Discriminator.ONE)
export class FirstImpl extends BaseModel {
  public override type!: Discriminator.ONE;

  @Enum('json')
  public kind!: 'json';
}

@DiscriminatorValue(Discriminator.TWO)
export class SecondImpl extends BaseModel {
  public override type!: Discriminator.TWO;
  
  @Property()
  public prop!: string;
}

export class ParentModel {
  @OneOf(FirstImpl, SecondImpl)
  public test?:
    | FirstImpl
    | SecondImpl;
}

@Controller('/test')
@Docs('api-v2')
@Name('Test')
export class TestController {

  @Get()
  @Returns(200, Array).Of(ParentModel)
  public get(): Promise<ParentModel> {
    return;
  }
}

Trace

TypeError: input.entries is not a function
    at mapMapper (/Users/domayorov/brightsec/project/node_modules/@tsed/schema/src/components/mapMapper.ts:18:6)
    at execMapper (/Users/domayorov/brightsec/project/node_modules/@tsed/schema/src/registries/JsonSchemaMapperContainer.ts:35:35)
    at anyMapper (/Users/domayorov/brightsec/project/node_modules/@tsed/schema/src/components/anyMapper.ts:25:30)
    at execMapper (/Users/domayorov/brightsec/project/node_modules/@tsed/schema/src/registries/JsonSchemaMapperContainer.ts:35:35)
    at propertiesMapper (/Users/domayorov/brightsec/project/node_modules/@tsed/schema/src/components/propertiesMapper.ts:10:20)
    at execMapper (/Users/domayorov/brightsec/project/node_modules/@tsed/schema/src/registries/JsonSchemaMapperContainer.ts:35:35)
    at /Users/domayorov/brightsec/project/node_modules/@tsed/schema/src/components/schemaMapper.ts:95:27
    at Array.reduce (<anonymous>)

Acceptance criteria

  • Swagger generation works
@Romakita
Copy link
Collaborator

Romakita commented Sep 3, 2023

@denis-maiorov-brightsec Thanks for the detailed issue :D

The fix is almost done!

@github-actions
Copy link

github-actions bot commented Sep 3, 2023

🎉 Are you happy?

If you appreciated the support, know that it is free and is carried out on personal time ;)

A support, even a little bit makes a difference for me and continues to bring you answers!

github opencollective

@Romakita
Copy link
Collaborator

Romakita commented Sep 3, 2023

🎉 This issue has been resolved in version 7.34.8 🎉

The release is available on:

Your semantic-release bot 📦🚀

@Romakita
Copy link
Collaborator

Romakita commented Sep 6, 2023

🎉 This issue has been resolved in version 7.35.0-beta.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
2 participants