swagger icon indicating copy to clipboard operation
swagger copied to clipboard

Nullable Enum not generated as nullable

Open jbdemonte opened this issue 2 years ago • 0 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Current behavior

Using the following annotation:

export class ClientResponseDto {
  @Expose()
  @ApiProperty({ enum: PaymentTermsEnum, enumName: 'PaymentTermsEnum', nullable: true })
  paymentTerms!: PaymentTermsEnum | null;

}

openapi-generator 5.4 generates:

export interface GetClientByIdResponseDto { 
    paymentTerms: PaymentTermsEnum;

I need to use the following workaround to get it nullable:

export class ClientResponseDto {
  @Expose()
  @ApiProperty({ oneOf: [{ type: 'enum', $ref: 'PaymentTermsEnum', nullable: true }] })
  paymentTerms!: PaymentTermsEnum | null;
}

=>


export interface GetClientByIdResponseDto {
    paymentTerms: PaymentTermsEnum | null;
}

Minimum reproduction code

https://github.com/jbdemonte/issue-nestjs-openapi-generator-nullable-enum

Steps to reproduce

  1. npm install
  2. npm run generate:angular-client

Expected behavior

the exported value type should be value!: FooBarEnum | null;

Package version

5.2.1

NestJS version

8.4.4

Node.js version

16.13.1

In which operating systems have you tested?

  • [X] macOS
  • [ ] Windows
  • [ ] Linux

Other

No response

jbdemonte avatar Apr 13 '22 10:04 jbdemonte