YousefED / typescript-json-schema

Generate json-schema from your Typescript sources
BSD 3-Clause "New" or "Revised" License
3.14k stars 322 forks source link

How do I produce an integer enum? #581

Closed samuelcolvin closed 9 months ago

samuelcolvin commented 9 months ago

Great library, thank you so much

I have the following interface

export interface HeadingProps {
  level: 1 | 2 | 3 | 4 | 5 | 6
  text: string
}

And for the level property, I'd like to produce the schema "level": {"enum": [1, 2, 3, 4, 5, 6], "type": "integer"}.

However no combination of @TJS-type and @enum gives me what I need - adding @TJS-type removes the enum key, and setting @enum won't change type.

How should I do this?

samuelcolvin commented 9 months ago

sorry for the noise, got it to work with this:


export interface HeadingProps {
  /**
   * @TJS-enum [1, 2, 3, 4, 5, 6]
   * @TJS-type integer
   */
  level: 1 | 2 | 3 | 4 | 5 | 6
  text: string
}