ts-generator icon indicating copy to clipboard operation
ts-generator copied to clipboard

Feature Request: ability to annotate integer fields

Open davidmoshal opened this issue 5 years ago • 1 comments

Goal: convey the concept of an integer to typescript, given that typescript doesn't have this concept, using JSON Schema.

Given Kotlin classes, we generate 2 files:

  1. Typescript using ts-generator.
  2. JSON Schema from that typescript using typescript-json-schema.

Then at runtime, we can validate any JSON object against the schema using ajv. This works fine.

Now the question of integers.

Given:

export interface Shape {
    /**
     * @minimum 0
     * @TJS-type integer
     */
    size: number;
}

Then:

  • typescript-json-schema can create the correct JSON Schema, and
  • ajv can validate it.

So, the questions are these:

  • is there a way for ts-generator to add // @TJS-type integer to the generated typescript number?
  • is there a way to decorate an integer such that it also outputs // @minimum 0?

If not, then one way around this I guess would be to use a special kotlin class for these integer types, which is manually edited one-time in the schema, but that seems a bit clunky, especially in a CI context.

davidmoshal avatar Apr 18 '20 06:04 davidmoshal

Maybe you could add this feature by using annotations, that way there is no need to use special classes.

ntrrgc avatar Apr 20 '20 13:04 ntrrgc