From 23d1531ff0bad559312db0a0d4ef4c9095386db0 Mon Sep 17 00:00:00 2001 From: Darcy Parker Date: Tue, 27 Sep 2016 08:07:06 -0400 Subject: [PATCH 1/6] Clean dist_tests before building tests --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5ac1ff78..7c835c3e 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "scripts": { "build": "npm run build-sources && npm test && npm run lint", "build-sources": "tsc -p ./tsconfig.json", - "build-tests": "tsc -p ./tsconfig.test.json", + "build-tests": "rm -rf ./dist_tests && tsc -p ./tsconfig.test.json", "watch": "tsc -p ./tsconfig.json --watch && tsc -p ./tsconfig.test.json --watch", "lint": "tslint -c tslint.json src/*.ts", "test": "npm run build-tests && ava", From 3cf83729baa0756635931280f8c371d1667a8a81 Mon Sep 17 00:00:00 2001 From: Darcy Parker Date: Tue, 27 Sep 2016 08:21:34 -0400 Subject: [PATCH 2/6] Use single quote literals in output to satisfy tslint rule --- src/TsTypes.ts | 8 +++++++- test/cases/anyOf.ts | 2 +- test/cases/enum.ts | 13 +++++++++---- test/cases/json-schema.ts | 4 ++-- test/cases/root-anyOf.ts | 2 +- 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/TsTypes.ts b/src/TsTypes.ts index 96008c9b..df20901f 100644 --- a/src/TsTypes.ts +++ b/src/TsTypes.ts @@ -103,7 +103,13 @@ export namespace TsType { export class Literal extends TsTypeBase { constructor(private value: any) { super() } _type() { - return JSON.stringify(this.value) + // if Literal is a string, format result with single quoted string literals + var stringValue = JSON.stringify(this.value) + const lastPos = stringValue.length - 1 + if (stringValue.charAt(0) === '"' && stringValue.charAt(lastPos) === '"') { + stringValue = `'${stringValue.substring(1, lastPos).replace(/'/g,'\\\'')}'` + } + return stringValue } } diff --git a/test/cases/anyOf.ts b/test/cases/anyOf.ts index 0037817d..de8f1f9c 100644 --- a/test/cases/anyOf.ts +++ b/test/cases/anyOf.ts @@ -41,7 +41,7 @@ export var types = `export interface Foo { b?: number; } export interface Bar { - a?: "a" | "b" | "c"; + a?: 'a' | 'b' | 'c'; [k: string]: any; } export interface Baz { diff --git a/test/cases/enum.ts b/test/cases/enum.ts index 9cfab1ce..b4f7d678 100644 --- a/test/cases/enum.ts +++ b/test/cases/enum.ts @@ -9,6 +9,10 @@ export var schema = { "impliedStringEnum": { "enum": ["a", "b", "c"] }, + "literalWithSingleQuote": { + "type": "string", + "enum": ["Some 'string' with inner single quote", "b", "c"] + }, "booleanEnum": { "type" : "boolean", "enum": [ true ] @@ -40,7 +44,7 @@ export var schema = { "enum": [-20.1, null, "foo", false] } }, - "required": ["stringEnum", "impliedStringEnum", "booleanEnum", "impliedBooleanEnum", "integerEnum", "impliedIntegerEnum", "impliedNamedIntegerEnum"], + "required": ["stringEnum", "impliedStringEnum", "literalWithSingleQuote", "booleanEnum", "impliedBooleanEnum", "integerEnum", "impliedIntegerEnum", "impliedNamedIntegerEnum"], "additionalProperties": false } @@ -61,8 +65,9 @@ export${useConstEnums ? ' const ' : ' '}enum ImpliedNamedIntegerEnum { Six = 6 } export interface Enum { - stringEnum: "a" | "b" | "c"; - impliedStringEnum: "a" | "b" | "c"; + stringEnum: 'a' | 'b' | 'c'; + impliedStringEnum: 'a' | 'b' | 'c'; + literalWithSingleQuote: 'Some \\\'string\\\' with inner single quote' | 'b' | 'c'; booleanEnum: true; impliedBooleanEnum: true; integerEnum: -1 | 0 | 1; @@ -70,7 +75,7 @@ export interface Enum { numberEnum?: -1.1 | 0 | 1.2; namedIntegerEnum?: NamedIntegerEnum; impliedNamedIntegerEnum: ImpliedNamedIntegerEnum; - impliedHeterogeneousEnum?: -20.1 | null | "foo" | false; + impliedHeterogeneousEnum?: -20.1 | null | 'foo' | false; }` } }) diff --git a/test/cases/json-schema.ts b/test/cases/json-schema.ts index 63af3f4b..86e465f3 100644 --- a/test/cases/json-schema.ts +++ b/test/cases/json-schema.ts @@ -158,7 +158,7 @@ export var configurations = [ export type PositiveIntegerDefault0 = PositiveInteger; export type SchemaArray = HttpJsonSchemaOrgDraft04Schema[]; export type StringArray = string[]; -export type SimpleTypes = "array" | "boolean" | "integer" | "null" | "number" | "object" | "string"; +export type SimpleTypes = 'array' | 'boolean' | 'integer' | 'null' | 'number' | 'object' | 'string'; /** * Core schema meta-schema */ @@ -210,7 +210,7 @@ export interface HttpJsonSchemaOrgDraft04Schema { settings: { declareSimpleType: false }, - types:`export type SimpleTypes = "array" | "boolean" | "integer" | "null" | "number" | "object" | "string"; + types:`export type SimpleTypes = 'array' | 'boolean' | 'integer' | 'null' | 'number' | 'object' | 'string'; /** * Core schema meta-schema */ diff --git a/test/cases/root-anyOf.ts b/test/cases/root-anyOf.ts index 50e91f61..95712801 100644 --- a/test/cases/root-anyOf.ts +++ b/test/cases/root-anyOf.ts @@ -32,7 +32,7 @@ export var types = `export interface Foo { b?: number; } export interface Bar { - a?: "a" | "b" | "c"; + a?: 'a' | 'b' | 'c'; [k: string]: any; } export interface Baz { From 71e35165ce6170b5317fafec918345a745f30429 Mon Sep 17 00:00:00 2001 From: Darcy Parker Date: Tue, 27 Sep 2016 08:28:32 -0400 Subject: [PATCH 3/6] disable some tslint rules in test schemas --- test/cases/additionalProperties.ts | 2 ++ test/cases/allOf.ts | 2 ++ test/cases/anyOf.ts | 2 ++ test/cases/array-of-type.ts | 2 ++ test/cases/basics.ts | 2 ++ test/cases/disjoint-type.ts | 2 ++ test/cases/enum.ts | 2 ++ test/cases/enumValidation.5.ts | 2 ++ test/cases/enumValidation.6.ts | 2 ++ test/cases/json-schema.ts | 2 ++ test/cases/named-property.ts | 2 ++ test/cases/not-extendable.ts | 2 ++ test/cases/ref.ts | 5 +++-- test/cases/root-anyOf.ts | 2 ++ test/cases/unnamedSchema.ts | 2 ++ test/cases/with-description-newlines.ts | 2 ++ test/cases/with-description.ts | 2 ++ 17 files changed, 35 insertions(+), 2 deletions(-) diff --git a/test/cases/additionalProperties.ts b/test/cases/additionalProperties.ts index f5c7a51c..97b768a4 100644 --- a/test/cases/additionalProperties.ts +++ b/test/cases/additionalProperties.ts @@ -1,3 +1,4 @@ +/* tslint:disable:quotemark object-literal-key-quotes */ export var schema = { "title": "AdditionalProperties", "type": "object", @@ -10,6 +11,7 @@ export var schema = { "type": "number" } } +/* tslint:enable:quotemark object-literal-key-quotes */ export var types = `export interface AdditionalProperties { foo?: string; diff --git a/test/cases/allOf.ts b/test/cases/allOf.ts index 6e8c2ff3..d60942bf 100644 --- a/test/cases/allOf.ts +++ b/test/cases/allOf.ts @@ -1,3 +1,4 @@ +/* tslint:disable:quotemark object-literal-key-quotes */ export var schema = { "title": "AllOf", "type": "object", @@ -30,6 +31,7 @@ export var schema = { "required": ["foo", "bar"], "additionalProperties": false } +/* tslint:enable:quotemark object-literal-key-quotes */ export var types = `export interface Foo { a: string; diff --git a/test/cases/anyOf.ts b/test/cases/anyOf.ts index de8f1f9c..aab6208c 100644 --- a/test/cases/anyOf.ts +++ b/test/cases/anyOf.ts @@ -1,3 +1,4 @@ +/* tslint:disable:quotemark object-literal-key-quotes */ export var schema = { "title": "AnyOf", "type": "object", @@ -34,6 +35,7 @@ export var schema = { "required": ["foo"], "additionalProperties": false } +/* tslint:enable:quotemark object-literal-key-quotes */ export var types = `export interface Foo { diff --git a/test/cases/array-of-type.ts b/test/cases/array-of-type.ts index 46db9f35..8a71fd5f 100644 --- a/test/cases/array-of-type.ts +++ b/test/cases/array-of-type.ts @@ -1,3 +1,4 @@ +/* tslint:disable:quotemark object-literal-key-quotes */ export var schema = { "title": "Array of type", "type": "object", @@ -22,6 +23,7 @@ export var schema = { } } } +/* tslint:enable:quotemark object-literal-key-quotes */ export var types = `export interface ArrayOfType { foo?: string[]; diff --git a/test/cases/basics.ts b/test/cases/basics.ts index 40597f8e..e48a30c7 100644 --- a/test/cases/basics.ts +++ b/test/cases/basics.ts @@ -1,3 +1,4 @@ +/* tslint:disable:quotemark object-literal-key-quotes */ export var schema = { "title": "Example Schema", "type": "object", @@ -25,6 +26,7 @@ export var schema = { }, "required": ["firstName", "lastName"] } +/* tslint:enable:quotemark object-literal-key-quotes */ export var configurations = [ { diff --git a/test/cases/disjoint-type.ts b/test/cases/disjoint-type.ts index 0460294c..a14290ef 100644 --- a/test/cases/disjoint-type.ts +++ b/test/cases/disjoint-type.ts @@ -1,3 +1,4 @@ +/* tslint:disable:quotemark object-literal-key-quotes */ export var schema = { "title": "Example Schema", "description": "My cool schema", @@ -12,6 +13,7 @@ export var schema = { }, "required": ["value"] } +/* tslint:enable:quotemark object-literal-key-quotes */ export var types = `/** * My cool schema diff --git a/test/cases/enum.ts b/test/cases/enum.ts index b4f7d678..c871420a 100644 --- a/test/cases/enum.ts +++ b/test/cases/enum.ts @@ -1,3 +1,4 @@ +/* tslint:disable:quotemark object-literal-key-quotes */ export var schema = { "title": "Enum", "type": "object", @@ -47,6 +48,7 @@ export var schema = { "required": ["stringEnum", "impliedStringEnum", "literalWithSingleQuote", "booleanEnum", "impliedBooleanEnum", "integerEnum", "impliedIntegerEnum", "impliedNamedIntegerEnum"], "additionalProperties": false } +/* tslint:enable:quotemark object-literal-key-quotes */ export var configurations = [false, true].map(useConstEnums => { return { diff --git a/test/cases/enumValidation.5.ts b/test/cases/enumValidation.5.ts index 364260d1..999121e3 100644 --- a/test/cases/enumValidation.5.ts +++ b/test/cases/enumValidation.5.ts @@ -1,3 +1,4 @@ +/* tslint:disable:quotemark object-literal-key-quotes */ export var schema = { "title": "Enum", "type": "object", @@ -11,6 +12,7 @@ export var schema = { "required": ["bar"], "additionalProperties": false } +/* tslint:enable:quotemark object-literal-key-quotes */ export var settings = { useTypescriptEnums: true diff --git a/test/cases/enumValidation.6.ts b/test/cases/enumValidation.6.ts index a639ea61..cc5515c2 100644 --- a/test/cases/enumValidation.6.ts +++ b/test/cases/enumValidation.6.ts @@ -1,3 +1,4 @@ +/* tslint:disable:quotemark object-literal-key-quotes */ export var schema = { "title": "Enum", "type": "object", @@ -11,6 +12,7 @@ export var schema = { "required": ["bar"], "additionalProperties": false } +/* tslint:enable:quotemark object-literal-key-quotes */ export var settings = { useTypescriptEnums: true diff --git a/test/cases/json-schema.ts b/test/cases/json-schema.ts index 86e465f3..57cc383c 100644 --- a/test/cases/json-schema.ts +++ b/test/cases/json-schema.ts @@ -1,3 +1,4 @@ +/* tslint:disable:quotemark object-literal-key-quotes */ export var schema = { "id": "http://json-schema.org/draft-04/schema#", "$schema": "http://json-schema.org/draft-04/schema#", @@ -148,6 +149,7 @@ export var schema = { }, "default": {} }; +/* tslint:enable:quotemark object-literal-key-quotes */ export var configurations = [ { diff --git a/test/cases/named-property.ts b/test/cases/named-property.ts index 7b95bf78..fec3f8fe 100644 --- a/test/cases/named-property.ts +++ b/test/cases/named-property.ts @@ -1,3 +1,4 @@ +/* tslint:disable:quotemark object-literal-key-quotes */ export var schema = { "title": "Example Schema", "description": "My cool schema", @@ -13,6 +14,7 @@ export var schema = { } } } +/* tslint:enable:quotemark object-literal-key-quotes */ // TODO: 2nd block comment should annotate UserIdArray, not users export var types = `export type UserIdArray = string[]; diff --git a/test/cases/not-extendable.ts b/test/cases/not-extendable.ts index e3ae1e5a..4500da05 100644 --- a/test/cases/not-extendable.ts +++ b/test/cases/not-extendable.ts @@ -1,3 +1,4 @@ +/* tslint:disable:quotemark object-literal-key-quotes */ export var schema = { "title": "Example Schema", "type": "object", @@ -17,6 +18,7 @@ export var schema = { "required": ["firstName", "lastName"], "additionalProperties": false } +/* tslint:enable:quotemark object-literal-key-quotes */ export var types = `export interface ExampleSchema { firstName: string; diff --git a/test/cases/ref.ts b/test/cases/ref.ts index 0a726335..8dbe6cb4 100644 --- a/test/cases/ref.ts +++ b/test/cases/ref.ts @@ -1,5 +1,5 @@ -export var schema = -{ +/* tslint:disable:quotemark object-literal-key-quotes */ +export var schema = { "title": "Referencing", "type": "object", "properties": { @@ -10,6 +10,7 @@ export var schema = "required": ["foo"], "additionalProperties": false } +/* tslint:enable:quotemark object-literal-key-quotes */ export var configurations = [ { diff --git a/test/cases/root-anyOf.ts b/test/cases/root-anyOf.ts index 95712801..1973d174 100644 --- a/test/cases/root-anyOf.ts +++ b/test/cases/root-anyOf.ts @@ -1,3 +1,4 @@ +/* tslint:disable:quotemark object-literal-key-quotes */ export var schema = { "title": "RootAnyOf", "anyOf": [ @@ -26,6 +27,7 @@ export var schema = { } } } +/* tslint:enable:quotemark object-literal-key-quotes */ export var types = `export interface Foo { a: string; diff --git a/test/cases/unnamedSchema.ts b/test/cases/unnamedSchema.ts index 654b7fb8..3987532e 100644 --- a/test/cases/unnamedSchema.ts +++ b/test/cases/unnamedSchema.ts @@ -1,3 +1,4 @@ +/* tslint:disable:quotemark object-literal-key-quotes */ export var schema = { "type": "object", "properties": { @@ -8,6 +9,7 @@ export var schema = { "required": ["foo"], "additionalProperties": false } +/* tslint:enable:quotemark object-literal-key-quotes */ export var types = `export interface UnnamedSchema { foo: string; diff --git a/test/cases/with-description-newlines.ts b/test/cases/with-description-newlines.ts index 5f46137b..957d6fab 100644 --- a/test/cases/with-description-newlines.ts +++ b/test/cases/with-description-newlines.ts @@ -1,3 +1,4 @@ +/* tslint:disable:quotemark object-literal-key-quotes */ export var schema = { "title": "Example Schema", "description": "My cool schema", @@ -18,6 +19,7 @@ export var schema = { }, "required": ["firstName", "lastName"] } +/* tslint:enable:quotemark object-literal-key-quotes */ export var types = `/** * My cool schema diff --git a/test/cases/with-description.ts b/test/cases/with-description.ts index 71038b1e..43f6128c 100644 --- a/test/cases/with-description.ts +++ b/test/cases/with-description.ts @@ -1,3 +1,4 @@ +/* tslint:disable:quotemark object-literal-key-quotes */ export var schema = { "title": "Example Schema", "description": "My cool schema", @@ -17,6 +18,7 @@ export var schema = { }, "required": ["firstName", "lastName"] } +/* tslint:enable:quotemark object-literal-key-quotes */ export var types = `/** * My cool schema From 7750ad9f1ffafab30749dc086a3ba9f4ce2253ef Mon Sep 17 00:00:00 2001 From: Darcy Parker Date: Tue, 27 Sep 2016 08:29:36 -0400 Subject: [PATCH 4/6] fix tslint no-consecutive-blank-lines --- test/cases/anyOf.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/test/cases/anyOf.ts b/test/cases/anyOf.ts index aab6208c..1445d36b 100644 --- a/test/cases/anyOf.ts +++ b/test/cases/anyOf.ts @@ -37,7 +37,6 @@ export var schema = { } /* tslint:enable:quotemark object-literal-key-quotes */ - export var types = `export interface Foo { a: string; b?: number; From 492324ddcdddbb35035b1d968b032f56317a3574 Mon Sep 17 00:00:00 2001 From: Darcy Parker Date: Tue, 27 Sep 2016 08:30:25 -0400 Subject: [PATCH 5/6] fix tslint missing whitespace --- test/cases/enum.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/cases/enum.ts b/test/cases/enum.ts index c871420a..310582fc 100644 --- a/test/cases/enum.ts +++ b/test/cases/enum.ts @@ -35,11 +35,11 @@ export var schema = { "namedIntegerEnum": { "type": "integer", "enum": [1, 2, 3], - "tsEnumNames": ["One","Two","Three"] + "tsEnumNames": ["One", "Two", "Three"] }, "impliedNamedIntegerEnum": { "enum": [4, 5, 6], - "tsEnumNames": ["Four","Five","Six"] + "tsEnumNames": ["Four", "Five", "Six"] }, "impliedHeterogeneousEnum": { "enum": [-20.1, null, "foo", false] From a88455aca176d9209dd5bacf074adb82488158c5 Mon Sep 17 00:00:00 2001 From: Darcy Parker Date: Tue, 27 Sep 2016 08:31:00 -0400 Subject: [PATCH 6/6] fix tslint unnecessary semicolon --- test/cases/json-schema.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cases/json-schema.ts b/test/cases/json-schema.ts index 57cc383c..1bdd1a28 100644 --- a/test/cases/json-schema.ts +++ b/test/cases/json-schema.ts @@ -148,7 +148,7 @@ export var schema = { "exclusiveMinimum": [ "minimum" ] }, "default": {} -}; +} /* tslint:enable:quotemark object-literal-key-quotes */ export var configurations = [