`strictIndexSignatures` option is ignored for single pattern properties
Opened this issue · 0 comments
yorinasub17 commented
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:
json-schema-to-typescript/src/parser.ts
Lines 407 to 427 in c826963
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:
json-schema-to-typescript/src/generator.ts
Lines 156 to 158 in c826963
I attempted a fix in this PR, here: #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;
}