Skip to content

Commit

Permalink
fix: add DefinitionTypes to extractLiterals() (#1717)
Browse files Browse the repository at this point in the history
  • Loading branch information
cengels authored Jul 4, 2023
1 parent 415a7a8 commit d9ad8ba
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Utils/extractLiterals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { UnknownTypeError } from "../Error/UnknownTypeError";
import { AliasType } from "../Type/AliasType";
import { BaseType } from "../Type/BaseType";
import { BooleanType } from "../Type/BooleanType";
import { DefinitionType } from "../Type/DefinitionType";
import { EnumType } from "../Type/EnumType";
import { LiteralType } from "../Type/LiteralType";
import { UnionType } from "../Type/UnionType";
Expand All @@ -20,7 +21,7 @@ function* _extractLiterals(type: BaseType): Iterable<string> {
}
return;
}
if (type instanceof AliasType) {
if (type instanceof AliasType || type instanceof DefinitionType) {
yield* _extractLiterals(type.getType());
return;
}
Expand Down
4 changes: 4 additions & 0 deletions test/valid-data-other.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ describe("valid-data-other", () => {
it("string-literals-null", assertValidSchema("string-literals-null", "MyObject"));
it("string-template-literals", assertValidSchema("string-template-literals", "MyObject"));
it("string-template-expression-literals", assertValidSchema("string-template-expression-literals", "MyObject"));
it(
"string-template-expression-literals-import",
assertValidSchema("string-template-expression-literals-import", "MyObject")
);

it("namespace-deep-1", assertValidSchema("namespace-deep-1", "RootNamespace.Def"));
it("namespace-deep-2", assertValidSchema("namespace-deep-2", "RootNamespace.SubNamespace.HelperA"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { MyType } from './types';

export interface MyObject {
value: `_${MyType}`;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"$ref": "#/definitions/MyObject",
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"MyObject": {
"additionalProperties": false,
"properties": {
"value": {
"enum": [
"_one",
"_two",
"_three"
],
"type": "string"
}
},
"required": [
"value"
],
"type": "object"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type MyType = 'one' | 'two' | 'three';

0 comments on commit d9ad8ba

Please sign in to comment.