openapi-codegen-ts icon indicating copy to clipboard operation
openapi-codegen-ts copied to clipboard

Support minLength=0 on Yaml->Ts generator

Open LsKoder opened this issue 2 years ago • 0 comments

Issue Description Yaml->Ts Generator miss minLength=0 from Yaml Def and generate wrong types (just string instead of WithinRangeString)

Current Behavior

Yaml Source:

EmptyString:
      type: string
      minLength: 0
      maxLength: 0

LimitedString:
      type: string
      minLength: 0
      maxLength: 4000

Ts Output:

export type EmptyString = t.TypeOf<typeof EmptyString>;
export const EmptyString = t.string;

export type LimitedString= t.TypeOf<typeof LimitedString>;
export const LimitedString= t.string;

Expected/Correct Behavior Ts Output:

export type EmptyString = t.TypeOf<typeof EmptyString>;
export const EmptyString = WithinRangeString(0, 1);

export type LimitedString= t.TypeOf<typeof LimitedString>;
export const LimitedString= WithinRangeString(0, 4001);

Solution: Into macros.njk file, change {% elif definition.minLength and definition.maxLength %} TO {% elif definition.minLength!==undefined and definition.maxLength!==undefined %} In this way, 0 value will be recognized and used

LsKoder avatar Oct 13 '23 09:10 LsKoder