Skip to content

Commit

Permalink
Merge pull request #45 from SupernaviX/string-literals-inline
Browse files Browse the repository at this point in the history
Fixes issue #42
  • Loading branch information
YousefED committed Jul 5, 2016
2 parents 4e5b351 + 08985ad commit b7df3ae
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 3 deletions.
3 changes: 3 additions & 0 deletions test/programs/string-literals-inline/main.ts
@@ -0,0 +1,3 @@
class MyObject {
foo: "ok" | "fail" | "abort"
}
17 changes: 17 additions & 0 deletions test/programs/string-literals-inline/schema.json
@@ -0,0 +1,17 @@
{
"type": "object",
"properties": {
"foo": {
"type": "string",
"enum": [
"ok",
"fail",
"abort"
]
}
},
"required": [
"foo"
],
"$schema": "http://json-schema.org/draft-04/schema#"
}
1 change: 1 addition & 0 deletions test/schema.test.ts
Expand Up @@ -40,6 +40,7 @@ describe("schema", function () {

assertSchema("enums-string", "main.ts", "MyObject");
assertSchema("string-literals", "main.ts", "MyObject");
assertSchema("string-literals-inline", "main.ts", "MyObject");

assertSchema("array-types", "main.ts", "MyArray");
assertSchema("map-types", "main.ts", "MyObject");
Expand Down
2 changes: 1 addition & 1 deletion typescript-json-schema.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion typescript-json-schema.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion typescript-json-schema.ts
Expand Up @@ -371,7 +371,7 @@ const fullName = tc.typeToString(clazzType, undefined, ts.TypeFormatFlags.UseFul
}

// aliased types must be handled slightly different
const asTypeAliasRef = asRef && ((reffedType && this.args.useTypeAliasRef) || isStringEnum);
const asTypeAliasRef = asRef && reffedType && (this.args.useTypeAliasRef || isStringEnum);
if (!asTypeAliasRef) {
if (isRawType || (typ.getFlags() & ts.TypeFlags.Anonymous)) {
asRef = false; // raw types and inline types cannot be reffed,
Expand Down

0 comments on commit b7df3ae

Please sign in to comment.