Skip to content

Commit

Permalink
Fix tuple handling (maxItems vs. additionalItems) (#397)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshkel authored Jan 1, 2021
1 parent ddeabea commit d7a7ea4
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 31 deletions.
11 changes: 1 addition & 10 deletions test/programs/type-aliases-fixed-size-array/schema.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalItems": {
"anyOf": [
{
"type": "string"
},
{
"type": "number"
}
]
},
"items": [
{
"type": "string"
Expand All @@ -18,6 +8,7 @@
"type": "number"
}
],
"maxItems": 2,
"minItems": 2,
"type": "array"
}
Expand Down
14 changes: 1 addition & 13 deletions test/programs/type-aliases-tuple-of-variable-length/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,6 @@
"type": "boolean"
}
],
"additionalItems": {
"anyOf": [
{
"type": "string"
},
{
"type": "number"
},
{
"type": "boolean"
}
]
},
"maxItems": 3,
"minItems": 2
}
4 changes: 2 additions & 2 deletions test/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ describe("schema", () => {
aliasRef: true,
topRef: false,
});
// disabled beacuse of #80
// disabled because of #80
// assertSchema("type-aliases-alias-ref-topref", "MyAlias", {
// useTypeAliasRef: true,
// useRootRef: true
Expand All @@ -210,7 +210,7 @@ describe("schema", () => {
aliasRef: true,
topRef: true,
});
// disabled beacuse of #80
// disabled because of #80
// assertSchema("type-aliases-recursive-alias-topref", "MyAlias", {
// useTypeAliasRef: true,
// useRootRef: true
Expand Down
10 changes: 4 additions & 6 deletions typescript-json-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export interface Definition extends Omit<JSONSchema7, RedefinedFields> {
defaultProperties?: string[];
typeof?: "function";

// Fields that must be redifined because they make use of this definition itself
// Fields that must be redefined because they make use of this definition itself
items?: DefinitionOrBoolean | DefinitionOrBoolean[];
additionalItems?: DefinitionOrBoolean;
contains?: JSONSchema7;
Expand Down Expand Up @@ -547,9 +547,7 @@ export class JsonSchemaGenerator {
definition.additionalItems = fixedTypes[fixedTypes.length - 1];
fixedTypes.splice(fixedTypes.length - 1, 1);
} else {
definition.additionalItems = {
anyOf: fixedTypes,
};
definition.maxItems = targetTupleType.fixedLength;
}
} else {
const propertyTypeString = this.tc.typeToString(
Expand Down Expand Up @@ -722,7 +720,7 @@ export class JsonSchemaGenerator {
// node
const exp = (<any>initial).expression;
const text = (<any>exp).text;
// if it is an expression with a text literal, chances are it is the enum convension:
// if it is an expression with a text literal, chances are it is the enum convention:
// CASELABEL = 'literal' as any
if (text) {
enumValues.push(text);
Expand Down Expand Up @@ -1429,7 +1427,7 @@ export function buildGenerator(
}
return onlyIncludeFiles.indexOf(file.fileName) >= 0;
}
// Use defaults unles otherwise specified
// Use defaults unless otherwise specified
const settings = getDefaultArgs();

for (const pref in args) {
Expand Down

0 comments on commit d7a7ea4

Please sign in to comment.