@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.
Files changed (120) hide show
  1. package/browser/index.cjs +5 -5
  2. package/browser/index.mjs +5 -5
  3. package/cjs/document/api-document.js +13 -8
  4. package/cjs/document/common/api-base.js +2 -1
  5. package/cjs/document/common/document-init-context.js +5 -0
  6. package/cjs/document/common/document-node.js +25 -29
  7. package/cjs/document/common/value.js +6 -2
  8. package/cjs/document/constants.js +1 -2
  9. package/cjs/document/data-type/api-field.js +16 -3
  10. package/cjs/document/data-type/complex-type-base.js +12 -3
  11. package/cjs/document/data-type/complex-type.js +12 -5
  12. package/cjs/document/data-type/data-type.js +16 -1
  13. package/cjs/document/data-type/enum-type.js +9 -2
  14. package/cjs/document/data-type/extended-types/base64.type.js +1 -0
  15. package/cjs/document/data-type/extended-types/date-string.type.js +1 -0
  16. package/cjs/document/data-type/extended-types/date-time-string.type.js +1 -0
  17. package/cjs/document/data-type/extended-types/date-time.type.js +1 -0
  18. package/cjs/document/data-type/extended-types/date.type.js +1 -0
  19. package/cjs/document/data-type/extended-types/email.type.js +1 -0
  20. package/cjs/document/data-type/extended-types/field-path.type.js +6 -2
  21. package/cjs/document/data-type/extended-types/filter.type.js +11 -4
  22. package/cjs/document/data-type/extended-types/object-id.type.js +1 -0
  23. package/cjs/document/data-type/extended-types/operation-result.type.js +1 -0
  24. package/cjs/document/data-type/extended-types/time.type.js +1 -0
  25. package/cjs/document/data-type/extended-types/url.type.js +1 -0
  26. package/cjs/document/data-type/extended-types/uuid.type.js +1 -0
  27. package/cjs/document/data-type/mapped-type.js +6 -3
  28. package/cjs/document/data-type/mixin-type.js +7 -4
  29. package/cjs/document/data-type/primitive-types/any.type.js +1 -0
  30. package/cjs/document/data-type/primitive-types/bigint.type.js +1 -0
  31. package/cjs/document/data-type/primitive-types/boolean.type.js +1 -0
  32. package/cjs/document/data-type/primitive-types/integer.type.js +1 -0
  33. package/cjs/document/data-type/primitive-types/null.type.js +1 -0
  34. package/cjs/document/data-type/primitive-types/number.type.js +1 -0
  35. package/cjs/document/data-type/primitive-types/string.type.js +1 -0
  36. package/cjs/document/data-type/simple-type.js +10 -3
  37. package/cjs/document/decorators/complex-type.decorator.js +1 -1
  38. package/cjs/document/decorators/simple-type.decorator.js +1 -1
  39. package/cjs/document/factory/api-document.factory.js +1 -0
  40. package/cjs/document/http/http-api.js +2 -2
  41. package/cjs/document/http/http-controller.js +5 -5
  42. package/cjs/document/http/http-media-type.js +3 -3
  43. package/cjs/document/http/http-multipart-field.js +2 -2
  44. package/cjs/document/http/http-operation-response.js +3 -3
  45. package/cjs/document/http/http-operation.js +5 -5
  46. package/cjs/document/http/http-parameter.js +2 -2
  47. package/cjs/document/http/http-request-body.js +4 -2
  48. package/cjs/filter/filter-rules.js +5 -4
  49. package/esm/document/api-document.js +13 -8
  50. package/esm/document/common/api-base.js +2 -1
  51. package/esm/document/common/document-init-context.js +5 -0
  52. package/esm/document/common/document-node.js +25 -29
  53. package/esm/document/common/value.js +6 -2
  54. package/esm/document/constants.js +0 -1
  55. package/esm/document/data-type/api-field.js +16 -3
  56. package/esm/document/data-type/complex-type-base.js +12 -3
  57. package/esm/document/data-type/complex-type.js +12 -5
  58. package/esm/document/data-type/data-type.js +16 -1
  59. package/esm/document/data-type/enum-type.js +9 -2
  60. package/esm/document/data-type/extended-types/base64.type.js +1 -0
  61. package/esm/document/data-type/extended-types/date-string.type.js +1 -0
  62. package/esm/document/data-type/extended-types/date-time-string.type.js +1 -0
  63. package/esm/document/data-type/extended-types/date-time.type.js +1 -0
  64. package/esm/document/data-type/extended-types/date.type.js +1 -0
  65. package/esm/document/data-type/extended-types/email.type.js +1 -0
  66. package/esm/document/data-type/extended-types/field-path.type.js +6 -2
  67. package/esm/document/data-type/extended-types/filter.type.js +11 -4
  68. package/esm/document/data-type/extended-types/object-id.type.js +1 -0
  69. package/esm/document/data-type/extended-types/operation-result.type.js +1 -0
  70. package/esm/document/data-type/extended-types/time.type.js +1 -0
  71. package/esm/document/data-type/extended-types/url.type.js +1 -0
  72. package/esm/document/data-type/extended-types/uuid.type.js +1 -0
  73. package/esm/document/data-type/mapped-type.js +6 -3
  74. package/esm/document/data-type/mixin-type.js +7 -4
  75. package/esm/document/data-type/primitive-types/any.type.js +1 -0
  76. package/esm/document/data-type/primitive-types/bigint.type.js +1 -0
  77. package/esm/document/data-type/primitive-types/boolean.type.js +1 -0
  78. package/esm/document/data-type/primitive-types/integer.type.js +1 -0
  79. package/esm/document/data-type/primitive-types/null.type.js +1 -0
  80. package/esm/document/data-type/primitive-types/number.type.js +1 -0
  81. package/esm/document/data-type/primitive-types/string.type.js +1 -0
  82. package/esm/document/data-type/simple-type.js +10 -3
  83. package/esm/document/decorators/complex-type.decorator.js +2 -2
  84. package/esm/document/decorators/simple-type.decorator.js +2 -2
  85. package/esm/document/factory/api-document.factory.js +1 -0
  86. package/esm/document/http/http-api.js +2 -2
  87. package/esm/document/http/http-controller.js +5 -5
  88. package/esm/document/http/http-media-type.js +3 -3
  89. package/esm/document/http/http-multipart-field.js +2 -2
  90. package/esm/document/http/http-operation-response.js +3 -3
  91. package/esm/document/http/http-operation.js +5 -5
  92. package/esm/document/http/http-parameter.js +2 -2
  93. package/esm/document/http/http-request-body.js +4 -2
  94. package/esm/filter/filter-rules.js +5 -4
  95. package/package.json +1 -1
  96. package/types/document/api-document.d.ts +8 -2
  97. package/types/document/common/api-base.d.ts +1 -1
  98. package/types/document/common/document-init-context.d.ts +2 -0
  99. package/types/document/common/document-node.d.ts +8 -14
  100. package/types/document/common/value.d.ts +2 -1
  101. package/types/document/constants.d.ts +0 -1
  102. package/types/document/data-type/api-field.d.ts +6 -11
  103. package/types/document/data-type/complex-type.d.ts +2 -1
  104. package/types/document/data-type/data-type.d.ts +7 -2
  105. package/types/document/data-type/enum-type.d.ts +2 -1
  106. package/types/document/data-type/extended-types/field-path.type.d.ts +2 -1
  107. package/types/document/data-type/extended-types/filter.type.d.ts +2 -1
  108. package/types/document/data-type/mapped-type.d.ts +2 -1
  109. package/types/document/data-type/mixin-type.d.ts +2 -1
  110. package/types/document/data-type/simple-type.d.ts +2 -1
  111. package/types/document/factory/api-document.factory.d.ts +2 -1
  112. package/types/document/http/http-api.d.ts +1 -1
  113. package/types/document/http/http-controller.d.ts +2 -1
  114. package/types/document/http/http-media-type.d.ts +2 -1
  115. package/types/document/http/http-multipart-field.d.ts +2 -1
  116. package/types/document/http/http-operation-response.d.ts +2 -1
  117. package/types/document/http/http-operation.d.ts +2 -1
  118. package/types/document/http/http-parameter.d.ts +2 -1
  119. package/types/document/http/http-request-body.d.ts +2 -1
  120. 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 ? (baseName ? baseName : this.base.toJSON()) : undefined,
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
- toJSON() {
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 ? (baseName ? baseName : this.base.toJSON()) : undefined,
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
  }
@@ -16,6 +16,7 @@ let Base64Type = class Base64Type {
16
16
  };
17
17
  Base64Type = __decorate([
18
18
  SimpleType({
19
+ name: 'base64',
19
20
  description: 'A stream of bytes, base64 encoded',
20
21
  nameMappings: {
21
22
  js: 'string',
@@ -34,6 +34,7 @@ __decorate([
34
34
  ], DateStringType.prototype, "maxValue", void 0);
35
35
  DateStringType = __decorate([
36
36
  (SimpleType({
37
+ name: 'datestring',
37
38
  description: 'Date string value',
38
39
  nameMappings: {
39
40
  js: 'string',
@@ -34,6 +34,7 @@ __decorate([
34
34
  ], DateTimeStringType.prototype, "maxValue", void 0);
35
35
  DateTimeStringType = __decorate([
36
36
  (SimpleType({
37
+ name: 'datetimestring',
37
38
  description: 'DateTime string value',
38
39
  nameMappings: {
39
40
  js: 'string',
@@ -52,6 +52,7 @@ __decorate([
52
52
  ], DateTimeType.prototype, "maxValue", void 0);
53
53
  DateTimeType = __decorate([
54
54
  (SimpleType({
55
+ name: 'datetime',
55
56
  description: 'A full datetime value',
56
57
  nameMappings: {
57
58
  js: 'string',
@@ -52,6 +52,7 @@ __decorate([
52
52
  ], DateType.prototype, "maxValue", void 0);
53
53
  DateType = __decorate([
54
54
  (SimpleType({
55
+ name: 'date',
55
56
  description: 'A date without time',
56
57
  nameMappings: {
57
58
  js: 'Date',
@@ -80,6 +80,7 @@ __decorate([
80
80
  ], EmailType.prototype, "blacklistedChars", void 0);
81
81
  EmailType = __decorate([
82
82
  (SimpleType({
83
+ name: 'email',
83
84
  description: 'An email value',
84
85
  nameMappings: {
85
86
  js: 'string',
@@ -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: dataType.name ? dataType.name : dataType.toJSON(),
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) {
@@ -16,6 +16,7 @@ let ObjectIdType = class ObjectIdType {
16
16
  };
17
17
  ObjectIdType = __decorate([
18
18
  SimpleType({
19
+ name: 'ObjectId',
19
20
  description: 'A MongoDB ObjectID value',
20
21
  nameMappings: {
21
22
  js: 'object',
@@ -37,6 +37,7 @@ __decorate([
37
37
  ], OperationResult.prototype, "errors", void 0);
38
38
  OperationResult = __decorate([
39
39
  ComplexType({
40
+ name: 'OperationResult',
40
41
  description: 'Operation result',
41
42
  }),
42
43
  __metadata("design:paramtypes", [Object])
@@ -38,6 +38,7 @@ __decorate([
38
38
  ], TimeType.prototype, "maxValue", void 0);
39
39
  TimeType = __decorate([
40
40
  (SimpleType({
41
+ name: 'time',
41
42
  description: 'Time string in 24h format',
42
43
  nameMappings: {
43
44
  js: 'string',
@@ -16,6 +16,7 @@ let UrlType = class UrlType {
16
16
  };
17
17
  UrlType = __decorate([
18
18
  (SimpleType({
19
+ name: 'url',
19
20
  description: 'A Uniform Resource Identifier Reference (RFC 3986 icon) value',
20
21
  nameMappings: {
21
22
  js: 'string',
@@ -22,6 +22,7 @@ __decorate([
22
22
  ], UuidType.prototype, "version", void 0);
23
23
  UuidType = __decorate([
24
24
  SimpleType({
25
+ name: 'uuid',
25
26
  description: 'A Universal Unique Identifier (UUID) value',
26
27
  nameMappings: {
27
28
  js: 'string',
@@ -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(t => {
62
- const baseName = this.node.getDataTypeNameWithNs(t);
63
- return baseName ? baseName : t.toJSON();
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
  }
@@ -16,6 +16,7 @@ let AnyType = class AnyType {
16
16
  };
17
17
  AnyType = __decorate([
18
18
  SimpleType({
19
+ name: 'any',
19
20
  description: 'Represents any value',
20
21
  }),
21
22
  __metadata("design:paramtypes", [Object])
@@ -23,6 +23,7 @@ let BigintType = class BigintType extends NumberType {
23
23
  };
24
24
  BigintType = __decorate([
25
25
  SimpleType({
26
+ name: 'bigint',
26
27
  description: 'BigInt number',
27
28
  nameMappings: {
28
29
  js: 'bigint',
@@ -16,6 +16,7 @@ let BooleanType = class BooleanType {
16
16
  };
17
17
  BooleanType = __decorate([
18
18
  SimpleType({
19
+ name: 'boolean',
19
20
  description: 'Simple true/false value',
20
21
  nameMappings: {
21
22
  js: 'boolean',
@@ -23,6 +23,7 @@ let IntegerType = class IntegerType extends NumberType {
23
23
  };
24
24
  IntegerType = __decorate([
25
25
  SimpleType({
26
+ name: 'integer',
26
27
  description: 'An integer number',
27
28
  nameMappings: {
28
29
  js: 'number',
@@ -16,6 +16,7 @@ let NullType = class NullType {
16
16
  };
17
17
  NullType = __decorate([
18
18
  SimpleType({
19
+ name: 'null',
19
20
  description: 'A Null value',
20
21
  nameMappings: {
21
22
  js: 'null',
@@ -35,6 +35,7 @@ __decorate([
35
35
  ], NumberType.prototype, "maxValue", void 0);
36
36
  NumberType = __decorate([
37
37
  SimpleType({
38
+ name: 'number',
38
39
  description: 'Both Integer as well as Floating-Point numbers',
39
40
  nameMappings: {
40
41
  js: 'number',
@@ -55,6 +55,7 @@ __decorate([
55
55
  ], StringType.prototype, "maxLength", void 0);
56
56
  StringType = __decorate([
57
57
  SimpleType({
58
+ name: 'string',
58
59
  description: 'A sequence of characters',
59
60
  nameMappings: {
60
61
  js: 'string',
@@ -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 ? (baseName ? baseName : this.base.toJSON()) : undefined,
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, EXTRACT_TYPENAME_PATTERN, } from '../constants.js';
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.match(EXTRACT_TYPENAME_PATTERN)?.[1] || 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, EXTRACT_TYPENAME_PATTERN, } from '../constants.js';
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.match(EXTRACT_TYPENAME_PATTERN)?.[1] || 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 ? this.content.map(x => x.toJSON()) : [],
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
  });