diff --git a/src/Utils/extractLiterals.ts b/src/Utils/extractLiterals.ts index 47df38664..21d740118 100644 --- a/src/Utils/extractLiterals.ts +++ b/src/Utils/extractLiterals.ts @@ -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 { EnumType } from "../Type/EnumType"; import { LiteralType } from "../Type/LiteralType"; import { UnionType } from "../Type/UnionType"; @@ -13,7 +14,7 @@ function* _extractLiterals(type: BaseType): Iterable { yield type.getValue().toString(); return; } - if (type instanceof UnionType) { + if (type instanceof UnionType || type instanceof EnumType) { for (const t of type.getTypes()) { yield* _extractLiterals(t); } diff --git a/test/valid-data-other.test.ts b/test/valid-data-other.test.ts index bc3047903..bae3b412d 100644 --- a/test/valid-data-other.test.ts +++ b/test/valid-data-other.test.ts @@ -7,6 +7,7 @@ describe("valid-data-other", () => { it("enums-compute", assertValidSchema("enums-compute", "Enum")); it("enums-mixed", assertValidSchema("enums-mixed", "Enum")); it("enums-member", assertValidSchema("enums-member", "MyObject")); + it("enums-template-literal", assertValidSchema("enums-template-literal", "MyObject")); it( "function-parameters-default-value", diff --git a/test/valid-data/enums-template-literal/main.ts b/test/valid-data/enums-template-literal/main.ts new file mode 100644 index 000000000..c84d3f455 --- /dev/null +++ b/test/valid-data/enums-template-literal/main.ts @@ -0,0 +1,8 @@ +enum MyEnum { + A = "a", + B = "b", +} + +export type MyObject = { + prop?: `${MyEnum}`; +} diff --git a/test/valid-data/enums-template-literal/schema.json b/test/valid-data/enums-template-literal/schema.json new file mode 100644 index 000000000..33c8a36b7 --- /dev/null +++ b/test/valid-data/enums-template-literal/schema.json @@ -0,0 +1,19 @@ +{ + "$ref": "#/definitions/MyObject", + "$schema": "http://json-schema.org/draft-07/schema#", + "definitions": { + "MyObject": { + "additionalProperties": false, + "properties": { + "prop": { + "enum": [ + "a", + "b" + ], + "type": "string" + } + }, + "type": "object" + } + } +}