@kaapi/kaapi 0.0.24 → 0.0.26
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/lib/app.d.ts +0 -3
- package/lib/app.js +33 -35
- package/lib/app.js.map +1 -1
- package/lib/declarations.d.ts +23 -0
- package/lib/index.d.ts +3 -2
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/services/docs/api-doc-mix-helpers.d.ts +1 -1
- package/lib/services/docs/doc-adapters.d.ts +108 -0
- package/lib/services/docs/doc-adapters.js +430 -0
- package/lib/services/docs/doc-adapters.js.map +1 -0
- package/lib/services/docs/docs-modifiers.d.ts +108 -0
- package/lib/services/docs/docs-modifiers.js +430 -0
- package/lib/services/docs/docs-modifiers.js.map +1 -0
- package/lib/services/docs/docs.d.ts +3 -3
- package/lib/services/docs/docs.js.map +1 -1
- package/lib/services/docs/generators.d.ts +29 -6
- package/lib/services/docs/generators.js +261 -37
- package/lib/services/docs/generators.js.map +1 -1
- package/lib/services/docs/modifiers.d.ts +111 -0
- package/lib/services/docs/modifiers.js +674 -0
- package/lib/services/docs/modifiers.js.map +1 -0
- package/lib/services/docs/utils.d.ts +2 -2
- package/package.json +5 -3
- package/types/overrides.d.ts +0 -30
|
@@ -0,0 +1,674 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _SchemaModifier_instances, _a, _SchemaModifier_convertOne, _SchemaModifier_convertMany, _SchemaModifier_convertObjectOf;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.GroupResponseDocsModifier = exports.ContextResponseDocsModifier = exports.ResponseDocsModifier = exports.RequestBodyDocsModifier = exports.MediaTypeModifier = exports.SchemaModifier = exports.ExampleModifier = void 0;
|
|
5
|
+
exports.groupResponses = groupResponses;
|
|
6
|
+
const tslib_1 = require("tslib");
|
|
7
|
+
const deep_extend_1 = require("./deep-extend");
|
|
8
|
+
const jsontoxml_1 = tslib_1.__importDefault(require("jsontoxml"));
|
|
9
|
+
const api_doc_generator_1 = require("@novice1/api-doc-generator");
|
|
10
|
+
// -------------------- CLASSES --------------------
|
|
11
|
+
class ExampleModifier {
|
|
12
|
+
constructor(name, example) {
|
|
13
|
+
this.name = name;
|
|
14
|
+
if (example) {
|
|
15
|
+
this.value = example.value;
|
|
16
|
+
this.externalValue = example.externalValue;
|
|
17
|
+
this.summary = example.summary;
|
|
18
|
+
this.description = example.description;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
getName() {
|
|
22
|
+
return this.name;
|
|
23
|
+
}
|
|
24
|
+
setValue(value) {
|
|
25
|
+
this.value = value;
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
getValue() {
|
|
29
|
+
return this.value;
|
|
30
|
+
}
|
|
31
|
+
setExternalValue(externalValue) {
|
|
32
|
+
this.externalValue = externalValue;
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
getExternalValue() {
|
|
36
|
+
return this.externalValue;
|
|
37
|
+
}
|
|
38
|
+
setSummary(summary) {
|
|
39
|
+
this.summary = summary;
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
getSummary() {
|
|
43
|
+
return this.summary;
|
|
44
|
+
}
|
|
45
|
+
setDescription(description) {
|
|
46
|
+
this.description = description;
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
getDescription() {
|
|
50
|
+
return this.description;
|
|
51
|
+
}
|
|
52
|
+
ref() {
|
|
53
|
+
return { $ref: `#/components/examples/${this.name}` };
|
|
54
|
+
}
|
|
55
|
+
toObject() {
|
|
56
|
+
return {
|
|
57
|
+
description: this.description,
|
|
58
|
+
externalValue: this.externalValue,
|
|
59
|
+
summary: this.summary,
|
|
60
|
+
value: this.value
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
toJSON() {
|
|
64
|
+
return this.toObject();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.ExampleModifier = ExampleModifier;
|
|
68
|
+
class SchemaModifier {
|
|
69
|
+
constructor(name, schema) {
|
|
70
|
+
_SchemaModifier_instances.add(this);
|
|
71
|
+
this.schema = {};
|
|
72
|
+
this.name = name;
|
|
73
|
+
if (schema) {
|
|
74
|
+
this.setSchema(schema);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
getName() {
|
|
78
|
+
return this.name;
|
|
79
|
+
}
|
|
80
|
+
setSchema(schema) {
|
|
81
|
+
this.schema = schema;
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
84
|
+
ref() {
|
|
85
|
+
return { $ref: `#/components/schemas/${this.name}` };
|
|
86
|
+
}
|
|
87
|
+
toObject() {
|
|
88
|
+
const _b = this.schema, { allOf, anyOf, oneOf, not, items, properties, additionalProperties } = _b, value = tslib_1.__rest(_b, ["allOf", "anyOf", "oneOf", "not", "items", "properties", "additionalProperties"]);
|
|
89
|
+
const valueToKeep = value;
|
|
90
|
+
if (allOf) {
|
|
91
|
+
valueToKeep.allOf = tslib_1.__classPrivateFieldGet(this, _SchemaModifier_instances, "m", _SchemaModifier_convertMany).call(this, allOf);
|
|
92
|
+
}
|
|
93
|
+
if (anyOf) {
|
|
94
|
+
valueToKeep.anyOf = tslib_1.__classPrivateFieldGet(this, _SchemaModifier_instances, "m", _SchemaModifier_convertMany).call(this, anyOf);
|
|
95
|
+
}
|
|
96
|
+
if (oneOf) {
|
|
97
|
+
valueToKeep.oneOf = tslib_1.__classPrivateFieldGet(this, _SchemaModifier_instances, "m", _SchemaModifier_convertMany).call(this, oneOf);
|
|
98
|
+
}
|
|
99
|
+
if (not) {
|
|
100
|
+
valueToKeep.not = tslib_1.__classPrivateFieldGet(this, _SchemaModifier_instances, "m", _SchemaModifier_convertOne).call(this, not);
|
|
101
|
+
}
|
|
102
|
+
if (items) {
|
|
103
|
+
valueToKeep.items = tslib_1.__classPrivateFieldGet(this, _SchemaModifier_instances, "m", _SchemaModifier_convertOne).call(this, items);
|
|
104
|
+
}
|
|
105
|
+
if (properties) {
|
|
106
|
+
valueToKeep.properties = tslib_1.__classPrivateFieldGet(this, _SchemaModifier_instances, "m", _SchemaModifier_convertObjectOf).call(this, properties);
|
|
107
|
+
}
|
|
108
|
+
if (typeof additionalProperties !== 'undefined') {
|
|
109
|
+
if (typeof additionalProperties === 'boolean') {
|
|
110
|
+
valueToKeep.additionalProperties = additionalProperties;
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
valueToKeep.additionalProperties = tslib_1.__classPrivateFieldGet(this, _SchemaModifier_instances, "m", _SchemaModifier_convertOne).call(this, additionalProperties);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return Object.assign({}, valueToKeep);
|
|
117
|
+
}
|
|
118
|
+
toJSON() {
|
|
119
|
+
return this.toObject();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
exports.SchemaModifier = SchemaModifier;
|
|
123
|
+
_a = SchemaModifier, _SchemaModifier_instances = new WeakSet(), _SchemaModifier_convertOne = function _SchemaModifier_convertOne(v) {
|
|
124
|
+
if ('ref' in v && typeof v.ref == 'function') {
|
|
125
|
+
return v.ref();
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
return new _a('tmp', v).toObject();
|
|
129
|
+
}
|
|
130
|
+
}, _SchemaModifier_convertMany = function _SchemaModifier_convertMany(v) {
|
|
131
|
+
const r = [];
|
|
132
|
+
for (const element of v) {
|
|
133
|
+
r.push(tslib_1.__classPrivateFieldGet(this, _SchemaModifier_instances, "m", _SchemaModifier_convertOne).call(this, element));
|
|
134
|
+
}
|
|
135
|
+
return r;
|
|
136
|
+
}, _SchemaModifier_convertObjectOf = function _SchemaModifier_convertObjectOf(v) {
|
|
137
|
+
const r = {};
|
|
138
|
+
for (const k in v) {
|
|
139
|
+
const vk = v[k];
|
|
140
|
+
r[k] = (tslib_1.__classPrivateFieldGet(this, _SchemaModifier_instances, "m", _SchemaModifier_convertOne).call(this, vk));
|
|
141
|
+
}
|
|
142
|
+
return r;
|
|
143
|
+
};
|
|
144
|
+
class MediaTypeModifier extends api_doc_generator_1.MediaTypeUtil {
|
|
145
|
+
constructor(mediaType) {
|
|
146
|
+
super({});
|
|
147
|
+
if (mediaType) {
|
|
148
|
+
const { examples, schema, encoding, example } = mediaType;
|
|
149
|
+
if (encoding)
|
|
150
|
+
this.setEncoding(encoding);
|
|
151
|
+
if (example)
|
|
152
|
+
this.setExample(example);
|
|
153
|
+
if (examples) {
|
|
154
|
+
this.setExamples(examples);
|
|
155
|
+
}
|
|
156
|
+
if (schema) {
|
|
157
|
+
this.setSchema(schema);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
setExamples(examples) {
|
|
162
|
+
this.examples = examples;
|
|
163
|
+
return this;
|
|
164
|
+
}
|
|
165
|
+
setSchema(schema) {
|
|
166
|
+
this.schema = schema;
|
|
167
|
+
return this;
|
|
168
|
+
}
|
|
169
|
+
toObject(noRef) {
|
|
170
|
+
const withSchema = {};
|
|
171
|
+
if (typeof this.schema !== 'undefined') {
|
|
172
|
+
if (this.schema instanceof SchemaModifier) {
|
|
173
|
+
withSchema.schema = this.schema.ref();
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
withSchema.schema = new SchemaModifier('tmp', this.schema).toObject();
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (typeof this.examples !== 'undefined') {
|
|
180
|
+
withSchema.examples = {};
|
|
181
|
+
for (const key in this.examples) {
|
|
182
|
+
const example = this.examples[key];
|
|
183
|
+
if (example instanceof ExampleModifier) {
|
|
184
|
+
if (noRef) {
|
|
185
|
+
withSchema.examples[key] = example.toObject();
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
withSchema.examples[key] = example.ref();
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
withSchema.examples[key] = example;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
const copy = (0, deep_extend_1.deepExtend)(super.toObject(), withSchema);
|
|
197
|
+
return copy;
|
|
198
|
+
}
|
|
199
|
+
toModel() {
|
|
200
|
+
return Object.assign(Object.assign({}, super.toObject()), { schema: this.schema, examples: this.examples });
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
exports.MediaTypeModifier = MediaTypeModifier;
|
|
204
|
+
function isContentFileSchema(schema) {
|
|
205
|
+
let r = false;
|
|
206
|
+
let nbProps = 0;
|
|
207
|
+
if ('type' in schema) {
|
|
208
|
+
if (schema.type !== 'string') {
|
|
209
|
+
return r;
|
|
210
|
+
}
|
|
211
|
+
nbProps++;
|
|
212
|
+
}
|
|
213
|
+
if ('contentMediaType' in schema) {
|
|
214
|
+
nbProps++;
|
|
215
|
+
}
|
|
216
|
+
if ('contentEncoding' in schema) {
|
|
217
|
+
nbProps++;
|
|
218
|
+
}
|
|
219
|
+
if ('$ref' in schema) {
|
|
220
|
+
nbProps++;
|
|
221
|
+
}
|
|
222
|
+
if ('$schema' in schema) {
|
|
223
|
+
nbProps++;
|
|
224
|
+
}
|
|
225
|
+
if (nbProps === Object.keys(schema).length) {
|
|
226
|
+
r = true;
|
|
227
|
+
}
|
|
228
|
+
return r;
|
|
229
|
+
}
|
|
230
|
+
function createElementJsontoxmlSample(name, schema) {
|
|
231
|
+
const res = {
|
|
232
|
+
name
|
|
233
|
+
};
|
|
234
|
+
if ('xml' in schema) {
|
|
235
|
+
let prefix = '';
|
|
236
|
+
const xml = schema.xml;
|
|
237
|
+
if (xml === null || xml === void 0 ? void 0 : xml.name) {
|
|
238
|
+
res.name = xml.name;
|
|
239
|
+
}
|
|
240
|
+
if (xml === null || xml === void 0 ? void 0 : xml.prefix) {
|
|
241
|
+
prefix = xml.prefix;
|
|
242
|
+
}
|
|
243
|
+
if (xml === null || xml === void 0 ? void 0 : xml.namespace) {
|
|
244
|
+
const xmlns = prefix ? `xmlns:${prefix}` : `xmlns:${res.name}`;
|
|
245
|
+
res.attrs = {
|
|
246
|
+
[xmlns]: xml.namespace
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
if (prefix) {
|
|
250
|
+
res.name = `${prefix}:${res.name}`;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return res;
|
|
254
|
+
}
|
|
255
|
+
function formatJsontoxmlSample(json, properties) {
|
|
256
|
+
for (const propName in properties) {
|
|
257
|
+
const propSchema = properties[propName];
|
|
258
|
+
const jsonChild = createJsontoxmlSample(propName, propSchema);
|
|
259
|
+
if ('xml' in propSchema) {
|
|
260
|
+
const xmlObject = propSchema.xml;
|
|
261
|
+
if (xmlObject === null || xmlObject === void 0 ? void 0 : xmlObject.attribute) {
|
|
262
|
+
json.attrs = json.attrs || {};
|
|
263
|
+
json.attrs[propName] = jsonChild.text || '';
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
json.children = json.children || [];
|
|
267
|
+
json.children.push(jsonChild);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
json.children = json.children || [];
|
|
272
|
+
json.children.push(jsonChild);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
function createJsontoxmlSample(name, schema) {
|
|
277
|
+
var _b, _c;
|
|
278
|
+
const res = createElementJsontoxmlSample(name, schema);
|
|
279
|
+
if ('type' in schema) {
|
|
280
|
+
if (schema.type === 'array') {
|
|
281
|
+
// no overdo: do not support anyOf or oneOf here
|
|
282
|
+
if (schema.items && 'type' in schema.items && typeof schema.items.type === 'string') {
|
|
283
|
+
let text;
|
|
284
|
+
const itemType = schema.items.type;
|
|
285
|
+
const itemSchema = schema.items;
|
|
286
|
+
if (typeof itemSchema.default !== 'undefined') {
|
|
287
|
+
text = `${itemSchema.default}`;
|
|
288
|
+
}
|
|
289
|
+
else if ((_b = itemSchema.examples) === null || _b === void 0 ? void 0 : _b.length) {
|
|
290
|
+
text = `${itemSchema.examples[0]}`;
|
|
291
|
+
}
|
|
292
|
+
else if (itemSchema.type === 'number' || itemSchema.type === 'integer') {
|
|
293
|
+
text = `${itemSchema.minimum ? itemSchema.minimum : (itemSchema.exclusiveMinimum ? itemSchema.exclusiveMinimum : 0)}`;
|
|
294
|
+
}
|
|
295
|
+
else if (itemSchema.type === 'boolean') {
|
|
296
|
+
text = 'true';
|
|
297
|
+
}
|
|
298
|
+
else if (itemSchema.type === 'string') {
|
|
299
|
+
text = `${itemSchema.format || itemSchema.type}`;
|
|
300
|
+
}
|
|
301
|
+
else if (itemSchema.format) {
|
|
302
|
+
text = `(${itemSchema.format})`;
|
|
303
|
+
}
|
|
304
|
+
else if (itemType) {
|
|
305
|
+
text = `(${itemType})`;
|
|
306
|
+
}
|
|
307
|
+
if (text) {
|
|
308
|
+
res.text = text;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
else if (schema.type === 'object' && schema.properties && Object.keys(schema.properties).length) {
|
|
313
|
+
formatJsontoxmlSample(res, schema.properties);
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
let text;
|
|
317
|
+
if (typeof schema.default !== 'undefined') {
|
|
318
|
+
text = `${schema.default}`;
|
|
319
|
+
}
|
|
320
|
+
else if ((_c = schema.examples) === null || _c === void 0 ? void 0 : _c.length) {
|
|
321
|
+
text = `${schema.examples[0]}`;
|
|
322
|
+
}
|
|
323
|
+
else if (schema.type === 'number' || schema.type === 'integer') {
|
|
324
|
+
text = `${schema.minimum ? schema.minimum : (schema.exclusiveMinimum ? schema.exclusiveMinimum : 0)}`;
|
|
325
|
+
}
|
|
326
|
+
else if (schema.type === 'boolean') {
|
|
327
|
+
text = 'true';
|
|
328
|
+
}
|
|
329
|
+
else if (schema.type === 'string') {
|
|
330
|
+
text = `${schema.format || schema.type}`;
|
|
331
|
+
}
|
|
332
|
+
else if (schema.format) {
|
|
333
|
+
text = `(${schema.format})`;
|
|
334
|
+
}
|
|
335
|
+
else if (schema.type) {
|
|
336
|
+
text = `(${schema.type})`;
|
|
337
|
+
}
|
|
338
|
+
if (text) {
|
|
339
|
+
res.text = text;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
return res;
|
|
344
|
+
}
|
|
345
|
+
function createRawSample(schema, deepLevel = 0) {
|
|
346
|
+
let sample;
|
|
347
|
+
if (deepLevel > 9 || !Object.keys(schema).length) {
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
if ('$ref' in schema && Object.keys(schema).length === 1) {
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
if ('default' in schema && typeof schema.default !== 'undefined') {
|
|
354
|
+
// default value
|
|
355
|
+
sample = schema.default;
|
|
356
|
+
}
|
|
357
|
+
else if ('enum' in schema && Array.isArray(schema.enum) && schema.enum.length) {
|
|
358
|
+
// default value
|
|
359
|
+
sample = schema.enum[0];
|
|
360
|
+
}
|
|
361
|
+
else if ('examples' in schema && Array.isArray(schema.examples) && schema.examples.length) {
|
|
362
|
+
// first example value
|
|
363
|
+
sample = schema.examples[0];
|
|
364
|
+
}
|
|
365
|
+
else if ('anyOf' in schema && Array.isArray(schema.anyOf) && schema.anyOf.length) {
|
|
366
|
+
// first example value
|
|
367
|
+
sample = createRawSample(schema.anyOf[0], deepLevel + 1);
|
|
368
|
+
}
|
|
369
|
+
else if ('oneOf' in schema && Array.isArray(schema.oneOf) && schema.oneOf.length) {
|
|
370
|
+
// first example value
|
|
371
|
+
sample = createRawSample(schema.oneOf[0], deepLevel + 1);
|
|
372
|
+
}
|
|
373
|
+
else if ('type' in schema) {
|
|
374
|
+
if (schema.type === 'object') {
|
|
375
|
+
const obj = {};
|
|
376
|
+
if (schema.properties) {
|
|
377
|
+
const props = schema.properties;
|
|
378
|
+
Object.keys(props).forEach(name => {
|
|
379
|
+
obj[name] = createRawSample(props[name], deepLevel + 1);
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
sample = obj;
|
|
383
|
+
}
|
|
384
|
+
else if (schema.type === 'array') {
|
|
385
|
+
const arr = [];
|
|
386
|
+
if (schema.items) {
|
|
387
|
+
const itemSample = createRawSample(schema.items, deepLevel + 1);
|
|
388
|
+
if (typeof itemSample !== 'undefined') {
|
|
389
|
+
arr.push(itemSample);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
sample = arr;
|
|
393
|
+
}
|
|
394
|
+
else if (schema.type === 'number' || schema.type === 'integer') {
|
|
395
|
+
sample = schema.minimum ? schema.minimum : (schema.exclusiveMinimum ? schema.exclusiveMinimum : 0);
|
|
396
|
+
}
|
|
397
|
+
else if (schema.type === 'boolean') {
|
|
398
|
+
sample = true;
|
|
399
|
+
}
|
|
400
|
+
else if (schema.format) {
|
|
401
|
+
sample = `<${schema.format}>`;
|
|
402
|
+
}
|
|
403
|
+
else if (schema.type === 'string') {
|
|
404
|
+
sample = '';
|
|
405
|
+
}
|
|
406
|
+
else {
|
|
407
|
+
sample = `<${schema.type}>`;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
return sample;
|
|
411
|
+
}
|
|
412
|
+
class RequestBodyDocsModifier {
|
|
413
|
+
constructor(name) {
|
|
414
|
+
this.content = {};
|
|
415
|
+
this.name = name || this.constructor.name;
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
*
|
|
419
|
+
* @param description A short description of the response.
|
|
420
|
+
* CommonMark syntax MAY be used for rich text representation.
|
|
421
|
+
*/
|
|
422
|
+
setDescription(description) {
|
|
423
|
+
this.description = description;
|
|
424
|
+
return this;
|
|
425
|
+
}
|
|
426
|
+
setName(name) {
|
|
427
|
+
this.name = name;
|
|
428
|
+
return this;
|
|
429
|
+
}
|
|
430
|
+
setRequired(isRequired) {
|
|
431
|
+
this.required = isRequired;
|
|
432
|
+
return this;
|
|
433
|
+
}
|
|
434
|
+
setRef(requestBodyRef) {
|
|
435
|
+
this.requestBodyRef = requestBodyRef;
|
|
436
|
+
return this;
|
|
437
|
+
}
|
|
438
|
+
getDescription() {
|
|
439
|
+
return this.description;
|
|
440
|
+
}
|
|
441
|
+
getName() {
|
|
442
|
+
return this.name;
|
|
443
|
+
}
|
|
444
|
+
isRequired() {
|
|
445
|
+
return !!this.required;
|
|
446
|
+
}
|
|
447
|
+
addMediaType(contentType, mediaType = {}) {
|
|
448
|
+
this.content = this.content || {};
|
|
449
|
+
if (mediaType instanceof MediaTypeModifier) {
|
|
450
|
+
this.content[contentType] = mediaType;
|
|
451
|
+
}
|
|
452
|
+
else {
|
|
453
|
+
this.content[contentType] = new MediaTypeModifier(mediaType);
|
|
454
|
+
}
|
|
455
|
+
return this;
|
|
456
|
+
}
|
|
457
|
+
ref() {
|
|
458
|
+
return { $ref: this.requestBodyRef || `#/components/requestBodies/${this.name}` };
|
|
459
|
+
}
|
|
460
|
+
toPostman() {
|
|
461
|
+
var _b;
|
|
462
|
+
const result = {};
|
|
463
|
+
const header = [];
|
|
464
|
+
for (const contentType in this.content) {
|
|
465
|
+
header.push({
|
|
466
|
+
key: 'Content-Type',
|
|
467
|
+
value: contentType
|
|
468
|
+
});
|
|
469
|
+
const mediaTypeModel = this.content[contentType].toModel();
|
|
470
|
+
const contentSchema = mediaTypeModel.schema;
|
|
471
|
+
result.mode = 'raw';
|
|
472
|
+
if (contentType === 'multipart/form-data') {
|
|
473
|
+
result.mode = 'formdata';
|
|
474
|
+
result.formdata = [];
|
|
475
|
+
if (contentSchema) {
|
|
476
|
+
const rawSchema = contentSchema instanceof SchemaModifier ?
|
|
477
|
+
contentSchema.toObject() : (!('$ref' in contentSchema) ? new SchemaModifier('tmp', contentSchema).toObject() : undefined);
|
|
478
|
+
if (rawSchema) {
|
|
479
|
+
if (rawSchema.properties) {
|
|
480
|
+
for (const key in rawSchema.properties) {
|
|
481
|
+
const propSchema = rawSchema.properties[key];
|
|
482
|
+
if ('$ref' in propSchema) {
|
|
483
|
+
result.formdata.push({
|
|
484
|
+
key,
|
|
485
|
+
type: 'text'
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
else {
|
|
489
|
+
const fieldType = propSchema.contentMediaType ? 'file' : 'text';
|
|
490
|
+
result.formdata.push({
|
|
491
|
+
key,
|
|
492
|
+
type: fieldType,
|
|
493
|
+
description: propSchema.description,
|
|
494
|
+
src: fieldType === 'file' ? [] : undefined,
|
|
495
|
+
disabled: ((_b = rawSchema.required) === null || _b === void 0 ? void 0 : _b.includes(key)) ? false : true
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
else if (!contentSchema || isContentFileSchema(contentSchema)) {
|
|
504
|
+
result.mode = 'file';
|
|
505
|
+
result.file = {
|
|
506
|
+
src: ''
|
|
507
|
+
};
|
|
508
|
+
result.disabled = false;
|
|
509
|
+
}
|
|
510
|
+
else {
|
|
511
|
+
// create raw value
|
|
512
|
+
if (typeof mediaTypeModel.example !== 'undefined') {
|
|
513
|
+
result.raw = `${mediaTypeModel.example}`;
|
|
514
|
+
}
|
|
515
|
+
// if there are examples
|
|
516
|
+
if (typeof mediaTypeModel.examples !== 'undefined' && Object.keys(mediaTypeModel.examples).length !== 0) {
|
|
517
|
+
for (const key in mediaTypeModel.examples) {
|
|
518
|
+
const example = mediaTypeModel.examples[key];
|
|
519
|
+
if (example instanceof ExampleModifier) {
|
|
520
|
+
result.raw = `${example.getValue()}`;
|
|
521
|
+
break;
|
|
522
|
+
}
|
|
523
|
+
else if (example && 'value' in example && typeof example.value !== 'undefined') {
|
|
524
|
+
result.raw = `${example.value}`;
|
|
525
|
+
break;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
// if no raw content was set
|
|
530
|
+
if (!result.raw) {
|
|
531
|
+
const rawSchema = contentSchema instanceof SchemaModifier ?
|
|
532
|
+
contentSchema.toObject() : (!('$ref' in contentSchema) ? new SchemaModifier('tmp', contentSchema).toObject() : undefined);
|
|
533
|
+
if (rawSchema) {
|
|
534
|
+
if (contentType === 'application/xml') {
|
|
535
|
+
// xml
|
|
536
|
+
const json = createElementJsontoxmlSample('element', rawSchema);
|
|
537
|
+
if ('properties' in rawSchema && rawSchema.properties) {
|
|
538
|
+
formatJsontoxmlSample(json, rawSchema.properties);
|
|
539
|
+
}
|
|
540
|
+
result.raw = (0, jsontoxml_1.default)([json], {
|
|
541
|
+
xmlHeader: true,
|
|
542
|
+
indent: ' '
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
else {
|
|
546
|
+
const sample = createRawSample(rawSchema);
|
|
547
|
+
if (typeof sample !== 'undefined') {
|
|
548
|
+
result.raw = JSON.stringify(sample, null, '\t');
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
break;
|
|
555
|
+
}
|
|
556
|
+
return { header, body: result };
|
|
557
|
+
}
|
|
558
|
+
toOpenAPI() {
|
|
559
|
+
const content = {};
|
|
560
|
+
for (const contentType in this.content) {
|
|
561
|
+
const modifier = this.content[contentType];
|
|
562
|
+
content[contentType] = modifier.toObject();
|
|
563
|
+
}
|
|
564
|
+
const result = {
|
|
565
|
+
content
|
|
566
|
+
};
|
|
567
|
+
if (this.description) {
|
|
568
|
+
result.description = this.description;
|
|
569
|
+
}
|
|
570
|
+
if (this.isRequired()) {
|
|
571
|
+
result.required = true;
|
|
572
|
+
}
|
|
573
|
+
return result;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
exports.RequestBodyDocsModifier = RequestBodyDocsModifier;
|
|
577
|
+
/**
|
|
578
|
+
* Set a name (setName) or a ref (setRef) for it to be used as a reference.
|
|
579
|
+
*/
|
|
580
|
+
class ResponseDocsModifier extends api_doc_generator_1.ResponseUtil {
|
|
581
|
+
constructor(name) {
|
|
582
|
+
super(name);
|
|
583
|
+
if (!name)
|
|
584
|
+
this.setName('');
|
|
585
|
+
}
|
|
586
|
+
toOpenAPIRefPreferred(ctxt = {}) {
|
|
587
|
+
let name = this.name;
|
|
588
|
+
if (this.code) {
|
|
589
|
+
name = `${this.code}`;
|
|
590
|
+
}
|
|
591
|
+
if (ctxt.code) {
|
|
592
|
+
name = `${ctxt.code}`;
|
|
593
|
+
}
|
|
594
|
+
if (ctxt.default) {
|
|
595
|
+
name = 'default';
|
|
596
|
+
}
|
|
597
|
+
if (this.default) {
|
|
598
|
+
name = 'default';
|
|
599
|
+
}
|
|
600
|
+
if (ctxt.ref) {
|
|
601
|
+
return {
|
|
602
|
+
[name]: {
|
|
603
|
+
$ref: ctxt.ref
|
|
604
|
+
}
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
if (this.ref) {
|
|
608
|
+
return {
|
|
609
|
+
[name]: {
|
|
610
|
+
$ref: this.ref
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
if (this.name) {
|
|
615
|
+
return {
|
|
616
|
+
[name]: {
|
|
617
|
+
$ref: `#/components/responses/${this.name}`
|
|
618
|
+
}
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
return this.toOpenAPI(ctxt);
|
|
622
|
+
}
|
|
623
|
+
withContext() {
|
|
624
|
+
return new ContextResponseDocsModifier(this);
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
exports.ResponseDocsModifier = ResponseDocsModifier;
|
|
628
|
+
class ContextResponseDocsModifier extends api_doc_generator_1.ContextResponseUtil {
|
|
629
|
+
toOpenAPI() {
|
|
630
|
+
const ctxt = {};
|
|
631
|
+
if (this.code) {
|
|
632
|
+
ctxt.code = this.code;
|
|
633
|
+
}
|
|
634
|
+
if (this.ref) {
|
|
635
|
+
ctxt.ref = this.ref;
|
|
636
|
+
}
|
|
637
|
+
if (this.links) {
|
|
638
|
+
ctxt.links = this.links;
|
|
639
|
+
}
|
|
640
|
+
if (this.default) {
|
|
641
|
+
ctxt.default = this.default;
|
|
642
|
+
}
|
|
643
|
+
if (this.responseUtil instanceof ResponseDocsModifier) {
|
|
644
|
+
return this.responseUtil.toOpenAPIRefPreferred(ctxt);
|
|
645
|
+
}
|
|
646
|
+
else {
|
|
647
|
+
return this.responseUtil.toOpenAPI(ctxt);
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
exports.ContextResponseDocsModifier = ContextResponseDocsModifier;
|
|
652
|
+
class GroupResponseDocsModifier extends api_doc_generator_1.GroupResponseUtil {
|
|
653
|
+
constructor(responseUtils) {
|
|
654
|
+
super(responseUtils);
|
|
655
|
+
this.responseUtils = responseUtils;
|
|
656
|
+
}
|
|
657
|
+
toOpenAPIRefPreferred() {
|
|
658
|
+
let r = {};
|
|
659
|
+
this.responseUtils.forEach(builder => {
|
|
660
|
+
if (builder instanceof ResponseDocsModifier) {
|
|
661
|
+
r = Object.assign(Object.assign({}, r), builder.toOpenAPIRefPreferred());
|
|
662
|
+
}
|
|
663
|
+
else {
|
|
664
|
+
r = Object.assign(Object.assign({}, r), builder.toOpenAPI());
|
|
665
|
+
}
|
|
666
|
+
});
|
|
667
|
+
return r;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
exports.GroupResponseDocsModifier = GroupResponseDocsModifier;
|
|
671
|
+
function groupResponses(...modifiers) {
|
|
672
|
+
return new GroupResponseDocsModifier(modifiers);
|
|
673
|
+
}
|
|
674
|
+
//# sourceMappingURL=modifiers.js.map
|