typescript-json-schema
Advanced tools
Comparing version 0.60.0 to 0.61.0
26
api.md
@@ -610,2 +610,11 @@ _Auto-generated file. Updated with NPM deploy. Update manually with 'yarn docs'._ | ||
## [const-as-enum](./test/programs/const-as-enum) | ||
```ts | ||
export interface MyObject { | ||
reference: true; | ||
} | ||
``` | ||
## [const-keyword](./test/programs/const-keyword) | ||
@@ -1449,2 +1458,19 @@ | ||
## [string-template-literal](./test/programs/string-template-literal) | ||
```ts | ||
interface MyObject { | ||
a: `@${string}`, | ||
b: `@${number}`, | ||
c: `@${bigint}`, | ||
d: `@${boolean}`, | ||
e: `@${undefined}`, | ||
f: `@${null}`, | ||
g: `${string}@`, | ||
h: `${number}@`, | ||
i: `${string}@${number}`, | ||
} | ||
``` | ||
## [symbol](./test/programs/symbol) | ||
@@ -1451,0 +1477,0 @@ |
@@ -56,2 +56,4 @@ "use strict"; | ||
.describe("tsNodeRegister", "Use ts-node/register (needed for requiring typescript files).") | ||
.boolean("constAsEnum").default("constAsEnum", defaultArgs.constAsEnum) | ||
.describe("constAsEnum", "Use enums with a single value when declaring constants. Needed for OpenAPI compatibility") | ||
.argv; | ||
@@ -81,2 +83,3 @@ (0, typescript_json_schema_1.exec)(args._[0], args._[1], { | ||
tsNodeRegister: args.tsNodeRegister, | ||
constAsEnum: args.constAsEnum, | ||
}); | ||
@@ -83,0 +86,0 @@ } |
@@ -31,2 +31,3 @@ import * as ts from "typescript"; | ||
tsNodeRegister: boolean; | ||
constAsEnum: boolean; | ||
}; | ||
@@ -83,2 +84,3 @@ export type PartialArgs = Partial<Args>; | ||
private userValidationKeywords; | ||
private constAsEnum; | ||
private typeNamesById; | ||
@@ -85,0 +87,0 @@ private typeIdsByName; |
@@ -88,2 +88,3 @@ "use strict"; | ||
tsNodeRegister: false, | ||
constAsEnum: false, | ||
}; | ||
@@ -332,2 +333,3 @@ } | ||
}, {}); | ||
this.constAsEnum = args.constAsEnum; | ||
} | ||
@@ -503,3 +505,8 @@ Object.defineProperty(JsonSchemaGenerator.prototype, "ReffedDefinitions", { | ||
} | ||
definition.const = value; | ||
if (this.constAsEnum) { | ||
definition.enum = [value]; | ||
} | ||
else { | ||
definition.const = value; | ||
} | ||
} | ||
@@ -519,2 +526,33 @@ else if (arrayType !== undefined) { | ||
} | ||
else if (propertyType.flags & ts.TypeFlags.TemplateLiteral) { | ||
definition.type = "string"; | ||
var texts = propertyType.texts, types = propertyType.types; | ||
var pattern = []; | ||
for (var i = 0; i < texts.length; i++) { | ||
var text = texts[i]; | ||
var type = types[i]; | ||
if (i === 0) { | ||
pattern.push("^"); | ||
} | ||
if (type) { | ||
if (type.flags & ts.TypeFlags.String) { | ||
pattern.push("".concat(text, ".*")); | ||
} | ||
if (type.flags & ts.TypeFlags.Number | ||
|| type.flags & ts.TypeFlags.BigInt) { | ||
pattern.push("".concat(text, "[0-9]*")); | ||
} | ||
if (type.flags & ts.TypeFlags.Undefined) { | ||
pattern.push("".concat(text, "undefined")); | ||
} | ||
if (type.flags & ts.TypeFlags.Null) { | ||
pattern.push("".concat(text, "null")); | ||
} | ||
} | ||
if (i === texts.length - 1) { | ||
pattern.push("".concat(text, "$")); | ||
} | ||
} | ||
definition.pattern = pattern.join(""); | ||
} | ||
else { | ||
@@ -521,0 +559,0 @@ definition.type = "array"; |
{ | ||
"name": "typescript-json-schema", | ||
"version": "0.60.0", | ||
"version": "0.61.0", | ||
"description": "typescript-json-schema generates JSON Schema files from your Typescript sources", | ||
@@ -5,0 +5,0 @@ "main": "dist/typescript-json-schema.js", |
@@ -54,2 +54,3 @@ # typescript-json-schema | ||
--tsNodeRegister Use ts-node/register (needed for require typescript files). [boolean] [default: false] | ||
--constAsEnum Use enums with a single value when declaring constants. [boolean] [default: false] | ||
``` | ||
@@ -56,0 +57,0 @@ |
@@ -56,2 +56,4 @@ import { exec, getDefaultArgs } from "./typescript-json-schema"; | ||
.describe("tsNodeRegister", "Use ts-node/register (needed for requiring typescript files).") | ||
.boolean("constAsEnum").default("constAsEnum", defaultArgs.constAsEnum) | ||
.describe("constAsEnum", "Use enums with a single value when declaring constants. Needed for OpenAPI compatibility") | ||
.argv; | ||
@@ -82,2 +84,3 @@ | ||
tsNodeRegister: args.tsNodeRegister, | ||
constAsEnum: args.constAsEnum, | ||
}); | ||
@@ -84,0 +87,0 @@ } |
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 too big to display
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
254199
3525
325