diff --git a/api.md b/api.md index bb47b106..94c3f5d2 100644 --- a/api.md +++ b/api.md @@ -1445,6 +1445,24 @@ class MyObject { ``` +## [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}`, + j: `${string}.${string}`, +} +``` + + ## [symbol](./test/programs/symbol) ```ts diff --git a/test/programs/string-template-literal/main.ts b/test/programs/string-template-literal/main.ts index 4b0745b0..f554704e 100644 --- a/test/programs/string-template-literal/main.ts +++ b/test/programs/string-template-literal/main.ts @@ -8,4 +8,5 @@ interface MyObject { g: `${string}@`, h: `${number}@`, i: `${string}@${number}`, + j: `${string}.${string}`, } \ No newline at end of file diff --git a/test/programs/string-template-literal/schema.json b/test/programs/string-template-literal/schema.json index cc39dd2c..cc1e1e08 100644 --- a/test/programs/string-template-literal/schema.json +++ b/test/programs/string-template-literal/schema.json @@ -39,6 +39,10 @@ "i": { "type": "string", "pattern": "^.*@[0-9]*$" + }, + "j": { + "type": "string", + "pattern": "^.*\\..*$" } }, "additionalProperties": false, @@ -51,7 +55,8 @@ "f", "g", "h", - "i" + "i", + "j" ], "$schema": "http://json-schema.org/draft-07/schema#" } \ No newline at end of file diff --git a/typescript-json-schema.ts b/typescript-json-schema.ts index 68c34bf2..a50d4a93 100644 --- a/typescript-json-schema.ts +++ b/typescript-json-schema.ts @@ -753,7 +753,7 @@ export class JsonSchemaGenerator { const {texts, types} = propertyType; const pattern = []; for (let i = 0; i < texts.length; i++) { - const text = texts[i]; + const text = texts[i].replace(/[\\^$.*+?()[\]{}|]/g, '\\$&'); const type = types[i]; if (i === 0) {