@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.
@@ -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.getExpandedModel(result)
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.getExpandedModel(model)
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.getExpandedModel(model)
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.getExpandedModel(model)
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.getExpandedModel(model)
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.getExpandedModel(model)
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.getExpandedModel(model)
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.getExpandedModel(model)
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.getExpandedModel(model)
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.getExpandedModel(model)
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.getExpandedModel(model)
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.getExpandedModel(model)
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.getExpandedModel(model)
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.getExpandedModel(model)
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.getExpandedModel(model)
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.getExpandedModel(model)
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.getExpandedModel(model)
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.getExpandedModel(model)
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.getExpandedModel(model)
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.getExpandedModel(model)
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.`)