UNPKG

ts-json-schema-generator

Version:

Generate JSON schema from your Typescript sources

21 lines (19 loc) 701 B
import type { Definition } from "../Schema/Definition.js"; import type { SubTypeFormatter } from "../SubTypeFormatter.js"; import type { BaseType } from "../Type/BaseType.js"; import { LiteralType } from "../Type/LiteralType.js"; import { typeName } from "../Utils/typeName.js"; export class LiteralTypeFormatter implements SubTypeFormatter { public supportsType(type: BaseType): boolean { return type instanceof LiteralType; } public getDefinition(type: LiteralType): Definition { return { type: typeName(type.getValue()), const: type.getValue(), }; } public getChildren(type: LiteralType): BaseType[] { return []; } }