@opra/common 1.4.4 → 1.5.0
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/browser/index.cjs +5 -5
- package/browser/index.mjs +5 -5
- package/cjs/document/api-document.js +13 -8
- package/cjs/document/common/api-base.js +2 -1
- package/cjs/document/common/document-init-context.js +5 -0
- package/cjs/document/common/document-node.js +25 -29
- package/cjs/document/common/value.js +6 -2
- package/cjs/document/constants.js +1 -2
- package/cjs/document/data-type/api-field.js +16 -3
- package/cjs/document/data-type/complex-type-base.js +12 -3
- package/cjs/document/data-type/complex-type.js +12 -5
- package/cjs/document/data-type/data-type.js +16 -1
- package/cjs/document/data-type/enum-type.js +9 -2
- package/cjs/document/data-type/extended-types/base64.type.js +1 -0
- package/cjs/document/data-type/extended-types/date-string.type.js +1 -0
- package/cjs/document/data-type/extended-types/date-time-string.type.js +1 -0
- package/cjs/document/data-type/extended-types/date-time.type.js +1 -0
- package/cjs/document/data-type/extended-types/date.type.js +1 -0
- package/cjs/document/data-type/extended-types/email.type.js +1 -0
- package/cjs/document/data-type/extended-types/field-path.type.js +6 -2
- package/cjs/document/data-type/extended-types/filter.type.js +11 -4
- package/cjs/document/data-type/extended-types/object-id.type.js +1 -0
- package/cjs/document/data-type/extended-types/operation-result.type.js +1 -0
- package/cjs/document/data-type/extended-types/time.type.js +1 -0
- package/cjs/document/data-type/extended-types/url.type.js +1 -0
- package/cjs/document/data-type/extended-types/uuid.type.js +1 -0
- package/cjs/document/data-type/mapped-type.js +6 -3
- package/cjs/document/data-type/mixin-type.js +7 -4
- package/cjs/document/data-type/primitive-types/any.type.js +1 -0
- package/cjs/document/data-type/primitive-types/bigint.type.js +1 -0
- package/cjs/document/data-type/primitive-types/boolean.type.js +1 -0
- package/cjs/document/data-type/primitive-types/integer.type.js +1 -0
- package/cjs/document/data-type/primitive-types/null.type.js +1 -0
- package/cjs/document/data-type/primitive-types/number.type.js +1 -0
- package/cjs/document/data-type/primitive-types/string.type.js +1 -0
- package/cjs/document/data-type/simple-type.js +10 -3
- package/cjs/document/decorators/complex-type.decorator.js +1 -1
- package/cjs/document/decorators/simple-type.decorator.js +1 -1
- package/cjs/document/factory/api-document.factory.js +1 -0
- package/cjs/document/http/http-api.js +2 -2
- package/cjs/document/http/http-controller.js +5 -5
- package/cjs/document/http/http-media-type.js +3 -3
- package/cjs/document/http/http-multipart-field.js +2 -2
- package/cjs/document/http/http-operation-response.js +3 -3
- package/cjs/document/http/http-operation.js +5 -5
- package/cjs/document/http/http-parameter.js +2 -2
- package/cjs/document/http/http-request-body.js +4 -2
- package/cjs/filter/filter-rules.js +5 -4
- package/esm/document/api-document.js +13 -8
- package/esm/document/common/api-base.js +2 -1
- package/esm/document/common/document-init-context.js +5 -0
- package/esm/document/common/document-node.js +25 -29
- package/esm/document/common/value.js +6 -2
- package/esm/document/constants.js +0 -1
- package/esm/document/data-type/api-field.js +16 -3
- package/esm/document/data-type/complex-type-base.js +12 -3
- package/esm/document/data-type/complex-type.js +12 -5
- package/esm/document/data-type/data-type.js +16 -1
- package/esm/document/data-type/enum-type.js +9 -2
- package/esm/document/data-type/extended-types/base64.type.js +1 -0
- package/esm/document/data-type/extended-types/date-string.type.js +1 -0
- package/esm/document/data-type/extended-types/date-time-string.type.js +1 -0
- package/esm/document/data-type/extended-types/date-time.type.js +1 -0
- package/esm/document/data-type/extended-types/date.type.js +1 -0
- package/esm/document/data-type/extended-types/email.type.js +1 -0
- package/esm/document/data-type/extended-types/field-path.type.js +6 -2
- package/esm/document/data-type/extended-types/filter.type.js +11 -4
- package/esm/document/data-type/extended-types/object-id.type.js +1 -0
- package/esm/document/data-type/extended-types/operation-result.type.js +1 -0
- package/esm/document/data-type/extended-types/time.type.js +1 -0
- package/esm/document/data-type/extended-types/url.type.js +1 -0
- package/esm/document/data-type/extended-types/uuid.type.js +1 -0
- package/esm/document/data-type/mapped-type.js +6 -3
- package/esm/document/data-type/mixin-type.js +7 -4
- package/esm/document/data-type/primitive-types/any.type.js +1 -0
- package/esm/document/data-type/primitive-types/bigint.type.js +1 -0
- package/esm/document/data-type/primitive-types/boolean.type.js +1 -0
- package/esm/document/data-type/primitive-types/integer.type.js +1 -0
- package/esm/document/data-type/primitive-types/null.type.js +1 -0
- package/esm/document/data-type/primitive-types/number.type.js +1 -0
- package/esm/document/data-type/primitive-types/string.type.js +1 -0
- package/esm/document/data-type/simple-type.js +10 -3
- package/esm/document/decorators/complex-type.decorator.js +2 -2
- package/esm/document/decorators/simple-type.decorator.js +2 -2
- package/esm/document/factory/api-document.factory.js +1 -0
- package/esm/document/http/http-api.js +2 -2
- package/esm/document/http/http-controller.js +5 -5
- package/esm/document/http/http-media-type.js +3 -3
- package/esm/document/http/http-multipart-field.js +2 -2
- package/esm/document/http/http-operation-response.js +3 -3
- package/esm/document/http/http-operation.js +5 -5
- package/esm/document/http/http-parameter.js +2 -2
- package/esm/document/http/http-request-body.js +4 -2
- package/esm/filter/filter-rules.js +5 -4
- package/package.json +1 -1
- package/types/document/api-document.d.ts +8 -2
- package/types/document/common/api-base.d.ts +1 -1
- package/types/document/common/document-init-context.d.ts +2 -0
- package/types/document/common/document-node.d.ts +8 -14
- package/types/document/common/value.d.ts +2 -1
- package/types/document/constants.d.ts +0 -1
- package/types/document/data-type/api-field.d.ts +6 -11
- package/types/document/data-type/complex-type.d.ts +2 -1
- package/types/document/data-type/data-type.d.ts +7 -2
- package/types/document/data-type/enum-type.d.ts +2 -1
- package/types/document/data-type/extended-types/field-path.type.d.ts +2 -1
- package/types/document/data-type/extended-types/filter.type.d.ts +2 -1
- package/types/document/data-type/mapped-type.d.ts +2 -1
- package/types/document/data-type/mixin-type.d.ts +2 -1
- package/types/document/data-type/simple-type.d.ts +2 -1
- package/types/document/factory/api-document.factory.d.ts +2 -1
- package/types/document/http/http-api.d.ts +1 -1
- package/types/document/http/http-controller.d.ts +2 -1
- package/types/document/http/http-media-type.d.ts +2 -1
- package/types/document/http/http-multipart-field.d.ts +2 -1
- package/types/document/http/http-operation-response.d.ts +2 -1
- package/types/document/http/http-operation.d.ts +2 -1
- package/types/document/http/http-parameter.d.ts +2 -1
- package/types/document/http/http-request-body.d.ts +2 -1
- package/types/filter/filter-rules.d.ts +3 -3
|
@@ -68,21 +68,28 @@ class ComplexTypeClass extends ComplexTypeBase {
|
|
|
68
68
|
return true;
|
|
69
69
|
return !!this.base?.extendsFrom(baseType);
|
|
70
70
|
}
|
|
71
|
-
toJSON() {
|
|
71
|
+
toJSON(options) {
|
|
72
72
|
const baseName = this.base
|
|
73
73
|
? this.node.getDataTypeNameWithNs(this.base)
|
|
74
74
|
: undefined;
|
|
75
|
+
if (options?.scopes && !this.base?.inScope(options?.scopes))
|
|
76
|
+
throw new TypeError(`Base type ${baseName ? '(' + baseName + ')' : ''} of ${this.name ? +this.name : 'embedded'} type ` +
|
|
77
|
+
`is not in required scope(s) [${options.scopes}`);
|
|
75
78
|
const out = omitUndefined({
|
|
76
79
|
...ComplexTypeBase.prototype.toJSON.call(this),
|
|
77
80
|
kind: this.kind,
|
|
78
|
-
base: this.base
|
|
81
|
+
base: this.base
|
|
82
|
+
? baseName
|
|
83
|
+
? baseName
|
|
84
|
+
: this.base.toJSON(options)
|
|
85
|
+
: undefined,
|
|
79
86
|
});
|
|
80
87
|
if (this.additionalFields) {
|
|
81
88
|
if (this.additionalFields instanceof DataType) {
|
|
82
89
|
const typeName = this.node.getDataTypeNameWithNs(this.additionalFields);
|
|
83
90
|
out.additionalFields = typeName
|
|
84
91
|
? typeName
|
|
85
|
-
: this.additionalFields.toJSON();
|
|
92
|
+
: this.additionalFields.toJSON(options);
|
|
86
93
|
}
|
|
87
94
|
else
|
|
88
95
|
out.additionalFields = this.additionalFields;
|
|
@@ -91,8 +98,8 @@ class ComplexTypeClass extends ComplexTypeBase {
|
|
|
91
98
|
const fields = {};
|
|
92
99
|
let i = 0;
|
|
93
100
|
for (const field of this.fields.values()) {
|
|
94
|
-
if (field.origin === this) {
|
|
95
|
-
fields[field.name] = field.toJSON();
|
|
101
|
+
if (field.origin === this && field.inScope(options?.scopes)) {
|
|
102
|
+
fields[field.name] = field.toJSON(options);
|
|
96
103
|
i++;
|
|
97
104
|
}
|
|
98
105
|
}
|
|
@@ -17,6 +17,7 @@ context) {
|
|
|
17
17
|
DocumentElement.call(this, owner);
|
|
18
18
|
const _this = asMutable(this);
|
|
19
19
|
_this.kind = initArgs.kind;
|
|
20
|
+
_this.scopes = initArgs.scopes;
|
|
20
21
|
_this.name = initArgs.name;
|
|
21
22
|
_this.description = initArgs.description;
|
|
22
23
|
_this.abstract = initArgs.abstract;
|
|
@@ -30,7 +31,21 @@ class DataTypeClass extends DocumentElement {
|
|
|
30
31
|
get embedded() {
|
|
31
32
|
return !this.name;
|
|
32
33
|
}
|
|
33
|
-
|
|
34
|
+
inScope(scopes) {
|
|
35
|
+
if (!this.scopes?.length || !scopes)
|
|
36
|
+
return true;
|
|
37
|
+
/** this.scope should match all required scopes */
|
|
38
|
+
scopes = Array.isArray(scopes) ? scopes : [scopes];
|
|
39
|
+
for (const scope of scopes) {
|
|
40
|
+
if (!this.scopes.some(s => {
|
|
41
|
+
return typeof s === 'string' ? scope === s : s.test(scope);
|
|
42
|
+
}))
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
// eslint-disable-next-line
|
|
48
|
+
toJSON(options) {
|
|
34
49
|
return omitUndefined({
|
|
35
50
|
kind: this.kind,
|
|
36
51
|
description: this.description,
|
|
@@ -48,13 +48,20 @@ class EnumTypeClass extends DataType {
|
|
|
48
48
|
generateCodec() {
|
|
49
49
|
return vg.isEnum(Object.keys(this.attributes));
|
|
50
50
|
}
|
|
51
|
-
toJSON() {
|
|
51
|
+
toJSON(options) {
|
|
52
52
|
const baseName = this.base
|
|
53
53
|
? this.node.getDataTypeNameWithNs(this.base)
|
|
54
54
|
: undefined;
|
|
55
|
+
if (options?.scopes && !this.base?.inScope(options?.scopes))
|
|
56
|
+
throw new TypeError(`Base type ${baseName ? '(' + baseName + ')' : ''} of ${this.name ? +this.name : 'embedded'} type ` +
|
|
57
|
+
`is not in required scope(s) [${options.scopes}`);
|
|
55
58
|
return omitUndefined({
|
|
56
59
|
...DataType.prototype.toJSON.call(this),
|
|
57
|
-
base: this.base
|
|
60
|
+
base: this.base
|
|
61
|
+
? baseName
|
|
62
|
+
? baseName
|
|
63
|
+
: this.base.toJSON(options)
|
|
64
|
+
: undefined,
|
|
58
65
|
attributes: cloneObject(this.ownAttributes),
|
|
59
66
|
});
|
|
60
67
|
}
|
|
@@ -18,15 +18,18 @@ let FieldPathType = class FieldPathType {
|
|
|
18
18
|
[ENCODER](properties, element) {
|
|
19
19
|
return this[DECODER](properties, element);
|
|
20
20
|
}
|
|
21
|
-
toJSON(properties, element) {
|
|
21
|
+
toJSON(properties, element, options) {
|
|
22
22
|
const dataType = properties.dataType
|
|
23
23
|
? element.node.getComplexType(properties.dataType)
|
|
24
24
|
: element.node.getComplexType('object');
|
|
25
25
|
const typeName = dataType
|
|
26
26
|
? element.node.getDataTypeNameWithNs(dataType)
|
|
27
27
|
: undefined;
|
|
28
|
+
if (options?.scopes && !dataType.inScope(options?.scopes))
|
|
29
|
+
throw new TypeError(`Data type ${typeName ? '(' + typeName + ')' : ''} ` +
|
|
30
|
+
`is not in required scope(s) [${options.scopes}`);
|
|
28
31
|
return {
|
|
29
|
-
dataType: typeName ? typeName : dataType.toJSON(),
|
|
32
|
+
dataType: typeName ? typeName : dataType.toJSON(options),
|
|
30
33
|
allowSigns: properties.allowSigns,
|
|
31
34
|
};
|
|
32
35
|
}
|
|
@@ -47,6 +50,7 @@ __decorate([
|
|
|
47
50
|
], FieldPathType.prototype, "allowSigns", void 0);
|
|
48
51
|
FieldPathType = __decorate([
|
|
49
52
|
SimpleType({
|
|
53
|
+
name: 'fieldpath',
|
|
50
54
|
description: 'Field path',
|
|
51
55
|
nameMappings: {
|
|
52
56
|
js: 'string',
|
|
@@ -21,12 +21,18 @@ let FilterType = class FilterType {
|
|
|
21
21
|
[ENCODER]() {
|
|
22
22
|
return encodeFilter;
|
|
23
23
|
}
|
|
24
|
-
toJSON(properties, element) {
|
|
24
|
+
toJSON(properties, element, options) {
|
|
25
25
|
const dataType = properties.dataType
|
|
26
26
|
? element.node.getComplexType(properties.dataType)
|
|
27
27
|
: element.node.getComplexType('object');
|
|
28
|
+
const typeName = dataType
|
|
29
|
+
? element.node.getDataTypeNameWithNs(dataType)
|
|
30
|
+
: undefined;
|
|
31
|
+
if (options?.scopes && !dataType.inScope(options?.scopes))
|
|
32
|
+
throw new TypeError(`Data type ${typeName ? '(' + typeName + ')' : ''} ` +
|
|
33
|
+
`is not in required scope(s) [${options.scopes}`);
|
|
28
34
|
return {
|
|
29
|
-
dataType:
|
|
35
|
+
dataType: typeName ? typeName : dataType.toJSON(options),
|
|
30
36
|
rules: properties.rules,
|
|
31
37
|
};
|
|
32
38
|
}
|
|
@@ -46,6 +52,7 @@ __decorate([
|
|
|
46
52
|
], FilterType.prototype, "rules", void 0);
|
|
47
53
|
FilterType = __decorate([
|
|
48
54
|
SimpleType({
|
|
55
|
+
name: 'filter',
|
|
49
56
|
description: 'A query filter',
|
|
50
57
|
nameMappings: {
|
|
51
58
|
js: 'object',
|
|
@@ -55,12 +62,12 @@ FilterType = __decorate([
|
|
|
55
62
|
__metadata("design:paramtypes", [Object])
|
|
56
63
|
], FilterType);
|
|
57
64
|
export { FilterType };
|
|
58
|
-
const decodeFilter = (dataType, rules) => validator('decodeFilter', (input, context, _this) => {
|
|
65
|
+
const decodeFilter = (dataType, rules, element) => validator('decodeFilter', (input, context, _this) => {
|
|
59
66
|
if (typeof input === 'string') {
|
|
60
67
|
try {
|
|
61
68
|
const filter = OpraFilter.parse(input);
|
|
62
69
|
if (rules)
|
|
63
|
-
return rules.normalizeFilter(filter, dataType);
|
|
70
|
+
return rules.normalizeFilter(filter, dataType, element);
|
|
64
71
|
return filter;
|
|
65
72
|
}
|
|
66
73
|
catch (e) {
|
|
@@ -85,13 +85,16 @@ class MappedTypeClass extends ComplexTypeBase {
|
|
|
85
85
|
return true;
|
|
86
86
|
return !!this.base?.extendsFrom(baseType);
|
|
87
87
|
}
|
|
88
|
-
toJSON() {
|
|
88
|
+
toJSON(options) {
|
|
89
89
|
const baseName = this.base
|
|
90
90
|
? this.node.getDataTypeNameWithNs(this.base)
|
|
91
91
|
: undefined;
|
|
92
|
+
if (options?.scopes && !this.base?.inScope(options?.scopes))
|
|
93
|
+
throw new TypeError(`Base type ${baseName ? '(' + baseName + ')' : ''} of ${this.name ? +this.name : 'embedded'} type ` +
|
|
94
|
+
`is not in required scope(s) [${options.scopes}`);
|
|
92
95
|
return omitUndefined({
|
|
93
|
-
...ComplexTypeBase.prototype.toJSON.call(this),
|
|
94
|
-
base: baseName ? baseName : this.base.toJSON(),
|
|
96
|
+
...ComplexTypeBase.prototype.toJSON.call(this, options),
|
|
97
|
+
base: baseName ? baseName : this.base.toJSON(options),
|
|
95
98
|
kind: this.kind,
|
|
96
99
|
pick: this.pick,
|
|
97
100
|
omit: this.omit,
|
|
@@ -54,13 +54,16 @@ class MixinTypeClass extends ComplexTypeBase {
|
|
|
54
54
|
}
|
|
55
55
|
return false;
|
|
56
56
|
}
|
|
57
|
-
toJSON() {
|
|
57
|
+
toJSON(options) {
|
|
58
58
|
return omitUndefined({
|
|
59
59
|
...ComplexTypeBase.prototype.toJSON.call(this),
|
|
60
60
|
kind: this.kind,
|
|
61
|
-
types: this.types.map(
|
|
62
|
-
const baseName = this.node.getDataTypeNameWithNs(
|
|
63
|
-
|
|
61
|
+
types: this.types.map(base => {
|
|
62
|
+
const baseName = this.node.getDataTypeNameWithNs(base);
|
|
63
|
+
if (options?.scopes && !base?.inScope(options?.scopes))
|
|
64
|
+
throw new TypeError(`Base type ${baseName ? '(' + baseName + ')' : ''} of ${this.name ? +this.name : 'embedded'} type ` +
|
|
65
|
+
`is not in required scope(s) [${options.scopes}`);
|
|
66
|
+
return baseName ? baseName : base.toJSON(options);
|
|
64
67
|
}),
|
|
65
68
|
});
|
|
66
69
|
}
|
|
@@ -80,20 +80,27 @@ class SimpleTypeClass extends DataType {
|
|
|
80
80
|
}
|
|
81
81
|
return isAny;
|
|
82
82
|
}
|
|
83
|
-
toJSON() {
|
|
83
|
+
toJSON(options) {
|
|
84
84
|
const attributes = omitUndefined(this.ownAttributes);
|
|
85
85
|
let properties;
|
|
86
86
|
if (this.properties && typeof this.properties.toJSON === 'function') {
|
|
87
|
-
properties = this.properties.toJSON(this.properties, this.owner);
|
|
87
|
+
properties = this.properties.toJSON(this.properties, this.owner, options);
|
|
88
88
|
}
|
|
89
89
|
else
|
|
90
90
|
properties = this.properties ? cloneObject(this.properties) : {};
|
|
91
91
|
const baseName = this.base
|
|
92
92
|
? this.node.getDataTypeNameWithNs(this.base)
|
|
93
93
|
: undefined;
|
|
94
|
+
if (options?.scopes && !this.base?.inScope(options?.scopes))
|
|
95
|
+
throw new TypeError(`Base type ${baseName ? '(' + baseName + ')' : ''} of ${this.name ? +this.name : 'embedded'} type ` +
|
|
96
|
+
`is not in required scope(s) [${options.scopes}`);
|
|
94
97
|
const out = omitUndefined({
|
|
95
98
|
...DataType.prototype.toJSON.apply(this),
|
|
96
|
-
base: this.base
|
|
99
|
+
base: this.base
|
|
100
|
+
? baseName
|
|
101
|
+
? baseName
|
|
102
|
+
: this.base.toJSON(options)
|
|
103
|
+
: undefined,
|
|
97
104
|
attributes: attributes && Object.keys(attributes).length ? attributes : undefined,
|
|
98
105
|
properties: Object.keys(properties).length ? properties : undefined,
|
|
99
106
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { omit } from '@jsopen/objects';
|
|
2
2
|
import { OpraSchema } from '../../schema/index.js';
|
|
3
|
-
import { CLASS_NAME_PATTERN, DATATYPE_METADATA
|
|
3
|
+
import { CLASS_NAME_PATTERN, DATATYPE_METADATA } from '../constants.js';
|
|
4
4
|
export function ComplexTypeDecorator(options) {
|
|
5
5
|
return function (target) {
|
|
6
6
|
let name;
|
|
@@ -11,7 +11,7 @@ export function ComplexTypeDecorator(options) {
|
|
|
11
11
|
name = options.name;
|
|
12
12
|
}
|
|
13
13
|
else {
|
|
14
|
-
name = target.name
|
|
14
|
+
name = target.name;
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
let metadata = Reflect.getOwnMetadata(DATATYPE_METADATA, target);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { OpraSchema } from '../../schema/index.js';
|
|
2
|
-
import { CLASS_NAME_PATTERN, DATATYPE_METADATA
|
|
2
|
+
import { CLASS_NAME_PATTERN, DATATYPE_METADATA } from '../constants.js';
|
|
3
3
|
export function SimpleTypeDecoratorFactory(options) {
|
|
4
4
|
const decoratorChain = [];
|
|
5
5
|
/**
|
|
@@ -14,7 +14,7 @@ export function SimpleTypeDecoratorFactory(options) {
|
|
|
14
14
|
name = options.name;
|
|
15
15
|
}
|
|
16
16
|
else {
|
|
17
|
-
name = target.name
|
|
17
|
+
name = target.name;
|
|
18
18
|
name = name.toLowerCase();
|
|
19
19
|
}
|
|
20
20
|
}
|
|
@@ -27,6 +27,7 @@ export class ApiDocumentFactory {
|
|
|
27
27
|
: new DocumentInitContext(options);
|
|
28
28
|
try {
|
|
29
29
|
const document = new ApiDocument();
|
|
30
|
+
document.scopes = context.scopes;
|
|
30
31
|
await factory.initDocument(document, context, schemaOrUrl);
|
|
31
32
|
if (context.error.details.length)
|
|
32
33
|
throw context.error;
|
|
@@ -20,7 +20,7 @@ export class HttpApi extends ApiBase {
|
|
|
20
20
|
const controller = this.findController(arg0);
|
|
21
21
|
return controller?.operations.get(operationName);
|
|
22
22
|
}
|
|
23
|
-
toJSON() {
|
|
23
|
+
toJSON(options) {
|
|
24
24
|
const schema = super.toJSON();
|
|
25
25
|
const out = {
|
|
26
26
|
...schema,
|
|
@@ -29,7 +29,7 @@ export class HttpApi extends ApiBase {
|
|
|
29
29
|
controllers: {},
|
|
30
30
|
};
|
|
31
31
|
for (const v of this.controllers.values()) {
|
|
32
|
-
out.controllers[v.name] = v.toJSON();
|
|
32
|
+
out.controllers[v.name] = v.toJSON(options);
|
|
33
33
|
}
|
|
34
34
|
return out;
|
|
35
35
|
}
|
|
@@ -111,7 +111,7 @@ class HttpControllerClass extends DocumentElement {
|
|
|
111
111
|
/**
|
|
112
112
|
*
|
|
113
113
|
*/
|
|
114
|
-
toJSON() {
|
|
114
|
+
toJSON(options) {
|
|
115
115
|
const out = omitUndefined({
|
|
116
116
|
kind: this.kind,
|
|
117
117
|
description: this.description,
|
|
@@ -120,25 +120,25 @@ class HttpControllerClass extends DocumentElement {
|
|
|
120
120
|
if (this.operations.size) {
|
|
121
121
|
out.operations = {};
|
|
122
122
|
for (const v of this.operations.values()) {
|
|
123
|
-
out.operations[v.name] = v.toJSON();
|
|
123
|
+
out.operations[v.name] = v.toJSON(options);
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
if (this.controllers.size) {
|
|
127
127
|
out.controllers = {};
|
|
128
128
|
for (const v of this.controllers.values()) {
|
|
129
|
-
out.controllers[v.name] = v.toJSON();
|
|
129
|
+
out.controllers[v.name] = v.toJSON(options);
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
if (this.types.size) {
|
|
133
133
|
out.types = {};
|
|
134
134
|
for (const v of this.types.values()) {
|
|
135
|
-
out.types[v.name] = v.toJSON();
|
|
135
|
+
out.types[v.name] = v.toJSON(options);
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
if (this.parameters.length) {
|
|
139
139
|
out.parameters = [];
|
|
140
140
|
for (const prm of this.parameters) {
|
|
141
|
-
out.parameters.push(prm.toJSON());
|
|
141
|
+
out.parameters.push(prm.toJSON(options));
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
return out;
|
|
@@ -48,7 +48,7 @@ class HttpMediaTypeClass extends DocumentElement {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
toJSON() {
|
|
51
|
+
toJSON(options) {
|
|
52
52
|
const typeName = this.type
|
|
53
53
|
? this.node.getDataTypeNameWithNs(this.type)
|
|
54
54
|
: undefined;
|
|
@@ -56,7 +56,7 @@ class HttpMediaTypeClass extends DocumentElement {
|
|
|
56
56
|
description: this.description,
|
|
57
57
|
contentType: this.contentType,
|
|
58
58
|
contentEncoding: this.contentEncoding,
|
|
59
|
-
type: typeName ? typeName : this.type?.toJSON(),
|
|
59
|
+
type: typeName ? typeName : this.type?.toJSON(options),
|
|
60
60
|
isArray: this.isArray,
|
|
61
61
|
example: this.example,
|
|
62
62
|
examples: this.examples,
|
|
@@ -67,7 +67,7 @@ class HttpMediaTypeClass extends DocumentElement {
|
|
|
67
67
|
maxTotalFileSize: this.maxTotalFileSize,
|
|
68
68
|
});
|
|
69
69
|
if (this.multipartFields?.length) {
|
|
70
|
-
out.multipartFields = this.multipartFields.map(x => x.toJSON());
|
|
70
|
+
out.multipartFields = this.multipartFields.map(x => x.toJSON(options));
|
|
71
71
|
}
|
|
72
72
|
return out;
|
|
73
73
|
}
|
|
@@ -17,12 +17,12 @@ export class HttpMultipartField extends HttpMediaType {
|
|
|
17
17
|
this.fieldType = initArgs.fieldType;
|
|
18
18
|
this.required = initArgs.required;
|
|
19
19
|
}
|
|
20
|
-
toJSON() {
|
|
20
|
+
toJSON(options) {
|
|
21
21
|
return omitUndefined({
|
|
22
22
|
fieldName: this.fieldName,
|
|
23
23
|
fieldType: this.fieldType,
|
|
24
24
|
required: this.required,
|
|
25
|
-
...super.toJSON(),
|
|
25
|
+
...super.toJSON(options),
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
28
|
}
|
|
@@ -23,10 +23,10 @@ export class HttpOperationResponse extends HttpMediaType {
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
toJSON() {
|
|
26
|
+
toJSON(options) {
|
|
27
27
|
const statusCode = this.statusCode.map(x => x.toJSON());
|
|
28
28
|
const out = omitUndefined({
|
|
29
|
-
...super.toJSON(),
|
|
29
|
+
...super.toJSON(options),
|
|
30
30
|
statusCode: statusCode.length === 1 && typeof statusCode[0] === 'number'
|
|
31
31
|
? statusCode[0]
|
|
32
32
|
: statusCode,
|
|
@@ -35,7 +35,7 @@ export class HttpOperationResponse extends HttpMediaType {
|
|
|
35
35
|
if (this.parameters.length) {
|
|
36
36
|
out.parameters = [];
|
|
37
37
|
for (const prm of this.parameters) {
|
|
38
|
-
out.parameters.push(prm.toJSON());
|
|
38
|
+
out.parameters.push(prm.toJSON(options));
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
return out;
|
|
@@ -67,7 +67,7 @@ class HttpOperationClass extends DocumentElement {
|
|
|
67
67
|
}
|
|
68
68
|
return this.path || '/';
|
|
69
69
|
}
|
|
70
|
-
toJSON() {
|
|
70
|
+
toJSON(options) {
|
|
71
71
|
const out = omitUndefined({
|
|
72
72
|
kind: OpraSchema.HttpOperation.Kind,
|
|
73
73
|
description: this.description,
|
|
@@ -75,22 +75,22 @@ class HttpOperationClass extends DocumentElement {
|
|
|
75
75
|
path: this.path,
|
|
76
76
|
mergePath: this.mergePath,
|
|
77
77
|
composition: this.composition,
|
|
78
|
-
requestBody: this.requestBody?.toJSON(),
|
|
78
|
+
requestBody: this.requestBody?.toJSON(options),
|
|
79
79
|
});
|
|
80
80
|
if (this.types.size) {
|
|
81
81
|
out.types = {};
|
|
82
82
|
for (const v of this.types.values()) {
|
|
83
|
-
out.types[v.name] = v.toJSON();
|
|
83
|
+
out.types[v.name] = v.toJSON(options);
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
if (this.parameters.length) {
|
|
87
87
|
out.parameters = [];
|
|
88
88
|
for (const prm of this.parameters) {
|
|
89
|
-
out.parameters.push(prm.toJSON());
|
|
89
|
+
out.parameters.push(prm.toJSON(options));
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
if (this.responses.length)
|
|
93
|
-
out.responses = this.responses.map(r => r.toJSON());
|
|
93
|
+
out.responses = this.responses.map(r => r.toJSON(options));
|
|
94
94
|
return out;
|
|
95
95
|
}
|
|
96
96
|
}
|
|
@@ -30,9 +30,9 @@ export const HttpParameter = function (owner, initArgs) {
|
|
|
30
30
|
* @class HttpParameter
|
|
31
31
|
*/
|
|
32
32
|
class HttpParameterClass extends Value {
|
|
33
|
-
toJSON() {
|
|
33
|
+
toJSON(options) {
|
|
34
34
|
return omitUndefined({
|
|
35
|
-
...super.toJSON(),
|
|
35
|
+
...super.toJSON(options),
|
|
36
36
|
name: this.name,
|
|
37
37
|
location: this.location,
|
|
38
38
|
arraySeparator: this.arraySeparator,
|
|
@@ -8,12 +8,14 @@ export class HttpRequestBody extends DocumentElement {
|
|
|
8
8
|
super(owner);
|
|
9
9
|
this.content = [];
|
|
10
10
|
}
|
|
11
|
-
toJSON() {
|
|
11
|
+
toJSON(options) {
|
|
12
12
|
return omitUndefined({
|
|
13
13
|
description: this.description,
|
|
14
14
|
required: this.required,
|
|
15
15
|
maxContentSize: this.maxContentSize,
|
|
16
|
-
content: this.content.length
|
|
16
|
+
content: this.content.length
|
|
17
|
+
? this.content.map(x => x.toJSON(options))
|
|
18
|
+
: [],
|
|
17
19
|
partial: this.partial,
|
|
18
20
|
allowPatchOperators: this.allowPatchOperators,
|
|
19
21
|
});
|