@api-client/core 0.6.14 → 0.6.15

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 (147) hide show
  1. package/build/browser.d.ts +9 -2
  2. package/build/browser.js +12 -2
  3. package/build/browser.js.map +1 -1
  4. package/build/index.d.ts +9 -2
  5. package/build/index.js +12 -2
  6. package/build/index.js.map +1 -1
  7. package/build/src/amf/AmfMixin.d.ts +395 -0
  8. package/build/src/amf/AmfMixin.js +1146 -0
  9. package/build/src/amf/AmfMixin.js.map +1 -0
  10. package/build/src/amf/AmfSerializer.d.ts +136 -0
  11. package/build/src/amf/AmfSerializer.js +1913 -0
  12. package/build/src/amf/AmfSerializer.js.map +1 -0
  13. package/build/src/amf/AmfShapeGenerator.d.ts +85 -0
  14. package/build/src/amf/AmfShapeGenerator.js +385 -0
  15. package/build/src/amf/AmfShapeGenerator.js.map +1 -0
  16. package/build/src/amf/AmfTypes.d.ts +24 -0
  17. package/build/src/amf/AmfTypes.js +122 -0
  18. package/build/src/amf/AmfTypes.js.map +1 -0
  19. package/build/src/amf/ApiExampleGenerator.d.ts +36 -0
  20. package/build/src/amf/ApiExampleGenerator.js +109 -0
  21. package/build/src/amf/ApiExampleGenerator.js.map +1 -0
  22. package/build/src/amf/ApiMonacoSchemaGenerator.d.ts +67 -0
  23. package/build/src/amf/ApiMonacoSchemaGenerator.js +243 -0
  24. package/build/src/amf/ApiMonacoSchemaGenerator.js.map +1 -0
  25. package/build/src/amf/ApiSchemaGenerator.d.ts +55 -0
  26. package/build/src/amf/ApiSchemaGenerator.js +94 -0
  27. package/build/src/amf/ApiSchemaGenerator.js.map +1 -0
  28. package/build/src/amf/ApiSchemaValues.d.ts +98 -0
  29. package/build/src/amf/ApiSchemaValues.js +382 -0
  30. package/build/src/amf/ApiSchemaValues.js.map +1 -0
  31. package/build/src/amf/Utils.d.ts +41 -0
  32. package/build/src/amf/Utils.js +176 -0
  33. package/build/src/amf/Utils.js.map +1 -0
  34. package/build/src/amf/data-node/DataNodeBase.d.ts +31 -0
  35. package/build/src/amf/data-node/DataNodeBase.js +77 -0
  36. package/build/src/amf/data-node/DataNodeBase.js.map +1 -0
  37. package/build/src/amf/data-node/JsonDataNodeGenerator.d.ts +15 -0
  38. package/build/src/amf/data-node/JsonDataNodeGenerator.js +24 -0
  39. package/build/src/amf/data-node/JsonDataNodeGenerator.js.map +1 -0
  40. package/build/src/amf/data-node/UrlEncodedDataNodeGenerator.d.ts +13 -0
  41. package/build/src/amf/data-node/UrlEncodedDataNodeGenerator.js +42 -0
  42. package/build/src/amf/data-node/UrlEncodedDataNodeGenerator.js.map +1 -0
  43. package/build/src/amf/data-node/XmlDataNodeGenerator.d.ts +21 -0
  44. package/build/src/amf/data-node/XmlDataNodeGenerator.js +30 -0
  45. package/build/src/amf/data-node/XmlDataNodeGenerator.js.map +1 -0
  46. package/build/src/amf/definitions/Amf.d.ts +362 -0
  47. package/build/src/amf/definitions/Amf.js +2 -0
  48. package/build/src/amf/definitions/Amf.js.map +1 -0
  49. package/build/src/amf/definitions/Api.d.ts +381 -0
  50. package/build/src/amf/definitions/Api.js +2 -0
  51. package/build/src/amf/definitions/Api.js.map +1 -0
  52. package/build/src/amf/definitions/Base.d.ts +11 -0
  53. package/build/src/amf/definitions/Base.js +2 -0
  54. package/build/src/amf/definitions/Base.js.map +1 -0
  55. package/build/src/amf/definitions/Namespace.d.ts +311 -0
  56. package/build/src/amf/definitions/Namespace.js +330 -0
  57. package/build/src/amf/definitions/Namespace.js.map +1 -0
  58. package/build/src/amf/definitions/Shapes.d.ts +309 -0
  59. package/build/src/amf/definitions/Shapes.js +87 -0
  60. package/build/src/amf/definitions/Shapes.js.map +1 -0
  61. package/build/src/amf/models/AmfDataNode.d.ts +68 -0
  62. package/build/src/amf/models/AmfDataNode.js +188 -0
  63. package/build/src/amf/models/AmfDataNode.js.map +1 -0
  64. package/build/src/amf/shape/ShapeBase.d.ts +75 -0
  65. package/build/src/amf/shape/ShapeBase.js +90 -0
  66. package/build/src/amf/shape/ShapeBase.js.map +1 -0
  67. package/build/src/amf/shape/ShapeJsonSchemaGenerator.d.ts +46 -0
  68. package/build/src/amf/shape/ShapeJsonSchemaGenerator.js +406 -0
  69. package/build/src/amf/shape/ShapeJsonSchemaGenerator.js.map +1 -0
  70. package/build/src/amf/shape/ShapeXmlSchemaGenerator.d.ts +84 -0
  71. package/build/src/amf/shape/ShapeXmlSchemaGenerator.js +820 -0
  72. package/build/src/amf/shape/ShapeXmlSchemaGenerator.js.map +1 -0
  73. package/build/src/models/data/Bindings.d.ts +161 -0
  74. package/build/src/models/data/Bindings.js +2 -0
  75. package/build/src/models/data/Bindings.js.map +1 -0
  76. package/build/src/models/data/DataAssociation.d.ts +135 -14
  77. package/build/src/models/data/DataAssociation.js +154 -21
  78. package/build/src/models/data/DataAssociation.js.map +1 -1
  79. package/build/src/models/data/DataAssociationSchema.d.ts +36 -0
  80. package/build/src/models/data/DataEntity.d.ts +54 -4
  81. package/build/src/models/data/DataEntity.js +85 -9
  82. package/build/src/models/data/DataEntity.js.map +1 -1
  83. package/build/src/models/data/DataFile.d.ts +3 -0
  84. package/build/src/models/data/DataFile.js +3 -0
  85. package/build/src/models/data/DataFile.js.map +1 -1
  86. package/build/src/models/data/DataModel.d.ts +1 -1
  87. package/build/src/models/data/DataModel.js.map +1 -1
  88. package/build/src/models/data/DataProperty.d.ts +107 -36
  89. package/build/src/models/data/DataProperty.js +147 -17
  90. package/build/src/models/data/DataProperty.js.map +1 -1
  91. package/data/apis/oas-date/oas-date.yaml +28 -0
  92. package/data/apis/oas-types/oas-types.yaml +159 -0
  93. package/data/apis/oas-unions/oas-unions.yaml +75 -0
  94. package/data/apis/raml-date/raml-date.raml +28 -0
  95. package/data/apis/recursive/recursive.raml +14 -0
  96. package/data/apis/schema-api/examples/person.json +14 -0
  97. package/data/apis/schema-api/examples/person.raml +14 -0
  98. package/data/apis/schema-api/examples/person.url.encoded +1 -0
  99. package/data/apis/schema-api/examples/person.xml +14 -0
  100. package/data/apis/schema-api/library/demo-types.raml +43 -0
  101. package/data/apis/schema-api/schema-api.raml +644 -0
  102. package/data/apis/schema-api/schemas/person.json +104 -0
  103. package/data/apis/schema-api/schemas/person.xsd +26 -0
  104. package/data/apis/schema-api/types/DemoPerson.raml +67 -0
  105. package/data/model.js +106 -0
  106. package/data/models/oas-date.json +637 -0
  107. package/data/models/oas-types.json +5352 -0
  108. package/data/models/oas-unions.json +1881 -0
  109. package/data/models/raml-date.json +1096 -0
  110. package/data/models/recursive.json +610 -0
  111. package/data/models/schema-api.json +37319 -0
  112. package/package.json +9 -6
  113. package/src/amf/AmfMixin.ts +1623 -0
  114. package/src/amf/AmfSerializer.ts +2028 -0
  115. package/src/amf/AmfShapeGenerator.ts +400 -0
  116. package/src/amf/AmfTypes.ts +126 -0
  117. package/src/amf/ApiExampleGenerator.ts +112 -0
  118. package/src/amf/ApiMonacoSchemaGenerator.ts +296 -0
  119. package/src/amf/ApiSchemaGenerator.ts +108 -0
  120. package/src/amf/ApiSchemaValues.ts +411 -0
  121. package/src/amf/Utils.ts +182 -0
  122. package/src/amf/data-node/DataNodeBase.ts +81 -0
  123. package/src/amf/data-node/JsonDataNodeGenerator.ts +26 -0
  124. package/src/amf/data-node/README.md +3 -0
  125. package/src/amf/data-node/UrlEncodedDataNodeGenerator.ts +43 -0
  126. package/src/amf/data-node/XmlDataNodeGenerator.ts +38 -0
  127. package/src/amf/definitions/Amf.ts +443 -0
  128. package/src/amf/definitions/Api.ts +427 -0
  129. package/src/amf/definitions/Base.ts +13 -0
  130. package/src/amf/definitions/Namespace.ts +341 -0
  131. package/src/amf/definitions/Shapes.ts +414 -0
  132. package/src/amf/models/AmfDataNode.ts +200 -0
  133. package/src/amf/shape/README.md +4 -0
  134. package/src/amf/shape/ShapeBase.ts +160 -0
  135. package/src/amf/shape/ShapeJsonSchemaGenerator.ts +422 -0
  136. package/src/amf/shape/ShapeXmlSchemaGenerator.ts +876 -0
  137. package/src/models/data/Bindings.ts +186 -0
  138. package/src/models/data/DataAssociation.ts +226 -29
  139. package/src/models/data/DataAssociationSchema.ts +38 -0
  140. package/src/models/data/DataEntity.ts +112 -14
  141. package/src/models/data/DataFile.ts +3 -0
  142. package/src/models/data/DataModel.ts +1 -1
  143. package/src/models/data/DataProperty.ts +191 -47
  144. package/build/src/models/data/DataPropertySchema.d.ts +0 -125
  145. package/build/src/models/data/DataPropertySchema.js +0 -33
  146. package/build/src/models/data/DataPropertySchema.js.map +0 -1
  147. package/src/models/data/DataPropertySchema.ts +0 -156
@@ -0,0 +1,1913 @@
1
+ import { AmfMixin, expandKey, findAmfType, getArrayItems } from "./AmfMixin.js";
2
+ import { AmfNamespace as ns } from './definitions/Namespace.js';
3
+ /**
4
+ * A class that takes AMF's ld+json model and outputs JavaScript interface of it.
5
+ */
6
+ export class AmfSerializer extends AmfMixin(Object) {
7
+ /**
8
+ * @param graph Optional AMF generated graph model.
9
+ */
10
+ constructor(graph) {
11
+ super();
12
+ if (graph) {
13
+ this.amf = graph;
14
+ }
15
+ }
16
+ /**
17
+ * @param types The list of graph object types. When not defined it returns an empty array.
18
+ * @returns The expanded types.
19
+ */
20
+ readTypes(types, context) {
21
+ let target = types;
22
+ if (typeof target === 'string') {
23
+ target = [target];
24
+ }
25
+ if (!Array.isArray(target)) {
26
+ return [];
27
+ }
28
+ return target.map((type) => this[expandKey](type, context));
29
+ }
30
+ /**
31
+ * @param object The API to serialize.
32
+ * @returns API summary, without complex objects.
33
+ */
34
+ apiSummary(object) {
35
+ const context = object['@context'];
36
+ const result = {
37
+ id: object['@id'],
38
+ types: this.readTypes(object['@type'], context),
39
+ customDomainProperties: this.customDomainProperties(object, context),
40
+ sourceMaps: this.sourceMap(object),
41
+ schemes: [],
42
+ accepts: [],
43
+ contentType: [],
44
+ documentations: [],
45
+ tags: [],
46
+ };
47
+ const name = this._getValue(object, ns.aml.vocabularies.core.name, context);
48
+ if (name && typeof name === 'string') {
49
+ result.name = name;
50
+ }
51
+ const description = this._getValue(object, ns.aml.vocabularies.core.description, context);
52
+ if (description && typeof description === 'string') {
53
+ result.description = description;
54
+ }
55
+ const version = this._getValue(object, ns.aml.vocabularies.core.version, context);
56
+ if (version && typeof version === 'string') {
57
+ result.version = version;
58
+ }
59
+ const termsOfService = this._getValue(object, ns.aml.vocabularies.core.termsOfService, context);
60
+ if (termsOfService && typeof termsOfService === 'string') {
61
+ result.termsOfService = termsOfService;
62
+ }
63
+ const accepts = object[this._getAmfKey(ns.aml.vocabularies.apiContract.accepts, context)];
64
+ if (Array.isArray(accepts) && accepts.length) {
65
+ result.accepts = this._getValueArray(object, ns.aml.vocabularies.apiContract.accepts, context);
66
+ }
67
+ const contentType = object[this._getAmfKey(ns.aml.vocabularies.apiContract.contentType, context)];
68
+ if (Array.isArray(contentType) && contentType.length) {
69
+ result.contentType = this._getValueArray(object, ns.aml.vocabularies.apiContract.contentType, context);
70
+ }
71
+ const schemes = object[this._getAmfKey(ns.aml.vocabularies.apiContract.scheme, context)];
72
+ if (Array.isArray(schemes) && schemes.length) {
73
+ result.schemes = this._getValueArray(object, ns.aml.vocabularies.apiContract.scheme, context);
74
+ }
75
+ let provider = object[this._getAmfKey(ns.aml.vocabularies.core.provider, context)];
76
+ if (Array.isArray(provider)) {
77
+ [provider] = provider;
78
+ }
79
+ if (provider) {
80
+ result.provider = this.provider(provider);
81
+ }
82
+ let license = object[this._getAmfKey(ns.aml.vocabularies.core.license, context)];
83
+ if (Array.isArray(license)) {
84
+ [license] = license;
85
+ }
86
+ if (license) {
87
+ result.license = this.license(license);
88
+ }
89
+ const tags = object[this._getAmfKey(ns.aml.vocabularies.apiContract.tag, context)];
90
+ if (Array.isArray(tags) && tags.length) {
91
+ result.tags = tags.map(t => this.tag(t));
92
+ }
93
+ const docs = object[this._getAmfKey(ns.aml.vocabularies.core.documentation, context)];
94
+ if (Array.isArray(docs) && docs.length) {
95
+ result.documentations = docs.map(d => this.documentation(d));
96
+ }
97
+ return result;
98
+ }
99
+ api(object, context) {
100
+ const objectContext = context || object['@context'];
101
+ const result = this.apiSummary(object);
102
+ result.endPoints = [];
103
+ result.servers = [];
104
+ result.security = [];
105
+ const endPoints = object[this._getAmfKey(ns.aml.vocabularies.apiContract.endpoint, objectContext)];
106
+ if (Array.isArray(endPoints) && endPoints.length) {
107
+ result.endPoints = endPoints.map(e => this.endPoint(e, objectContext));
108
+ }
109
+ const servers = object[this._getAmfKey(ns.aml.vocabularies.apiContract.server, objectContext)];
110
+ if (Array.isArray(servers) && servers.length) {
111
+ result.servers = servers.map(s => this.server(s, objectContext));
112
+ }
113
+ const security = object[this._getAmfKey(ns.aml.vocabularies.security.security, objectContext)];
114
+ if (Array.isArray(security) && security.length) {
115
+ result.security = security.map(s => this.securityRequirement(s, objectContext));
116
+ }
117
+ return result;
118
+ }
119
+ webApi(object, context) {
120
+ return this.api(object, context);
121
+ }
122
+ asyncApi(object, context) {
123
+ return this.api(object, context);
124
+ }
125
+ provider(object, context) {
126
+ const objectContext = context || object['@context'];
127
+ const result = {
128
+ id: object['@id'],
129
+ types: this.readTypes(object['@type'], objectContext),
130
+ customDomainProperties: this.customDomainProperties(object, objectContext),
131
+ sourceMaps: this.sourceMap(object, objectContext),
132
+ };
133
+ const name = this._getValue(object, ns.aml.vocabularies.core.name, objectContext);
134
+ if (name && typeof name === 'string') {
135
+ result.name = name;
136
+ }
137
+ const url = this._getLinkValue(object, ns.aml.vocabularies.core.url, objectContext);
138
+ if (url && typeof url === 'string') {
139
+ result.url = url;
140
+ }
141
+ const email = this._getValue(object, ns.aml.vocabularies.core.email, objectContext);
142
+ if (email && typeof email === 'string') {
143
+ result.email = email;
144
+ }
145
+ return result;
146
+ }
147
+ license(object, context) {
148
+ const objectContext = context || object['@context'];
149
+ const result = {
150
+ id: object['@id'],
151
+ types: this.readTypes(object['@type'], objectContext),
152
+ customDomainProperties: this.customDomainProperties(object, objectContext),
153
+ sourceMaps: this.sourceMap(object, objectContext),
154
+ };
155
+ const name = this._getValue(object, ns.aml.vocabularies.core.name, objectContext);
156
+ if (name && typeof name === 'string') {
157
+ result.name = name;
158
+ }
159
+ const url = this._getLinkValue(object, ns.aml.vocabularies.core.url, objectContext);
160
+ if (url && typeof url === 'string') {
161
+ result.url = url;
162
+ }
163
+ return result;
164
+ }
165
+ /**
166
+ * @param object The AMF Server to serialize.
167
+ * @returns Serialized Server
168
+ */
169
+ server(object, context) {
170
+ const objectContext = context || object['@context'];
171
+ const url = this._getValue(object, ns.aml.vocabularies.core.urlTemplate, objectContext) || '';
172
+ const result = ({
173
+ id: object['@id'],
174
+ types: this.readTypes(object['@type'], objectContext),
175
+ url,
176
+ variables: [],
177
+ customDomainProperties: this.customDomainProperties(object, objectContext),
178
+ sourceMaps: this.sourceMap(object, objectContext),
179
+ });
180
+ const description = this._getValue(object, ns.aml.vocabularies.core.description, objectContext);
181
+ if (description && typeof description === 'string') {
182
+ result.description = description;
183
+ }
184
+ const variables = (object[this._getAmfKey(ns.aml.vocabularies.apiContract.variable, objectContext)]);
185
+ if (Array.isArray(variables) && variables.length) {
186
+ result.variables = variables.map((p) => this.parameter(p, objectContext));
187
+ }
188
+ const protocol = (this._getValue(object, ns.aml.vocabularies.apiContract.protocol, objectContext));
189
+ const protocolVersion = (this._getValue(object, ns.aml.vocabularies.apiContract.protocolVersion, objectContext));
190
+ if (protocol) {
191
+ result.protocol = protocol;
192
+ }
193
+ if (protocolVersion) {
194
+ result.protocolVersion = protocolVersion;
195
+ }
196
+ const security = (object[this._getAmfKey(ns.aml.vocabularies.security.security, objectContext)]);
197
+ if (Array.isArray(security) && security.length) {
198
+ result.security = security.map((p) => this.securityRequirement(p, objectContext));
199
+ }
200
+ return result;
201
+ }
202
+ /**
203
+ * @param object The Parameter to serialize.
204
+ * @returns Serialized Parameter
205
+ */
206
+ parameter(object, context) {
207
+ const objectContext = context || object['@context'];
208
+ const result = ({
209
+ id: object['@id'],
210
+ types: this.readTypes(object['@type'], objectContext),
211
+ payloads: [],
212
+ examples: [],
213
+ customDomainProperties: this.customDomainProperties(object, objectContext),
214
+ sourceMaps: this.sourceMap(object, objectContext),
215
+ });
216
+ const name = this._getValue(object, ns.aml.vocabularies.core.name, objectContext);
217
+ if (name && typeof name === 'string') {
218
+ result.name = name;
219
+ }
220
+ const paramName = this._getValue(object, ns.aml.vocabularies.apiContract.paramName, objectContext);
221
+ if (paramName && typeof paramName === 'string') {
222
+ result.paramName = paramName;
223
+ }
224
+ const description = this._getValue(object, ns.aml.vocabularies.core.description, objectContext);
225
+ if (description && typeof description === 'string') {
226
+ result.description = description;
227
+ }
228
+ const required = this._getValue(object, ns.aml.vocabularies.apiContract.required, objectContext);
229
+ if (typeof required === 'boolean') {
230
+ result.required = required;
231
+ }
232
+ const allowEmptyValue = this._getValue(object, ns.aml.vocabularies.apiContract.allowEmptyValue, objectContext);
233
+ if (typeof allowEmptyValue === 'boolean') {
234
+ result.allowEmptyValue = allowEmptyValue;
235
+ }
236
+ const deprecated = this._getValue(object, ns.aml.vocabularies.document.deprecated, objectContext);
237
+ if (typeof deprecated === 'boolean') {
238
+ result.deprecated = deprecated;
239
+ }
240
+ const explode = this._getValue(object, ns.aml.vocabularies.apiContract.explode, objectContext);
241
+ if (typeof explode === 'boolean') {
242
+ result.explode = explode;
243
+ }
244
+ const allowReserved = this._getValue(object, ns.aml.vocabularies.apiContract.allowReserved, objectContext);
245
+ if (typeof allowReserved === 'boolean') {
246
+ result.allowReserved = allowReserved;
247
+ }
248
+ const style = this._getValue(object, ns.aml.vocabularies.apiContract.style, objectContext);
249
+ if (style && typeof style === 'string') {
250
+ result.style = style;
251
+ }
252
+ const binding = this._getValue(object, ns.aml.vocabularies.apiContract.binding, objectContext);
253
+ if (binding && typeof binding === 'string') {
254
+ result.binding = binding;
255
+ }
256
+ const schemas = object[this._getAmfKey(ns.aml.vocabularies.shapes.schema, objectContext)];
257
+ if (Array.isArray(schemas) && schemas.length) {
258
+ const [schema] = schemas;
259
+ result.schema = this.unknownShape(schema, {
260
+ trackedId: object['@id'],
261
+ }, objectContext);
262
+ }
263
+ const payloads = object[this._getAmfKey(ns.aml.vocabularies.apiContract.payload, objectContext)];
264
+ if (Array.isArray(payloads) && payloads.length) {
265
+ result.payloads = payloads.map(p => this.payload(p, objectContext));
266
+ }
267
+ const examples = object[this._getAmfKey(ns.aml.vocabularies.apiContract.examples, objectContext)];
268
+ if (Array.isArray(examples) && examples.length) {
269
+ result.examples = examples.map(e => this.example(e, objectContext));
270
+ }
271
+ return result;
272
+ }
273
+ unknownShape(object, options, context) {
274
+ const objectContext = context || object['@context'];
275
+ const types = this.readTypes(object['@type'], objectContext);
276
+ if (types.includes(ns.aml.vocabularies.shapes.ScalarShape)) {
277
+ return this.scalarShape(object, options, objectContext);
278
+ }
279
+ if (types.includes(ns.w3.shacl.NodeShape)) {
280
+ return this.nodeShape(object, options, objectContext);
281
+ }
282
+ if (types.includes(ns.aml.vocabularies.shapes.UnionShape)) {
283
+ return this.unionShape(object, options, objectContext);
284
+ }
285
+ if (types.includes(ns.aml.vocabularies.shapes.FileShape)) {
286
+ return this.fileShape(object, options, objectContext);
287
+ }
288
+ if (types.includes(ns.aml.vocabularies.shapes.SchemaShape)) {
289
+ return this.schemaShape(object, options, objectContext);
290
+ }
291
+ // this must be before the ArrayShape
292
+ if (types.includes(ns.aml.vocabularies.shapes.TupleShape)) {
293
+ return this.tupleShape(object, options, objectContext);
294
+ }
295
+ if (types.includes(ns.aml.vocabularies.shapes.ArrayShape) || types.includes(ns.aml.vocabularies.shapes.MatrixShape)) {
296
+ return this.arrayShape(object, options, objectContext);
297
+ }
298
+ if (types.includes(ns.aml.vocabularies.shapes.RecursiveShape)) {
299
+ return this.recursiveShape(object, objectContext);
300
+ }
301
+ // recursiveShape
302
+ return this.anyShape(object, options, objectContext);
303
+ }
304
+ isLink(object, context) {
305
+ const objectContext = context || object['@context'];
306
+ return !!this._getLinkValue(object, ns.aml.vocabularies.document.linkTarget, objectContext);
307
+ }
308
+ getLinkTarget(object, context) {
309
+ const objectContext = context || object['@context'];
310
+ const id = this._getLinkValue(object, ns.aml.vocabularies.document.linkTarget, objectContext);
311
+ if (!id) {
312
+ return undefined;
313
+ }
314
+ return this[findAmfType](id, objectContext);
315
+ }
316
+ shape(object, context) {
317
+ const objectContext = context || object['@context'];
318
+ this._resolve(object);
319
+ let linkLabel;
320
+ let target = object;
321
+ if (this.isLink(target)) {
322
+ linkLabel = (this._getValue(target, ns.aml.vocabularies.document.linkLabel, objectContext));
323
+ const id = this._getLinkValue(target, ns.aml.vocabularies.document.linkTarget, objectContext);
324
+ const value = this[findAmfType](id, objectContext);
325
+ if (value) {
326
+ target = value;
327
+ }
328
+ }
329
+ const result = ({
330
+ id: target['@id'],
331
+ types: this.readTypes(object['@type'], objectContext),
332
+ values: [],
333
+ inherits: [],
334
+ or: [],
335
+ and: [],
336
+ xone: [],
337
+ customDomainProperties: this.customDomainProperties(object, objectContext),
338
+ sourceMaps: this.sourceMap(object, objectContext),
339
+ });
340
+ if (linkLabel) {
341
+ result.linkLabel = linkLabel;
342
+ }
343
+ const name = this._getValue(target, ns.w3.shacl.name, objectContext);
344
+ if (name && typeof name === 'string') {
345
+ result.name = name;
346
+ }
347
+ const displayName = this._getValue(target, ns.aml.vocabularies.core.displayName, objectContext);
348
+ if (displayName && typeof displayName === 'string') {
349
+ result.displayName = displayName;
350
+ }
351
+ else {
352
+ const coreName = this._getValue(target, ns.aml.vocabularies.core.name, objectContext);
353
+ if (coreName && typeof coreName === 'string') {
354
+ result.displayName = coreName;
355
+ }
356
+ }
357
+ const description = this._getValue(target, ns.aml.vocabularies.core.description, objectContext);
358
+ if (description && typeof description === 'string') {
359
+ result.description = description;
360
+ }
361
+ const defaultValueStr = this._getValue(target, ns.w3.shacl.defaultValueStr, objectContext);
362
+ if (defaultValueStr && typeof defaultValueStr === 'string') {
363
+ result.defaultValueStr = defaultValueStr;
364
+ }
365
+ const deprecated = this._getValue(target, ns.aml.vocabularies.shapes.deprecated, objectContext);
366
+ if (typeof deprecated === 'boolean') {
367
+ result.deprecated = deprecated;
368
+ }
369
+ const readOnly = this._getValue(target, ns.aml.vocabularies.shapes.readOnly, objectContext);
370
+ if (typeof readOnly === 'boolean') {
371
+ result.readOnly = readOnly;
372
+ }
373
+ const writeOnly = this._getValue(target, ns.aml.vocabularies.shapes.writeOnly, objectContext);
374
+ if (typeof writeOnly === 'boolean') {
375
+ result.writeOnly = writeOnly;
376
+ }
377
+ const defValue = target[this._getAmfKey(ns.w3.shacl.defaultValue, objectContext)];
378
+ if (Array.isArray(defValue) && defValue.length) {
379
+ result.defaultValue = this.unknownDataNode(defValue[0], objectContext);
380
+ }
381
+ // @TODO:
382
+ // if (Array.isArray(inherits) && inherits.length) {
383
+ // result.inherits = inherits.map((item) => this.unknownShape(item));
384
+ // }
385
+ const orKey = this._getAmfKey(ns.w3.shacl.or, objectContext);
386
+ const orGroup = (target[orKey]);
387
+ if (Array.isArray(orGroup) && orGroup.length) {
388
+ result.or = orGroup.map((item) => this.unknownShape(item, undefined, objectContext));
389
+ }
390
+ const andKey = this._getAmfKey(ns.w3.shacl.and, objectContext);
391
+ const andGroup = (target[andKey]);
392
+ if (Array.isArray(andGroup) && andGroup.length) {
393
+ result.and = andGroup.map((item) => this.unknownShape(item, undefined, objectContext));
394
+ }
395
+ const xoneKey = this._getAmfKey(ns.w3.shacl.xone, objectContext);
396
+ const xone = (target[xoneKey]);
397
+ if (Array.isArray(xone) && xone.length) {
398
+ result.xone = xone.map((item) => this.unknownShape(item, undefined, objectContext));
399
+ }
400
+ const valuesList = target[this._getAmfKey(ns.w3.shacl.in, objectContext)];
401
+ if (Array.isArray(valuesList) && valuesList.length) {
402
+ const [values] = valuesList;
403
+ const prefix = ns.w3.rdfSchema.key;
404
+ const prefixCompact = this._getAmfKey(prefix, objectContext);
405
+ Object.keys(values).forEach((key) => {
406
+ if (key.startsWith(prefix) || key.startsWith(prefixCompact)) {
407
+ let value = values[key];
408
+ if (Array.isArray(value)) {
409
+ [value] = value;
410
+ }
411
+ const processed = this.unknownDataNode(value, objectContext);
412
+ if (processed) {
413
+ result.values.push(processed);
414
+ }
415
+ }
416
+ });
417
+ }
418
+ const notKey = this._getAmfKey(ns.w3.shacl.not, objectContext);
419
+ let not = target[notKey];
420
+ if (not) {
421
+ if (Array.isArray(not)) {
422
+ [not] = not;
423
+ }
424
+ result.not = this.unknownShape(not, undefined, objectContext);
425
+ }
426
+ return result;
427
+ }
428
+ anyShape(object, options = {}, context) {
429
+ const objectContext = context || object['@context'];
430
+ let target = object;
431
+ const result = (this.shape(target, objectContext));
432
+ if (this.isLink(target)) {
433
+ const value = (this.getLinkTarget(target, objectContext));
434
+ if (value) {
435
+ target = value;
436
+ }
437
+ }
438
+ result.examples = [];
439
+ const examples = target[this._getAmfKey(ns.aml.vocabularies.apiContract.examples, objectContext)];
440
+ if (Array.isArray(examples) && examples.length) {
441
+ if (options.trackedId) {
442
+ const filtered = this.filterTrackedExamples(examples, options.trackedId, objectContext);
443
+ result.examples = filtered.map((item) => this.example(item, objectContext));
444
+ }
445
+ else {
446
+ const filtered = this.filterNonTrackedExamples(examples, objectContext);
447
+ result.examples = filtered.map((item) => this.example(item, objectContext));
448
+ }
449
+ }
450
+ const docs = target[this._getAmfKey(ns.aml.vocabularies.core.documentation, objectContext)];
451
+ if (Array.isArray(docs) && docs.length) {
452
+ const [documentation] = docs;
453
+ result.documentation = this.documentation(documentation, objectContext);
454
+ }
455
+ const xml = target[this._getAmfKey(ns.aml.vocabularies.shapes.xmlSerialization, objectContext)];
456
+ if (Array.isArray(xml) && xml.length) {
457
+ result.xmlSerialization = this.xmlSerializer(xml[0], objectContext);
458
+ }
459
+ return result;
460
+ }
461
+ /**
462
+ * Filters examples that should be rendered for a payload identified by `trackedId`.
463
+ *
464
+ * This function is copied from old `api-example-generator/ExampleGenerator`.
465
+ */
466
+ filterTrackedExamples(examples, trackedId, context) {
467
+ const { docSourceMaps } = ns.aml.vocabularies;
468
+ const sourceKey = this._getAmfKey(docSourceMaps.sources, context);
469
+ const trackedKey = this._getAmfKey(docSourceMaps.trackedElement, context);
470
+ const longId = trackedId.indexOf('amf') === -1 ? `amf://id${trackedId}` : trackedId;
471
+ return examples.filter((item) => {
472
+ let example = item;
473
+ if (Array.isArray(example)) {
474
+ [example] = example;
475
+ }
476
+ let sm = example[sourceKey];
477
+ if (!sm) {
478
+ return true;
479
+ }
480
+ if (Array.isArray(sm)) {
481
+ [sm] = sm;
482
+ }
483
+ let tracked = sm[trackedKey];
484
+ if (!tracked) {
485
+ return true;
486
+ }
487
+ if (Array.isArray(tracked)) {
488
+ [tracked] = tracked;
489
+ }
490
+ const { value } = this.synthesizedField(tracked, context);
491
+ if (!value) {
492
+ return true;
493
+ }
494
+ const ids = value.split(',');
495
+ if (ids.indexOf(longId) !== -1 || ids.indexOf(trackedId) !== -1) {
496
+ return true;
497
+ }
498
+ return false;
499
+ });
500
+ }
501
+ /**
502
+ * Kind of the opposite of the `filterTrackedExamples`. It gathers examples that only have been
503
+ * defined for the parent Shape (ed in the type declaration). It filters out all examples
504
+ * defined in a payload.
505
+ */
506
+ filterNonTrackedExamples(examples, context) {
507
+ const { docSourceMaps } = ns.aml.vocabularies;
508
+ const sourceKey = this._getAmfKey(docSourceMaps.sources, context);
509
+ const trackedKey = this._getAmfKey(docSourceMaps.trackedElement, context);
510
+ return examples.filter((item) => {
511
+ let example = item;
512
+ if (Array.isArray(example)) {
513
+ [example] = example;
514
+ }
515
+ let sm = example[sourceKey];
516
+ if (!sm) {
517
+ return true;
518
+ }
519
+ if (Array.isArray(sm)) {
520
+ [sm] = sm;
521
+ }
522
+ let tracked = sm[trackedKey];
523
+ if (!tracked) {
524
+ return true;
525
+ }
526
+ if (Array.isArray(tracked)) {
527
+ [tracked] = tracked;
528
+ }
529
+ const { value } = this.synthesizedField(tracked, context);
530
+ if (!value) {
531
+ return true;
532
+ }
533
+ return false;
534
+ });
535
+ }
536
+ scalarShape(object, options = {}, context) {
537
+ const objectContext = context || object['@context'];
538
+ let target = object;
539
+ const result = (this.anyShape(target, options, objectContext));
540
+ if (this.isLink(target)) {
541
+ const value = (this.getLinkTarget(target, objectContext));
542
+ if (value) {
543
+ target = value;
544
+ }
545
+ }
546
+ const pattern = this._getValue(target, ns.w3.shacl.pattern, objectContext);
547
+ if (pattern && typeof pattern === 'string') {
548
+ result.pattern = pattern;
549
+ }
550
+ const dataType = this._getLinkValue(target, ns.w3.shacl.datatype, objectContext);
551
+ if (dataType && typeof dataType === 'string') {
552
+ result.dataType = dataType;
553
+ }
554
+ const format = this._getValue(target, ns.aml.vocabularies.shapes.format, objectContext);
555
+ if (format && typeof format === 'string') {
556
+ result.format = format;
557
+ }
558
+ const multipleOf = this._getValue(target, ns.aml.vocabularies.shapes.multipleOf, objectContext);
559
+ if (typeof multipleOf === 'number') {
560
+ result.multipleOf = multipleOf;
561
+ }
562
+ const minInclusive = this._getValue(target, ns.w3.shacl.minInclusive, objectContext);
563
+ if (typeof minInclusive === 'number') {
564
+ result.minimum = minInclusive;
565
+ result.exclusiveMinimum = false;
566
+ }
567
+ const maxInclusive = this._getValue(target, ns.w3.shacl.maxInclusive, objectContext);
568
+ if (typeof maxInclusive === 'number') {
569
+ result.maximum = maxInclusive;
570
+ result.exclusiveMaximum = false;
571
+ }
572
+ const minLength = this._getValue(target, ns.w3.shacl.minLength, objectContext);
573
+ if (typeof minLength === 'number') {
574
+ result.minLength = minLength;
575
+ }
576
+ const maxLength = this._getValue(target, ns.w3.shacl.maxLength, objectContext);
577
+ if (typeof maxLength === 'number') {
578
+ result.maxLength = maxLength;
579
+ }
580
+ return result;
581
+ }
582
+ nodeShape(object, options = {}, context) {
583
+ const objectContext = context || object['@context'];
584
+ let target = object;
585
+ const result = (this.anyShape(target, options, objectContext));
586
+ if (this.isLink(target)) {
587
+ const value = this.getLinkTarget(target, objectContext);
588
+ if (value) {
589
+ target = value;
590
+ }
591
+ }
592
+ const discriminator = this._getValue(target, ns.aml.vocabularies.shapes.discriminator, objectContext);
593
+ if (discriminator && typeof discriminator === 'string') {
594
+ result.discriminator = discriminator;
595
+ }
596
+ const discriminatorValue = this._getValue(target, ns.aml.vocabularies.shapes.discriminatorValue, objectContext);
597
+ if (discriminatorValue && typeof discriminatorValue === 'string') {
598
+ result.discriminatorValue = discriminatorValue;
599
+ }
600
+ const closed = this._getValue(target, ns.w3.shacl.closed, objectContext);
601
+ if (typeof closed === 'boolean') {
602
+ result.closed = closed;
603
+ }
604
+ result.customShapeProperties = [];
605
+ result.customShapePropertyDefinitions = [];
606
+ result.dependencies = [];
607
+ // todo: not sure what the keys are.
608
+ // if (!minProperties.isNull) {
609
+ // result.minProperties = minProperties.value();
610
+ // }
611
+ // if (!maxProperties.isNull) {
612
+ // result.maxProperties = maxProperties.value();
613
+ // }
614
+ // if (Array.isArray(customShapeProperties) && customShapeProperties.length) {
615
+ // result.customShapeProperties = customShapeProperties.map((item) => item.id);
616
+ // } else {
617
+ // result.customShapeProperties = [];
618
+ // }
619
+ // if (Array.isArray(customShapePropertyDefinitions) && customShapePropertyDefinitions.length) {
620
+ // result.customShapePropertyDefinitions = customShapePropertyDefinitions.map((item) => item.id);
621
+ // } else {
622
+ // result.customShapePropertyDefinitions = [];
623
+ // }
624
+ const properties = (target[this._getAmfKey(ns.w3.shacl.property, objectContext)]);
625
+ if (Array.isArray(properties) && properties.length) {
626
+ result.properties = properties.map((item) => this.propertyShape(item, objectContext));
627
+ }
628
+ else {
629
+ result.properties = [];
630
+ }
631
+ // if (Array.isArray(dependencies) && dependencies.length) {
632
+ // result.dependencies = dependencies.map((item) => item.id);
633
+ // } else {
634
+ // result.dependencies = [];
635
+ // }
636
+ return result;
637
+ }
638
+ propertyShape(object, context) {
639
+ const objectContext = context || object['@context'];
640
+ let target = object;
641
+ const result = (this.shape(target, objectContext));
642
+ if (this.isLink(target)) {
643
+ const value = this.getLinkTarget(target, objectContext);
644
+ if (value) {
645
+ target = value;
646
+ }
647
+ }
648
+ const path = this._getLinkValue(target, ns.w3.shacl.path, objectContext);
649
+ if (path && typeof path === 'string') {
650
+ result.path = path;
651
+ }
652
+ const minCount = this._getValue(target, ns.w3.shacl.minCount, objectContext);
653
+ if (typeof minCount === 'number') {
654
+ result.minCount = minCount;
655
+ }
656
+ const maxCount = this._getValue(target, ns.w3.shacl.maxCount, objectContext);
657
+ if (typeof maxCount === 'number') {
658
+ result.maxCount = maxCount;
659
+ }
660
+ // if (!patternName.isNullOrEmpty) {
661
+ // result.patternName = patternName.value();
662
+ // }
663
+ const ranges = (target[this._getAmfKey(ns.aml.vocabularies.shapes.range, objectContext)]);
664
+ if (Array.isArray(ranges) && ranges.length) {
665
+ const [range] = ranges;
666
+ result.range = this.unknownShape(range, undefined, objectContext);
667
+ }
668
+ return result;
669
+ }
670
+ unionShape(object, options = {}, context) {
671
+ const objectContext = context || object['@context'];
672
+ const anyOf = (object[this._getAmfKey(ns.aml.vocabularies.shapes.anyOf, objectContext)]);
673
+ const result = (this.anyShape(object, options, objectContext));
674
+ if (Array.isArray(anyOf) && anyOf.length) {
675
+ const opt = { ...options, trackedId: undefined };
676
+ result.anyOf = anyOf.map((shape) => this.unknownShape(shape, opt, objectContext));
677
+ }
678
+ else {
679
+ result.anyOf = [];
680
+ }
681
+ return result;
682
+ }
683
+ fileShape(object, options = {}, context) {
684
+ const objectContext = context || object['@context'];
685
+ let target = object;
686
+ const result = (this.anyShape(target, options, objectContext));
687
+ if (this.isLink(target)) {
688
+ const value = (this.getLinkTarget(target, objectContext));
689
+ if (value) {
690
+ target = value;
691
+ }
692
+ }
693
+ const pattern = this._getValue(target, ns.w3.shacl.pattern, objectContext);
694
+ if (pattern && typeof pattern === 'string') {
695
+ result.pattern = pattern;
696
+ }
697
+ const fileTypes = (this._getValueArray(target, ns.aml.vocabularies.shapes.fileType, objectContext));
698
+ if (Array.isArray(fileTypes) && fileTypes.length) {
699
+ result.fileTypes = fileTypes;
700
+ }
701
+ const minLength = this._getValue(target, ns.w3.shacl.minLength, objectContext);
702
+ if (typeof minLength === 'number') {
703
+ result.minLength = minLength;
704
+ }
705
+ const maxLength = this._getValue(target, ns.w3.shacl.maxLength, objectContext);
706
+ if (typeof maxLength === 'number') {
707
+ result.maxLength = maxLength;
708
+ }
709
+ const minInclusive = this._getValue(target, ns.w3.shacl.minInclusive, objectContext);
710
+ if (typeof minInclusive === 'number') {
711
+ result.minimum = minInclusive;
712
+ result.exclusiveMinimum = false;
713
+ }
714
+ const maxInclusive = this._getValue(target, ns.w3.shacl.maxInclusive, objectContext);
715
+ if (typeof maxInclusive === 'number') {
716
+ result.maximum = maxInclusive;
717
+ result.exclusiveMaximum = false;
718
+ }
719
+ const format = this._getValue(target, ns.aml.vocabularies.shapes.format, objectContext);
720
+ if (format && typeof format === 'string') {
721
+ result.format = format;
722
+ }
723
+ const multipleOf = this._getValue(target, ns.aml.vocabularies.shapes.multipleOf, objectContext);
724
+ if (typeof multipleOf === 'number') {
725
+ result.multipleOf = multipleOf;
726
+ }
727
+ return result;
728
+ }
729
+ schemaShape(object, options = {}, context) {
730
+ const objectContext = context || object['@context'];
731
+ let target = object;
732
+ const result = (this.anyShape(target, options, objectContext));
733
+ if (this.isLink(target)) {
734
+ const value = (this.getLinkTarget(target, objectContext));
735
+ if (value) {
736
+ target = value;
737
+ }
738
+ }
739
+ const mediaType = this._getValue(target, ns.aml.vocabularies.core.mediaType, objectContext);
740
+ if (mediaType && typeof mediaType === 'string') {
741
+ result.mediaType = mediaType;
742
+ }
743
+ const raw = this._getValue(target, ns.aml.vocabularies.document.raw, objectContext);
744
+ if (raw && typeof raw === 'string') {
745
+ result.raw = raw;
746
+ }
747
+ return result;
748
+ }
749
+ recursiveShape(object, context) {
750
+ const objectContext = context || object['@context'];
751
+ let target = object;
752
+ const result = (this.shape(target, objectContext));
753
+ if (this.isLink(target)) {
754
+ const value = (this.getLinkTarget(target, objectContext));
755
+ if (value) {
756
+ target = value;
757
+ }
758
+ }
759
+ const fp = this._getLinkValue(object, ns.aml.vocabularies.shapes.fixPoint, objectContext);
760
+ if (fp && typeof fp === 'string') {
761
+ result.fixPoint = fp;
762
+ }
763
+ return result;
764
+ }
765
+ dataArrangeShape(object, options = {}, context) {
766
+ const objectContext = context || object['@context'];
767
+ let target = object;
768
+ const result = (this.anyShape(target, options, objectContext));
769
+ if (this.isLink(target)) {
770
+ const value = (this.getLinkTarget(target, objectContext));
771
+ if (value) {
772
+ target = value;
773
+ }
774
+ }
775
+ //
776
+ // const { minItems, maxItems, uniqueItems } = object;
777
+ // if (!minItems.isNull) {
778
+ // result.minItems = minItems.value();
779
+ // }
780
+ // if (!maxItems.isNull) {
781
+ // result.maxItems = maxItems.value();
782
+ // }
783
+ // if (!uniqueItems.isNull) {
784
+ // result.uniqueItems = uniqueItems.value();
785
+ // }
786
+ return result;
787
+ }
788
+ arrayShape(object, options = {}, context) {
789
+ const objectContext = context || object['@context'];
790
+ let target = object;
791
+ const result = (this.dataArrangeShape(target, options, objectContext));
792
+ if (this.isLink(target)) {
793
+ const value = (this.getLinkTarget(target, objectContext));
794
+ if (value) {
795
+ target = value;
796
+ }
797
+ }
798
+ const items = target[this._getAmfKey(ns.aml.vocabularies.shapes.items, objectContext)];
799
+ if (Array.isArray(items) && items.length) {
800
+ const [item] = items;
801
+ result.items = this.unknownShape(item, undefined, objectContext);
802
+ }
803
+ return result;
804
+ }
805
+ tupleShape(object, options, context) {
806
+ const objectContext = context || object['@context'];
807
+ let target = object;
808
+ const result = (this.dataArrangeShape(target, options, objectContext));
809
+ if (this.isLink(target)) {
810
+ const value = (this.getLinkTarget(target, objectContext));
811
+ if (value) {
812
+ target = value;
813
+ }
814
+ }
815
+ const items = target[this._getAmfKey(ns.aml.vocabularies.shapes.items, objectContext)];
816
+ const prefix = this._getAmfKey(ns.w3.rdfSchema.key, objectContext);
817
+ if (Array.isArray(items) && items.length) {
818
+ result.items = [];
819
+ items.forEach((item) => {
820
+ if (Array.isArray(item)) {
821
+ [item] = item;
822
+ }
823
+ Object.keys(item).filter(k => k.startsWith(prefix)).forEach((key) => {
824
+ let shape = item[key];
825
+ if (Array.isArray(shape)) {
826
+ [shape] = shape;
827
+ }
828
+ const value = this.unknownShape(shape, undefined, objectContext);
829
+ result.items.push(value);
830
+ });
831
+ });
832
+ }
833
+ else {
834
+ result.items = [];
835
+ }
836
+ return result;
837
+ }
838
+ /**
839
+ * @param object The CreativeWork to serialize.
840
+ * @returns Serialized CreativeWork
841
+ */
842
+ documentation(object, context) {
843
+ const objectContext = context || object['@context'];
844
+ const result = ({
845
+ id: object['@id'],
846
+ types: this.readTypes(object['@type'], objectContext),
847
+ customDomainProperties: this.customDomainProperties(object, objectContext),
848
+ sourceMaps: this.sourceMap(object, objectContext),
849
+ });
850
+ const url = this._getLinkValue(object, ns.aml.vocabularies.core.url, objectContext);
851
+ if (url && typeof url === 'string') {
852
+ result.url = url;
853
+ }
854
+ const description = this._getValue(object, ns.aml.vocabularies.core.description, objectContext);
855
+ if (description && typeof description === 'string') {
856
+ result.description = description;
857
+ }
858
+ const title = this._getValue(object, ns.aml.vocabularies.core.title, objectContext);
859
+ if (title && typeof title === 'string') {
860
+ result.title = title;
861
+ }
862
+ return result;
863
+ }
864
+ /**
865
+ * @param object The Example to serialize.
866
+ * @returns Serialized Example
867
+ */
868
+ example(object, context) {
869
+ const objectContext = context || object['@context'];
870
+ this._resolve(object);
871
+ const result = ({
872
+ id: object['@id'],
873
+ types: this.readTypes(object['@type'], objectContext),
874
+ customDomainProperties: this.customDomainProperties(object, objectContext),
875
+ sourceMaps: this.sourceMap(object, objectContext),
876
+ strict: false,
877
+ });
878
+ const strict = this._getValue(object, ns.aml.vocabularies.document.strict, objectContext);
879
+ if (typeof strict === 'boolean') {
880
+ result.strict = strict;
881
+ }
882
+ const name = this._getValue(object, ns.aml.vocabularies.core.name, objectContext);
883
+ if (name && typeof name === 'string') {
884
+ result.name = name;
885
+ }
886
+ const displayName = this._getValue(object, ns.aml.vocabularies.core.displayName, objectContext);
887
+ if (displayName && typeof displayName === 'string') {
888
+ result.displayName = displayName;
889
+ }
890
+ const description = this._getValue(object, ns.aml.vocabularies.core.description, objectContext);
891
+ if (description && typeof description === 'string') {
892
+ result.description = description;
893
+ }
894
+ const raw = this._getValue(object, ns.aml.vocabularies.document.raw, objectContext);
895
+ if (raw && typeof raw === 'string') {
896
+ result.value = raw;
897
+ }
898
+ const location = this._getValue(object, ns.aml.vocabularies.document.location, objectContext);
899
+ if (location && typeof location === 'string') {
900
+ result.location = location;
901
+ }
902
+ // if (!mediaType.isNullOrEmpty) {
903
+ // result.mediaType = mediaType.value();
904
+ // }
905
+ const structuredValue = object[this._getAmfKey(ns.aml.vocabularies.document.structuredValue, objectContext)];
906
+ if (Array.isArray(structuredValue) && structuredValue.length) {
907
+ const [value] = structuredValue;
908
+ result.structuredValue = this.unknownDataNode(value, objectContext);
909
+ }
910
+ return result;
911
+ }
912
+ xmlSerializer(object, context) {
913
+ const objectContext = context || object['@context'];
914
+ const result = ({
915
+ id: object['@id'],
916
+ types: this.readTypes(object['@type'], objectContext),
917
+ customDomainProperties: this.customDomainProperties(object, objectContext),
918
+ sourceMaps: this.sourceMap(object, objectContext),
919
+ });
920
+ const xmlAttribute = this._getValue(object, ns.aml.vocabularies.shapes.xmlAttribute, objectContext);
921
+ if (typeof xmlAttribute === 'boolean') {
922
+ result.attribute = xmlAttribute;
923
+ }
924
+ const wrapped = this._getValue(object, ns.aml.vocabularies.shapes.xmlWrapped, objectContext);
925
+ if (typeof wrapped === 'boolean') {
926
+ result.wrapped = wrapped;
927
+ }
928
+ const name = this._getValue(object, ns.aml.vocabularies.shapes.xmlName, objectContext);
929
+ if (name && typeof name === 'string') {
930
+ result.name = name;
931
+ }
932
+ const xmlNs = this._getValue(object, ns.aml.vocabularies.shapes.xmlNamespace, objectContext);
933
+ if (xmlNs && typeof xmlNs === 'string') {
934
+ result.namespace = xmlNs;
935
+ }
936
+ const xmlPrefix = this._getValue(object, ns.aml.vocabularies.shapes.xmlPrefix, objectContext);
937
+ if (xmlPrefix && typeof xmlPrefix === 'string') {
938
+ result.prefix = xmlPrefix;
939
+ }
940
+ return result;
941
+ }
942
+ unknownDataNode(object, context) {
943
+ const types = this.readTypes(object['@type'], context);
944
+ if (types.includes(ns.aml.vocabularies.data.Scalar)) {
945
+ return this.scalarNode(object, context);
946
+ }
947
+ if (types.includes(ns.aml.vocabularies.data.Object)) {
948
+ return this.objectNode(object, context);
949
+ }
950
+ if (types.includes(ns.aml.vocabularies.data.Array)) {
951
+ return this.arrayNode(object, context);
952
+ }
953
+ return undefined;
954
+ }
955
+ dataNode(object, context) {
956
+ const result = {
957
+ id: object['@id'],
958
+ types: this.readTypes(object['@type'], context),
959
+ customDomainProperties: this.customDomainProperties(object, context),
960
+ };
961
+ const name = this._getValue(object, ns.aml.vocabularies.core.name, context);
962
+ if (name && typeof name === 'string') {
963
+ result.name = name;
964
+ }
965
+ return result;
966
+ }
967
+ scalarNode(object, context) {
968
+ const objectContext = context || object['@context'];
969
+ const result = (this.dataNode(object, context));
970
+ const value = this._getValue(object, ns.aml.vocabularies.data.value, objectContext);
971
+ if (value && typeof value === 'string') {
972
+ result.value = value;
973
+ }
974
+ const dataType = this._getLinkValue(object, ns.w3.shacl.datatype, objectContext);
975
+ if (dataType && typeof dataType === 'string') {
976
+ result.dataType = dataType;
977
+ }
978
+ return result;
979
+ }
980
+ objectNode(object, context) {
981
+ const objectContext = context || object['@context'];
982
+ const result = (this.dataNode(object, context));
983
+ result.properties = {};
984
+ const prefix = ns.aml.vocabularies.data.key;
985
+ const prefixCompact = `${this._getAmfKey(prefix, objectContext)}:`;
986
+ Object.keys(object).forEach((key) => {
987
+ if (key.startsWith(prefix) || key.startsWith(prefixCompact)) {
988
+ let value = object[key];
989
+ if (Array.isArray(value)) {
990
+ [value] = value;
991
+ }
992
+ const name = key.replace(prefix, '').replace(prefixCompact, '');
993
+ const nodeValue = this.unknownDataNode(value, context);
994
+ if (nodeValue) {
995
+ result.properties[name] = nodeValue;
996
+ }
997
+ }
998
+ });
999
+ return result;
1000
+ }
1001
+ arrayNode(object, context) {
1002
+ const objectContext = context || object['@context'];
1003
+ const result = (this.dataNode(object, objectContext));
1004
+ result.members = [];
1005
+ const members = (this._computePropertyArray(object, ns.w3.rdfSchema.member));
1006
+ if (Array.isArray(members) && members.length) {
1007
+ result.members = members.map((item) => this.unknownDataNode(item));
1008
+ }
1009
+ return result;
1010
+ }
1011
+ /**
1012
+ * Adds the custom domain properties to the currently processed property, a.k.a annotations.
1013
+ * @returns The list of custom domain properties.
1014
+ */
1015
+ customDomainProperties(object, context) {
1016
+ const result = [];
1017
+ const objectContext = context || object['@context'];
1018
+ const ids = this._getLinkValues(object, ns.aml.vocabularies.document.customDomainProperties, objectContext);
1019
+ if (Array.isArray(ids) && ids.length) {
1020
+ ids.forEach((id) => {
1021
+ const key = `amf://id${id}`;
1022
+ let value = (object[id] || object[key]);
1023
+ if (!value) {
1024
+ return;
1025
+ }
1026
+ if (Array.isArray(value)) {
1027
+ [value] = value;
1028
+ }
1029
+ const extension = this.unknownDataNode(value, objectContext);
1030
+ const name = this._getValue(value, ns.aml.vocabularies.core.extensionName, objectContext);
1031
+ if (!name || !extension) {
1032
+ return;
1033
+ }
1034
+ const cdp = ({
1035
+ id: key,
1036
+ name,
1037
+ extension,
1038
+ });
1039
+ result.push(cdp);
1040
+ });
1041
+ }
1042
+ return result;
1043
+ }
1044
+ endPoint(object, context) {
1045
+ const objectContext = context || object['@context'];
1046
+ const result = ({
1047
+ id: object['@id'],
1048
+ types: this.readTypes(object['@type'], objectContext),
1049
+ customDomainProperties: this.customDomainProperties(object, objectContext),
1050
+ sourceMaps: this.sourceMap(object),
1051
+ path: '',
1052
+ operations: [],
1053
+ parameters: [],
1054
+ payloads: [],
1055
+ servers: [],
1056
+ security: [],
1057
+ extends: [],
1058
+ });
1059
+ const path = this._getValue(object, ns.aml.vocabularies.apiContract.path, objectContext);
1060
+ if (path && typeof path === 'string') {
1061
+ result.path = path;
1062
+ }
1063
+ const name = this._getValue(object, ns.aml.vocabularies.core.name, objectContext);
1064
+ if (name && typeof name === 'string') {
1065
+ result.name = name;
1066
+ }
1067
+ const description = this._getValue(object, ns.aml.vocabularies.core.description, objectContext);
1068
+ if (description && typeof description === 'string') {
1069
+ result.description = description;
1070
+ }
1071
+ const summary = this._getValue(object, ns.aml.vocabularies.core.summary, objectContext);
1072
+ if (summary && typeof summary === 'string') {
1073
+ result.summary = summary;
1074
+ }
1075
+ const operations = this[getArrayItems](object, ns.aml.vocabularies.apiContract.supportedOperation, objectContext);
1076
+ if (Array.isArray(operations) && operations.length) {
1077
+ result.operations = operations.map(i => this.operation(i, objectContext));
1078
+ }
1079
+ const parameters = this[getArrayItems](object, ns.aml.vocabularies.apiContract.parameter, objectContext);
1080
+ if (Array.isArray(parameters) && parameters.length) {
1081
+ result.parameters = parameters.map(i => this.parameter(i, objectContext));
1082
+ }
1083
+ const payloads = this[getArrayItems](object, ns.aml.vocabularies.apiContract.payload, objectContext);
1084
+ if (Array.isArray(payloads) && payloads.length) {
1085
+ result.payloads = payloads.map(i => this.payload(/** @type Payload */ i, objectContext));
1086
+ }
1087
+ const servers = this[getArrayItems](object, ns.aml.vocabularies.apiContract.server, objectContext);
1088
+ if (Array.isArray(servers) && servers.length) {
1089
+ result.servers = servers.map(i => this.server(i, objectContext));
1090
+ }
1091
+ const security = this[getArrayItems](object, ns.aml.vocabularies.security.security, objectContext);
1092
+ if (Array.isArray(security) && security.length) {
1093
+ result.security = security.map(i => this.securityRequirement(i, objectContext));
1094
+ }
1095
+ const extensions = this[getArrayItems](object, ns.aml.vocabularies.document.extends, objectContext);
1096
+ if (Array.isArray(extensions) && extensions.length) {
1097
+ result.extends = [];
1098
+ extensions.forEach((ex) => {
1099
+ let extension = ex;
1100
+ if (Array.isArray(extension)) {
1101
+ [extension] = extension;
1102
+ }
1103
+ if (this._hasType(extension, ns.aml.vocabularies.apiContract.ParametrizedResourceType, objectContext)) {
1104
+ result.extends.push(this.parametrizedResourceType(extension, objectContext));
1105
+ }
1106
+ else if (this._hasType(extension, ns.aml.vocabularies.apiContract.ParametrizedTrait, objectContext)) {
1107
+ result.extends.push(this.parametrizedTrait(extension, objectContext));
1108
+ }
1109
+ });
1110
+ }
1111
+ return result;
1112
+ }
1113
+ operation(object, context) {
1114
+ const objectContext = context || object['@context'];
1115
+ const result = ({
1116
+ id: object['@id'],
1117
+ types: this.readTypes(object['@type'], objectContext),
1118
+ customDomainProperties: this.customDomainProperties(object, objectContext),
1119
+ sourceMaps: this.sourceMap(object),
1120
+ method: '',
1121
+ deprecated: false,
1122
+ callbacks: [],
1123
+ responses: [],
1124
+ servers: [],
1125
+ security: [],
1126
+ accepts: [],
1127
+ schemes: [],
1128
+ contentType: [],
1129
+ tags: [],
1130
+ extends: [],
1131
+ });
1132
+ const method = this._getValue(object, ns.aml.vocabularies.apiContract.method, objectContext);
1133
+ if (method && typeof method === 'string') {
1134
+ result.method = method;
1135
+ }
1136
+ const name = this._getValue(object, ns.aml.vocabularies.core.name, objectContext);
1137
+ if (name && typeof name === 'string') {
1138
+ result.name = name;
1139
+ }
1140
+ const description = this._getValue(object, ns.aml.vocabularies.core.description, objectContext);
1141
+ if (description && typeof description === 'string') {
1142
+ result.description = description;
1143
+ }
1144
+ const summary = this._getValue(object, ns.aml.vocabularies.apiContract.guiSummary, objectContext);
1145
+ if (summary && typeof summary === 'string') {
1146
+ result.summary = summary;
1147
+ }
1148
+ const deprecated = this._getValue(object, ns.aml.vocabularies.core.deprecated, objectContext);
1149
+ if (typeof deprecated === 'boolean') {
1150
+ result.deprecated = deprecated;
1151
+ }
1152
+ const operationId = this._getValue(object, ns.aml.vocabularies.apiContract.operationId, objectContext);
1153
+ if (operationId && typeof operationId === 'string') {
1154
+ result.operationId = operationId;
1155
+ }
1156
+ const accepts = (this._getValueArray(object, ns.aml.vocabularies.apiContract.accepts, objectContext));
1157
+ if (Array.isArray(accepts)) {
1158
+ result.accepts = accepts;
1159
+ }
1160
+ const schemes = (this._getValueArray(object, ns.aml.vocabularies.apiContract.scheme, objectContext));
1161
+ if (Array.isArray(schemes)) {
1162
+ result.schemes = schemes;
1163
+ }
1164
+ const contentType = (this._getValueArray(object, ns.aml.vocabularies.apiContract.contentType, objectContext));
1165
+ if (Array.isArray(contentType)) {
1166
+ result.contentType = contentType;
1167
+ }
1168
+ let expects = object[this._getAmfKey(ns.aml.vocabularies.apiContract.expects, objectContext)];
1169
+ if (expects) {
1170
+ if (Array.isArray(expects)) {
1171
+ [expects] = expects;
1172
+ }
1173
+ result.request = this.request(expects, objectContext);
1174
+ }
1175
+ let documentation = object[this._getAmfKey(ns.aml.vocabularies.core.documentation, objectContext)];
1176
+ if (documentation) {
1177
+ if (Array.isArray(documentation)) {
1178
+ [documentation] = documentation;
1179
+ }
1180
+ result.documentation = this.documentation(documentation, objectContext);
1181
+ }
1182
+ const responses = object[this._getAmfKey(ns.aml.vocabularies.apiContract.returns, objectContext)];
1183
+ if (Array.isArray(responses)) {
1184
+ result.responses = responses.map(r => this.response(r, objectContext));
1185
+ }
1186
+ const callbacks = object[this._getAmfKey(ns.aml.vocabularies.apiContract.callback, objectContext)];
1187
+ if (Array.isArray(callbacks)) {
1188
+ result.callbacks = callbacks.map(c => this.callback(c, objectContext));
1189
+ }
1190
+ const servers = object[this._getAmfKey(ns.aml.vocabularies.apiContract.server, objectContext)];
1191
+ if (Array.isArray(servers)) {
1192
+ result.servers = servers.map(s => this.server(s));
1193
+ }
1194
+ const security = object[this._getAmfKey(ns.aml.vocabularies.security.security, objectContext)];
1195
+ if (Array.isArray(security)) {
1196
+ result.security = security.map(s => this.securityRequirement(s, objectContext));
1197
+ }
1198
+ const tags = object[this._getAmfKey(ns.aml.vocabularies.apiContract.tag, objectContext)];
1199
+ if (Array.isArray(tags) && tags.length) {
1200
+ result.tags = tags.map(s => this.tag(s, objectContext));
1201
+ }
1202
+ const traits = object[this._getAmfKey(ns.aml.vocabularies.document.extends, objectContext)];
1203
+ if (Array.isArray(traits) && traits.length) {
1204
+ result.extends = traits.map(t => this.parametrizedTrait(t, objectContext));
1205
+ }
1206
+ return result;
1207
+ }
1208
+ tag(object, context) {
1209
+ const objectContext = context || object['@context'];
1210
+ const result = ({
1211
+ id: object['@id'],
1212
+ types: this.readTypes(object['@type'], objectContext),
1213
+ customDomainProperties: this.customDomainProperties(object, objectContext),
1214
+ sourceMaps: this.sourceMap(object),
1215
+ name: '',
1216
+ });
1217
+ const name = this._getValue(object, ns.aml.vocabularies.core.name, objectContext);
1218
+ if (name && typeof name === 'string') {
1219
+ result.name = name;
1220
+ }
1221
+ return result;
1222
+ }
1223
+ callback(object, context) {
1224
+ const objectContext = context || object['@context'];
1225
+ const result = ({
1226
+ id: object['@id'],
1227
+ types: this.readTypes(object['@type'], objectContext),
1228
+ customDomainProperties: this.customDomainProperties(object, objectContext),
1229
+ sourceMaps: this.sourceMap(object),
1230
+ });
1231
+ const name = this._getValue(object, ns.aml.vocabularies.core.name, objectContext);
1232
+ if (name && typeof name === 'string') {
1233
+ result.name = name;
1234
+ }
1235
+ const expression = this._getValue(object, ns.aml.vocabularies.apiContract.expression, objectContext);
1236
+ if (expression && typeof expression === 'string') {
1237
+ result.expression = expression;
1238
+ }
1239
+ let endpoint = object[this._getAmfKey(ns.aml.vocabularies.apiContract.endpoint, objectContext)];
1240
+ if (endpoint) {
1241
+ if (Array.isArray(endpoint)) {
1242
+ [endpoint] = endpoint;
1243
+ }
1244
+ result.endpoint = this.endPoint(endpoint, objectContext);
1245
+ }
1246
+ return result;
1247
+ }
1248
+ request(object, context) {
1249
+ const objectContext = context || object['@context'];
1250
+ const result = ({
1251
+ id: object['@id'],
1252
+ types: this.readTypes(object['@type'], objectContext),
1253
+ customDomainProperties: this.customDomainProperties(object, objectContext),
1254
+ sourceMaps: this.sourceMap(object),
1255
+ required: false,
1256
+ headers: [],
1257
+ queryParameters: [],
1258
+ payloads: [],
1259
+ uriParameters: [],
1260
+ cookieParameters: [],
1261
+ });
1262
+ const description = this._getValue(object, ns.aml.vocabularies.core.description, objectContext);
1263
+ if (description && typeof description === 'string') {
1264
+ result.description = description;
1265
+ }
1266
+ const required = this._getValue(object, ns.aml.vocabularies.apiContract.required, objectContext);
1267
+ if (required && typeof required === 'boolean') {
1268
+ result.required = required;
1269
+ }
1270
+ let queryString = object[this._getAmfKey(ns.aml.vocabularies.apiContract.queryString, objectContext)];
1271
+ if (queryString) {
1272
+ if (Array.isArray(queryString)) {
1273
+ [queryString] = queryString;
1274
+ }
1275
+ result.queryString = this.unknownShape(queryString, undefined, objectContext);
1276
+ }
1277
+ const headers = this[getArrayItems](object, ns.aml.vocabularies.apiContract.header, objectContext);
1278
+ if (Array.isArray(headers) && headers.length) {
1279
+ result.headers = headers.map(p => this.parameter(p, objectContext));
1280
+ }
1281
+ const queryParameters = this[getArrayItems](object, ns.aml.vocabularies.apiContract.parameter, objectContext);
1282
+ if (Array.isArray(queryParameters) && queryParameters.length) {
1283
+ result.queryParameters = queryParameters.map(p => this.parameter(p, objectContext));
1284
+ }
1285
+ const uriParameters = this[getArrayItems](object, ns.aml.vocabularies.apiContract.uriParameter, objectContext);
1286
+ if (Array.isArray(uriParameters) && uriParameters.length) {
1287
+ result.uriParameters = uriParameters.map(p => this.parameter(p, objectContext));
1288
+ }
1289
+ const cookieParameters = this[getArrayItems](object, ns.aml.vocabularies.apiContract.cookieParameter, objectContext);
1290
+ if (Array.isArray(cookieParameters) && cookieParameters.length) {
1291
+ result.cookieParameters = cookieParameters.map(p => this.parameter(p, objectContext));
1292
+ }
1293
+ const payloads = this[getArrayItems](object, ns.aml.vocabularies.apiContract.payload, objectContext);
1294
+ if (Array.isArray(payloads) && payloads.length) {
1295
+ result.payloads = payloads.map(p => this.payload(p, objectContext));
1296
+ }
1297
+ return result;
1298
+ }
1299
+ response(object, context) {
1300
+ const objectContext = context || object['@context'];
1301
+ const result = ({
1302
+ id: object['@id'],
1303
+ types: this.readTypes(object['@type'], objectContext),
1304
+ customDomainProperties: this.customDomainProperties(object, objectContext),
1305
+ sourceMaps: this.sourceMap(object, objectContext),
1306
+ headers: [],
1307
+ payloads: [],
1308
+ examples: [],
1309
+ links: [],
1310
+ });
1311
+ const name = this._getValue(object, ns.aml.vocabularies.core.name, objectContext);
1312
+ if (name && typeof name === 'string') {
1313
+ result.name = name;
1314
+ }
1315
+ const description = this._getValue(object, ns.aml.vocabularies.core.description, objectContext);
1316
+ if (description && typeof description === 'string') {
1317
+ result.description = description;
1318
+ }
1319
+ const statusCode = this._getValue(object, ns.aml.vocabularies.apiContract.statusCode, objectContext);
1320
+ if (statusCode && typeof statusCode === 'string') {
1321
+ result.statusCode = statusCode;
1322
+ }
1323
+ const headers = this[getArrayItems](object, ns.aml.vocabularies.apiContract.header, objectContext);
1324
+ if (Array.isArray(headers) && headers.length) {
1325
+ result.headers = headers.map(p => this.parameter(p, objectContext));
1326
+ }
1327
+ const payloads = this[getArrayItems](object, ns.aml.vocabularies.apiContract.payload, objectContext);
1328
+ if (Array.isArray(payloads) && payloads.length) {
1329
+ result.payloads = payloads.map(p => this.payload(p, objectContext));
1330
+ }
1331
+ const examples = object[this._getAmfKey(ns.aml.vocabularies.apiContract.examples, objectContext)];
1332
+ if (Array.isArray(examples) && examples.length) {
1333
+ result.examples = examples.map(e => this.example(e, objectContext));
1334
+ }
1335
+ const links = object[this._getAmfKey(ns.aml.vocabularies.apiContract.link, objectContext)];
1336
+ if (Array.isArray(links) && links.length) {
1337
+ result.links = links.map(p => this.templatedLink(p, objectContext));
1338
+ }
1339
+ return result;
1340
+ }
1341
+ payload(object, context) {
1342
+ const objectContext = context || object['@context'];
1343
+ const result = ({
1344
+ id: object['@id'],
1345
+ types: this.readTypes(object['@type'], objectContext),
1346
+ customDomainProperties: this.customDomainProperties(object, objectContext),
1347
+ sourceMaps: this.sourceMap(object, objectContext),
1348
+ examples: [],
1349
+ // encoding: [],
1350
+ });
1351
+ const name = this._getValue(object, ns.aml.vocabularies.core.name, objectContext);
1352
+ if (name && typeof name === 'string') {
1353
+ result.name = name;
1354
+ }
1355
+ const mediaType = this._getValue(object, ns.aml.vocabularies.core.mediaType, objectContext);
1356
+ if (mediaType && typeof mediaType === 'string') {
1357
+ result.mediaType = mediaType;
1358
+ }
1359
+ let schema = object[this._getAmfKey(ns.aml.vocabularies.shapes.schema, objectContext)];
1360
+ if (schema) {
1361
+ if (Array.isArray(schema)) {
1362
+ [schema] = schema;
1363
+ }
1364
+ result.schema = this.unknownShape(schema, {
1365
+ trackedId: result.id,
1366
+ }, objectContext);
1367
+ }
1368
+ const examples = object[this._getAmfKey(ns.aml.vocabularies.apiContract.examples, objectContext)];
1369
+ if (Array.isArray(examples) && examples.length) {
1370
+ result.examples = examples.map(e => this.example(e, objectContext));
1371
+ }
1372
+ // if (Array.isArray(encoding) && encoding.length) {
1373
+ // result.encoding = encoding.map((p) => p.id);
1374
+ // }
1375
+ return result;
1376
+ }
1377
+ templatedLink(object, context) {
1378
+ const objectContext = context || object['@context'];
1379
+ const result = ({
1380
+ id: object['@id'],
1381
+ types: this.readTypes(object['@type'], objectContext),
1382
+ customDomainProperties: this.customDomainProperties(object, objectContext),
1383
+ sourceMaps: this.sourceMap(object, objectContext),
1384
+ mapping: [],
1385
+ });
1386
+ const name = this._getValue(object, ns.aml.vocabularies.core.name, objectContext);
1387
+ if (name && typeof name === 'string') {
1388
+ result.name = name;
1389
+ }
1390
+ const description = this._getValue(object, ns.aml.vocabularies.core.description, objectContext);
1391
+ if (description && typeof description === 'string') {
1392
+ result.description = description;
1393
+ }
1394
+ const operationId = this._getValue(object, ns.aml.vocabularies.apiContract.operationId, objectContext);
1395
+ if (operationId && typeof operationId === 'string') {
1396
+ result.operationId = operationId;
1397
+ }
1398
+ let server = object[this._getAmfKey(ns.aml.vocabularies.apiContract.server, objectContext)];
1399
+ if (server) {
1400
+ if (Array.isArray(server)) {
1401
+ [server] = server;
1402
+ }
1403
+ result.server = this.server(server, objectContext);
1404
+ }
1405
+ let mapping = (object[this._getAmfKey(ns.aml.vocabularies.apiContract.mapping, objectContext)]);
1406
+ if (mapping) {
1407
+ if (mapping && !Array.isArray(mapping)) {
1408
+ mapping = [mapping];
1409
+ }
1410
+ if (mapping) {
1411
+ result.mapping = mapping.map(item => this.iriTemplateMapping(item, objectContext));
1412
+ }
1413
+ }
1414
+ // if (!template.isNullOrEmpty) {
1415
+ // result.template = template.value();
1416
+ // }
1417
+ // if (!requestBody.isNullOrEmpty) {
1418
+ // result.requestBody = requestBody.value();
1419
+ // }
1420
+ return result;
1421
+ }
1422
+ iriTemplateMapping(object, context) {
1423
+ const objectContext = context || object['@context'];
1424
+ const result = ({
1425
+ id: object['@id'],
1426
+ types: this.readTypes(object['@type'], objectContext),
1427
+ customDomainProperties: this.customDomainProperties(object, objectContext),
1428
+ sourceMaps: this.sourceMap(object, objectContext),
1429
+ });
1430
+ const templateVariable = this._getValue(object, ns.aml.vocabularies.apiContract.templateVariable, objectContext);
1431
+ if (templateVariable && typeof templateVariable === 'string') {
1432
+ result.templateVariable = templateVariable;
1433
+ }
1434
+ const linkExpression = this._getValue(object, ns.aml.vocabularies.apiContract.linkExpression, objectContext);
1435
+ if (linkExpression && typeof linkExpression === 'string') {
1436
+ result.linkExpression = linkExpression;
1437
+ }
1438
+ return result;
1439
+ }
1440
+ parametrizedSecurityScheme(object, context) {
1441
+ const objectContext = context || object['@context'];
1442
+ const result = ({
1443
+ id: object['@id'],
1444
+ types: this.readTypes(object['@type'], objectContext),
1445
+ customDomainProperties: this.customDomainProperties(object, objectContext),
1446
+ sourceMaps: this.sourceMap(object, objectContext),
1447
+ });
1448
+ const name = this._getValue(object, ns.aml.vocabularies.core.name, objectContext);
1449
+ if (name && typeof name === 'string') {
1450
+ result.name = name;
1451
+ }
1452
+ let scheme = object[this._getAmfKey(ns.aml.vocabularies.security.scheme, objectContext)];
1453
+ if (scheme) {
1454
+ if (Array.isArray(scheme)) {
1455
+ [scheme] = scheme;
1456
+ }
1457
+ result.scheme = this.securityScheme(scheme, objectContext);
1458
+ }
1459
+ let settings = object[this._getAmfKey(ns.aml.vocabularies.security.settings, objectContext)];
1460
+ if (settings) {
1461
+ if (Array.isArray(settings)) {
1462
+ [settings] = settings;
1463
+ }
1464
+ result.settings = this.securitySettings(settings, objectContext);
1465
+ }
1466
+ return result;
1467
+ }
1468
+ securitySchemeListItem(object, context) {
1469
+ const objectContext = context || object['@context'];
1470
+ const result = ({
1471
+ id: object['@id'],
1472
+ types: this.readTypes(object['@type'], objectContext),
1473
+ type: '',
1474
+ });
1475
+ const type = this._getValue(object, ns.aml.vocabularies.security.type, objectContext);
1476
+ if (type && typeof type === 'string') {
1477
+ result.type = type;
1478
+ }
1479
+ const name = this._getValue(object, ns.aml.vocabularies.core.name, objectContext);
1480
+ if (name && typeof name === 'string') {
1481
+ result.name = name;
1482
+ }
1483
+ const displayName = this._getValue(object, ns.aml.vocabularies.core.displayName, objectContext);
1484
+ if (displayName && typeof displayName === 'string') {
1485
+ result.displayName = displayName;
1486
+ }
1487
+ return result;
1488
+ }
1489
+ securityScheme(object, context) {
1490
+ const objectContext = context || object['@context'];
1491
+ const result = ({
1492
+ id: object['@id'],
1493
+ types: this.readTypes(object['@type'], objectContext),
1494
+ customDomainProperties: this.customDomainProperties(object, objectContext),
1495
+ sourceMaps: this.sourceMap(object, objectContext),
1496
+ headers: [],
1497
+ queryParameters: [],
1498
+ responses: [],
1499
+ });
1500
+ const name = this._getValue(object, ns.aml.vocabularies.core.name, objectContext);
1501
+ if (name && typeof name === 'string') {
1502
+ result.name = name;
1503
+ }
1504
+ const displayName = this._getValue(object, ns.aml.vocabularies.core.displayName, objectContext);
1505
+ if (displayName && typeof displayName === 'string') {
1506
+ result.displayName = displayName;
1507
+ }
1508
+ const description = this._getValue(object, ns.aml.vocabularies.core.description, objectContext);
1509
+ if (description && typeof description === 'string') {
1510
+ result.description = description;
1511
+ }
1512
+ const type = this._getValue(object, ns.aml.vocabularies.security.type, objectContext);
1513
+ if (type && typeof type === 'string') {
1514
+ result.type = type;
1515
+ }
1516
+ let settings = object[this._getAmfKey(ns.aml.vocabularies.security.settings, objectContext)];
1517
+ if (settings) {
1518
+ if (Array.isArray(settings)) {
1519
+ [settings] = settings;
1520
+ }
1521
+ result.settings = this.securitySettings(settings, objectContext);
1522
+ }
1523
+ let queryString = object[this._getAmfKey(ns.aml.vocabularies.apiContract.queryString, objectContext)];
1524
+ if (queryString) {
1525
+ if (Array.isArray(queryString)) {
1526
+ [queryString] = queryString;
1527
+ }
1528
+ result.queryString = this.unknownShape(queryString, undefined, objectContext);
1529
+ }
1530
+ const headers = this[getArrayItems](object, ns.aml.vocabularies.apiContract.header, objectContext);
1531
+ if (Array.isArray(headers) && headers.length) {
1532
+ result.headers = headers.map(p => this.parameter(p, objectContext));
1533
+ }
1534
+ const queryParameters = this[getArrayItems](object, ns.aml.vocabularies.apiContract.parameter, objectContext);
1535
+ if (Array.isArray(queryParameters) && queryParameters.length) {
1536
+ result.queryParameters = queryParameters.map(p => this.parameter(p, objectContext));
1537
+ }
1538
+ const responses = this[getArrayItems](object, ns.aml.vocabularies.apiContract.response, objectContext);
1539
+ if (Array.isArray(responses) && responses.length) {
1540
+ result.responses = responses.map(p => this.response(p, objectContext));
1541
+ }
1542
+ return result;
1543
+ }
1544
+ securityRequirement(object, context) {
1545
+ const objectContext = context || object['@context'];
1546
+ const result = ({
1547
+ id: object['@id'],
1548
+ types: this.readTypes(object['@type'], objectContext),
1549
+ customDomainProperties: this.customDomainProperties(object, objectContext),
1550
+ sourceMaps: this.sourceMap(object, objectContext),
1551
+ schemes: [],
1552
+ });
1553
+ const name = this._getValue(object, ns.aml.vocabularies.core.name, objectContext);
1554
+ if (name && typeof name === 'string') {
1555
+ result.name = name;
1556
+ }
1557
+ const schemes = (object[this._getAmfKey(ns.aml.vocabularies.security.schemes, objectContext)]);
1558
+ if (Array.isArray(schemes) && schemes.length) {
1559
+ result.schemes = schemes.map(p => this.parametrizedSecurityScheme(p, objectContext));
1560
+ }
1561
+ return result;
1562
+ }
1563
+ securitySettings(object, context) {
1564
+ const objectContext = context || object['@context'];
1565
+ const types = this.readTypes(object['@type'], objectContext);
1566
+ if (types.includes(ns.aml.vocabularies.security.OAuth1Settings)) {
1567
+ return this.oAuth1Settings(object, objectContext);
1568
+ }
1569
+ if (types.includes(ns.aml.vocabularies.security.OAuth2Settings)) {
1570
+ return this.oAuth2Settings(object, objectContext);
1571
+ }
1572
+ if (types.includes(ns.aml.vocabularies.security.ApiKeySettings)) {
1573
+ return this.apiKeySettings(object, objectContext);
1574
+ }
1575
+ if (types.includes(ns.aml.vocabularies.security.HttpSettings)) {
1576
+ return this.httpSettings(object, objectContext);
1577
+ }
1578
+ if (types.includes(ns.aml.vocabularies.security.OpenIdConnectSettings)) {
1579
+ return this.openIdConnectSettings(object, objectContext);
1580
+ }
1581
+ return this.settings(object, objectContext);
1582
+ }
1583
+ /**
1584
+ * @param {Settings} object
1585
+ * @param context
1586
+ * @returns {ApiSecuritySettings}
1587
+ */
1588
+ settings(object, context) {
1589
+ const objectContext = context || object['@context'];
1590
+ const result = ({
1591
+ id: object['@id'],
1592
+ types: this.readTypes(object['@type'], objectContext),
1593
+ customDomainProperties: this.customDomainProperties(object, objectContext),
1594
+ sourceMaps: this.sourceMap(object, objectContext),
1595
+ });
1596
+ // if (additionalProperties && additionalProperties.id) {
1597
+ // result.additionalProperties = this.unknownDataNode(additionalProperties);
1598
+ // }
1599
+ return result;
1600
+ }
1601
+ oAuth1Settings(object, context) {
1602
+ const objectContext = context || object['@context'];
1603
+ const result = (this.settings(object, objectContext));
1604
+ const authorizationUri = this._getValue(object, ns.aml.vocabularies.security.authorizationUri, objectContext);
1605
+ if (authorizationUri && typeof authorizationUri === 'string') {
1606
+ result.authorizationUri = authorizationUri;
1607
+ }
1608
+ const requestTokenUri = this._getValue(object, ns.aml.vocabularies.security.requestTokenUri, objectContext);
1609
+ if (requestTokenUri && typeof requestTokenUri === 'string') {
1610
+ result.requestTokenUri = requestTokenUri;
1611
+ }
1612
+ const tokenCredentialsUri = this._getValue(object, ns.aml.vocabularies.security.tokenCredentialsUri, objectContext);
1613
+ if (tokenCredentialsUri && typeof tokenCredentialsUri === 'string') {
1614
+ result.tokenCredentialsUri = tokenCredentialsUri;
1615
+ }
1616
+ const signatures = (this._getValueArray(object, ns.aml.vocabularies.security.signature, objectContext));
1617
+ if (Array.isArray(signatures) && signatures.length) {
1618
+ result.signatures = signatures;
1619
+ }
1620
+ else {
1621
+ result.signatures = [];
1622
+ }
1623
+ return result;
1624
+ }
1625
+ oAuth2Settings(object, context) {
1626
+ const objectContext = context || object['@context'];
1627
+ const result = this.settings(object, objectContext);
1628
+ const grants = (this._getValueArray(object, ns.aml.vocabularies.security.authorizationGrant, objectContext));
1629
+ if (Array.isArray(grants) && grants.length) {
1630
+ result.authorizationGrants = grants;
1631
+ }
1632
+ else {
1633
+ result.authorizationGrants = [];
1634
+ }
1635
+ const flows = (object[this._getAmfKey(ns.aml.vocabularies.security.flows, objectContext)]);
1636
+ if (Array.isArray(flows) && flows.length) {
1637
+ result.flows = flows.map((p) => this.oAuth2Flow(p, objectContext));
1638
+ }
1639
+ else {
1640
+ result.flows = [];
1641
+ }
1642
+ return result;
1643
+ }
1644
+ oAuth2Flow(object, context) {
1645
+ const objectContext = context || object['@context'];
1646
+ const result = ({
1647
+ id: object['@id'],
1648
+ types: this.readTypes(object['@type'], objectContext),
1649
+ customDomainProperties: this.customDomainProperties(object, objectContext),
1650
+ scopes: [],
1651
+ sourceMaps: this.sourceMap(object, objectContext),
1652
+ });
1653
+ const authorizationUri = this._getValue(object, ns.aml.vocabularies.security.authorizationUri, objectContext);
1654
+ if (authorizationUri && typeof authorizationUri === 'string') {
1655
+ result.authorizationUri = authorizationUri;
1656
+ }
1657
+ const accessTokenUri = this._getValue(object, ns.aml.vocabularies.security.accessTokenUri, objectContext);
1658
+ if (accessTokenUri && typeof accessTokenUri === 'string') {
1659
+ result.accessTokenUri = accessTokenUri;
1660
+ }
1661
+ const flow = this._getValue(object, ns.aml.vocabularies.security.flow, objectContext);
1662
+ if (flow && typeof flow === 'string') {
1663
+ result.flow = flow;
1664
+ }
1665
+ const refreshUri = this._getValue(object, ns.aml.vocabularies.security.refreshUri, objectContext);
1666
+ if (refreshUri && typeof refreshUri === 'string') {
1667
+ result.refreshUri = refreshUri;
1668
+ }
1669
+ const scopes = object[this._getAmfKey(ns.aml.vocabularies.security.scope, objectContext)];
1670
+ if (Array.isArray(scopes) && scopes.length) {
1671
+ result.scopes = scopes.map((p) => this.scope(p, objectContext));
1672
+ }
1673
+ return result;
1674
+ }
1675
+ scope(object, context) {
1676
+ const objectContext = context || object['@context'];
1677
+ const result = ({
1678
+ id: object['@id'],
1679
+ types: this.readTypes(object['@type'], objectContext),
1680
+ customDomainProperties: this.customDomainProperties(object, objectContext),
1681
+ sourceMaps: this.sourceMap(object, objectContext),
1682
+ });
1683
+ const name = this._getValue(object, ns.aml.vocabularies.core.name, objectContext);
1684
+ if (name && typeof name === 'string') {
1685
+ result.name = name;
1686
+ }
1687
+ const description = this._getValue(object, ns.aml.vocabularies.core.description, objectContext);
1688
+ if (description && typeof description === 'string') {
1689
+ result.description = description;
1690
+ }
1691
+ return result;
1692
+ }
1693
+ apiKeySettings(object, context) {
1694
+ const objectContext = context || object['@context'];
1695
+ const result = (this.settings(object, objectContext));
1696
+ const name = this._getValue(object, ns.aml.vocabularies.core.name, objectContext);
1697
+ if (name && typeof name === 'string') {
1698
+ result.name = name;
1699
+ }
1700
+ const inParam = this._getValue(object, ns.aml.vocabularies.security.in, objectContext);
1701
+ if (inParam && typeof inParam === 'string') {
1702
+ result.in = inParam;
1703
+ }
1704
+ return result;
1705
+ }
1706
+ httpSettings(object, context) {
1707
+ const objectContext = context || object['@context'];
1708
+ const result = (this.settings(object, objectContext));
1709
+ const scheme = this._getValue(object, ns.aml.vocabularies.security.scheme, objectContext);
1710
+ if (scheme && typeof scheme === 'string') {
1711
+ result.scheme = scheme;
1712
+ }
1713
+ const bearerFormat = this._getValue(object, ns.aml.vocabularies.security.bearerFormat, objectContext);
1714
+ if (bearerFormat && typeof bearerFormat === 'string') {
1715
+ result.bearerFormat = bearerFormat;
1716
+ }
1717
+ return result;
1718
+ }
1719
+ openIdConnectSettings(object, context) {
1720
+ const objectContext = context || object['@context'];
1721
+ const result = (this.settings(object, objectContext));
1722
+ const url = this._getValue(object, ns.aml.vocabularies.security.openIdConnectUrl, objectContext);
1723
+ if (url && typeof url === 'string') {
1724
+ result.url = url;
1725
+ }
1726
+ return result;
1727
+ }
1728
+ /**
1729
+ * Serializes source maps, when available.
1730
+ */
1731
+ sourceMap(object, context) {
1732
+ const objectContext = context || object['@context'];
1733
+ let sm = object[this._getAmfKey(ns.aml.vocabularies.docSourceMaps.sources, objectContext)];
1734
+ if (!sm) {
1735
+ return undefined;
1736
+ }
1737
+ if (Array.isArray(sm)) {
1738
+ [sm] = sm;
1739
+ }
1740
+ const result = ({
1741
+ id: sm['@id'],
1742
+ types: this.readTypes(sm['@type']),
1743
+ });
1744
+ const synthesizedField = sm[this._getAmfKey(ns.aml.vocabularies.docSourceMaps.synthesizedField, objectContext)];
1745
+ if (Array.isArray(synthesizedField) && synthesizedField.length) {
1746
+ result.synthesizedField = synthesizedField.map(i => this.synthesizedField(i, objectContext));
1747
+ }
1748
+ const lexical = sm[this._getAmfKey(ns.aml.vocabularies.docSourceMaps.lexical, objectContext)];
1749
+ if (Array.isArray(lexical) && lexical.length) {
1750
+ result.lexical = lexical.map(i => this.synthesizedField(i, objectContext));
1751
+ }
1752
+ const trackedElement = sm[this._getAmfKey(ns.aml.vocabularies.docSourceMaps.trackedElement, objectContext)];
1753
+ if (Array.isArray(trackedElement) && trackedElement.length) {
1754
+ result.trackedElement = this.synthesizedField(trackedElement[0], objectContext);
1755
+ }
1756
+ const autoName = sm[this._getAmfKey(ns.aml.vocabularies.docSourceMaps.autoGeneratedName, objectContext)];
1757
+ if (Array.isArray(autoName) && autoName.length) {
1758
+ result.autoGeneratedName = autoName.map(i => this.synthesizedField(i, objectContext));
1759
+ }
1760
+ const jsonSchema = sm[this._getAmfKey(ns.aml.vocabularies.docSourceMaps.parsedJsonSchema, objectContext)];
1761
+ if (Array.isArray(jsonSchema) && jsonSchema.length) {
1762
+ result.parsedJsonSchema = this.synthesizedField(jsonSchema[0], objectContext);
1763
+ }
1764
+ const declaredElement = sm[this._getAmfKey(ns.aml.vocabularies.docSourceMaps.declaredElement, objectContext)];
1765
+ if (Array.isArray(declaredElement) && declaredElement.length) {
1766
+ result.declaredElement = this.synthesizedField(declaredElement[0], objectContext);
1767
+ }
1768
+ return result;
1769
+ }
1770
+ synthesizedField(object, context) {
1771
+ // compact model
1772
+ if (typeof object === 'string') {
1773
+ return {
1774
+ id: 'synthesizedField/generated',
1775
+ value: object,
1776
+ };
1777
+ }
1778
+ const result = {
1779
+ id: object['@id'],
1780
+ value: '',
1781
+ };
1782
+ const element = this._getValue(object, ns.aml.vocabularies.docSourceMaps.element, context);
1783
+ if (typeof element === 'string') {
1784
+ result.element = element;
1785
+ }
1786
+ const value = this._getValue(object, ns.aml.vocabularies.docSourceMaps.value, context);
1787
+ if (typeof value === 'string') {
1788
+ result.value = value;
1789
+ }
1790
+ return result;
1791
+ }
1792
+ parametrizedDeclaration(object, context) {
1793
+ const objectContext = context || object['@context'];
1794
+ const result = ({
1795
+ id: object['@id'],
1796
+ types: this.readTypes(object['@type'], objectContext),
1797
+ variables: [],
1798
+ customDomainProperties: this.customDomainProperties(object, objectContext),
1799
+ sourceMaps: this.sourceMap(object, objectContext),
1800
+ });
1801
+ const name = this._getValue(object, ns.aml.vocabularies.core.name, objectContext);
1802
+ if (name && typeof name === 'string') {
1803
+ result.name = name;
1804
+ }
1805
+ const variables = object[this._getAmfKey(ns.aml.vocabularies.document.variable, objectContext)];
1806
+ if (Array.isArray(variables)) {
1807
+ variables.forEach((item) => {
1808
+ result.variables.push(this.variableValue(item, objectContext));
1809
+ });
1810
+ }
1811
+ const targets = object[this._getAmfKey(ns.aml.vocabularies.document.target, objectContext)];
1812
+ if (Array.isArray(targets) && targets.length) {
1813
+ const [target] = targets;
1814
+ result.target = this.abstractDeclaration(target, objectContext);
1815
+ }
1816
+ return result;
1817
+ }
1818
+ parametrizedTrait(object, context) {
1819
+ const objectContext = context || object['@context'];
1820
+ const result = (this.parametrizedDeclaration(object, objectContext));
1821
+ return result;
1822
+ }
1823
+ parametrizedResourceType(object, context) {
1824
+ const objectContext = context || object['@context'];
1825
+ const result = (this.parametrizedDeclaration(object, objectContext));
1826
+ return result;
1827
+ }
1828
+ variableValue(object, context) {
1829
+ const objectContext = context || object['@context'];
1830
+ const name = this._getValue(object, ns.aml.vocabularies.core.name, objectContext);
1831
+ const result = ({
1832
+ id: object['@id'],
1833
+ types: this.readTypes(object['@type'], objectContext),
1834
+ customDomainProperties: this.customDomainProperties(object, objectContext),
1835
+ sourceMaps: this.sourceMap(object, objectContext),
1836
+ name,
1837
+ });
1838
+ const values = object[this._getAmfKey(ns.aml.vocabularies.document.value, objectContext)];
1839
+ if (Array.isArray(values)) {
1840
+ const [item] = values;
1841
+ result.value = this.unknownDataNode(item, objectContext);
1842
+ }
1843
+ return result;
1844
+ }
1845
+ abstractDeclaration(object, context) {
1846
+ const objectContext = context || object['@context'];
1847
+ const name = this._getValue(object, ns.aml.vocabularies.core.name, objectContext);
1848
+ const result = ({
1849
+ id: object['@id'],
1850
+ types: this.readTypes(object['@type'], objectContext),
1851
+ customDomainProperties: this.customDomainProperties(object, objectContext),
1852
+ sourceMaps: this.sourceMap(object, objectContext),
1853
+ name,
1854
+ variables: [],
1855
+ });
1856
+ const variables = (this._getValueArray(object, ns.aml.vocabularies.document.variable, objectContext));
1857
+ if (Array.isArray(variables)) {
1858
+ result.variables = variables;
1859
+ }
1860
+ const description = this._getValue(object, ns.aml.vocabularies.core.description, objectContext);
1861
+ if (description && typeof description === 'string') {
1862
+ result.description = description;
1863
+ }
1864
+ const dataNode = object[this._getAmfKey(ns.aml.vocabularies.document.dataNode, objectContext)];
1865
+ if (Array.isArray(dataNode)) {
1866
+ const [item] = dataNode;
1867
+ result.dataNode = this.unknownDataNode(item, objectContext);
1868
+ }
1869
+ return result;
1870
+ }
1871
+ /**
1872
+ * @param object The EndPoint to serialize as a list item.
1873
+ * @returns Serialized EndPoint as a list item.
1874
+ */
1875
+ endPointWithOperationsListItem(object, context) {
1876
+ const path = this._getValue(object, ns.aml.vocabularies.apiContract.path, context);
1877
+ const result = ({
1878
+ id: object['@id'],
1879
+ path,
1880
+ operations: [],
1881
+ });
1882
+ const operations = this[getArrayItems](object, ns.aml.vocabularies.apiContract.supportedOperation, context);
1883
+ if (Array.isArray(operations) && operations.length) {
1884
+ result.operations = operations.map(i => this.operationListItem(i, context));
1885
+ }
1886
+ const name = this._getValue(object, ns.aml.vocabularies.core.name, context);
1887
+ if (name && typeof name === 'string') {
1888
+ result.name = name;
1889
+ }
1890
+ return result;
1891
+ }
1892
+ /**
1893
+ * @param object The Operation to serialize as a list item.
1894
+ * @param context A context to use. If not set, it looks for the context of the passed model
1895
+ * @returns Serialized Operation as a list item.
1896
+ */
1897
+ operationListItem(object, context) {
1898
+ const result = ({
1899
+ id: object['@id'],
1900
+ method: '',
1901
+ });
1902
+ const method = this._getValue(object, ns.aml.vocabularies.apiContract.method, context);
1903
+ if (method && typeof method === 'string') {
1904
+ result.method = method;
1905
+ }
1906
+ const name = this._getValue(object, ns.aml.vocabularies.core.name, context);
1907
+ if (name && typeof name === 'string') {
1908
+ result.name = name;
1909
+ }
1910
+ return result;
1911
+ }
1912
+ }
1913
+ //# sourceMappingURL=AmfSerializer.js.map