@api-client/core 0.6.13 → 0.6.16

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