@api-client/core 0.11.0 → 0.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/src/amf/AmfMixin.d.ts +2 -15
- package/build/src/amf/AmfMixin.d.ts.map +1 -1
- package/build/src/amf/AmfMixin.js +7 -28
- package/build/src/amf/AmfMixin.js.map +1 -1
- package/build/src/modeling/DataAssociation.d.ts +7 -0
- package/build/src/modeling/DataAssociation.d.ts.map +1 -1
- package/build/src/modeling/DataAssociation.js +12 -0
- package/build/src/modeling/DataAssociation.js.map +1 -1
- package/build/src/modeling/DataEntity.d.ts +64 -9
- package/build/src/modeling/DataEntity.d.ts.map +1 -1
- package/build/src/modeling/DataEntity.js +128 -16
- package/build/src/modeling/DataEntity.js.map +1 -1
- package/build/src/modeling/DataFormat.d.ts +8 -0
- package/build/src/modeling/DataFormat.d.ts.map +1 -1
- package/build/src/modeling/DataFormat.js +1 -0
- package/build/src/modeling/DataFormat.js.map +1 -1
- package/build/src/modeling/DataNamespace.d.ts +6 -0
- package/build/src/modeling/DataNamespace.d.ts.map +1 -1
- package/build/src/modeling/DataNamespace.js +9 -0
- package/build/src/modeling/DataNamespace.js.map +1 -1
- package/data/models/example-generator-api.json +6 -6
- package/package.json +17 -3
- package/src/amf/AmfMixin.ts +10 -31
- package/src/modeling/DataAssociation.ts +13 -0
- package/src/modeling/DataEntity.ts +152 -16
- package/src/modeling/DataFormat.ts +10 -0
- package/src/modeling/DataNamespace.ts +13 -0
- package/tests/unit/amf/AmfLoader.ts +20 -31
- package/tests/unit/modeling/data_entity.spec.ts +481 -0
- package/tsconfig.browser.json +2 -1
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
// @ts-expect-error Used in testing
|
|
3
|
-
import { AmfModelExpander } from 'amf-json-ld-lib'
|
|
4
1
|
import { readFile } from 'fs/promises'
|
|
5
2
|
import { AmfMixin } from '../../../src/amf/AmfMixin.js'
|
|
6
3
|
import { AmfSerializer } from '../../../src/amf/AmfSerializer.js'
|
|
@@ -56,23 +53,15 @@ export class AmfLoader extends AmfMixin(Object) {
|
|
|
56
53
|
if (opts.noExpand) {
|
|
57
54
|
return result
|
|
58
55
|
}
|
|
59
|
-
let amf = this.
|
|
56
|
+
let amf = this._expand(result)
|
|
60
57
|
if (Array.isArray(amf)) {
|
|
61
58
|
;[amf] = amf
|
|
62
59
|
}
|
|
63
60
|
return amf
|
|
64
61
|
}
|
|
65
62
|
|
|
66
|
-
getExpandedModel(model: any): IAmfDocument {
|
|
67
|
-
let amf = model
|
|
68
|
-
if (!AmfModelExpander.isInExpandedForm(amf)) {
|
|
69
|
-
amf = this._expand(amf)
|
|
70
|
-
}
|
|
71
|
-
return amf
|
|
72
|
-
}
|
|
73
|
-
|
|
74
63
|
lookupEndpoint(model: IAmfDocument, path: string): IAmfEndPoint {
|
|
75
|
-
const amf = this.
|
|
64
|
+
const amf = this._expand(model)
|
|
76
65
|
this.amf = amf
|
|
77
66
|
const webApi = this._computeApi(amf)
|
|
78
67
|
if (!webApi) {
|
|
@@ -92,7 +81,7 @@ export class AmfLoader extends AmfMixin(Object) {
|
|
|
92
81
|
}
|
|
93
82
|
|
|
94
83
|
getEndpoint(model: IAmfDocument, path: string): IApiEndPoint {
|
|
95
|
-
const amf = this.
|
|
84
|
+
const amf = this._expand(model)
|
|
96
85
|
const op = this.lookupEndpoint(amf, path)
|
|
97
86
|
if (!op) {
|
|
98
87
|
throw new Error(`Unknown endpoint for path ${path}`)
|
|
@@ -102,7 +91,7 @@ export class AmfLoader extends AmfMixin(Object) {
|
|
|
102
91
|
}
|
|
103
92
|
|
|
104
93
|
lookupOperation(model: IAmfDocument, endpoint: string, operation: string): IAmfOperation {
|
|
105
|
-
const amf = this.
|
|
94
|
+
const amf = this._expand(model)
|
|
106
95
|
const endPoint = this.lookupEndpoint(amf, endpoint)
|
|
107
96
|
const opKey = this._getAmfKey(ns.aml.vocabularies.apiContract.supportedOperation)
|
|
108
97
|
// @ts-expect-error Used in testing
|
|
@@ -117,7 +106,7 @@ export class AmfLoader extends AmfMixin(Object) {
|
|
|
117
106
|
}
|
|
118
107
|
|
|
119
108
|
getOperation(model: IAmfDocument, endpoint: string, operation: string): IApiOperation {
|
|
120
|
-
const amf = this.
|
|
109
|
+
const amf = this._expand(model)
|
|
121
110
|
const op = this.lookupOperation(amf, endpoint, operation)
|
|
122
111
|
if (!op) {
|
|
123
112
|
throw new Error(`Unknown operation for path ${endpoint} and method ${operation}`)
|
|
@@ -168,7 +157,7 @@ export class AmfLoader extends AmfMixin(Object) {
|
|
|
168
157
|
}
|
|
169
158
|
|
|
170
159
|
getPayloads(model: IAmfDocument, endpoint: string, operation: string): IApiPayload[] {
|
|
171
|
-
const amf = this.
|
|
160
|
+
const amf = this._expand(model)
|
|
172
161
|
|
|
173
162
|
const payloads = this.lookupPayloads(amf, endpoint, operation)
|
|
174
163
|
if (!payloads) {
|
|
@@ -179,7 +168,7 @@ export class AmfLoader extends AmfMixin(Object) {
|
|
|
179
168
|
}
|
|
180
169
|
|
|
181
170
|
lookupSecurity(model: IAmfDocument, name: string): IAmfSecurityScheme | undefined {
|
|
182
|
-
const amf = this.
|
|
171
|
+
const amf = this._expand(model)
|
|
183
172
|
|
|
184
173
|
this.amf = amf
|
|
185
174
|
const declares = this._computeDeclares(amf) || []
|
|
@@ -214,7 +203,7 @@ export class AmfLoader extends AmfMixin(Object) {
|
|
|
214
203
|
}
|
|
215
204
|
|
|
216
205
|
getSecurity(model: IAmfDocument, name: string): IApiSecurityScheme {
|
|
217
|
-
const amf = this.
|
|
206
|
+
const amf = this._expand(model)
|
|
218
207
|
const security = this.lookupSecurity(amf, name)
|
|
219
208
|
if (!security) {
|
|
220
209
|
throw new Error(`No security named ${name}`)
|
|
@@ -224,7 +213,7 @@ export class AmfLoader extends AmfMixin(Object) {
|
|
|
224
213
|
}
|
|
225
214
|
|
|
226
215
|
lookupShape(model: IAmfDocument, name: string): IAmfShape | undefined {
|
|
227
|
-
const amf = this.
|
|
216
|
+
const amf = this._expand(model)
|
|
228
217
|
this.amf = amf
|
|
229
218
|
const declares = this._computeDeclares(amf) || []
|
|
230
219
|
let shape = declares.find((item) => {
|
|
@@ -252,7 +241,7 @@ export class AmfLoader extends AmfMixin(Object) {
|
|
|
252
241
|
}
|
|
253
242
|
|
|
254
243
|
getShape(model: IAmfDocument, name: string): IShapeUnion {
|
|
255
|
-
const amf = this.
|
|
244
|
+
const amf = this._expand(model)
|
|
256
245
|
const shape = this.lookupShape(amf, name)
|
|
257
246
|
if (!shape) {
|
|
258
247
|
throw new Error(`No API shape named ${name}`)
|
|
@@ -262,7 +251,7 @@ export class AmfLoader extends AmfMixin(Object) {
|
|
|
262
251
|
}
|
|
263
252
|
|
|
264
253
|
lookupDocumentation(model: IAmfDocument, name: string): IAmfCreativeWork | undefined {
|
|
265
|
-
const amf = this.
|
|
254
|
+
const amf = this._expand(model)
|
|
266
255
|
this.amf = amf
|
|
267
256
|
const webApi = this._computeApi(amf)
|
|
268
257
|
if (!webApi) {
|
|
@@ -280,7 +269,7 @@ export class AmfLoader extends AmfMixin(Object) {
|
|
|
280
269
|
}
|
|
281
270
|
|
|
282
271
|
getDocumentation(model: IAmfDocument, name: string): IApiDocumentation {
|
|
283
|
-
const amf = this.
|
|
272
|
+
const amf = this._expand(model)
|
|
284
273
|
const shape = this.lookupDocumentation(amf, name)
|
|
285
274
|
if (!shape) {
|
|
286
275
|
throw new Error(`No documentation named ${name}`)
|
|
@@ -290,7 +279,7 @@ export class AmfLoader extends AmfMixin(Object) {
|
|
|
290
279
|
}
|
|
291
280
|
|
|
292
281
|
lookupEncodes(model: IAmfDocument): IAmfWebApi {
|
|
293
|
-
const amf = this.
|
|
282
|
+
const amf = this._expand(model)
|
|
294
283
|
this.amf = amf
|
|
295
284
|
const key = this._getAmfKey(ns.aml.vocabularies.document.encodes) as string
|
|
296
285
|
// @ts-expect-error Used in testing
|
|
@@ -308,7 +297,7 @@ export class AmfLoader extends AmfMixin(Object) {
|
|
|
308
297
|
}
|
|
309
298
|
|
|
310
299
|
getResponses(model: IAmfDocument, endpoint: string, operation: string): IApiResponse[] {
|
|
311
|
-
const amf = this.
|
|
300
|
+
const amf = this._expand(model)
|
|
312
301
|
const responses = this.lookupResponses(amf, endpoint, operation)
|
|
313
302
|
const serializer = new AmfSerializer(amf)
|
|
314
303
|
return responses.map((i) => serializer.response(i))
|
|
@@ -335,7 +324,7 @@ export class AmfLoader extends AmfMixin(Object) {
|
|
|
335
324
|
* @param code The response's status code
|
|
336
325
|
*/
|
|
337
326
|
getResponse(model: IAmfDocument, endpoint: string, operation: string, code: string): IApiResponse {
|
|
338
|
-
const amf = this.
|
|
327
|
+
const amf = this._expand(model)
|
|
339
328
|
const response = this.lookupResponse(amf, endpoint, operation, code)
|
|
340
329
|
const serializer = new AmfSerializer(amf)
|
|
341
330
|
return serializer.response(response)
|
|
@@ -355,7 +344,7 @@ export class AmfLoader extends AmfMixin(Object) {
|
|
|
355
344
|
}
|
|
356
345
|
|
|
357
346
|
getRequest(model: IAmfDocument, endpoint: string, operation: string): IApiRequest {
|
|
358
|
-
const amf = this.
|
|
347
|
+
const amf = this._expand(model)
|
|
359
348
|
const request = this.lookupRequest(amf, endpoint, operation)
|
|
360
349
|
if (!request) {
|
|
361
350
|
throw new Error(`No request found in operation ${operation} and path ${endpoint}`)
|
|
@@ -383,14 +372,14 @@ export class AmfLoader extends AmfMixin(Object) {
|
|
|
383
372
|
* @param code The response's status code
|
|
384
373
|
*/
|
|
385
374
|
getResponsePayloads(model: IAmfDocument, path: string, operation: string, code: string): IApiPayload[] {
|
|
386
|
-
const amf = this.
|
|
375
|
+
const amf = this._expand(model)
|
|
387
376
|
const payloads = this.lookupResponsePayloads(amf, path, operation, code)
|
|
388
377
|
const serializer = new AmfSerializer(amf)
|
|
389
378
|
return payloads.map((p) => serializer.payload(p))
|
|
390
379
|
}
|
|
391
380
|
|
|
392
381
|
lookupServers(model: IAmfDocument): IAmfServer[] | undefined {
|
|
393
|
-
const amf = this.
|
|
382
|
+
const amf = this._expand(model)
|
|
394
383
|
this.amf = amf
|
|
395
384
|
const webApi = this._computeApi(amf)
|
|
396
385
|
if (!webApi) {
|
|
@@ -406,7 +395,7 @@ export class AmfLoader extends AmfMixin(Object) {
|
|
|
406
395
|
}
|
|
407
396
|
|
|
408
397
|
getServers(model: IAmfDocument): IApiServer[] | undefined {
|
|
409
|
-
const amf = this.
|
|
398
|
+
const amf = this._expand(model)
|
|
410
399
|
const servers = this.lookupServers(amf)
|
|
411
400
|
if (servers) {
|
|
412
401
|
const serializer = new AmfSerializer(amf)
|
|
@@ -494,7 +483,7 @@ export class AmfLoader extends AmfMixin(Object) {
|
|
|
494
483
|
* @param param The param name
|
|
495
484
|
*/
|
|
496
485
|
getParameter(model: IAmfDocument, endpoint: string, operation: string, param: string): IApiParameter {
|
|
497
|
-
const amf = this.
|
|
486
|
+
const amf = this._expand(model)
|
|
498
487
|
const expects = this.lookupExpects(amf, endpoint, operation)
|
|
499
488
|
if (!expects) {
|
|
500
489
|
throw new Error(`The operation ${operation} of endpoint ${endpoint} has no request.`)
|