Skip to content
Permalink
Browse files

Support stringified booleans in JSON Schema

  • Loading branch information...
schani committed Jul 11, 2018
1 parent 1dc8735 commit dcd2b2657a114cec5d5adbdd134e37b2c2678afd
Showing with 6 additions and 3 deletions.
  1. +3 −1 src/quicktype-core/StringTypes.ts
  2. +2 −1 src/quicktype-core/Type.ts
  3. +1 −1 test/fixtures.ts
@@ -185,7 +185,7 @@ function isIntegerString(s: string): boolean {
* @param s The string for which to determine the transformed string type kind.
*/
export function inferTransformedStringTypeKindForString(s: string): TransformedStringTypeKind | undefined {
if (s.length === 0 || "0123456789-".indexOf(s[0]) < 0) return undefined;
if (s.length === 0 || "0123456789-ft".indexOf(s[0]) < 0) return undefined;

if (isDate(s)) {
return "date";
@@ -195,6 +195,8 @@ export function inferTransformedStringTypeKindForString(s: string): TransformedS
return "date-time";
} else if (isIntegerString(s)) {
return "integer-string";
} else if (s === "false" || s === "true") {
return "bool-string";
}
return undefined;
}
@@ -51,7 +51,8 @@ export const transformedStringTypeTargetTypeKinds = {
date: { jsonSchema: "date", primitive: undefined },
time: { jsonSchema: "time", primitive: undefined },
"date-time": { jsonSchema: "date-time", primitive: undefined },
"integer-string": { jsonSchema: "integer", primitive: "integer" } as TransformedStringTypeTargets
"integer-string": { jsonSchema: "integer", primitive: "integer" } as TransformedStringTypeTargets,
"bool-string": { jsonSchema: "boolean", primitive: "bool" } as TransformedStringTypeTargets
};

export const transformedStringTypeTargetTypeKindsMap = mapFromObject(transformedStringTypeTargetTypeKinds as {
@@ -375,7 +375,7 @@ class JSONSchemaJSONFixture extends JSONToXToYFixture {
let input = JSON.parse(fs.readFileSync(filename, "utf8"));
let schema = JSON.parse(fs.readFileSync(this.language.output, "utf8"));

let ajv = new Ajv({ format: "full", unknownFormats: ["integer"] });
let ajv = new Ajv({ format: "full", unknownFormats: ["integer", "boolean"] });
// Make Ajv's date-time compatible with what we recognize. All non-standard
// JSON formats that we use for transformed type kinds must be registered here
// with a validation function.

0 comments on commit dcd2b26

Please sign in to comment.
You can’t perform that action at this time.