Skip to content

Commit d7a7ea4

Browse files
authored
Fix tuple handling (maxItems vs. additionalItems) (YousefED#397)
1 parent ddeabea commit d7a7ea4

File tree

4 files changed

+8
-31
lines changed

4 files changed

+8
-31
lines changed

Diff for: test/programs/type-aliases-fixed-size-array/schema.json

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
{
22
"$schema": "http://json-schema.org/draft-07/schema#",
3-
"additionalItems": {
4-
"anyOf": [
5-
{
6-
"type": "string"
7-
},
8-
{
9-
"type": "number"
10-
}
11-
]
12-
},
133
"items": [
144
{
155
"type": "string"
@@ -18,6 +8,7 @@
188
"type": "number"
199
}
2010
],
11+
"maxItems": 2,
2112
"minItems": 2,
2213
"type": "array"
2314
}

Diff for: test/programs/type-aliases-tuple-of-variable-length/schema.json

+1-13
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,6 @@
1212
"type": "boolean"
1313
}
1414
],
15-
"additionalItems": {
16-
"anyOf": [
17-
{
18-
"type": "string"
19-
},
20-
{
21-
"type": "number"
22-
},
23-
{
24-
"type": "boolean"
25-
}
26-
]
27-
},
15+
"maxItems": 3,
2816
"minItems": 2
2917
}

Diff for: test/schema.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ describe("schema", () => {
201201
aliasRef: true,
202202
topRef: false,
203203
});
204-
// disabled beacuse of #80
204+
// disabled because of #80
205205
// assertSchema("type-aliases-alias-ref-topref", "MyAlias", {
206206
// useTypeAliasRef: true,
207207
// useRootRef: true
@@ -210,7 +210,7 @@ describe("schema", () => {
210210
aliasRef: true,
211211
topRef: true,
212212
});
213-
// disabled beacuse of #80
213+
// disabled because of #80
214214
// assertSchema("type-aliases-recursive-alias-topref", "MyAlias", {
215215
// useTypeAliasRef: true,
216216
// useRootRef: true

Diff for: typescript-json-schema.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export interface Definition extends Omit<JSONSchema7, RedefinedFields> {
9696
defaultProperties?: string[];
9797
typeof?: "function";
9898

99-
// Fields that must be redifined because they make use of this definition itself
99+
// Fields that must be redefined because they make use of this definition itself
100100
items?: DefinitionOrBoolean | DefinitionOrBoolean[];
101101
additionalItems?: DefinitionOrBoolean;
102102
contains?: JSONSchema7;
@@ -547,9 +547,7 @@ export class JsonSchemaGenerator {
547547
definition.additionalItems = fixedTypes[fixedTypes.length - 1];
548548
fixedTypes.splice(fixedTypes.length - 1, 1);
549549
} else {
550-
definition.additionalItems = {
551-
anyOf: fixedTypes,
552-
};
550+
definition.maxItems = targetTupleType.fixedLength;
553551
}
554552
} else {
555553
const propertyTypeString = this.tc.typeToString(
@@ -722,7 +720,7 @@ export class JsonSchemaGenerator {
722720
// node
723721
const exp = (<any>initial).expression;
724722
const text = (<any>exp).text;
725-
// if it is an expression with a text literal, chances are it is the enum convension:
723+
// if it is an expression with a text literal, chances are it is the enum convention:
726724
// CASELABEL = 'literal' as any
727725
if (text) {
728726
enumValues.push(text);
@@ -1429,7 +1427,7 @@ export function buildGenerator(
14291427
}
14301428
return onlyIncludeFiles.indexOf(file.fileName) >= 0;
14311429
}
1432-
// Use defaults unles otherwise specified
1430+
// Use defaults unless otherwise specified
14331431
const settings = getDefaultArgs();
14341432

14351433
for (const pref in args) {

0 commit comments

Comments
 (0)