@tsofist/schema-forge 2.5.0 → 2.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import '../util/patch.extended-annotations-reader';
|
|
2
2
|
import { SchemaObject } from 'ajv';
|
|
3
|
-
import {
|
|
4
|
-
import { Node, TupleTypeNode } from 'typescript';
|
|
3
|
+
import { CompletedConfig } from 'ts-json-schema-generator';
|
|
5
4
|
import { SchemaForgeOptions } from '../types';
|
|
6
5
|
import { TypeExposeKind } from './types';
|
|
7
6
|
interface Options {
|
|
@@ -18,11 +17,4 @@ interface Options {
|
|
|
18
17
|
shrinkDefinitionNames: SchemaForgeOptions['shrinkDefinitionNames'];
|
|
19
18
|
}
|
|
20
19
|
export declare function generateSchemaByDraftTypes(options: Options): Promise<SchemaObject>;
|
|
21
|
-
export declare class TupleTypeParser implements SubNodeParser {
|
|
22
|
-
protected readonly childNodeParser: ChainNodeParser;
|
|
23
|
-
protected readonly allowUseFallbackDescription: boolean | undefined;
|
|
24
|
-
constructor(childNodeParser: ChainNodeParser, allowUseFallbackDescription: boolean | undefined);
|
|
25
|
-
supportsNode(node: Node): boolean;
|
|
26
|
-
createType(node: TupleTypeNode, context: Context): TupleType;
|
|
27
|
-
}
|
|
28
20
|
export {};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TupleTypeParser = void 0;
|
|
4
3
|
exports.generateSchemaByDraftTypes = generateSchemaByDraftTypes;
|
|
5
4
|
require("../util/patch.extended-annotations-reader");
|
|
6
5
|
const error_1 = require("@tsofist/stem/lib/error");
|
|
@@ -59,7 +58,6 @@ async function generateSchemaByDraftTypes(options) {
|
|
|
59
58
|
const replacement = new Set();
|
|
60
59
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
61
60
|
for (const name of Object.keys(result.definitions)) {
|
|
62
|
-
console.log('DEF::::', name);
|
|
63
61
|
const r = options.shrinkDefinitionNames(name);
|
|
64
62
|
if (r) {
|
|
65
63
|
if (replacement.has(r) || r in result.definitions) {
|
|
@@ -72,11 +70,11 @@ async function generateSchemaByDraftTypes(options) {
|
|
|
72
70
|
delete result.definitions[name];
|
|
73
71
|
// rename references
|
|
74
72
|
const targets = (0, jsonpath_plus_1.JSONPath)({
|
|
75
|
-
path: `$..[?(@ && @.$ref == "#/definitions/${name}")]`,
|
|
73
|
+
path: `$..[?(@ && @.$ref == "#/definitions/${escapeDefinitionNameForJSONPath(name)}")]`,
|
|
76
74
|
json: result,
|
|
77
75
|
eval: 'safe',
|
|
78
76
|
});
|
|
79
|
-
targets
|
|
77
|
+
targets?.forEach((item) => {
|
|
80
78
|
item.$ref = item.$ref.replace(`#/definitions/${name}`, `#/definitions/${r}`);
|
|
81
79
|
});
|
|
82
80
|
}
|
|
@@ -95,6 +93,9 @@ async function generateSchemaByDraftTypes(options) {
|
|
|
95
93
|
}).validateSchema(result, true);
|
|
96
94
|
return result;
|
|
97
95
|
}
|
|
96
|
+
function escapeDefinitionNameForJSONPath(value) {
|
|
97
|
+
return value.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
|
|
98
|
+
}
|
|
98
99
|
class TupleTypeParser {
|
|
99
100
|
constructor(childNodeParser, allowUseFallbackDescription) {
|
|
100
101
|
Object.defineProperty(this, "childNodeParser", {
|
|
@@ -119,8 +120,6 @@ class TupleTypeParser {
|
|
|
119
120
|
if ((0, typescript_1.isNamedTupleMember)(element)) {
|
|
120
121
|
const description = (0, tsc_1.readJSDocDescription)(element, this.allowUseFallbackDescription);
|
|
121
122
|
const nullable = type instanceof ts_json_schema_generator_1.AnnotatedType ? type.isNullable() : false;
|
|
122
|
-
if (nullable)
|
|
123
|
-
console.log(description, nullable);
|
|
124
123
|
return description ? new ts_json_schema_generator_1.AnnotatedType(type, { description }, nullable) : type;
|
|
125
124
|
}
|
|
126
125
|
return type;
|
|
@@ -128,7 +127,6 @@ class TupleTypeParser {
|
|
|
128
127
|
return new ts_json_schema_generator_1.TupleType(items);
|
|
129
128
|
}
|
|
130
129
|
}
|
|
131
|
-
exports.TupleTypeParser = TupleTypeParser;
|
|
132
130
|
class ArrayLiteralExpressionIdentifierParser {
|
|
133
131
|
constructor(checker) {
|
|
134
132
|
Object.defineProperty(this, "checker", {
|