Skip to content

Commit 872a8ce

Browse files
committed
Name all configs the same as the command line options
1 parent 3d81206 commit 872a8ce

File tree

2 files changed

+139
-138
lines changed

2 files changed

+139
-138
lines changed

test/schema.test.ts

+89-88
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ ajv.addMetaSchema(metaSchema, "http://json-schema.org/draft-04/schema#");
1212

1313
const BASE = "test/programs/";
1414

15-
export function assertSchema(group: string, name: string, type: string, settings: TJS.PartialArgs = {}, compilerOptions?: CompilerOptions) {
15+
export function assertSchema(group: string, type: string, settings: TJS.PartialArgs = {}, compilerOptions?: CompilerOptions) {
1616
it(group + " should create correct schema", () => {
1717
if (!("generateRequired" in settings)) {
18-
settings.generateRequired = true;
18+
settings.required = true;
1919
}
2020

21-
const actual = TJS.generateSchema(TJS.getProgramFromFiles([resolve(BASE + group + "/" + name)], compilerOptions), type, settings);
21+
const actual = TJS.generateSchema(TJS.getProgramFromFiles([resolve(BASE + group + "/main.ts")], compilerOptions), type, settings);
2222

2323
const file = readFileSync(BASE + group + "/schema.json", "utf8");
2424
const expected = JSON.parse(file);
@@ -65,109 +65,110 @@ describe("interfaces", () => {
6565
});
6666

6767
describe("schema", () => {
68-
assertSchema("array-and-description", "main.ts", "MyObject");
69-
assertSchema("class-single", "main.ts", "MyObject");
70-
assertSchema("class-extends", "main.ts", "MyObject");
7168

72-
assertSchema("interface-single", "main.ts", "MyObject");
73-
assertSchema("interface-multi", "main.ts", "MyObject");
74-
assertSchema("interface-extends", "main.ts", "MyObject");
69+
describe("type aliases", () => {
70+
assertSchema("type-alias-single", "MyString");
71+
assertSchema("type-aliases", "MyObject", {
72+
aliasRef: true
73+
});
74+
assertSchema("type-aliases-fixed-size-array", "MyFixedSizeArray");
75+
assertSchema("type-aliases-multitype-array", "MyArray");
76+
assertSchema("type-aliases-local-namsepace", "MyObject", {
77+
aliasRef: true
78+
});
79+
80+
assertSchema("type-aliases-alias-ref", "MyAlias", {
81+
aliasRef: true,
82+
topRef: false
83+
});
84+
// disabled beacuse of #80
85+
// assertSchema("type-aliases-alias-ref-topref", "MyAlias", {
86+
// useTypeAliasRef: true,
87+
// useRootRef: true
88+
// });
89+
assertSchema("type-aliases-recursive-object-topref", "MyObject", {
90+
aliasRef: true,
91+
topRef: true
92+
});
93+
// disabled beacuse of #80
94+
// assertSchema("type-aliases-recursive-alias-topref", "MyAlias", {
95+
// useTypeAliasRef: true,
96+
// useRootRef: true
97+
// });
98+
assertSchema("type-no-aliases-recursive-topref", "MyAlias", {
99+
aliasRef: false,
100+
topRef: true
101+
});
102+
});
75103

76-
assertSchema("interface-recursion", "main.ts", "MyObject", {
77-
useRootRef: true
104+
describe("enums", () => {
105+
assertSchema("enums-string", "MyObject");
106+
assertSchema("enums-number", "MyObject");
107+
assertSchema("enums-number-initialized", "Enum");
108+
assertSchema("enums-compiled-compute", "Enum");
109+
assertSchema("enums-mixed", "MyObject");
78110
});
79111

80-
assertSchema("module-interface-single", "main.ts", "MyObject");
112+
describe("unions and intersections", () => {
113+
assertSchema("type-union", "MyObject");
114+
assertSchema("type-intersection", "MyObject", {
115+
noExtraProps: true
116+
});
117+
assertSchema("type-union-tagged", "Shape");
118+
assertSchema("type-aliases-union-namespace", "MyModel");
119+
});
81120

82-
// not supported right now
83-
// assertSchema("module-interface-deep", "main.ts", "Def");
121+
describe("annotations", () => {
122+
assertSchema("annotation-default", "MyObject");
84123

85-
assertSchema("enums-string", "main.ts", "MyObject");
86-
assertSchema("enums-number", "main.ts", "MyObject");
87-
assertSchema("enums-number-initialized", "main.ts", "Enum");
88-
assertSchema("enums-compiled-compute", "main.ts", "Enum");
89-
assertSchema("enums-mixed", "main.ts", "MyObject");
90-
assertSchema("string-literals", "main.ts", "MyObject");
91-
assertSchema("string-literals-inline", "main.ts", "MyObject");
124+
assertSchema("typeof-keyword", "MyObject", {typeOfKeyword: true});
92125

93-
assertSchema("array-readonly", "main.ts", "MyReadOnlyArray");
94-
assertSchema("array-types", "main.ts", "MyArray");
95-
assertSchema("map-types", "main.ts", "MyObject");
126+
assertSchema("user-validation-keywords", "MyObject", {
127+
validationKeywords: [ "chance", "important" ]
128+
});
129+
});
96130

97-
assertSchema("namespace", "main.ts", "Type");
131+
describe("other", () => {
132+
assertSchema("array-and-description", "MyObject");
133+
assertSchema("class-single", "MyObject");
134+
assertSchema("class-extends", "MyObject");
98135

99-
assertSchema("type-anonymous", "main.ts", "MyObject");
100-
assertSchema("type-primitives", "main.ts", "MyObject");
101-
assertSchema("type-nullable", "main.ts", "MyObject");
136+
assertSchema("interface-single", "MyObject");
137+
assertSchema("interface-multi", "MyObject");
138+
assertSchema("interface-extends", "MyObject");
102139

103-
assertSchema("optionals", "main.ts", "MyObject");
140+
assertSchema("interface-recursion", "MyObject", {
141+
topRef: true
142+
});
104143

105-
assertSchema("comments", "main.ts", "MyObject");
106-
assertSchema("comments-override", "main.ts", "MyObject");
144+
assertSchema("module-interface-single", "MyObject");
107145

108-
assertSchema("force-type", "main.ts", "MyObject");
109-
assertSchema("force-type-imported", "main.ts", "MyObject");
146+
// not supported right now
147+
// assertSchema("module-interface-deep", "Def");
110148

111-
/**
112-
* Type aliases
113-
*/
149+
assertSchema("string-literals", "MyObject");
150+
assertSchema("string-literals-inline", "MyObject");
114151

115-
assertSchema("type-alias-single", "main.ts", "MyString");
116-
assertSchema("type-aliases", "main.ts", "MyObject", {
117-
useTypeAliasRef: true
118-
});
119-
assertSchema("type-aliases-fixed-size-array", "main.ts", "MyFixedSizeArray");
120-
assertSchema("type-aliases-multitype-array", "main.ts", "MyArray");
121-
assertSchema("type-aliases-local-namsepace", "main.ts", "MyObject", {
122-
useTypeAliasRef: true
123-
});
152+
assertSchema("array-readonly", "MyReadOnlyArray");
153+
assertSchema("array-types", "MyArray");
154+
assertSchema("map-types", "MyObject");
124155

125-
assertSchema("type-aliases-alias-ref", "main.ts", "MyAlias", {
126-
useTypeAliasRef: true,
127-
useRootRef: false
128-
});
129-
// disabled beacuse of #80
130-
// assertSchema("type-aliases-alias-ref-topref", "main.ts", "MyAlias", {
131-
// useTypeAliasRef: true,
132-
// useRootRef: true
133-
// });
134-
assertSchema("type-aliases-recursive-object-topref", "main.ts", "MyObject", {
135-
useTypeAliasRef: true,
136-
useRootRef: true
137-
});
138-
// disabled beacuse of #80
139-
// assertSchema("type-aliases-recursive-alias-topref", "main.ts", "MyAlias", {
140-
// useTypeAliasRef: true,
141-
// useRootRef: true
142-
// });
143-
assertSchema("type-no-aliases-recursive-topref", "main.ts", "MyAlias", {
144-
useTypeAliasRef: false,
145-
useRootRef: true
146-
});
147-
148-
/**
149-
* unions and intersections
150-
*/
151-
152-
assertSchema("type-union", "main.ts", "MyObject");
153-
assertSchema("type-intersection", "main.ts", "MyObject", {
154-
disableExtraProperties: true
155-
});
156-
assertSchema("type-union-tagged", "main.ts", "Shape");
157-
assertSchema("type-aliases-union-namespace", "main.ts", "MyModel");
156+
assertSchema("namespace", "Type");
158157

159-
assertSchema("strict-null-checks", "main.ts", "MyObject", undefined, {
160-
strictNullChecks: true
161-
});
158+
assertSchema("type-anonymous", "MyObject");
159+
assertSchema("type-primitives", "MyObject");
160+
assertSchema("type-nullable", "MyObject");
162161

163-
/**
164-
* annotations
165-
*/
162+
assertSchema("optionals", "MyObject");
166163

167-
assertSchema("annotation-default", "main.ts", "MyObject");
164+
assertSchema("comments", "MyObject");
165+
assertSchema("comments-override", "MyObject");
168166

169-
assertSchema("typeof-keyword", "main.ts", "MyObject", {useTypeOfKeyword: true});
167+
assertSchema("force-type", "MyObject");
168+
assertSchema("force-type-imported", "MyObject");
170169

171-
const userValidationOpts = { validationKeywords: [ "chance", "important" ] };
172-
assertSchema("user-validation-keywords", "main.ts", "MyObject", userValidationOpts);
170+
assertSchema("strict-null-checks", "MyObject", undefined, {
171+
strictNullChecks: true
172+
});
173+
});
173174
});

0 commit comments

Comments
 (0)