Skip to content

Commit

Permalink
Upgrade to latest spec: disallow nullable mappings (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
ucarion committed Apr 4, 2020
1 parent ee8609f commit 5b8f0f6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion json-typedef-spec
12 changes: 8 additions & 4 deletions src/schema.ts
Expand Up @@ -171,6 +171,10 @@ export function isValidSchema(schema: Schema, root?: Schema): boolean {
return false;
}

if (subSchema.nullable) {
return false;
}

if (schema.discriminator in (subSchema.properties || {})) {
return false;
}
Expand Down Expand Up @@ -214,7 +218,7 @@ const VALID_FORMS = [
// Values form
[false, false, false, false, false, false, false, true, false, false],
// Discriminator form
[false, false, false, false, false, false, false, false, true, true]
[false, false, false, false, false, false, false, false, true, true],
];

// List of valid values that the "type" keyboard may take on.
Expand All @@ -229,7 +233,7 @@ const VALID_TYPES = [
"int32",
"uint32",
"string",
"timestamp"
"timestamp",
];

export function isSchema(data: unknown): data is Schema {
Expand Down Expand Up @@ -271,7 +275,7 @@ export function isSchema(data: unknown): data is Schema {
additionalProperties !== undefined,
values !== undefined,
discriminator !== undefined,
mapping !== undefined
mapping !== undefined,
];

let formOk = false;
Expand Down Expand Up @@ -334,7 +338,7 @@ export function isSchema(data: unknown): data is Schema {
return false;
}

if (!enum_.every(elem => typeof elem === "string")) {
if (!enum_.every((elem) => typeof elem === "string")) {
return false;
}
}
Expand Down

0 comments on commit 5b8f0f6

Please sign in to comment.