Skip to content

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

@LsKoder

Description

@LsKoder

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions