@goast/core 0.0.5 → 0.0.6
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.
- package/cjs/lib/collect/collector.js +4 -0
- package/cjs/lib/parse/parser.js +7 -1
- package/cjs/lib/transform/transform-schema.js +30 -11
- package/cjs/lib/utils/source-builder.js +47 -10
- package/esm/lib/collect/collector.js +4 -0
- package/esm/lib/parse/parser.js +7 -1
- package/esm/lib/transform/transform-schema.js +30 -11
- package/esm/lib/utils/source-builder.js +47 -10
- package/package.json +1 -1
- package/types/lib/collect/helpers.d.ts +3 -2
- package/types/lib/parse/types.d.ts +5 -2
- package/types/lib/transform/api-types.d.ts +6 -0
- package/types/lib/transform/transform-schema.d.ts +1 -1
- package/types/lib/utils/source-builder.d.ts +23 -6
|
@@ -56,6 +56,7 @@ function collectPathItem(data, pathItems, path) {
|
|
|
56
56
|
}
|
|
57
57
|
function collectSchema(data, schemas) {
|
|
58
58
|
(0, helpers_1.collect)(data, schemas, (data, schema) => {
|
|
59
|
+
var _a;
|
|
59
60
|
const key = `${schema.$src.file}#${schema.$src.path}`;
|
|
60
61
|
if (data.schemas.has(key))
|
|
61
62
|
return;
|
|
@@ -75,6 +76,9 @@ function collectSchema(data, schemas) {
|
|
|
75
76
|
if (typeof schema.additionalItems === 'object') {
|
|
76
77
|
collectSchema(data, schema.additionalItems);
|
|
77
78
|
}
|
|
79
|
+
if (typeof schema.discriminator === 'object') {
|
|
80
|
+
(0, helpers_1.collectRecord)(data, (_a = schema.discriminator) === null || _a === void 0 ? void 0 : _a.mapping, collectSchema);
|
|
81
|
+
}
|
|
78
82
|
});
|
|
79
83
|
}
|
|
80
84
|
function collectParameter(data, parameters) {
|
package/cjs/lib/parse/parser.js
CHANGED
|
@@ -11,6 +11,7 @@ const yaml_1 = tslib_1.__importDefault(require("yaml"));
|
|
|
11
11
|
const deref_proxy_1 = require("./deref-proxy");
|
|
12
12
|
const collector_1 = require("../collect/collector");
|
|
13
13
|
const transformer_1 = require("../transform/transformer");
|
|
14
|
+
const utils_1 = require("../utils");
|
|
14
15
|
class OpenApiParser {
|
|
15
16
|
constructor() {
|
|
16
17
|
this._loadedDocuments = new Map();
|
|
@@ -61,7 +62,9 @@ class OpenApiParser {
|
|
|
61
62
|
if (key === '$ref')
|
|
62
63
|
continue;
|
|
63
64
|
const v = value[key];
|
|
64
|
-
if (
|
|
65
|
+
if ((0, utils_1.isNullish)(v))
|
|
66
|
+
continue;
|
|
67
|
+
if (typeof v === 'object') {
|
|
65
68
|
if (Array.isArray(v)) {
|
|
66
69
|
result[key] = yield Promise.all(v.map((v, index) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
67
70
|
if (v && typeof v === 'object') {
|
|
@@ -76,6 +79,9 @@ class OpenApiParser {
|
|
|
76
79
|
result[key] = yield this.dereference(file, `${path}/${String(key)}`, v);
|
|
77
80
|
}
|
|
78
81
|
}
|
|
82
|
+
if (typeof v === 'string' && path.endsWith('/discriminator/mapping')) {
|
|
83
|
+
result[key] = yield this.resolveReference(file, { $ref: v });
|
|
84
|
+
}
|
|
79
85
|
}
|
|
80
86
|
return result;
|
|
81
87
|
});
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.transformSchema = void 0;
|
|
4
4
|
const helpers_1 = require("./helpers");
|
|
5
5
|
const utils_1 = require("../utils");
|
|
6
|
-
function transformSchema(context, schema
|
|
6
|
+
function transformSchema(context, schema) {
|
|
7
7
|
var _a, _b;
|
|
8
8
|
if (!schema) {
|
|
9
9
|
throw new Error('Schema is required.');
|
|
@@ -33,12 +33,11 @@ function transformSchema(context, schema, isReference = false) {
|
|
|
33
33
|
kind = (0, helpers_1.determineSchemaKind)(schema);
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
const ref = schema.$ref ? transformSchema(context, schema.$ref, true) : undefined;
|
|
37
36
|
const id = context.idGenerator.generateId('schema');
|
|
38
37
|
const nameInfo = (0, helpers_1.determineSchemaName)(schema, id);
|
|
39
|
-
const
|
|
38
|
+
const incompleteSchema = {
|
|
40
39
|
$src: Object.assign(Object.assign({}, schema.$src), { component: schema }),
|
|
41
|
-
$ref:
|
|
40
|
+
$ref: undefined,
|
|
42
41
|
id,
|
|
43
42
|
name: nameInfo.name,
|
|
44
43
|
isNameGenerated: nameInfo.isGenerated,
|
|
@@ -54,16 +53,25 @@ function transformSchema(context, schema, isReference = false) {
|
|
|
54
53
|
custom: (0, helpers_1.getCustomFields)(schema),
|
|
55
54
|
not: schema.not ? transformSchema(context, schema.not) : undefined,
|
|
56
55
|
const: schema.const,
|
|
56
|
+
discriminator: schema.discriminator
|
|
57
|
+
? {
|
|
58
|
+
propertyName: typeof schema.discriminator === 'string' ? schema.discriminator : schema.discriminator.propertyName,
|
|
59
|
+
mapping: {},
|
|
60
|
+
}
|
|
61
|
+
: undefined,
|
|
62
|
+
inheritedSchemas: [],
|
|
57
63
|
};
|
|
58
|
-
context.incompleteSchemas.set(schemaSource,
|
|
64
|
+
context.incompleteSchemas.set(schemaSource, incompleteSchema);
|
|
65
|
+
if (schema.$ref) {
|
|
66
|
+
incompleteSchema.$ref = transformSchema(context, schema.$ref);
|
|
67
|
+
}
|
|
59
68
|
const extensions = schemaTransformers[kind](schema, context);
|
|
60
|
-
Object.assign(
|
|
69
|
+
const completeSchema = Object.assign(incompleteSchema, extensions);
|
|
70
|
+
resolveDescriminatorMapping(context, completeSchema);
|
|
61
71
|
context.incompleteSchemas.delete(schemaSource);
|
|
62
|
-
context.transformed.schemas.set(openApiObjectId,
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
return result;
|
|
72
|
+
context.transformed.schemas.set(openApiObjectId, completeSchema);
|
|
73
|
+
context.schemas.set(schemaSource, completeSchema);
|
|
74
|
+
return completeSchema;
|
|
67
75
|
}
|
|
68
76
|
exports.transformSchema = transformSchema;
|
|
69
77
|
const schemaTransformers = {
|
|
@@ -139,3 +147,14 @@ const schemaTransformers = {
|
|
|
139
147
|
null: () => ({ type: 'null' }),
|
|
140
148
|
unknown: () => ({}),
|
|
141
149
|
};
|
|
150
|
+
function resolveDescriminatorMapping(context, schema) {
|
|
151
|
+
const discriminator = schema.$src.component.discriminator;
|
|
152
|
+
if (!discriminator || typeof discriminator === 'string' || !discriminator.mapping)
|
|
153
|
+
return;
|
|
154
|
+
for (const key of Object.keys(discriminator.mapping)) {
|
|
155
|
+
const mappedSchemaRef = discriminator.mapping[key];
|
|
156
|
+
const mappedSchema = transformSchema(context, mappedSchemaRef);
|
|
157
|
+
schema.discriminator.mapping[key] = mappedSchema;
|
|
158
|
+
mappedSchema.inheritedSchemas.push(schema);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
@@ -242,17 +242,22 @@ class SourceBuilder extends string_utils_1.StringBuilder {
|
|
|
242
242
|
}
|
|
243
243
|
/**
|
|
244
244
|
* Adds one indentation level. If the current line already contains characters, only subsequent lines are affected.
|
|
245
|
-
* @param builderFn The function to add indented content.
|
|
245
|
+
* @param builderFn The function to add indented content or the content itself.
|
|
246
246
|
* @param condition The condition to check before adding indentation.
|
|
247
247
|
* @returns A reference to this instance.
|
|
248
248
|
*/
|
|
249
|
-
indent(
|
|
249
|
+
indent(builderFnOrString, condition = true) {
|
|
250
250
|
const shouldIndent = (0, condition_1.evalCondition)(condition);
|
|
251
251
|
if (shouldIndent) {
|
|
252
252
|
this.currentIndentLevel++;
|
|
253
253
|
}
|
|
254
254
|
try {
|
|
255
|
-
|
|
255
|
+
if (typeof builderFnOrString === 'string') {
|
|
256
|
+
this.append(builderFnOrString);
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
builderFnOrString(this);
|
|
260
|
+
}
|
|
256
261
|
}
|
|
257
262
|
finally {
|
|
258
263
|
if (shouldIndent) {
|
|
@@ -264,14 +269,29 @@ class SourceBuilder extends string_utils_1.StringBuilder {
|
|
|
264
269
|
/**
|
|
265
270
|
* Adds parentheses around the specified content and adds one indentation level.
|
|
266
271
|
* @param brackets The brackets to use.
|
|
267
|
-
* @param
|
|
272
|
+
* @param builderFnOrString The function to add content inside parentheses or one string that should be parenthesized.
|
|
268
273
|
* @param indent Whether to indent the content inside parentheses. Defaults to `true`.
|
|
269
274
|
* @returns A reference to this instance.
|
|
270
275
|
*/
|
|
271
|
-
parenthesize(brackets,
|
|
276
|
+
parenthesize(brackets, builderFnOrString, indent = true) {
|
|
272
277
|
var _a, _b;
|
|
273
278
|
this.append((_a = brackets[0]) !== null && _a !== void 0 ? _a : '');
|
|
274
|
-
this.indent(
|
|
279
|
+
this.indent(builderFnOrString, indent);
|
|
280
|
+
this.append((_b = brackets[1]) !== null && _b !== void 0 ? _b : '');
|
|
281
|
+
return this;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Adds parentheses around the specified content and adds one indentation level. Line breaks are added after start and before end of the parentheses.
|
|
285
|
+
* @param brackets The brackets to use.
|
|
286
|
+
* @param builderFnOrString The function to add content inside parentheses or one string that should be parenthesized.
|
|
287
|
+
* @param indent Whether to indent the content inside parentheses. Defaults to `true`.
|
|
288
|
+
* @returns A reference to this instance.
|
|
289
|
+
*/
|
|
290
|
+
parenthesizeMultiline(brackets, builderFnOrString, indent = true) {
|
|
291
|
+
var _a, _b;
|
|
292
|
+
this.appendLine((_a = brackets[0]) !== null && _a !== void 0 ? _a : '');
|
|
293
|
+
this.indent(builderFnOrString, indent);
|
|
294
|
+
this.ensureCurrentLineEmpty();
|
|
275
295
|
this.append((_b = brackets[1]) !== null && _b !== void 0 ? _b : '');
|
|
276
296
|
return this;
|
|
277
297
|
}
|
|
@@ -279,16 +299,33 @@ class SourceBuilder extends string_utils_1.StringBuilder {
|
|
|
279
299
|
* Adds parentheses around the specified content if the specified condition is true.
|
|
280
300
|
* @param condition The condition to check before adding parentheses.
|
|
281
301
|
* @param brackets The brackets to use.
|
|
282
|
-
* @param
|
|
302
|
+
* @param builderFnOrString The function to add content inside parentheses or one string that should be parenthesized.
|
|
303
|
+
* @param indent Whether to indent the content inside parentheses. Defaults to `true`.
|
|
304
|
+
* @returns A reference to this instance.
|
|
305
|
+
*/
|
|
306
|
+
parenthesizeIf(condition, brackets, builderFnOrString, indent) {
|
|
307
|
+
if ((0, condition_1.evalCondition)(condition)) {
|
|
308
|
+
this.parenthesize(brackets, builderFnOrString, indent !== null && indent !== void 0 ? indent : true);
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
this.indent(builderFnOrString, indent !== null && indent !== void 0 ? indent : false);
|
|
312
|
+
}
|
|
313
|
+
return this;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Adds parentheses around the specified content if the specified condition is true. Line breaks are added after start and before end of the parentheses.
|
|
317
|
+
* @param condition The condition to check before adding parentheses.
|
|
318
|
+
* @param brackets The brackets to use.
|
|
319
|
+
* @param builderFnOrString The function to add content inside parentheses or one string that should be parenthesized.
|
|
283
320
|
* @param indent Whether to indent the content inside parentheses. Defaults to `true`.
|
|
284
321
|
* @returns A reference to this instance.
|
|
285
322
|
*/
|
|
286
|
-
|
|
323
|
+
parenthesizeMultilineIf(condition, brackets, builderFnOrString, indent) {
|
|
287
324
|
if ((0, condition_1.evalCondition)(condition)) {
|
|
288
|
-
this.
|
|
325
|
+
this.parenthesizeMultiline(brackets, builderFnOrString, indent !== null && indent !== void 0 ? indent : true);
|
|
289
326
|
}
|
|
290
327
|
else {
|
|
291
|
-
this.indent(
|
|
328
|
+
this.indent(builderFnOrString, indent !== null && indent !== void 0 ? indent : false);
|
|
292
329
|
}
|
|
293
330
|
return this;
|
|
294
331
|
}
|
|
@@ -52,6 +52,7 @@ function collectPathItem(data, pathItems, path) {
|
|
|
52
52
|
}
|
|
53
53
|
function collectSchema(data, schemas) {
|
|
54
54
|
collect(data, schemas, (data, schema) => {
|
|
55
|
+
var _a;
|
|
55
56
|
const key = `${schema.$src.file}#${schema.$src.path}`;
|
|
56
57
|
if (data.schemas.has(key))
|
|
57
58
|
return;
|
|
@@ -71,6 +72,9 @@ function collectSchema(data, schemas) {
|
|
|
71
72
|
if (typeof schema.additionalItems === 'object') {
|
|
72
73
|
collectSchema(data, schema.additionalItems);
|
|
73
74
|
}
|
|
75
|
+
if (typeof schema.discriminator === 'object') {
|
|
76
|
+
collectRecord(data, (_a = schema.discriminator) === null || _a === void 0 ? void 0 : _a.mapping, collectSchema);
|
|
77
|
+
}
|
|
74
78
|
});
|
|
75
79
|
}
|
|
76
80
|
function collectParameter(data, parameters) {
|
package/esm/lib/parse/parser.js
CHANGED
|
@@ -8,6 +8,7 @@ import YAML from 'yaml';
|
|
|
8
8
|
import { createDerefProxy } from './deref-proxy';
|
|
9
9
|
import { collectOpenApi } from '../collect/collector';
|
|
10
10
|
import { transformOpenApi } from '../transform/transformer';
|
|
11
|
+
import { isNullish } from '../utils';
|
|
11
12
|
export class OpenApiParser {
|
|
12
13
|
constructor() {
|
|
13
14
|
this._loadedDocuments = new Map();
|
|
@@ -58,7 +59,9 @@ export class OpenApiParser {
|
|
|
58
59
|
if (key === '$ref')
|
|
59
60
|
continue;
|
|
60
61
|
const v = value[key];
|
|
61
|
-
if (v
|
|
62
|
+
if (isNullish(v))
|
|
63
|
+
continue;
|
|
64
|
+
if (typeof v === 'object') {
|
|
62
65
|
if (Array.isArray(v)) {
|
|
63
66
|
result[key] = yield Promise.all(v.map((v, index) => __awaiter(this, void 0, void 0, function* () {
|
|
64
67
|
if (v && typeof v === 'object') {
|
|
@@ -73,6 +76,9 @@ export class OpenApiParser {
|
|
|
73
76
|
result[key] = yield this.dereference(file, `${path}/${String(key)}`, v);
|
|
74
77
|
}
|
|
75
78
|
}
|
|
79
|
+
if (typeof v === 'string' && path.endsWith('/discriminator/mapping')) {
|
|
80
|
+
result[key] = yield this.resolveReference(file, { $ref: v });
|
|
81
|
+
}
|
|
76
82
|
}
|
|
77
83
|
return result;
|
|
78
84
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { determineSchemaAccessibility, determineSchemaKind, determineSchemaName, getCustomFields, getOpenApiObjectIdentifier, transformAdditionalProperties, transformSchemaProperties, } from './helpers';
|
|
2
2
|
import { createOverwriteProxy } from '../utils';
|
|
3
|
-
export function transformSchema(context, schema
|
|
3
|
+
export function transformSchema(context, schema) {
|
|
4
4
|
var _a, _b;
|
|
5
5
|
if (!schema) {
|
|
6
6
|
throw new Error('Schema is required.');
|
|
@@ -30,12 +30,11 @@ export function transformSchema(context, schema, isReference = false) {
|
|
|
30
30
|
kind = determineSchemaKind(schema);
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
const ref = schema.$ref ? transformSchema(context, schema.$ref, true) : undefined;
|
|
34
33
|
const id = context.idGenerator.generateId('schema');
|
|
35
34
|
const nameInfo = determineSchemaName(schema, id);
|
|
36
|
-
const
|
|
35
|
+
const incompleteSchema = {
|
|
37
36
|
$src: Object.assign(Object.assign({}, schema.$src), { component: schema }),
|
|
38
|
-
$ref:
|
|
37
|
+
$ref: undefined,
|
|
39
38
|
id,
|
|
40
39
|
name: nameInfo.name,
|
|
41
40
|
isNameGenerated: nameInfo.isGenerated,
|
|
@@ -51,16 +50,25 @@ export function transformSchema(context, schema, isReference = false) {
|
|
|
51
50
|
custom: getCustomFields(schema),
|
|
52
51
|
not: schema.not ? transformSchema(context, schema.not) : undefined,
|
|
53
52
|
const: schema.const,
|
|
53
|
+
discriminator: schema.discriminator
|
|
54
|
+
? {
|
|
55
|
+
propertyName: typeof schema.discriminator === 'string' ? schema.discriminator : schema.discriminator.propertyName,
|
|
56
|
+
mapping: {},
|
|
57
|
+
}
|
|
58
|
+
: undefined,
|
|
59
|
+
inheritedSchemas: [],
|
|
54
60
|
};
|
|
55
|
-
context.incompleteSchemas.set(schemaSource,
|
|
61
|
+
context.incompleteSchemas.set(schemaSource, incompleteSchema);
|
|
62
|
+
if (schema.$ref) {
|
|
63
|
+
incompleteSchema.$ref = transformSchema(context, schema.$ref);
|
|
64
|
+
}
|
|
56
65
|
const extensions = schemaTransformers[kind](schema, context);
|
|
57
|
-
Object.assign(
|
|
66
|
+
const completeSchema = Object.assign(incompleteSchema, extensions);
|
|
67
|
+
resolveDescriminatorMapping(context, completeSchema);
|
|
58
68
|
context.incompleteSchemas.delete(schemaSource);
|
|
59
|
-
context.transformed.schemas.set(openApiObjectId,
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
return result;
|
|
69
|
+
context.transformed.schemas.set(openApiObjectId, completeSchema);
|
|
70
|
+
context.schemas.set(schemaSource, completeSchema);
|
|
71
|
+
return completeSchema;
|
|
64
72
|
}
|
|
65
73
|
const schemaTransformers = {
|
|
66
74
|
oneOf: (schema, context) => {
|
|
@@ -135,3 +143,14 @@ const schemaTransformers = {
|
|
|
135
143
|
null: () => ({ type: 'null' }),
|
|
136
144
|
unknown: () => ({}),
|
|
137
145
|
};
|
|
146
|
+
function resolveDescriminatorMapping(context, schema) {
|
|
147
|
+
const discriminator = schema.$src.component.discriminator;
|
|
148
|
+
if (!discriminator || typeof discriminator === 'string' || !discriminator.mapping)
|
|
149
|
+
return;
|
|
150
|
+
for (const key of Object.keys(discriminator.mapping)) {
|
|
151
|
+
const mappedSchemaRef = discriminator.mapping[key];
|
|
152
|
+
const mappedSchema = transformSchema(context, mappedSchemaRef);
|
|
153
|
+
schema.discriminator.mapping[key] = mappedSchema;
|
|
154
|
+
mappedSchema.inheritedSchemas.push(schema);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
@@ -239,17 +239,22 @@ export class SourceBuilder extends StringBuilder {
|
|
|
239
239
|
}
|
|
240
240
|
/**
|
|
241
241
|
* Adds one indentation level. If the current line already contains characters, only subsequent lines are affected.
|
|
242
|
-
* @param builderFn The function to add indented content.
|
|
242
|
+
* @param builderFn The function to add indented content or the content itself.
|
|
243
243
|
* @param condition The condition to check before adding indentation.
|
|
244
244
|
* @returns A reference to this instance.
|
|
245
245
|
*/
|
|
246
|
-
indent(
|
|
246
|
+
indent(builderFnOrString, condition = true) {
|
|
247
247
|
const shouldIndent = evalCondition(condition);
|
|
248
248
|
if (shouldIndent) {
|
|
249
249
|
this.currentIndentLevel++;
|
|
250
250
|
}
|
|
251
251
|
try {
|
|
252
|
-
|
|
252
|
+
if (typeof builderFnOrString === 'string') {
|
|
253
|
+
this.append(builderFnOrString);
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
builderFnOrString(this);
|
|
257
|
+
}
|
|
253
258
|
}
|
|
254
259
|
finally {
|
|
255
260
|
if (shouldIndent) {
|
|
@@ -261,14 +266,29 @@ export class SourceBuilder extends StringBuilder {
|
|
|
261
266
|
/**
|
|
262
267
|
* Adds parentheses around the specified content and adds one indentation level.
|
|
263
268
|
* @param brackets The brackets to use.
|
|
264
|
-
* @param
|
|
269
|
+
* @param builderFnOrString The function to add content inside parentheses or one string that should be parenthesized.
|
|
265
270
|
* @param indent Whether to indent the content inside parentheses. Defaults to `true`.
|
|
266
271
|
* @returns A reference to this instance.
|
|
267
272
|
*/
|
|
268
|
-
parenthesize(brackets,
|
|
273
|
+
parenthesize(brackets, builderFnOrString, indent = true) {
|
|
269
274
|
var _a, _b;
|
|
270
275
|
this.append((_a = brackets[0]) !== null && _a !== void 0 ? _a : '');
|
|
271
|
-
this.indent(
|
|
276
|
+
this.indent(builderFnOrString, indent);
|
|
277
|
+
this.append((_b = brackets[1]) !== null && _b !== void 0 ? _b : '');
|
|
278
|
+
return this;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Adds parentheses around the specified content and adds one indentation level. Line breaks are added after start and before end of the parentheses.
|
|
282
|
+
* @param brackets The brackets to use.
|
|
283
|
+
* @param builderFnOrString The function to add content inside parentheses or one string that should be parenthesized.
|
|
284
|
+
* @param indent Whether to indent the content inside parentheses. Defaults to `true`.
|
|
285
|
+
* @returns A reference to this instance.
|
|
286
|
+
*/
|
|
287
|
+
parenthesizeMultiline(brackets, builderFnOrString, indent = true) {
|
|
288
|
+
var _a, _b;
|
|
289
|
+
this.appendLine((_a = brackets[0]) !== null && _a !== void 0 ? _a : '');
|
|
290
|
+
this.indent(builderFnOrString, indent);
|
|
291
|
+
this.ensureCurrentLineEmpty();
|
|
272
292
|
this.append((_b = brackets[1]) !== null && _b !== void 0 ? _b : '');
|
|
273
293
|
return this;
|
|
274
294
|
}
|
|
@@ -276,16 +296,33 @@ export class SourceBuilder extends StringBuilder {
|
|
|
276
296
|
* Adds parentheses around the specified content if the specified condition is true.
|
|
277
297
|
* @param condition The condition to check before adding parentheses.
|
|
278
298
|
* @param brackets The brackets to use.
|
|
279
|
-
* @param
|
|
299
|
+
* @param builderFnOrString The function to add content inside parentheses or one string that should be parenthesized.
|
|
300
|
+
* @param indent Whether to indent the content inside parentheses. Defaults to `true`.
|
|
301
|
+
* @returns A reference to this instance.
|
|
302
|
+
*/
|
|
303
|
+
parenthesizeIf(condition, brackets, builderFnOrString, indent) {
|
|
304
|
+
if (evalCondition(condition)) {
|
|
305
|
+
this.parenthesize(brackets, builderFnOrString, indent !== null && indent !== void 0 ? indent : true);
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
this.indent(builderFnOrString, indent !== null && indent !== void 0 ? indent : false);
|
|
309
|
+
}
|
|
310
|
+
return this;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Adds parentheses around the specified content if the specified condition is true. Line breaks are added after start and before end of the parentheses.
|
|
314
|
+
* @param condition The condition to check before adding parentheses.
|
|
315
|
+
* @param brackets The brackets to use.
|
|
316
|
+
* @param builderFnOrString The function to add content inside parentheses or one string that should be parenthesized.
|
|
280
317
|
* @param indent Whether to indent the content inside parentheses. Defaults to `true`.
|
|
281
318
|
* @returns A reference to this instance.
|
|
282
319
|
*/
|
|
283
|
-
|
|
320
|
+
parenthesizeMultilineIf(condition, brackets, builderFnOrString, indent) {
|
|
284
321
|
if (evalCondition(condition)) {
|
|
285
|
-
this.
|
|
322
|
+
this.parenthesizeMultiline(brackets, builderFnOrString, indent !== null && indent !== void 0 ? indent : true);
|
|
286
323
|
}
|
|
287
324
|
else {
|
|
288
|
-
this.indent(
|
|
325
|
+
this.indent(builderFnOrString, indent !== null && indent !== void 0 ? indent : false);
|
|
289
326
|
}
|
|
290
327
|
return this;
|
|
291
328
|
}
|
package/package.json
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { OpenApiCollectorData } from './types';
|
|
2
|
-
|
|
3
|
-
export declare function
|
|
2
|
+
import { Nullable } from '../utils';
|
|
3
|
+
export declare function collect<T extends Record<`x-${string}`, unknown>>(data: OpenApiCollectorData, obj: Nullable<T | Nullable<T>[]>, func: (data: OpenApiCollectorData, obj: NonNullable<T>) => void): void;
|
|
4
|
+
export declare function collectRecord<T extends Record<`x-${string}`, unknown>>(data: OpenApiCollectorData, obj: Nullable<Record<string, Nullable<T>>>, func: (data: OpenApiCollectorData, obj: NonNullable<T>, key: string) => void): void;
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { OpenApiDocument, OpenApiReference } from './openapi-types';
|
|
1
|
+
import { OpenApiDiscriminator, OpenApiDocument, OpenApiReference, OpenApiSchema } from './openapi-types';
|
|
2
2
|
export type DerefSource<T> = {
|
|
3
3
|
file: string;
|
|
4
4
|
path: string;
|
|
5
5
|
document: Deref<OpenApiDocument>;
|
|
6
6
|
originalComponent: T;
|
|
7
7
|
};
|
|
8
|
-
type
|
|
8
|
+
type _DerefDiscriminator = Omit<OpenApiDiscriminator, 'mapping'> & {
|
|
9
|
+
mapping?: Record<string, Deref<OpenApiSchema>>;
|
|
10
|
+
};
|
|
11
|
+
type _Deref<T extends object> = T extends OpenApiDiscriminator ? _DerefDiscriminator : {
|
|
9
12
|
[K in keyof T as K extends keyof OpenApiReference ? never : K]: Deref<T[K]>;
|
|
10
13
|
} & {
|
|
11
14
|
$src: DerefSource<T>;
|
|
@@ -88,6 +88,10 @@ export type ApiSchemaProperty = {
|
|
|
88
88
|
name: string;
|
|
89
89
|
schema: ApiSchema;
|
|
90
90
|
};
|
|
91
|
+
export type ApiSchemaDiscriminator = {
|
|
92
|
+
propertyName: string;
|
|
93
|
+
mapping: Record<string, ApiSchema>;
|
|
94
|
+
};
|
|
91
95
|
export type ApiSchemaComponent = ApiComponent<OpenApiSchema>;
|
|
92
96
|
export type ApiSchemaBase = ApiSchemaComponent & {
|
|
93
97
|
name: string;
|
|
@@ -103,6 +107,8 @@ export type ApiSchemaBase = ApiSchemaComponent & {
|
|
|
103
107
|
required: Set<string>;
|
|
104
108
|
custom: Record<string, unknown>;
|
|
105
109
|
not: ApiSchema | undefined;
|
|
110
|
+
discriminator: ApiSchemaDiscriminator | undefined;
|
|
111
|
+
inheritedSchemas: ApiSchema[];
|
|
106
112
|
};
|
|
107
113
|
export type ApiSchema<T extends ApiSchemaKind = ApiSchemaKind> = ApiSchemaBase & ApiSchemaExtensions<T>;
|
|
108
114
|
type AdditionalCombinedSchemaProperties = {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { ApiSchema } from './api-types';
|
|
2
2
|
import { OpenApiTransformerContext } from './types';
|
|
3
3
|
import { Deref, OpenApiSchema } from '../parse';
|
|
4
|
-
export declare function transformSchema<T extends Deref<OpenApiSchema>>(context: OpenApiTransformerContext, schema: T
|
|
4
|
+
export declare function transformSchema<T extends Deref<OpenApiSchema>>(context: OpenApiTransformerContext, schema: T): ApiSchema;
|
|
@@ -148,28 +148,45 @@ export declare class SourceBuilder extends StringBuilder {
|
|
|
148
148
|
applyIfElse(condition: Condition, builderFn: (builder: this) => void, elseBuilderFn: (builder: this) => void): this;
|
|
149
149
|
/**
|
|
150
150
|
* Adds one indentation level. If the current line already contains characters, only subsequent lines are affected.
|
|
151
|
-
* @param builderFn The function to add indented content.
|
|
151
|
+
* @param builderFn The function to add indented content or the content itself.
|
|
152
152
|
* @param condition The condition to check before adding indentation.
|
|
153
153
|
* @returns A reference to this instance.
|
|
154
154
|
*/
|
|
155
|
-
indent(
|
|
155
|
+
indent(builderFnOrString: ((builder: this) => void) | string, condition?: Condition): this;
|
|
156
156
|
/**
|
|
157
157
|
* Adds parentheses around the specified content and adds one indentation level.
|
|
158
158
|
* @param brackets The brackets to use.
|
|
159
|
-
* @param
|
|
159
|
+
* @param builderFnOrString The function to add content inside parentheses or one string that should be parenthesized.
|
|
160
160
|
* @param indent Whether to indent the content inside parentheses. Defaults to `true`.
|
|
161
161
|
* @returns A reference to this instance.
|
|
162
162
|
*/
|
|
163
|
-
parenthesize(brackets: Paratheses,
|
|
163
|
+
parenthesize(brackets: Paratheses, builderFnOrString: ((builder: this) => void) | string, indent?: boolean): this;
|
|
164
|
+
/**
|
|
165
|
+
* Adds parentheses around the specified content and adds one indentation level. Line breaks are added after start and before end of the parentheses.
|
|
166
|
+
* @param brackets The brackets to use.
|
|
167
|
+
* @param builderFnOrString The function to add content inside parentheses or one string that should be parenthesized.
|
|
168
|
+
* @param indent Whether to indent the content inside parentheses. Defaults to `true`.
|
|
169
|
+
* @returns A reference to this instance.
|
|
170
|
+
*/
|
|
171
|
+
parenthesizeMultiline(brackets: Paratheses, builderFnOrString: ((builder: this) => void) | string, indent?: boolean): this;
|
|
164
172
|
/**
|
|
165
173
|
* Adds parentheses around the specified content if the specified condition is true.
|
|
166
174
|
* @param condition The condition to check before adding parentheses.
|
|
167
175
|
* @param brackets The brackets to use.
|
|
168
|
-
* @param
|
|
176
|
+
* @param builderFnOrString The function to add content inside parentheses or one string that should be parenthesized.
|
|
177
|
+
* @param indent Whether to indent the content inside parentheses. Defaults to `true`.
|
|
178
|
+
* @returns A reference to this instance.
|
|
179
|
+
*/
|
|
180
|
+
parenthesizeIf(condition: Condition, brackets: Paratheses, builderFnOrString: ((builder: this) => void) | string, indent?: boolean): this;
|
|
181
|
+
/**
|
|
182
|
+
* Adds parentheses around the specified content if the specified condition is true. Line breaks are added after start and before end of the parentheses.
|
|
183
|
+
* @param condition The condition to check before adding parentheses.
|
|
184
|
+
* @param brackets The brackets to use.
|
|
185
|
+
* @param builderFnOrString The function to add content inside parentheses or one string that should be parenthesized.
|
|
169
186
|
* @param indent Whether to indent the content inside parentheses. Defaults to `true`.
|
|
170
187
|
* @returns A reference to this instance.
|
|
171
188
|
*/
|
|
172
|
-
|
|
189
|
+
parenthesizeMultilineIf(condition: Condition, brackets: Paratheses, builderFnOrString: ((builder: this) => void) | string, indent?: boolean): this;
|
|
173
190
|
/**
|
|
174
191
|
* Adds content for each item in the specified array.
|
|
175
192
|
* @param items The items to add content for.
|