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

Support minLength=0 on Yaml->Ts generator #323

Open
LsKoder opened this issue Oct 13, 2023 · 0 comments
Open

Support minLength=0 on Yaml->Ts generator #323

LsKoder opened this issue Oct 13, 2023 · 0 comments

Comments

@LsKoder
Copy link

LsKoder commented Oct 13, 2023

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

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

1 participant