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

Support additionalProperties index definition

Open adamduren opened this issue 6 years ago • 4 comments

Is it possible to support a custom index definition for additionalProperties?

Currently the output is: [k: string]: MyInterface. It would be beneficial if it could be customized like so [k in MyEnum]: MyInterface for stricter typing.

adamduren avatar Jan 16 '19 20:01 adamduren

This is a neat idea, but I don't think it jives with the specification.

https://json-schema.org/latest/json-schema-validation.html#rfc.section.6.4.2

Do you have a specific use case, and a proposal for how we could extend JSON-Schema to support this?

bcherny avatar Feb 04 '19 07:02 bcherny

@bcherny Thanks for the response. The link provided in for additionalItems vs additionalProperties but the gist appears to be the same. Would you prefer to close this or leave it open? I'm good either way.

Since enums are finite I should list all of the properties in my enum. If validation that all enum properties are accounted for that could be achieved in a pre-processing script with a mapping of what objects should enumerate which enums.

adamduren avatar Mar 13 '19 14:03 adamduren

Is this a use-case for custom properties when using additionalProperties?

additionalProperties:
  type: string
  tsPropertyEnumType: MyEnum

This would result in:

[k in MyEnum]: string

I'm trying to re-use enum (string union) as my property type. My work around was to just add the properties manually.

jgornick avatar Jul 28 '21 02:07 jgornick