ts-json-schema-generator
Advanced tools
Comparing version 2.1.0-next.1 to 2.1.0-next.2
{ | ||
"name": "ts-json-schema-generator", | ||
"version": "2.1.0-next.1", | ||
"version": "2.1.0-next.2", | ||
"description": "Generate JSON schema from your Typescript sources", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -11,2 +11,4 @@ import ts from "typescript"; | ||
import { StringType } from "../Type/StringType.js"; | ||
import { LiteralType } from "../Type/LiteralType.js"; | ||
import { isLiteralUnion } from "../TypeFormatter/LiteralUnionTypeFormatter.js"; | ||
export class IntersectionNodeParser { | ||
@@ -27,4 +29,10 @@ typeChecker; | ||
} | ||
if (types.length === 2 && types.some((t) => t instanceof StringType) && types.some((t) => isEmptyObject(t))) { | ||
return new StringType(true); | ||
if (types.length === 2 && types.some((t) => isEmptyObject(t))) { | ||
if (types.some((t) => t instanceof StringType)) { | ||
return new StringType(true); | ||
} | ||
const nonObject = types.find((t) => !isEmptyObject(t)); | ||
if (nonObject instanceof LiteralType || (nonObject instanceof UnionType && isLiteralUnion(nonObject))) { | ||
return nonObject; | ||
} | ||
} | ||
@@ -31,0 +39,0 @@ return translate(types); |
@@ -10,1 +10,2 @@ import { Definition } from "../Schema/Definition.js"; | ||
} | ||
export declare function isLiteralUnion(type: UnionType): boolean; |
@@ -72,3 +72,3 @@ import { LiteralType } from "../Type/LiteralType.js"; | ||
} | ||
function isLiteralUnion(type) { | ||
export function isLiteralUnion(type) { | ||
return flattenTypes(type).every((item) => item instanceof LiteralType || item instanceof NullType || item instanceof StringType); | ||
@@ -75,0 +75,0 @@ } |
{ | ||
"name": "ts-json-schema-generator", | ||
"version": "2.1.0-next.1", | ||
"version": "2.1.0-next.2", | ||
"description": "Generate JSON schema from your Typescript sources", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -14,2 +14,4 @@ import ts from "typescript"; | ||
import { StringType } from "../Type/StringType.js"; | ||
import { LiteralType } from "../Type/LiteralType.js"; | ||
import { isLiteralUnion } from "../TypeFormatter/LiteralUnionTypeFormatter.js"; | ||
@@ -35,4 +37,10 @@ export class IntersectionNodeParser implements SubNodeParser { | ||
// handle autocomplete hacks like `string & {}` | ||
if (types.length === 2 && types.some((t) => t instanceof StringType) && types.some((t) => isEmptyObject(t))) { | ||
return new StringType(true); | ||
if (types.length === 2 && types.some((t) => isEmptyObject(t))) { | ||
if (types.some((t) => t instanceof StringType)) { | ||
return new StringType(true); | ||
} | ||
const nonObject = types.find((t) => !isEmptyObject(t)); | ||
if (nonObject instanceof LiteralType || (nonObject instanceof UnionType && isLiteralUnion(nonObject))) { | ||
return nonObject; | ||
} | ||
} | ||
@@ -39,0 +47,0 @@ |
@@ -86,3 +86,3 @@ import { Definition } from "../Schema/Definition.js"; | ||
function isLiteralUnion(type: UnionType): boolean { | ||
export function isLiteralUnion(type: UnionType): boolean { | ||
return flattenTypes(type).every( | ||
@@ -89,0 +89,0 @@ (item) => item instanceof LiteralType || item instanceof NullType || item instanceof StringType, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
811013
12143