json-schema-to-typescript icon indicating copy to clipboard operation
json-schema-to-typescript copied to clipboard

Add option to prepend "readonly" to all fields

Open Bluscream opened this issue 1 year ago • 1 comments

This would be nice to ensure i don't accidentally try playing with values from responses but create my own local copy instead

Example:

start "" json2ts -i "schemas/pietsmiet.de/*.schema.json" -o "src/responses/pietsmiet.de/" --inferStringEnumKeysFromValues true --readonly true
export interface PietsmietDEConfig {
    readonly API: Record<string, Record<string, string>>;
    readonly URLs: Record<string, string>;
    readonly Limits: Record<string, number>;
    readonly Orders: Record<string, string>;
    readonly Platform: Record<string, string>;
    readonly Stream: Record<string, string>;
  }
...

Bluscream avatar Sep 02 '24 22:09 Bluscream

It would make sense to emit all types as readonly, gated behind a --readonly option.

bcherny avatar Sep 28 '24 18:09 bcherny