`strictIndexSignatures` option is ignored for single pattern properties
When generating for objects that have patternProperties with the strictIndexSignatures option, json-schema-to-typescript does not honor the strictIndexSignatures option.
I traced this down to this area of code:
https://github.com/bcherny/json-schema-to-typescript/blob/c82696300269e6de73818372b07d13a2f9ceeba7/src/parser.ts#L407-L427
Where it returns the keyName as [k: string] in the singlePatternProperty case but doesn't update the keyName property of the ast, which is used by the strictIndexSignatures routine:
https://github.com/bcherny/json-schema-to-typescript/blob/c82696300269e6de73818372b07d13a2f9ceeba7/src/generator.ts#L156-L158
I attempted a fix in this PR, here: https://github.com/bcherny/json-schema-to-typescript/pull/560
Example schema
{
"type": "object",
"properties": {
"maybe": {
"type": "string",
},
"pattern": {
"type": "object",
"properties": {
"maybe": {
"type": "string"
}
},
"patternProperties": {
"leaf|tree": {
"type": "array"
}
}
}
}
}
Expected output
export interface Experiment {
maybe?: string;
pattern?: {
maybe?: string;
/**
* This interface was referenced by `undefined`'s JSON-Schema definition
* via the `patternProperty` "leaf|tree".
*/
[k: string]: unknown[] | undefined;
};
[k: string]: unknown | undefined;
}
Actual output
export interface Experiment {
maybe?: string;
pattern?: {
maybe?: string;
/**
* This interface was referenced by `undefined`'s JSON-Schema definition
* via the `patternProperty` "leaf|tree".
*/
[k: string]: unknown[];
};
[k: string]: unknown | undefined;
}
Related
- https://github.com/bcherny/json-schema-to-typescript/issues/235
- https://github.com/bcherny/json-schema-to-typescript/issues/477