@api-client/core 0.19.10 → 0.19.11

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 (429) hide show
  1. package/LICENSE.md +9 -63
  2. package/bin/test.ts +1 -12
  3. package/build/src/browser.d.ts +0 -15
  4. package/build/src/browser.d.ts.map +1 -1
  5. package/build/src/browser.js +0 -17
  6. package/build/src/browser.js.map +1 -1
  7. package/build/src/events/EventTypes.d.ts +0 -6
  8. package/build/src/events/EventTypes.d.ts.map +1 -1
  9. package/build/src/events/EventTypes.js +0 -2
  10. package/build/src/events/EventTypes.js.map +1 -1
  11. package/build/src/events/Events.d.ts +0 -2
  12. package/build/src/events/Events.d.ts.map +1 -1
  13. package/build/src/events/Events.js +0 -2
  14. package/build/src/events/Events.js.map +1 -1
  15. package/build/src/index.d.ts +0 -15
  16. package/build/src/index.d.ts.map +1 -1
  17. package/build/src/index.js +0 -17
  18. package/build/src/index.js.map +1 -1
  19. package/build/src/modeling/Bindings.d.ts +3 -3
  20. package/build/src/modeling/Bindings.d.ts.map +1 -1
  21. package/build/src/modeling/Bindings.js.map +1 -1
  22. package/build/src/modeling/DomainAssociation.d.ts +5 -5
  23. package/build/src/modeling/DomainAssociation.d.ts.map +1 -1
  24. package/build/src/modeling/DomainAssociation.js.map +1 -1
  25. package/build/src/modeling/DomainEntity.d.ts +2 -3
  26. package/build/src/modeling/DomainEntity.d.ts.map +1 -1
  27. package/build/src/modeling/DomainEntity.js +1 -1
  28. package/build/src/modeling/DomainEntity.js.map +1 -1
  29. package/build/src/modeling/DomainProperty.d.ts +2 -3
  30. package/build/src/modeling/DomainProperty.d.ts.map +1 -1
  31. package/build/src/modeling/DomainProperty.js +1 -1
  32. package/build/src/modeling/DomainProperty.js.map +1 -1
  33. package/build/src/modeling/ai/types.d.ts +2 -2
  34. package/build/src/modeling/ai/types.d.ts.map +1 -1
  35. package/build/src/modeling/ai/types.js.map +1 -1
  36. package/build/src/{amf → modeling/amf}/DataValueGenerator.d.ts +1 -1
  37. package/build/src/modeling/amf/DataValueGenerator.d.ts.map +1 -0
  38. package/build/src/{amf → modeling/amf}/DataValueGenerator.js +2 -3
  39. package/build/src/modeling/amf/DataValueGenerator.js.map +1 -0
  40. package/build/src/modeling/amf/ShapeGenerator.d.ts +20 -20
  41. package/build/src/modeling/amf/ShapeGenerator.d.ts.map +1 -1
  42. package/build/src/modeling/amf/ShapeGenerator.js +16 -18
  43. package/build/src/modeling/amf/ShapeGenerator.js.map +1 -1
  44. package/build/src/modeling/amf/core_types.d.ts +9 -0
  45. package/build/src/modeling/amf/core_types.d.ts.map +1 -0
  46. package/build/src/modeling/amf/core_types.js +45 -0
  47. package/build/src/modeling/amf/core_types.js.map +1 -0
  48. package/build/src/models/http-flows/LegacyTranslator.js +1 -1
  49. package/build/src/models/http-flows/LegacyTranslator.js.map +1 -1
  50. package/build/src/runtime/http-runner/HttpFlows.js +1 -1
  51. package/build/src/runtime/http-runner/HttpFlows.js.map +1 -1
  52. package/build/tsconfig.tsbuildinfo +1 -1
  53. package/eslint.config.js +0 -1
  54. package/package.json +11 -14
  55. package/src/events/EventTypes.ts +0 -2
  56. package/src/events/Events.ts +0 -2
  57. package/src/modeling/Bindings.ts +3 -3
  58. package/src/modeling/DomainAssociation.ts +5 -5
  59. package/src/modeling/DomainEntity.ts +3 -4
  60. package/src/modeling/DomainProperty.ts +3 -4
  61. package/src/modeling/ai/types.ts +2 -2
  62. package/src/{amf → modeling/amf}/DataValueGenerator.ts +3 -4
  63. package/src/modeling/amf/ShapeGenerator.ts +45 -61
  64. package/src/modeling/amf/core_types.ts +47 -0
  65. package/src/models/http-flows/LegacyTranslator.ts +1 -1
  66. package/src/runtime/http-runner/HttpFlows.ts +1 -1
  67. package/tests/unit/{amf → modeling/amf}/data_value_generator.spec.ts +2 -2
  68. package/tests/unit/modeling/amf/shape_generator.spec.ts +146 -167
  69. package/tests/unit/modeling/domain_asociation.spec.ts +13 -13
  70. package/tests/unit/runtime/runners/http_assertion_runner.spec.ts +1 -1
  71. package/tests/unit/runtime/runners/http_flow_runner.spec.ts +1 -1
  72. package/tests/unit/runtime/runners/project_runner.spec.ts +1 -1
  73. package/tests/unit/runtime/runners/request_runner.spec.ts +1 -1
  74. package/tests/unit/runtime/runners/serial_runner.spec.ts +1 -1
  75. package/build/src/amf/AmfMixin.d.ts +0 -396
  76. package/build/src/amf/AmfMixin.d.ts.map +0 -1
  77. package/build/src/amf/AmfMixin.js +0 -1138
  78. package/build/src/amf/AmfMixin.js.map +0 -1
  79. package/build/src/amf/AmfSerializer.d.ts +0 -137
  80. package/build/src/amf/AmfSerializer.d.ts.map +0 -1
  81. package/build/src/amf/AmfSerializer.js +0 -1947
  82. package/build/src/amf/AmfSerializer.js.map +0 -1
  83. package/build/src/amf/AmfTypes.d.ts +0 -25
  84. package/build/src/amf/AmfTypes.d.ts.map +0 -1
  85. package/build/src/amf/AmfTypes.js +0 -143
  86. package/build/src/amf/AmfTypes.js.map +0 -1
  87. package/build/src/amf/ApiExampleGenerator.d.ts +0 -40
  88. package/build/src/amf/ApiExampleGenerator.d.ts.map +0 -1
  89. package/build/src/amf/ApiExampleGenerator.js +0 -112
  90. package/build/src/amf/ApiExampleGenerator.js.map +0 -1
  91. package/build/src/amf/ApiMonacoSchemaGenerator.d.ts +0 -68
  92. package/build/src/amf/ApiMonacoSchemaGenerator.d.ts.map +0 -1
  93. package/build/src/amf/ApiMonacoSchemaGenerator.js +0 -248
  94. package/build/src/amf/ApiMonacoSchemaGenerator.js.map +0 -1
  95. package/build/src/amf/ApiSchemaGenerator.d.ts +0 -56
  96. package/build/src/amf/ApiSchemaGenerator.d.ts.map +0 -1
  97. package/build/src/amf/ApiSchemaGenerator.js +0 -94
  98. package/build/src/amf/ApiSchemaGenerator.js.map +0 -1
  99. package/build/src/amf/ApiSchemaValues.d.ts +0 -111
  100. package/build/src/amf/ApiSchemaValues.d.ts.map +0 -1
  101. package/build/src/amf/ApiSchemaValues.js +0 -463
  102. package/build/src/amf/ApiSchemaValues.js.map +0 -1
  103. package/build/src/amf/DataValueGenerator.d.ts.map +0 -1
  104. package/build/src/amf/DataValueGenerator.js.map +0 -1
  105. package/build/src/amf/Parsing.d.ts +0 -48
  106. package/build/src/amf/Parsing.d.ts.map +0 -1
  107. package/build/src/amf/Parsing.js +0 -2
  108. package/build/src/amf/Parsing.js.map +0 -1
  109. package/build/src/amf/Utils.d.ts +0 -37
  110. package/build/src/amf/Utils.d.ts.map +0 -1
  111. package/build/src/amf/Utils.js +0 -169
  112. package/build/src/amf/Utils.js.map +0 -1
  113. package/build/src/amf/data-node/DataNodeBase.d.ts +0 -34
  114. package/build/src/amf/data-node/DataNodeBase.d.ts.map +0 -1
  115. package/build/src/amf/data-node/DataNodeBase.js +0 -77
  116. package/build/src/amf/data-node/DataNodeBase.js.map +0 -1
  117. package/build/src/amf/data-node/JsonDataNodeGenerator.d.ts +0 -15
  118. package/build/src/amf/data-node/JsonDataNodeGenerator.d.ts.map +0 -1
  119. package/build/src/amf/data-node/JsonDataNodeGenerator.js +0 -23
  120. package/build/src/amf/data-node/JsonDataNodeGenerator.js.map +0 -1
  121. package/build/src/amf/data-node/UrlEncodedDataNodeGenerator.d.ts +0 -14
  122. package/build/src/amf/data-node/UrlEncodedDataNodeGenerator.d.ts.map +0 -1
  123. package/build/src/amf/data-node/UrlEncodedDataNodeGenerator.js +0 -48
  124. package/build/src/amf/data-node/UrlEncodedDataNodeGenerator.js.map +0 -1
  125. package/build/src/amf/data-node/XmlDataNodeGenerator.d.ts +0 -22
  126. package/build/src/amf/data-node/XmlDataNodeGenerator.d.ts.map +0 -1
  127. package/build/src/amf/data-node/XmlDataNodeGenerator.js +0 -34
  128. package/build/src/amf/data-node/XmlDataNodeGenerator.js.map +0 -1
  129. package/build/src/amf/definitions/Amf.d.ts +0 -363
  130. package/build/src/amf/definitions/Amf.d.ts.map +0 -1
  131. package/build/src/amf/definitions/Amf.js +0 -3
  132. package/build/src/amf/definitions/Amf.js.map +0 -1
  133. package/build/src/amf/definitions/Api.d.ts +0 -383
  134. package/build/src/amf/definitions/Api.d.ts.map +0 -1
  135. package/build/src/amf/definitions/Api.js +0 -2
  136. package/build/src/amf/definitions/Api.js.map +0 -1
  137. package/build/src/amf/definitions/Base.d.ts +0 -12
  138. package/build/src/amf/definitions/Base.d.ts.map +0 -1
  139. package/build/src/amf/definitions/Base.js +0 -2
  140. package/build/src/amf/definitions/Base.js.map +0 -1
  141. package/build/src/amf/definitions/Namespace.d.ts +0 -327
  142. package/build/src/amf/definitions/Namespace.d.ts.map +0 -1
  143. package/build/src/amf/definitions/Namespace.js +0 -346
  144. package/build/src/amf/definitions/Namespace.js.map +0 -1
  145. package/build/src/amf/definitions/Shapes.d.ts +0 -312
  146. package/build/src/amf/definitions/Shapes.d.ts.map +0 -1
  147. package/build/src/amf/definitions/Shapes.js +0 -87
  148. package/build/src/amf/definitions/Shapes.js.map +0 -1
  149. package/build/src/amf/models/AmfDataNode.d.ts +0 -67
  150. package/build/src/amf/models/AmfDataNode.d.ts.map +0 -1
  151. package/build/src/amf/models/AmfDataNode.js +0 -192
  152. package/build/src/amf/models/AmfDataNode.js.map +0 -1
  153. package/build/src/amf/shape/ShapeBase.d.ts +0 -74
  154. package/build/src/amf/shape/ShapeBase.d.ts.map +0 -1
  155. package/build/src/amf/shape/ShapeBase.js +0 -93
  156. package/build/src/amf/shape/ShapeBase.js.map +0 -1
  157. package/build/src/amf/shape/ShapeJsonSchemaGenerator.d.ts +0 -47
  158. package/build/src/amf/shape/ShapeJsonSchemaGenerator.d.ts.map +0 -1
  159. package/build/src/amf/shape/ShapeJsonSchemaGenerator.js +0 -420
  160. package/build/src/amf/shape/ShapeJsonSchemaGenerator.js.map +0 -1
  161. package/build/src/amf/shape/ShapeXmlSchemaGenerator.d.ts +0 -85
  162. package/build/src/amf/shape/ShapeXmlSchemaGenerator.d.ts.map +0 -1
  163. package/build/src/amf/shape/ShapeXmlSchemaGenerator.js +0 -852
  164. package/build/src/amf/shape/ShapeXmlSchemaGenerator.js.map +0 -1
  165. package/build/src/events/amf/AmfEventTypes.d.ts +0 -7
  166. package/build/src/events/amf/AmfEventTypes.d.ts.map +0 -1
  167. package/build/src/events/amf/AmfEventTypes.js +0 -7
  168. package/build/src/events/amf/AmfEventTypes.js.map +0 -1
  169. package/build/src/events/amf/AmfEvents.d.ts +0 -34
  170. package/build/src/events/amf/AmfEvents.d.ts.map +0 -1
  171. package/build/src/events/amf/AmfEvents.js +0 -63
  172. package/build/src/events/amf/AmfEvents.js.map +0 -1
  173. package/build/src/mocking/RandExp.d.ts +0 -55
  174. package/build/src/mocking/RandExp.d.ts.map +0 -1
  175. package/build/src/mocking/RandExp.js +0 -302
  176. package/build/src/mocking/RandExp.js.map +0 -1
  177. package/build/src/mocking/lib/ret.d.ts +0 -16
  178. package/build/src/mocking/lib/ret.d.ts.map +0 -1
  179. package/build/src/mocking/lib/ret.js +0 -284
  180. package/build/src/mocking/lib/ret.js.map +0 -1
  181. package/data/apis/APIC-187/APIC-187.raml +0 -21
  182. package/data/apis/APIC-187/dataType.raml +0 -132
  183. package/data/apis/APIC-187/example.raml +0 -84
  184. package/data/apis/APIC-188/APIC-188.raml +0 -21
  185. package/data/apis/APIC-188/dataType.raml +0 -132
  186. package/data/apis/APIC-188/example.raml +0 -84
  187. package/data/apis/APIC-233/APIC-233.raml +0 -15
  188. package/data/apis/APIC-391/APIC-391.raml +0 -44
  189. package/data/apis/APIC-391/examples/post-body-request-example.raml +0 -7
  190. package/data/apis/APIC-483/APIC-483.raml +0 -16
  191. package/data/apis/APIC-483/example/list-of-bank-succ.json +0 -32
  192. package/data/apis/APIC-483/schema/response-retrieve-list-bank.json +0 -68
  193. package/data/apis/APIC-487/APIC-487.raml +0 -36
  194. package/data/apis/APIC-655/APIC-655.raml +0 -44
  195. package/data/apis/APIC-655/delivery.json +0 -12
  196. package/data/apis/APIC-689/APIC-689.raml +0 -20
  197. package/data/apis/APIC-690/APIC-690.raml +0 -17
  198. package/data/apis/APIC-690/datatypes/Address.raml +0 -10
  199. package/data/apis/APIC-690/datatypes/Customer.raml +0 -17
  200. package/data/apis/APIC-690/examples/CustomerExample2.raml +0 -17
  201. package/data/apis/APIC-690/examples/CustomersExample.raml +0 -34
  202. package/data/apis/SE-10469/Purchase-Order-oagis-id-dd32f9c6c01048a19e15c423c9c741ae.json +0 -1383
  203. package/data/apis/SE-10469/SE-10469.raml +0 -11
  204. package/data/apis/SE-13092/Examples/PersonExample.raml +0 -7
  205. package/data/apis/SE-13092/SE-13092.raml +0 -37
  206. package/data/apis/SE-13092/datatypes/Address.raml +0 -5
  207. package/data/apis/SE-13092/datatypes/InlineType.raml +0 -5
  208. package/data/apis/SE-13092/datatypes/Person.raml +0 -15
  209. package/data/apis/SE-22063/SE-22063.raml +0 -14
  210. package/data/apis/SE-22063/stock.raml +0 -41
  211. package/data/apis/amf-helper-api/amf-helper-api.raml +0 -1024
  212. package/data/apis/amf-helper-api/examples/comment-example.json +0 -42
  213. package/data/apis/amf-helper-api/examples/commentCreateRequest-example.json +0 -7
  214. package/data/apis/amf-helper-api/examples/commentList-example.json +0 -48
  215. package/data/apis/amf-helper-api/examples/person.json +0 -14
  216. package/data/apis/amf-helper-api/examples/person.raml +0 -13
  217. package/data/apis/amf-helper-api/examples/person.xml +0 -14
  218. package/data/apis/amf-helper-api/libraries/comment-lib.raml +0 -143
  219. package/data/apis/amf-helper-api/library.raml +0 -7
  220. package/data/apis/amf-helper-api/schemas/person.json +0 -104
  221. package/data/apis/amf-helper-api/schemas/person.xsd +0 -26
  222. package/data/apis/amf-helper-api/traits/file.raml +0 -33
  223. package/data/apis/amf-helper-api/traits/pagination.raml +0 -80
  224. package/data/apis/amf-helper-api/traits/results.raml +0 -19
  225. package/data/apis/amf-helper-api/traits/visibility.raml +0 -14
  226. package/data/apis/amf-helper-api/types/app-person.raml +0 -101
  227. package/data/apis/amf-helper-api/types/dimensions.raml +0 -24
  228. package/data/apis/amf-helper-api/types/external-type.raml +0 -7
  229. package/data/apis/amf-helper-api/types/image.raml +0 -23
  230. package/data/apis/amf-helper-api/types/product.raml +0 -52
  231. package/data/apis/amf-helper-api/types/resource.raml +0 -11
  232. package/data/apis/amf-helper-api/types/standard-request.raml +0 -50
  233. package/data/apis/amf-helper-api/types/user.raml +0 -37
  234. package/data/apis/arc-demo-api/arc-demo-api.raml +0 -468
  235. package/data/apis/arc-demo-api/examples/e400.xml +0 -4
  236. package/data/apis/arc-demo-api/examples/e401.xml +0 -4
  237. package/data/apis/arc-demo-api/examples/e404.xml +0 -4
  238. package/data/apis/arc-demo-api/examples/image.xml +0 -5
  239. package/data/apis/arc-demo-api/examples/messages-example.json +0 -22
  240. package/data/apis/arc-demo-api/examples/messages-sent-example.json +0 -15
  241. package/data/apis/arc-demo-api/examples/person.json +0 -14
  242. package/data/apis/arc-demo-api/examples/person.url.encoded +0 -1
  243. package/data/apis/arc-demo-api/examples/person.xml +0 -14
  244. package/data/apis/arc-demo-api/examples/product.xml +0 -9
  245. package/data/apis/arc-demo-api/library.raml +0 -36
  246. package/data/apis/arc-demo-api/resourceTypes/app-person.raml +0 -49
  247. package/data/apis/arc-demo-api/resourceTypes/example-types.raml +0 -45
  248. package/data/apis/arc-demo-api/resourceTypes/image.raml +0 -23
  249. package/data/apis/arc-demo-api/resourceTypes/message-sent-type.raml +0 -23
  250. package/data/apis/arc-demo-api/resourceTypes/message-type.raml +0 -33
  251. package/data/apis/arc-demo-api/resourceTypes/product.raml +0 -52
  252. package/data/apis/arc-demo-api/resourceTypes/resource.raml +0 -11
  253. package/data/apis/arc-demo-api/schemas/error-response.xsd +0 -11
  254. package/data/apis/arc-demo-api/schemas/image.xsd +0 -11
  255. package/data/apis/arc-demo-api/schemas/person.json +0 -104
  256. package/data/apis/arc-demo-api/schemas/person.xsd +0 -26
  257. package/data/apis/arc-demo-api/schemas/product.xsd +0 -17
  258. package/data/apis/arc-demo-api/securitySchemes/basic.raml +0 -5
  259. package/data/apis/arc-demo-api/securitySchemes/oauth_2_0.raml +0 -29
  260. package/data/apis/arc-demo-api/securitySchemes/x-custom.raml +0 -26
  261. package/data/apis/arc-demo-api/traits/adminable.raml +0 -23
  262. package/data/apis/arc-demo-api/traits/pagination.raml +0 -83
  263. package/data/apis/arc-demo-api/traits/rate-limited.raml +0 -9
  264. package/data/apis/async-api/async-api.yaml +0 -96
  265. package/data/apis/example-generator-api/contact-email-example.raml +0 -6
  266. package/data/apis/example-generator-api/contact-example.raml +0 -5
  267. package/data/apis/example-generator-api/contact-fax-example.raml +0 -5
  268. package/data/apis/example-generator-api/contact-website-example.raml +0 -2
  269. package/data/apis/example-generator-api/example-1.raml +0 -6
  270. package/data/apis/example-generator-api/example-2.raml +0 -9
  271. package/data/apis/example-generator-api/example-3.raml +0 -4
  272. package/data/apis/example-generator-api/example-4.raml +0 -2
  273. package/data/apis/example-generator-api/example-5.raml +0 -4
  274. package/data/apis/example-generator-api/example-6.raml +0 -2
  275. package/data/apis/example-generator-api/example-7.raml +0 -5
  276. package/data/apis/example-generator-api/example-generator-api.raml +0 -423
  277. package/data/apis/example-generator-api/example.json +0 -14
  278. package/data/apis/example-generator-api/example.xml +0 -15
  279. package/data/apis/example-generator-api/example.xsd +0 -26
  280. package/data/apis/example-generator-api/examples/employee.raml +0 -7
  281. package/data/apis/example-generator-api/examples/employees.raml +0 -7
  282. package/data/apis/example-generator-api/linked-named-example.raml +0 -21
  283. package/data/apis/example-generator-api/named-example-with-link.raml +0 -5
  284. package/data/apis/example-generator-api/named-example.raml +0 -9
  285. package/data/apis/example-generator-api/user-json-example.raml +0 -17
  286. package/data/apis/example-generator-api/user-raml-example.raml +0 -37
  287. package/data/apis/example-generator-api/user.json +0 -8
  288. package/data/apis/example-generator-api/user.raml +0 -18
  289. package/data/apis/example-generator-api/users-json-example.raml +0 -17
  290. package/data/apis/example-generator-api/users-raml-example.raml +0 -32
  291. package/data/apis/example-generator-api/users.json +0 -8
  292. package/data/apis/expanded-api/expanded-api.raml +0 -8
  293. package/data/apis/flattened-api/flattened-api.raml +0 -8
  294. package/data/apis/multiple-servers/multiple-servers.yaml +0 -112
  295. package/data/apis/oas-3-api/oas-3-api.yaml +0 -356
  296. package/data/apis/oas-date/oas-date.yaml +0 -28
  297. package/data/apis/oas-types/oas-types.yaml +0 -159
  298. package/data/apis/oas-unions/oas-unions.yaml +0 -75
  299. package/data/apis/petstore/petstore.yaml +0 -954
  300. package/data/apis/raml-date/raml-date.raml +0 -28
  301. package/data/apis/recursive/recursive.raml +0 -14
  302. package/data/apis/schema-api/examples/person.json +0 -14
  303. package/data/apis/schema-api/examples/person.raml +0 -14
  304. package/data/apis/schema-api/examples/person.url.encoded +0 -1
  305. package/data/apis/schema-api/examples/person.xml +0 -14
  306. package/data/apis/schema-api/library/demo-types.raml +0 -43
  307. package/data/apis/schema-api/schema-api.raml +0 -656
  308. package/data/apis/schema-api/schemas/person.json +0 -104
  309. package/data/apis/schema-api/schemas/person.xsd +0 -26
  310. package/data/apis/schema-api/types/DemoPerson.raml +0 -67
  311. package/data/apis/secured-api/oauth-2-custom-settings.raml +0 -143
  312. package/data/apis/secured-api/oauth2-header-delivery.raml +0 -13
  313. package/data/apis/secured-api/oauth2-no-delivery.raml +0 -8
  314. package/data/apis/secured-api/oauth2-no-grants.raml +0 -12
  315. package/data/apis/secured-api/oauth2-pkce.raml +0 -13
  316. package/data/apis/secured-api/oauth2-query-delivery.raml +0 -13
  317. package/data/apis/secured-api/oauth_1_0.raml +0 -8
  318. package/data/apis/secured-api/oauth_1_0_no-settings.raml +0 -3
  319. package/data/apis/secured-api/oauth_1_0_no-signature.raml +0 -7
  320. package/data/apis/secured-api/oauth_1_0_signature.raml +0 -8
  321. package/data/apis/secured-api/passthrough-querystring.raml +0 -16
  322. package/data/apis/secured-api/passthrough.raml +0 -24
  323. package/data/apis/secured-api/secured-api.raml +0 -231
  324. package/data/apis/secured-api/x-custom.raml +0 -33
  325. package/data/apis/secured-api/x-other.raml +0 -29
  326. package/data/apis/secured-api/x-query-string.raml +0 -16
  327. package/data/apis/tracked-examples/datatypes/employee.raml +0 -5
  328. package/data/apis/tracked-examples/examples/employee.raml +0 -4
  329. package/data/apis/tracked-examples/examples/employees.raml +0 -8
  330. package/data/apis/tracked-examples/tracked-to-linked.raml +0 -28
  331. package/data/model.js +0 -129
  332. package/data/models/APIC-187.json +0 -11416
  333. package/data/models/APIC-188.json +0 -11416
  334. package/data/models/APIC-233.json +0 -539
  335. package/data/models/APIC-391.json +0 -1903
  336. package/data/models/APIC-483.json +0 -3110
  337. package/data/models/APIC-487.json +0 -1225
  338. package/data/models/APIC-655.json +0 -3145
  339. package/data/models/APIC-689.json +0 -797
  340. package/data/models/APIC-690.json +0 -5992
  341. package/data/models/SE-10469.json +0 -22898
  342. package/data/models/SE-13092.json +0 -2769
  343. package/data/models/SE-22063.json +0 -2314
  344. package/data/models/amf-helper-api.json +0 -84457
  345. package/data/models/arc-demo-api.json +0 -52041
  346. package/data/models/async-api.json +0 -3227
  347. package/data/models/example-generator-api.json +0 -45209
  348. package/data/models/expanded-api.json +0 -251
  349. package/data/models/flattened-api.json +0 -251
  350. package/data/models/multiple-servers.json +0 -2769
  351. package/data/models/oas-3-api.json +0 -10590
  352. package/data/models/oas-date.json +0 -637
  353. package/data/models/oas-types.json +0 -5352
  354. package/data/models/oas-unions.json +0 -1935
  355. package/data/models/petstore.json +0 -27712
  356. package/data/models/raml-date.json +0 -1114
  357. package/data/models/recursive.json +0 -610
  358. package/data/models/schema-api.json +0 -35527
  359. package/data/models/secured-api.json +0 -21071
  360. package/data/models/tracked-to-linked.json +0 -1914
  361. package/src/amf/AmfMixin.ts +0 -1726
  362. package/src/amf/AmfSerializer.ts +0 -2358
  363. package/src/amf/AmfTypes.ts +0 -147
  364. package/src/amf/ApiExampleGenerator.ts +0 -122
  365. package/src/amf/ApiMonacoSchemaGenerator.ts +0 -332
  366. package/src/amf/ApiSchemaGenerator.ts +0 -115
  367. package/src/amf/ApiSchemaValues.ts +0 -509
  368. package/src/amf/Parsing.ts +0 -50
  369. package/src/amf/Utils.ts +0 -172
  370. package/src/amf/data-node/DataNodeBase.ts +0 -83
  371. package/src/amf/data-node/JsonDataNodeGenerator.ts +0 -24
  372. package/src/amf/data-node/README.md +0 -3
  373. package/src/amf/data-node/UrlEncodedDataNodeGenerator.ts +0 -49
  374. package/src/amf/data-node/XmlDataNodeGenerator.ts +0 -46
  375. package/src/amf/definitions/Amf.ts +0 -440
  376. package/src/amf/definitions/Api.ts +0 -445
  377. package/src/amf/definitions/Base.ts +0 -13
  378. package/src/amf/definitions/Namespace.ts +0 -357
  379. package/src/amf/definitions/Shapes.ts +0 -438
  380. package/src/amf/models/AmfDataNode.ts +0 -210
  381. package/src/amf/shape/README.md +0 -4
  382. package/src/amf/shape/ShapeBase.ts +0 -174
  383. package/src/amf/shape/ShapeJsonSchemaGenerator.ts +0 -457
  384. package/src/amf/shape/ShapeXmlSchemaGenerator.ts +0 -933
  385. package/src/events/amf/AmfEventTypes.ts +0 -6
  386. package/src/events/amf/AmfEvents.ts +0 -78
  387. package/src/mocking/RandExp.ts +0 -335
  388. package/src/mocking/lib/ret.ts +0 -279
  389. package/tests/unit/amf/APIC-187.spec.ts +0 -41
  390. package/tests/unit/amf/APIC-188.spec.ts +0 -30
  391. package/tests/unit/amf/APIC-233.spec.ts +0 -32
  392. package/tests/unit/amf/APIC-391.spec.ts +0 -39
  393. package/tests/unit/amf/APIC-487.spec.ts +0 -44
  394. package/tests/unit/amf/APIC-655.spec.ts +0 -41
  395. package/tests/unit/amf/APIC-689.spec.ts +0 -28
  396. package/tests/unit/amf/APIC-690.spec.ts +0 -93
  397. package/tests/unit/amf/AmfLoader.ts +0 -538
  398. package/tests/unit/amf/AmfMixin.spec.ts +0 -1707
  399. package/tests/unit/amf/ApiExampleGenerator.spec.ts +0 -250
  400. package/tests/unit/amf/ApiMonacoSchemaGenerator.spec.ts +0 -183
  401. package/tests/unit/amf/ApiSchemaValues.spec.ts +0 -602
  402. package/tests/unit/amf/Namepsace.spec.ts +0 -494
  403. package/tests/unit/amf/SE-10469.spec.ts +0 -35
  404. package/tests/unit/amf/SE-13092.spec.ts +0 -64
  405. package/tests/unit/amf/SE-22063.spec.ts +0 -45
  406. package/tests/unit/amf/raml-examples.spec.ts +0 -43
  407. package/tests/unit/amf/schema_gen_array.spec.ts +0 -199
  408. package/tests/unit/amf/schema_gen_oas.spec.ts +0 -140
  409. package/tests/unit/amf/schema_gen_object.spec.ts +0 -279
  410. package/tests/unit/amf/schema_gen_scalar.spec.ts +0 -143
  411. package/tests/unit/amf/schema_gen_union.spec.ts +0 -401
  412. package/tests/unit/amf/schema_gen_unknown.spec.ts +0 -42
  413. package/tests/unit/amf/schema_gen_xml.spec.ts +0 -726
  414. package/tests/unit/amf/serializer/APIC-483.spec.ts +0 -36
  415. package/tests/unit/amf/serializer/Anotations.spec.ts +0 -50
  416. package/tests/unit/amf/serializer/Api.spec.ts +0 -210
  417. package/tests/unit/amf/serializer/Documentation.spec.ts +0 -52
  418. package/tests/unit/amf/serializer/Endpoints.spec.ts +0 -172
  419. package/tests/unit/amf/serializer/Operations.spec.ts +0 -330
  420. package/tests/unit/amf/serializer/Parameters.spec.ts +0 -149
  421. package/tests/unit/amf/serializer/PayloadExamples.spec.ts +0 -152
  422. package/tests/unit/amf/serializer/Security.spec.ts +0 -626
  423. package/tests/unit/amf/serializer/Server.spec.ts +0 -78
  424. package/tests/unit/amf/serializer/Shapes.spec.ts +0 -304
  425. package/tests/unit/amf/serializer/SourceMaps.spec.ts +0 -52
  426. package/tests/unit/amf/shapes/ShapeXmlSchemaGenerator.spec.ts +0 -28
  427. package/tests/unit/amf/tracked-to-linked.spec.ts +0 -90
  428. package/tests/unit/amf/xml-data-processing.spec.ts +0 -217
  429. package/tests/unit/events/amf.spec.ts +0 -151
@@ -1,1726 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- /* eslint-disable @typescript-eslint/no-unused-vars */
3
- /**
4
- @license
5
- Copyright 2018 The Advanced REST client authors <arc@mulesoft.com>
6
- Licensed under the Apache License, Version 2.0 (the "License"); you may not
7
- use this file except in compliance with the License. You may obtain a copy of
8
- the License at
9
- http://www.apache.org/licenses/LICENSE-2.0
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
- WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
- License for the specific language governing permissions and limitations under
14
- the License.
15
- */
16
- import { AmfModelExpander } from 'amf-json-ld-lib'
17
- import {
18
- IAmfDocument,
19
- IAmfDomainElement,
20
- IAmfEndPoint,
21
- IAmfLdValue,
22
- IAmfSecurityScheme,
23
- IAmfShape,
24
- IAmfWebApi,
25
- IAmfOperation,
26
- IAmfAsyncApi,
27
- IAmfServer,
28
- IAmfRequest,
29
- } from './definitions/Amf.js'
30
- import { AmfNamespace as ns } from './definitions/Namespace.js'
31
-
32
- export const findAmfType = Symbol('findAmfType')
33
- export const findReferenceObject = Symbol('findReferenceObject')
34
- export const getArrayItems = Symbol('getArrayItems')
35
- export const computeReferenceSecurity = Symbol('computeReferenceSecurity')
36
-
37
- export interface ServersQueryOptions {
38
- /**
39
- * An EndPoint to look for the servers in
40
- */
41
- endpointId?: string
42
- /**
43
- * An Operation to look for the servers in
44
- */
45
- methodId?: string
46
- }
47
-
48
- export interface ServerQueryOptions {
49
- /**
50
- * An EndPoint to look for the servers in. Required if Operation is provided
51
- */
52
- endpointId?: string
53
- /**
54
- * An Operation to look for the servers in
55
- */
56
- methodId?: string
57
- /**
58
- * Optional selected server id
59
- */
60
- id?: string
61
- }
62
-
63
- type Constructor<T = object> = new (...args: any[]) => T
64
-
65
- export declare class AmfMixinInterface {
66
- amf?: IAmfDocument
67
- _amf?: IAmfDocument
68
- /**
69
- * This is an abstract method to be implemented by the components.
70
- * If, instead, the component uses `amf` setter you must use `super.amf` to
71
- * set the value.
72
- * @param amf Current AMF model. Can be undefined.
73
- */
74
- _amfChanged(amf?: IAmfDocument): void
75
-
76
- /**
77
- * Expands flattened AMF model
78
- */
79
- _expand(amf: unknown): IAmfDocument
80
-
81
- /**
82
- * Returns compact model key for given value.
83
- * @param property AMF original property
84
- * @param context A context to use. If not set, it looks for the context of the passed model
85
- * @returns Compact model property name or the same value if value not found in the context.
86
- */
87
- _getAmfKey(property?: string, context?: Record<string, string>): string
88
-
89
- /**
90
- * Ensures that the model is AMF object.
91
- *
92
- * @param amf AMF json/ld model
93
- * @returns The API spec
94
- */
95
- _ensureAmfModel(amf: unknown): IAmfDocument | undefined
96
-
97
- /**
98
- * Ensures that the value is an array.
99
- * It returns undefined when there's no value.
100
- * It returns the same array if the value is already an array.
101
- * It returns new array of the item is not an array.
102
- *
103
- * @param value An item to test
104
- */
105
- _ensureArray(value?: any): unknown[] | undefined
106
-
107
- /**
108
- * Gets a single scalar value from a model.
109
- * @param model Amf model to extract the value from.
110
- * @param untrustedKey Model key to search for the value
111
- * @param context A context to use. If not set, it looks for the context of the passed model
112
- * @returns Value for key
113
- */
114
- _getValue(
115
- model: IAmfDomainElement,
116
- untrustedKey: string,
117
- context?: Record<string, string>
118
- ): string | number | boolean | undefined | null
119
-
120
- /**
121
- * Gets values from a model as an array of `@value` properties.
122
- * @param model Amf model to extract the value from.
123
- * @param untrustedKey Model key to search for the value
124
- * @param context A context to use. If not set, it looks for the context of the passed model
125
- * @returns The value for key
126
- */
127
- _getValueArray(
128
- model: IAmfDomainElement,
129
- untrustedKey: string,
130
- context?: Record<string, string>
131
- ): (string | number | boolean | null)[] | undefined
132
-
133
- /**
134
- * Reads an array from the model.
135
- *
136
- * @param model Amf model to extract the value from.
137
- * @param untrustedKey Model key to search for the value
138
- * @param context A context to use. If not set, it looks for the context of the passed model
139
- * @returns Value for the key
140
- */
141
- [getArrayItems](
142
- model?: IAmfDomainElement,
143
- untrustedKey?: string,
144
- context?: Record<string, string>
145
- ): IAmfDomainElement[] | undefined
146
-
147
- /**
148
- * Reads the value of the `@id` property.
149
- * @param model Amf model to extract the value from.
150
- * @param untrustedKey Model key to search for the @id
151
- * @param context A context to use. If not set, it looks for the context of the passed model
152
- */
153
- _getLinkValue(model: IAmfDomainElement, untrustedKey: string, context?: Record<string, string>): string | undefined
154
-
155
- /**
156
- * Reads the list of value for the `@id` property.
157
- * @param model Amf model to extract the value from.
158
- * @param untrustedKey Model key to search for the @id
159
- * @param context A context to use. If not set, it looks for the context of the passed model
160
- */
161
- _getLinkValues(model: IAmfDomainElement, untrustedKey: string, context?: Record<string, string>): string[] | undefined
162
-
163
- /**
164
- * Checks if a model has a type.
165
- * @param model Model to test
166
- * @param type Type name
167
- * @param context A context to use. If not set, it looks for the context of the passed model
168
- * @returns True if model has a type.
169
- */
170
- _hasType(model?: IAmfDomainElement, type?: string, context?: Record<string, string>): boolean
171
-
172
- /**
173
- * Checks if a shape has a property.
174
- * @param shape The shape to test
175
- * @param untrustedKey Property name to test
176
- * @param context A context to use. If not set, it looks for the context of the passed model
177
- */
178
- _hasProperty(shape: IAmfDomainElement, untrustedKey: string, context?: Record<string, string>): boolean
179
-
180
- /**
181
- * Computes array value of a property in a model (shape).
182
- *
183
- * @param shape AMF shape object
184
- * @param untrustedKey Property name
185
- * @param context A context to use. If not set, it looks for the context of the passed model
186
- */
187
- _computePropertyArray(
188
- shape?: IAmfDomainElement,
189
- untrustedKey?: string,
190
- context?: Record<string, string>
191
- ): (string | number | boolean | null | object)[] | undefined
192
-
193
- /**
194
- * Computes API version from the AMF model.
195
- *
196
- * @param amf
197
- * @param context A context to use. If not set, it looks for the context of the passed model
198
- */
199
- _computeApiVersion(amf?: IAmfDocument, context?: Record<string, string>): string | undefined
200
-
201
- /**
202
- * Computes model's `encodes` property.
203
- *
204
- * @param model AMF data model
205
- * @param context A context to use. If not set, it looks for the context of the passed model
206
- * @returns List of encodes
207
- */
208
- _computeEncodes(model?: IAmfDocument, context?: Record<string, string>): IAmfDomainElement | undefined
209
-
210
- /**
211
- * Computes list of declarations in the AMF api model.
212
- *
213
- * @param model AMF json/ld model for an API
214
- * @param context A context to use. If not set, it looks for the context of the passed model
215
- * @returns List of declarations
216
- */
217
- _computeDeclares(model?: IAmfDocument, context?: Record<string, string>): IAmfDomainElement[] | undefined
218
-
219
- /**
220
- * Computes list of references in the AMF api model.
221
- *
222
- * @param model AMF json/ld model for an API
223
- * @param context A context to use. If not set, it looks for the context of the passed model
224
- * @returns List of declarations
225
- */
226
- _computeReferences(model?: IAmfDocument, context?: Record<string, string>): IAmfDomainElement[] | undefined
227
-
228
- /**
229
- * Computes AMF's `http://schema.org/WebAPI` model
230
- *
231
- * @param model AMF json/ld model for an API
232
- * @param context A context to use. If not set, it looks for the context of the passed model
233
- * @returns Web API declaration.
234
- */
235
- _computeWebApi(model?: IAmfDocument, context?: Record<string, string>): IAmfWebApi | undefined
236
-
237
- /**
238
- * Computes AMF's `http://schema.org/API` model
239
- *
240
- * @param model AMF json/ld model for an API
241
- * @param context A context to use. If not set, it looks for the context of the passed model
242
- * @returns API declaration.
243
- */
244
- _computeApi(model?: IAmfDocument, context?: Record<string, string>): IAmfAsyncApi | IAmfWebApi | undefined
245
-
246
- /**
247
- * Returns whether an AMF node is a WebAPI node
248
- *
249
- * @param model AMF json/ld model for an API
250
- * @param context A context to use. If not set, it looks for the context of the passed model
251
- */
252
- _isWebAPI(model?: IAmfDocument, context?: Record<string, string>): boolean
253
-
254
- /**
255
- * Returns whether an AMF node is an AsyncAPI node
256
- *
257
- * @param model AMF json/ld model for an API
258
- * @param context A context to use. If not set, it looks for the context of the passed model
259
- */
260
- _isAsyncAPI(model?: IAmfDocument, context?: Record<string, string>): boolean
261
-
262
- /**
263
- * Returns whether an AMF node is an API node
264
- *
265
- * @param model AMF json/ld model for an API
266
- * @param context A context to use. If not set, it looks for the context of the passed model
267
- */
268
- _isAPI(model?: IAmfDocument, context?: Record<string, string>): boolean
269
-
270
- /**
271
- * Determines whether a partial model is valid for reading servers from
272
- * Current valid values:
273
- * - Operation
274
- * - Endpoint
275
- * @param model The partial model to evaluate
276
- * @param context A context to use. If not set, it looks for the context of the passed model
277
- * @returns Whether the model's type is part of the array of valid node types from which
278
- * to read servers
279
- * @private
280
- */
281
- _isValidServerPartial(model: IAmfDomainElement | IAmfDomainElement[], context?: Record<string, string>): boolean
282
-
283
- /**
284
- * @param options Server query options
285
- * @param context A context to use. If not set, it looks for the context of the passed model
286
- * @returns List of servers for method, if defined, or endpoint, if defined, or root level
287
- */
288
- _getServers(options?: ServersQueryOptions, context?: Record<string, string>): IAmfServer[] | undefined
289
-
290
- /**
291
- * Computes value for the `expects` property.
292
- *
293
- * @param method AMF `supportedOperation` model
294
- * @param context A context to use. If not set, it looks for the context of the passed model
295
- */
296
- _computeExpects(method?: IAmfOperation, context?: Record<string, string>): IAmfRequest | undefined
297
-
298
- /**
299
- * Computes list of endpoints from a WebApi model.
300
- * @param webApi
301
- * @param context A context to use. If not set, it looks for the context of the passed model
302
- * @returns An array of endpoints.
303
- */
304
- _computeEndpoints(webApi?: IAmfWebApi, context?: Record<string, string>): IAmfEndPoint[] | undefined
305
- /**
306
- * Computes model for an endpoint documentation.
307
- *
308
- * @param webApi Current value of `webApi` property
309
- * @param id Selected shape ID
310
- * @param context A context to use. If not set, it looks for the context of the passed model
311
- * @returns An endpoint definition
312
- */
313
- _computeEndpointModel(webApi?: IAmfWebApi, id?: string, context?: Record<string, string>): IAmfEndPoint | undefined
314
-
315
- /**
316
- * Computes method for the method documentation.
317
- *
318
- * @param webApi Current value of `webApi` property
319
- * @param selected Selected shape
320
- * @param context A context to use. If not set, it looks for the context of the passed model
321
- * @returns A method definition
322
- */
323
- _computeMethodModel(
324
- webApi?: IAmfWebApi,
325
- selected?: string,
326
- context?: Record<string, string>
327
- ): IAmfOperation | undefined
328
-
329
- /**
330
- * Computes an endpoint for a method.
331
- * @param webApi The WebApi AMF model
332
- * @param methodId Method id
333
- * @param context A context to use. If not set, it looks for the context of the passed model
334
- * @returns An endpoint model of undefined.
335
- */
336
- _computeMethodEndpoint(
337
- webApi?: IAmfWebApi,
338
- methodId?: string,
339
- context?: Record<string, string>
340
- ): IAmfEndPoint | undefined
341
-
342
- /**
343
- * Computes a list of methods for an endpoint that contains a method with
344
- * given id.
345
- *
346
- * @param webApi WebApi model
347
- * @param methodId Method id.
348
- * @param context A context to use. If not set, it looks for the context of the passed model
349
- * @returns A list of sibling methods or undefined.
350
- */
351
- __computeMethodsListForMethod(
352
- webApi?: IAmfWebApi,
353
- methodId?: string,
354
- context?: Record<string, string>
355
- ): IAmfOperation[] | undefined
356
-
357
- /**
358
- * Computes a type documentation model.
359
- *
360
- * @param declares Current value of `declares` property
361
- * @param references Current value of `references` property
362
- * @param selected Selected shape
363
- * @param context A context to use. If not set, it looks for the context of the passed model
364
- * @returns A type definition
365
- */
366
- _computeType(
367
- declares?: IAmfDomainElement[],
368
- references?: IAmfDomainElement[],
369
- selected?: string,
370
- context?: Record<string, string>
371
- ): IAmfShape | undefined
372
-
373
- /**
374
- * Finds a type in the model declares and references.
375
- * @param domainId The domain id of the type (AMF's shape).
376
- * @param context A context to use. If not set, it looks for the context of the passed model
377
- * @returns The AMF shape or undefined when not found.
378
- */
379
- [findAmfType](domainId?: string, context?: Record<string, string>): IAmfShape | undefined
380
-
381
- /**
382
- * Searches for an object in model's references list.
383
- * It does not resolve the object (useful for handling links correctly).
384
- *
385
- * @param domainId The domain of the object to find in the references.
386
- * @param context A context to use. If not set, it looks for the context of the passed model
387
- * @returns The domain object or undefined.
388
- */
389
- [findReferenceObject](domainId: string, context?: Record<string, string>): IAmfDomainElement | undefined
390
-
391
- /**
392
- * Computes a type model from a reference (library for example).
393
- * @param reference AMF model for a reference to extract the data from
394
- * @param selected Node ID to look for
395
- * @param context A context to use. If not set, it looks for the context of the passed model
396
- * @returns Type definition or undefined if not found.
397
- */
398
- _computeReferenceType(
399
- reference?: IAmfDomainElement,
400
- selected?: string,
401
- context?: Record<string, string>
402
- ): IAmfShape | undefined
403
-
404
- /**
405
- * Computes a documentation model.
406
- *
407
- * @param webApi Current value of `webApi` property
408
- * @param selected Selected shape
409
- * @param context A context to use. If not set, it looks for the context of the passed model
410
- */
411
- _computeDocument(
412
- webApi?: IAmfDomainElement,
413
- selected?: string,
414
- context?: Record<string, string>
415
- ): IAmfDomainElement | undefined
416
-
417
- /**
418
- * Resolves a reference to an external fragment.
419
- *
420
- * @param shape A shape to resolve
421
- * @param context A context to use. If not set, it looks for the context of the passed model
422
- * @returns Resolved shape.
423
- */
424
- _resolve(shape: any, context?: Record<string, string>): any
425
-
426
- /**
427
- * @param amf References object to search in
428
- * @param id Id of the shape to resolve
429
- * @param context A context to use. If not set, it looks for the context of the passed model
430
- * @returns Resolved shape for given reference, undefined otherwise
431
- */
432
- _getLinkTarget(amf?: IAmfDocument, id?: string, context?: Record<string, string>): IAmfDomainElement | undefined
433
-
434
- /**
435
- * Resolves the shape of a given reference.
436
- *
437
- * @param references References object to search in
438
- * @param id Id of the shape to resolve
439
- * @param context A context to use. If not set, it looks for the context of the passed model
440
- * @returns Resolved shape for given reference, undefined otherwise
441
- */
442
- _obtainShapeFromReferences(
443
- references?: IAmfDomainElement[],
444
- id?: string,
445
- context?: Record<string, string>
446
- ): IAmfDomainElement | undefined
447
-
448
- /**
449
- * Searches a node with a given ID in an array
450
- *
451
- * @param array Array to search for a given ID
452
- * @param id Id to search for
453
- * @returns Node with the given ID when found, undefined otherwise
454
- */
455
- _findById(array?: IAmfDomainElement[], id?: string): IAmfDomainElement | undefined
456
-
457
- _getReferenceId(amf?: IAmfDocument, id?: string, context?: Record<string, string>): IAmfDomainElement | undefined
458
-
459
- _resolveRecursive(shape: any, context?: Record<string, string>): void
460
-
461
- /**
462
- * Merge two shapes together. If the resulting shape has one of the "special merge" keys,
463
- * then the special merge function for that key will be used to match that property
464
- * @param shapeA AMF node
465
- * @param shapeB AMF node
466
- * @param context A context to use. If not set, it looks for the context of the passed model
467
- * @returns Merged AMF node
468
- */
469
- _mergeShapes(shapeA: any, shapeB: any, context?: Record<string, string>): any
470
-
471
- /**
472
- * Obtains source map sources value from two shapes and returns the merged result
473
- * If neither shape has a sources node, then an empty object will be returned.
474
- * Result is wrapped in an array as per AMF model standard
475
- * @param shapeA AMF node
476
- * @param shapeB AMF node
477
- * @param context A context to use. If not set, it looks for the context of the passed model
478
- * @returns Empty object or resulting merge, wrapped in an array
479
- * @private
480
- */
481
- _mergeSourceMapsSources(shapeA: any, shapeB: any, context?: Record<string, string>): (any | object)[]
482
-
483
- /**
484
- * Expands the key property from compacted mode to full mode.
485
- * @param value The value to process
486
- * @returns The expanded value.
487
- */
488
- _expandKey(value: string, context?: Record<string, string>): string
489
-
490
- /**
491
- * Computes a security model from a reference (library for example).
492
- * @param domainId Domain id of the security requirement to find.
493
- * @param context A context to use. If not set, it looks for the context of the passed model
494
- * @returns Type definition or undefined if not found.
495
- */
496
- findSecurityScheme(domainId: string, context?: Record<string, string>): IAmfSecurityScheme | undefined
497
-
498
- /**
499
- * Computes a security model from a reference (library for example).
500
- * @param reference AMF model for a reference to extract the data from
501
- * @param selected Node ID to look for
502
- * @param context A context to use. If not set, it looks for the context of the passed model
503
- * @returns Type definition or undefined if not found.
504
- */
505
- [computeReferenceSecurity](
506
- reference: IAmfDomainElement,
507
- selected: string,
508
- context?: Record<string, string>
509
- ): IAmfSecurityScheme | undefined
510
-
511
- /**
512
- * Collects domain objects by a domain type.
513
- * @param source The element to search for declare/encoded objects.
514
- * @param type The domain type
515
- * @param context A context to use. If not set, it looks for the context of the passed model
516
- */
517
- getByType(source: IAmfDomainElement, type: string, context?: Record<string, string>): IAmfDomainElement[]
518
- }
519
-
520
- /**
521
- * Common functions used by AMF components to compute AMF values.
522
- */
523
- export const AmfMixin = <T extends Constructor<any>>(superClass: T): Constructor<AmfMixinInterface> & T => {
524
- class AmfMixin extends superClass {
525
- _amf?: IAmfDocument
526
- __cachedKeys?: any
527
- __lastSetValue?: unknown
528
-
529
- get amf(): IAmfDocument | undefined {
530
- return this._amf
531
- }
532
-
533
- set amf(value: IAmfDocument | undefined) {
534
- if (this._amf === value || this.__lastSetValue === value) {
535
- return
536
- }
537
- this.__lastSetValue = value
538
- const expanded = value ? this._expand(value) : undefined
539
- // Cached keys cannot be static as this element can be used in the sane
540
- // document with different AMF models
541
- this.__cachedKeys = {}
542
- this._amf = expanded
543
- this._amfChanged(expanded)
544
- }
545
-
546
- /**
547
- * This is an abstract method to be implemented by the components.
548
- * If, instead, the component uses `amf` setter you must use `super.amf` to
549
- * set the value.
550
- * @param amf Current AMF model. Can be undefined.
551
- */
552
- _amfChanged(amf?: IAmfDocument): void {
553
- // ...
554
- }
555
-
556
- /**
557
- * Expands flattened AMF model
558
- */
559
- _expand(amf: any): IAmfDocument {
560
- return AmfModelExpander.expand(amf) as IAmfDocument
561
- }
562
-
563
- /**
564
- * Returns compact model key for given value.
565
- * @param property AMF original property
566
- * @param context A context to use. If not set, it looks for the context of the passed model
567
- * @returns Compact model property name or the same value if value not found in the context.
568
- */
569
- _getAmfKey(property?: string, context?: Record<string, string>): string {
570
- if (!property) {
571
- return ''
572
- }
573
- let { amf } = this
574
- if (!amf && !context) {
575
- return property
576
- }
577
- if (Array.isArray(amf)) {
578
- ;[amf] = amf
579
- }
580
- if (!this.__cachedKeys) {
581
- this.__cachedKeys = {}
582
- }
583
- const ctx = (context || (amf && amf['@context'])) as Record<string, string> | undefined
584
- if (!ctx || !property) {
585
- return property
586
- }
587
- const cache = this.__cachedKeys
588
- if (property in cache) {
589
- return cache[property]
590
- }
591
- property = String(property)
592
- const hashIndex = property.indexOf('#')
593
- const hashProperty = property.substring(0, hashIndex + 1)
594
- const keys = Object.keys(ctx)
595
- for (let i = 0, len = keys.length; i < len; i++) {
596
- const k = keys[i]
597
- if (ctx[k] === property) {
598
- cache[property] = k
599
- return k
600
- }
601
- if (hashIndex === -1 && property.indexOf(ctx[k]) === 0) {
602
- const result = property.replace(ctx[k], `${k}:`)
603
- cache[property] = result
604
- return result
605
- }
606
- if (ctx[k] === hashProperty) {
607
- const result = `${k}:${property.substring(hashIndex + 1)}`
608
- cache[property] = result
609
- return result
610
- }
611
- }
612
- return property
613
- }
614
-
615
- /**
616
- * Ensures that the model is AMF object.
617
- *
618
- * @param amf AMF json/ld model
619
- * @returns The API spec
620
- */
621
- _ensureAmfModel(amf: any): IAmfDocument | undefined {
622
- if (!amf) {
623
- return undefined
624
- }
625
- if (Array.isArray(amf)) {
626
- ;[amf] = amf
627
- }
628
- if (this._hasType(amf, ns.aml.vocabularies.document.Document)) {
629
- return amf
630
- }
631
- return undefined
632
- }
633
-
634
- /**
635
- * Ensures that the value is an array.
636
- * It returns undefined when there's no value.
637
- * It returns the same array if the value is already an array.
638
- * It returns new array of the item is not an array.
639
- *
640
- * @param value An item to test
641
- */
642
- _ensureArray(value?: any): unknown[] | undefined {
643
- if (!value) {
644
- return undefined
645
- }
646
- if (value instanceof Array) {
647
- return value
648
- }
649
- return [value]
650
- }
651
-
652
- /**
653
- * Gets a single scalar value from a model.
654
- * @param model Amf model to extract the value from.
655
- * @param untrustedKey Model key to search for the value
656
- * @param context A context to use. If not set, it looks for the context of the passed model
657
- * @returns Value for key
658
- */
659
- _getValue(
660
- model: IAmfDomainElement,
661
- untrustedKey: string,
662
- context?: Record<string, string>
663
- ): string | number | boolean | undefined | null {
664
- const key = this._getAmfKey(untrustedKey, context)
665
- if (!key) {
666
- return undefined
667
- }
668
- let data = model && (model[key as keyof IAmfDomainElement] as string | number | boolean | undefined | null)
669
- if (!data) {
670
- // This includes "undefined", "false", "null" and "0"
671
- return data
672
- }
673
- if (Array.isArray(data)) {
674
- ;[data] = data
675
- }
676
- if (!data) {
677
- return undefined
678
- }
679
- const type = typeof data
680
- if (['string', 'number', 'boolean', 'undefined'].includes(type)) {
681
- return data
682
- }
683
- return (data as unknown as IAmfLdValue<any>)['@value']
684
- }
685
-
686
- /**
687
- * Gets values from a model as an array of `@value` properties.
688
- * @param model Amf model to extract the value from.
689
- * @param untrustedKey Model key to search for the value
690
- * @param context A context to use. If not set, it looks for the context of the passed model
691
- * @returns The value for key
692
- */
693
- _getValueArray(
694
- model: IAmfDomainElement,
695
- untrustedKey: string,
696
- context?: Record<string, string>
697
- ): (string | number | boolean | null)[] | undefined {
698
- const key = this._getAmfKey(untrustedKey, context)
699
- if (!key) {
700
- return undefined
701
- }
702
- const data = model && (this._ensureArray((model as any)[key]) as any[])
703
- if (!Array.isArray(data)) {
704
- return undefined
705
- }
706
- return data.map((item) => item['@value'] || item)
707
- }
708
-
709
- /**
710
- * Reads an array from the model.
711
- *
712
- * @param model Amf model to extract the value from.
713
- * @param untrustedKey Model key to search for the value
714
- * @param context A context to use. If not set, it looks for the context of the passed model
715
- * @returns Value for the key
716
- */
717
- [getArrayItems](
718
- model?: IAmfDomainElement,
719
- untrustedKey?: string,
720
- context?: Record<string, string>
721
- ): IAmfDomainElement[] | undefined {
722
- const k = this._getAmfKey(untrustedKey, context)
723
- if (!k) {
724
- return undefined
725
- }
726
- const data = model && (this._ensureArray((model as any)[k]) as IAmfDomainElement[])
727
- if (!Array.isArray(data)) {
728
- return undefined
729
- }
730
- return data
731
- }
732
-
733
- /**
734
- * Reads the value of the `@id` property.
735
- * @param model Amf model to extract the value from.
736
- * @param untrustedKey Model key to search for the @id
737
- * @param context A context to use. If not set, it looks for the context of the passed model
738
- */
739
- _getLinkValue(
740
- model: IAmfDomainElement,
741
- untrustedKey: string,
742
- context?: Record<string, string>
743
- ): string | undefined {
744
- const k = this._getAmfKey(untrustedKey, context)
745
- if (!k) {
746
- return undefined
747
- }
748
- let data = model && (model as any)[k]
749
- if (!data) {
750
- return undefined
751
- }
752
- if (Array.isArray(data)) {
753
- ;[data] = data
754
- }
755
- if (!data) {
756
- return undefined
757
- }
758
- return data['@id']
759
- }
760
-
761
- /**
762
- * Reads the list of value for the `@id` property.
763
- * @param model Amf model to extract the value from.
764
- * @param untrustedKey Model key to search for the @id
765
- * @param context A context to use. If not set, it looks for the context of the passed model
766
- */
767
- _getLinkValues(
768
- model: IAmfDomainElement,
769
- untrustedKey: string,
770
- context?: Record<string, string>
771
- ): string[] | undefined {
772
- const k = this._getAmfKey(untrustedKey, context)
773
- if (!k) {
774
- return undefined
775
- }
776
- let data = (model && (model as any)[k]) as IAmfDomainElement[] | undefined
777
- if (!data) {
778
- return undefined
779
- }
780
- if (!Array.isArray(data)) {
781
- data = [data]
782
- }
783
- return data.map((i) => i['@id'])
784
- }
785
-
786
- /**
787
- * Checks if a model has a type.
788
- * @param model Model to test
789
- * @param type Type name
790
- * @param context A context to use. If not set, it looks for the context of the passed model
791
- * @returns True if model has a type.
792
- */
793
- _hasType(model?: IAmfDomainElement, type?: string, context?: Record<string, string>): boolean {
794
- const types = this._ensureArray(model && model['@type'])
795
- if (!types || !types.length) {
796
- return false
797
- }
798
- const key = this._getAmfKey(type, context)
799
- for (const type of types) {
800
- if (type === key) {
801
- return true
802
- }
803
- }
804
- return false
805
- }
806
-
807
- /**
808
- * Checks if a shape has a property.
809
- * @param shape The shape to test
810
- * @param untrustedKey Property name to test
811
- * @param context A context to use. If not set, it looks for the context of the passed model
812
- */
813
- _hasProperty(shape: IAmfDomainElement, untrustedKey: string, context?: Record<string, string>): boolean {
814
- const key = this._getAmfKey(untrustedKey, context) as string
815
- return !!(shape && key && key in shape)
816
- }
817
-
818
- /**
819
- * Computes array value of a property in a model (shape).
820
- *
821
- * @param shape AMF shape object
822
- * @param untrustedKey Property name
823
- * @param context A context to use. If not set, it looks for the context of the passed model
824
- */
825
- _computePropertyArray(
826
- shape?: IAmfDomainElement,
827
- untrustedKey?: string,
828
- context?: Record<string, string>
829
- ): (string | number | boolean | null | object)[] | undefined {
830
- if (!shape) {
831
- return undefined
832
- }
833
- const key = this._getAmfKey(untrustedKey, context)
834
- if (!key) {
835
- return undefined
836
- }
837
- const data = this._ensureArray(shape && (shape as any)[key])
838
- if (!data || !Array.isArray(data)) {
839
- return undefined
840
- }
841
- return data as (string | number | boolean | null | object)[]
842
- }
843
-
844
- /**
845
- * Computes API version from the AMF model.
846
- *
847
- * @param amf
848
- * @param context A context to use. If not set, it looks for the context of the passed model
849
- */
850
- _computeApiVersion(amf?: IAmfDocument, context?: Record<string, string>): string | undefined {
851
- const api = this._computeApi(amf)
852
- if (!api) {
853
- return undefined
854
- }
855
- return this._getValue(api, ns.aml.vocabularies.core.version, context) as string
856
- }
857
-
858
- /**
859
- * Computes model's `encodes` property.
860
- *
861
- * @param model AMF data model
862
- * @param context A context to use. If not set, it looks for the context of the passed model
863
- * @returns List of encodes
864
- */
865
- _computeEncodes(model?: IAmfDocument, context?: Record<string, string>): IAmfDomainElement | undefined {
866
- if (!model) {
867
- return undefined
868
- }
869
- if (Array.isArray(model)) {
870
- ;[model] = model
871
- }
872
- const key = this._getAmfKey(ns.aml.vocabularies.document.encodes, context)
873
- if (!key) {
874
- return undefined
875
- }
876
- const data = (model as any)[key]
877
- if (data) {
878
- return Array.isArray(data) ? data[0] : data
879
- }
880
- return undefined
881
- }
882
-
883
- /**
884
- * Computes list of declarations in the AMF api model.
885
- *
886
- * @param model AMF json/ld model for an API
887
- * @param context A context to use. If not set, it looks for the context of the passed model
888
- * @returns List of declarations
889
- */
890
- _computeDeclares(model?: IAmfDocument, context?: Record<string, string>): IAmfDomainElement[] | undefined {
891
- if (!model) {
892
- return undefined
893
- }
894
- if (Array.isArray(model)) {
895
- ;[model] = model
896
- }
897
- if (!model) {
898
- return undefined
899
- }
900
- const key = this._getAmfKey(ns.aml.vocabularies.document.declares, context)
901
- if (!key) {
902
- return undefined
903
- }
904
- const data = this._ensureArray((model as any)[key]) as IAmfDomainElement[]
905
- return Array.isArray(data) ? data : undefined
906
- }
907
-
908
- /**
909
- * Computes list of references in the AMF api model.
910
- *
911
- * @param model AMF json/ld model for an API
912
- * @param context A context to use. If not set, it looks for the context of the passed model
913
- * @returns List of declarations
914
- */
915
- _computeReferences(model?: IAmfDocument, context?: Record<string, string>): IAmfDomainElement[] | undefined {
916
- if (!model) {
917
- return undefined
918
- }
919
- if (Array.isArray(model)) {
920
- ;[model] = model
921
- }
922
- if (!model) {
923
- return undefined
924
- }
925
- const key = this._getAmfKey(ns.aml.vocabularies.document.references, context)
926
- if (!key) {
927
- return undefined
928
- }
929
- const data = this._ensureArray((model as any)[key]) as IAmfDomainElement[]
930
- return data instanceof Array ? data : undefined
931
- }
932
-
933
- /**
934
- * Computes AMF's `http://schema.org/WebAPI` model
935
- *
936
- * @param model AMF json/ld model for an API
937
- * @param context A context to use. If not set, it looks for the context of the passed model
938
- * @returns Web API declaration.
939
- */
940
- _computeWebApi(model?: IAmfDocument, context?: Record<string, string>): IAmfWebApi | undefined {
941
- const enc = this._computeEncodes(model, context)
942
- if (!enc) {
943
- return undefined
944
- }
945
- if (this._hasType(enc, ns.aml.vocabularies.apiContract.WebAPI, context)) {
946
- return enc
947
- }
948
- return undefined
949
- }
950
-
951
- /**
952
- * Computes AMF's `http://schema.org/API` model
953
- *
954
- * @param model AMF json/ld model for an API
955
- * @param context A context to use. If not set, it looks for the context of the passed model
956
- * @returns API declaration.
957
- */
958
- _computeApi(model?: IAmfDocument, context?: Record<string, string>): IAmfAsyncApi | IAmfWebApi | undefined {
959
- const enc = this._computeEncodes(model, context)
960
- if (!enc) {
961
- return undefined
962
- }
963
- if (this._isAPI(model, context) || this._isWebAPI(model, context) || this._isAsyncAPI(model, context)) {
964
- return enc
965
- }
966
- return undefined
967
- }
968
-
969
- /**
970
- * Returns whether an AMF node is a WebAPI node
971
- *
972
- * @param model AMF json/ld model for an API
973
- * @param context A context to use. If not set, it looks for the context of the passed model
974
- */
975
- _isWebAPI(model?: IAmfDocument, context?: Record<string, string>): boolean {
976
- const enc = this._computeEncodes(model, context)
977
- if (!enc) {
978
- return false
979
- }
980
- return this._hasType(enc, ns.aml.vocabularies.apiContract.WebAPI, context)
981
- }
982
-
983
- /**
984
- * Returns whether an AMF node is an AsyncAPI node
985
- *
986
- * @param model AMF json/ld model for an API
987
- * @param context A context to use. If not set, it looks for the context of the passed model
988
- */
989
- _isAsyncAPI(model?: IAmfDocument, context?: Record<string, string>): boolean {
990
- const enc = this._computeEncodes(model, context)
991
- if (!enc) {
992
- return false
993
- }
994
- return this._hasType(enc, ns.aml.vocabularies.apiContract.AsyncAPI, context)
995
- }
996
-
997
- /**
998
- * Returns whether an AMF node is an API node
999
- *
1000
- * @param model AMF json/ld model for an API
1001
- * @param context A context to use. If not set, it looks for the context of the passed model
1002
- */
1003
- _isAPI(model?: IAmfDocument, context?: Record<string, string>): boolean {
1004
- const enc = this._computeEncodes(model, context)
1005
- if (!enc) {
1006
- return false
1007
- }
1008
- return this._hasType(enc, ns.aml.vocabularies.apiContract.API, context)
1009
- }
1010
-
1011
- /**
1012
- * Determines whether a partial model is valid for reading servers from
1013
- * Current valid values:
1014
- * - Operation
1015
- * - Endpoint
1016
- * @param model The partial model to evaluate
1017
- * @param context A context to use. If not set, it looks for the context of the passed model
1018
- * @returns Whether the model's type is part of the array of valid node types from which
1019
- * to read servers
1020
- * @private
1021
- */
1022
- _isValidServerPartial(model: IAmfDomainElement | IAmfDomainElement[], context?: Record<string, string>): boolean {
1023
- if (Array.isArray(model)) {
1024
- ;[model] = model
1025
- }
1026
- if (!model) {
1027
- return false
1028
- }
1029
- const oKey = ns.aml.vocabularies.apiContract.Operation
1030
- const eKey = ns.aml.vocabularies.apiContract.EndPoint
1031
- const allowedPartialModelTypes = [this._getAmfKey(oKey, context), this._getAmfKey(eKey, context)]
1032
- const types = model['@type']
1033
- for (const type of types) {
1034
- if (allowedPartialModelTypes.indexOf(type) !== -1) {
1035
- return true
1036
- }
1037
- }
1038
- return false
1039
- }
1040
-
1041
- /**
1042
- * @param options Server query options
1043
- * @param context A context to use. If not set, it looks for the context of the passed model
1044
- * @returns List of servers for method, if defined, or endpoint, if defined, or root level
1045
- */
1046
- _getServers(options: ServersQueryOptions = {}, context?: Record<string, string>): IAmfServer[] | undefined {
1047
- const { endpointId, methodId } = options
1048
- const { amf } = this
1049
- if (!amf) {
1050
- return undefined
1051
- }
1052
- let api = this._computeApi(amf, context)
1053
- if (Array.isArray(api)) {
1054
- ;[api] = api
1055
- }
1056
- if (!api) {
1057
- if (this._isValidServerPartial(amf, context)) {
1058
- api = amf
1059
- } else {
1060
- return undefined
1061
- }
1062
- }
1063
-
1064
- const serverKey = this._getAmfKey(ns.aml.vocabularies.apiContract.server, context)
1065
-
1066
- const getRootServers = (): IAmfServer[] | undefined =>
1067
- this[getArrayItems](api, serverKey, context) as IAmfServer[]
1068
- const getEndpointServers = (): IAmfServer[] | undefined => {
1069
- const endpoint = this._computeEndpointModel(api, endpointId, context)
1070
- const servers = this[getArrayItems](endpoint, serverKey, context) as IAmfServer[]
1071
- if (servers) {
1072
- return servers
1073
- }
1074
- return getRootServers()
1075
- }
1076
- const getMethodServers = (): IAmfServer[] | undefined => {
1077
- const method = this._computeMethodModel(api, methodId, context)
1078
- const servers = this[getArrayItems](method, serverKey, context) as IAmfServer[]
1079
- if (servers) {
1080
- return servers
1081
- }
1082
- return getEndpointServers()
1083
- }
1084
-
1085
- if (methodId) {
1086
- return getMethodServers()
1087
- }
1088
- if (endpointId) {
1089
- return getEndpointServers()
1090
- }
1091
- return getRootServers()
1092
- }
1093
-
1094
- /**
1095
- * Computes value for the `expects` property.
1096
- *
1097
- * @param method AMF `supportedOperation` model
1098
- * @param context A context to use. If not set, it looks for the context of the passed model
1099
- */
1100
- _computeExpects(method?: IAmfOperation, context?: Record<string, string>): IAmfRequest | undefined {
1101
- const operationKey = ns.aml.vocabularies.apiContract.Operation
1102
- const expectsKey = ns.aml.vocabularies.apiContract.expects
1103
- if (this._hasType(method, operationKey, context)) {
1104
- const key = this._getAmfKey(expectsKey, context) as string
1105
- const expects = this._ensureArray((method as any)[key])
1106
- if (expects) {
1107
- return Array.isArray(expects) ? (expects[0] as IAmfRequest) : (expects as IAmfRequest)
1108
- }
1109
- }
1110
- return undefined
1111
- }
1112
-
1113
- /**
1114
- * Computes list of endpoints from a WebApi model.
1115
- * @param webApi
1116
- * @param context A context to use. If not set, it looks for the context of the passed model
1117
- * @returns An array of endpoints.
1118
- */
1119
- _computeEndpoints(webApi?: IAmfWebApi, context?: Record<string, string>): IAmfEndPoint[] | undefined {
1120
- if (!webApi) {
1121
- return []
1122
- }
1123
- const endpointKey = ns.aml.vocabularies.apiContract.endpoint
1124
- const key = this._getAmfKey(endpointKey, context) as string
1125
- return this._ensureArray((webApi as any)[key]) as IAmfEndPoint[]
1126
- }
1127
-
1128
- /**
1129
- * Computes model for an endpoint documentation.
1130
- *
1131
- * @param webApi Current value of `webApi` property
1132
- * @param id Selected shape ID
1133
- * @param context A context to use. If not set, it looks for the context of the passed model
1134
- * @returns An endpoint definition
1135
- */
1136
- _computeEndpointModel(
1137
- webApi?: IAmfWebApi,
1138
- id?: string,
1139
- context?: Record<string, string>
1140
- ): IAmfEndPoint | undefined {
1141
- if (this._hasType(webApi, ns.aml.vocabularies.apiContract.EndPoint, context)) {
1142
- return webApi
1143
- }
1144
- const endpoints = this._computeEndpoints(webApi, context)
1145
- if (!endpoints) {
1146
- return undefined
1147
- }
1148
- return endpoints.find((item) => item['@id'] === id)
1149
- }
1150
-
1151
- /**
1152
- * Computes method for the method documentation.
1153
- *
1154
- * @param webApi Current value of `webApi` property
1155
- * @param selected Selected shape
1156
- * @param context A context to use. If not set, it looks for the context of the passed model
1157
- * @returns A method definition
1158
- */
1159
- _computeMethodModel(
1160
- webApi?: IAmfWebApi,
1161
- selected?: string,
1162
- context?: Record<string, string>
1163
- ): IAmfOperation | undefined {
1164
- const methods = this.__computeMethodsListForMethod(webApi, selected, context)
1165
- if (!methods) {
1166
- return undefined
1167
- }
1168
- return methods.find((item) => item['@id'] === selected)
1169
- }
1170
-
1171
- /**
1172
- * Computes an endpoint for a method.
1173
- * @param webApi The WebApi AMF model
1174
- * @param methodId Method id
1175
- * @param context A context to use. If not set, it looks for the context of the passed model
1176
- * @returns An endpoint model of undefined.
1177
- */
1178
- _computeMethodEndpoint(
1179
- webApi?: IAmfWebApi,
1180
- methodId?: string,
1181
- context?: Record<string, string>
1182
- ): IAmfEndPoint | undefined {
1183
- if (!webApi || !methodId) {
1184
- return undefined
1185
- }
1186
- if (this._hasType(webApi, ns.aml.vocabularies.apiContract.EndPoint, context)) {
1187
- return webApi
1188
- }
1189
- const endpoints = this._computeEndpoints(webApi, context)
1190
- if (!endpoints) {
1191
- return undefined
1192
- }
1193
- const opKey = this._getAmfKey(ns.aml.vocabularies.apiContract.supportedOperation, context)
1194
- for (let i = 0, len = endpoints.length; i < len; i++) {
1195
- const endpoint = endpoints[i]
1196
- let methods = (endpoint as any)[opKey] as IAmfOperation[]
1197
- if (!methods) {
1198
- continue
1199
- }
1200
- if (!Array.isArray(methods)) {
1201
- methods = [methods]
1202
- }
1203
- for (let j = 0, jLen = methods.length; j < jLen; j++) {
1204
- if (methods[j]['@id'] === methodId) {
1205
- return endpoint
1206
- }
1207
- }
1208
- }
1209
- return undefined
1210
- }
1211
-
1212
- /**
1213
- * Computes a list of methods for an endpoint that contains a method with
1214
- * given id.
1215
- *
1216
- * @param webApi WebApi model
1217
- * @param methodId Method id.
1218
- * @param context A context to use. If not set, it looks for the context of the passed model
1219
- * @returns A list of sibling methods or undefined.
1220
- */
1221
- __computeMethodsListForMethod(
1222
- webApi?: IAmfWebApi,
1223
- methodId?: string,
1224
- context?: Record<string, string>
1225
- ): IAmfOperation[] | undefined {
1226
- const endpoint = this._computeMethodEndpoint(webApi, methodId, context)
1227
- if (!endpoint) {
1228
- return undefined
1229
- }
1230
- const opKey = this._getAmfKey(ns.aml.vocabularies.apiContract.supportedOperation, context)
1231
- return this._ensureArray((endpoint as any)[opKey]) as IAmfOperation[] | undefined
1232
- }
1233
-
1234
- /**
1235
- * Computes a type documentation model.
1236
- *
1237
- * @param declares Current value of `declares` property
1238
- * @param references Current value of `references` property
1239
- * @param selected Selected shape
1240
- * @param context A context to use. If not set, it looks for the context of the passed model
1241
- * @returns A type definition
1242
- */
1243
- _computeType(
1244
- declares?: IAmfDomainElement[],
1245
- references?: IAmfDomainElement[],
1246
- selected?: string,
1247
- context?: Record<string, string>
1248
- ): IAmfShape | undefined {
1249
- if ((!declares && !references) || !selected) {
1250
- return undefined
1251
- }
1252
- // In compact model some IDs are presented in long version (in source maps for examples)
1253
- // This must test for this case as well.
1254
- const compactId = selected.replace('amf://id', '')
1255
- let type = declares && declares.find((item) => item['@id'] === selected || item['@id'] === compactId)
1256
- if (!type && references && references.length) {
1257
- for (let i = 0, len = references.length; i < len; i++) {
1258
- if (!this._hasType(references[i], ns.aml.vocabularies.document.Module)) {
1259
- continue
1260
- }
1261
- type = this._computeReferenceType(references[i], selected, context)
1262
- if (type) {
1263
- break
1264
- }
1265
- }
1266
- }
1267
- return type
1268
- }
1269
-
1270
- /**
1271
- * Finds a type in the model declares and references.
1272
- * @param domainId The domain id of the type (AMF's shape).
1273
- * @param context A context to use. If not set, it looks for the context of the passed model
1274
- * @returns The AMF shape or undefined when not found.
1275
- */
1276
- [findAmfType](domainId?: string, context?: Record<string, string>): IAmfShape | undefined {
1277
- let { amf } = this
1278
- if (!amf || !domainId) {
1279
- return undefined
1280
- }
1281
- if (Array.isArray(amf)) {
1282
- ;[amf] = amf
1283
- }
1284
- const declares = this._computeDeclares(amf, context)
1285
- const compactId = domainId.replace('amf://id', '')
1286
- if (Array.isArray(declares)) {
1287
- const result = declares.find((item) => item['@id'] === domainId || item['@id'] === compactId)
1288
- if (result) {
1289
- return result
1290
- }
1291
- }
1292
- return this[findReferenceObject](domainId)
1293
- }
1294
-
1295
- /**
1296
- * Searches for an object in model's references list.
1297
- * It does not resolve the object (useful for handling links correctly).
1298
- *
1299
- * @param domainId The domain of the object to find in the references.
1300
- * @param context A context to use. If not set, it looks for the context of the passed model
1301
- * @returns The domain object or undefined.
1302
- */
1303
- [findReferenceObject](domainId: string, context?: Record<string, string>): IAmfDomainElement | undefined {
1304
- let { amf } = this
1305
- if (Array.isArray(amf)) {
1306
- ;[amf] = amf
1307
- }
1308
- if (!amf) {
1309
- return undefined
1310
- }
1311
- const references = this._computeReferences(amf, context)
1312
- if (!Array.isArray(references) || !references.length) {
1313
- return undefined
1314
- }
1315
- const compactId = domainId.replace('amf://id', '')
1316
- for (let i = 0, len = references.length; i < len; i++) {
1317
- const ref = /** @type IAmfDocument */ references[i]
1318
- const declares = this._computeDeclares(ref, context)
1319
- if (!Array.isArray(declares)) {
1320
- continue
1321
- }
1322
- for (let j = 0, lenDecl = declares.length; j < lenDecl; j++) {
1323
- let declared = declares[j]
1324
- if (Array.isArray(declared)) {
1325
- ;[declared] = declared
1326
- }
1327
- if (declared['@id'] === domainId || declared['@id'] === compactId) {
1328
- return declared
1329
- }
1330
- }
1331
- }
1332
- return undefined
1333
- }
1334
-
1335
- /**
1336
- * Computes a type model from a reference (library for example).
1337
- * @param reference AMF model for a reference to extract the data from
1338
- * @param selected Node ID to look for
1339
- * @param context A context to use. If not set, it looks for the context of the passed model
1340
- * @returns Type definition or undefined if not found.
1341
- */
1342
- _computeReferenceType(
1343
- reference?: IAmfDomainElement,
1344
- selected?: string,
1345
- context?: Record<string, string>
1346
- ): IAmfShape | undefined {
1347
- const declare = this._computeDeclares(reference, context)
1348
- if (!declare || !selected) {
1349
- return undefined
1350
- }
1351
- // In compact model some IDs are presented in long version (in source maps for examples)
1352
- // This must test for this case as well.
1353
- const compactId = selected.replace('amf://id', '')
1354
- let result = declare.find((item) => {
1355
- if (Array.isArray(item)) {
1356
- ;[item] = item
1357
- }
1358
- return item['@id'] === selected || item['@id'] === compactId
1359
- })
1360
- if (Array.isArray(result)) {
1361
- ;[result] = result
1362
- }
1363
- return this._resolve(result)
1364
- }
1365
-
1366
- /**
1367
- * Computes a documentation model.
1368
- *
1369
- * @param webApi Current value of `webApi` property
1370
- * @param selected Selected shape
1371
- * @param context A context to use. If not set, it looks for the context of the passed model
1372
- */
1373
- _computeDocument(
1374
- webApi?: IAmfDomainElement,
1375
- selected?: string,
1376
- context?: Record<string, string>
1377
- ): IAmfDomainElement | undefined {
1378
- if (!webApi || !selected) {
1379
- return undefined
1380
- }
1381
- const key = this._getAmfKey(ns.aml.vocabularies.core.documentation, context)
1382
- const docs = this._ensureArray((webApi as any)[key]) as IAmfDomainElement[]
1383
- return docs && docs.find((item) => ((item as any)['@id'] as string) === selected)
1384
- }
1385
-
1386
- /**
1387
- * Resolves a reference to an external fragment.
1388
- *
1389
- * @param shape A shape to resolve
1390
- * @param context A context to use. If not set, it looks for the context of the passed model
1391
- * @returns Resolved shape.
1392
- */
1393
- _resolve(shape: any, context?: Record<string, string>): any {
1394
- const { amf } = this
1395
- if (typeof shape !== 'object' || Array.isArray(shape) || !amf || shape.__apicResolved) {
1396
- return shape
1397
- }
1398
- let refKey = this._getAmfKey(ns.aml.vocabularies.document.linkTarget, context)
1399
- let refValue = this._ensureArray(shape[refKey]) as IAmfDomainElement[]
1400
- let refData
1401
- if (refValue) {
1402
- const rk = refValue[0]['@id']
1403
- if (rk === shape['@id']) {
1404
- // recursive shape.
1405
- shape.__apicResolved = true
1406
- return shape
1407
- }
1408
- refData = this._getLinkTarget(amf, rk, context)
1409
- } else {
1410
- refKey = this._getAmfKey(ns.aml.vocabularies.document.referenceId, context)
1411
- refValue = this._ensureArray(shape[refKey]) as IAmfDomainElement[]
1412
- if (refValue) {
1413
- const rk = refValue[0]['@id']
1414
- if (rk === shape['@id']) {
1415
- // recursive shape.
1416
- shape.__apicResolved = true
1417
- return shape
1418
- }
1419
- refData = this._getReferenceId(amf, rk, context)
1420
- }
1421
- }
1422
- if (!refData) {
1423
- this._resolveRecursive(shape)
1424
- shape.__apicResolved = true
1425
- return shape
1426
- }
1427
- const copy = { ...refData } as any
1428
- delete copy['@id']
1429
- const types = copy['@type']
1430
- if (types) {
1431
- if (shape['@type']) {
1432
- shape['@type'] = shape['@type'].concat(types)
1433
- } else {
1434
- shape['@type'] = types
1435
- }
1436
- delete copy['@type']
1437
- }
1438
- this._mergeShapes(shape, copy, context)
1439
- shape.__apicResolved = true
1440
- this._resolveRecursive(shape)
1441
- return shape
1442
- }
1443
-
1444
- /**
1445
- * @param amf References object to search in
1446
- * @param id Id of the shape to resolve
1447
- * @param context A context to use. If not set, it looks for the context of the passed model
1448
- * @returns Resolved shape for given reference, undefined otherwise
1449
- */
1450
- _getLinkTarget(amf?: IAmfDocument, id?: string, context?: Record<string, string>): IAmfDomainElement | undefined {
1451
- if (!amf || !id) {
1452
- return undefined
1453
- }
1454
- let target
1455
- const declares = this._computeDeclares(amf, context)
1456
- if (declares) {
1457
- target = this._findById(declares, id)
1458
- }
1459
- if (!target) {
1460
- const references = this._computeReferences(amf, context)
1461
- target = this._obtainShapeFromReferences(references, id, context)
1462
- }
1463
- if (!target) {
1464
- return undefined
1465
- }
1466
- // Declaration may contain references
1467
- target = this._resolve(target)
1468
- return target
1469
- }
1470
-
1471
- /**
1472
- * Resolves the shape of a given reference.
1473
- *
1474
- * @param references References object to search in
1475
- * @param id Id of the shape to resolve
1476
- * @param context A context to use. If not set, it looks for the context of the passed model
1477
- * @returns Resolved shape for given reference, undefined otherwise
1478
- */
1479
- _obtainShapeFromReferences(
1480
- references?: IAmfDomainElement[],
1481
- id?: string,
1482
- context?: Record<string, string>
1483
- ): IAmfDomainElement | undefined {
1484
- if (!Array.isArray(references) || !references.length) {
1485
- return undefined
1486
- }
1487
- let target
1488
- for (const _ref of references) {
1489
- // case of fragment that encodes the shape
1490
- const encoded = this._computeEncodes(_ref, context)
1491
- if (encoded && encoded['@id'] === id) {
1492
- target = encoded
1493
- break
1494
- }
1495
- // case of a library which declares types
1496
- if (!encoded) {
1497
- target = this._findById(this._computeDeclares(_ref, context), id)
1498
- if (target) break
1499
- }
1500
- }
1501
- return target
1502
- }
1503
-
1504
- /**
1505
- * Searches a node with a given ID in an array
1506
- *
1507
- * @param array Array to search for a given ID
1508
- * @param id Id to search for
1509
- * @returns Node with the given ID when found, undefined otherwise
1510
- */
1511
- _findById(array?: IAmfDomainElement[], id?: string): IAmfDomainElement | undefined {
1512
- if (!array) return undefined
1513
- let target
1514
- for (const _current of array) {
1515
- if (_current && _current['@id'] === id) {
1516
- target = _current
1517
- break
1518
- }
1519
- }
1520
- return target
1521
- }
1522
-
1523
- _getReferenceId(amf?: IAmfDocument, id?: string, context?: Record<string, string>): IAmfDomainElement | undefined {
1524
- if (!amf || !id) {
1525
- return undefined
1526
- }
1527
- const refs = this._computeReferences(amf, context)
1528
- if (!refs) {
1529
- return undefined
1530
- }
1531
- for (const _ref of refs) {
1532
- const enc = this._computeEncodes(_ref, context)
1533
- if (enc) {
1534
- if (enc['@id'] === id) {
1535
- return enc
1536
- }
1537
- }
1538
- }
1539
- return undefined
1540
- }
1541
-
1542
- _resolveRecursive(shape: any, context?: Record<string, string>): void {
1543
- Object.keys(shape).forEach((key) => {
1544
- const currentShape = shape[key]
1545
- if (Array.isArray(currentShape)) {
1546
- for (let i = 0, len = currentShape.length; i < len; i++) {
1547
- currentShape[i] = this._resolve(currentShape[i])
1548
- }
1549
- } else if (typeof currentShape === 'object') {
1550
- shape[key] = this._resolve(currentShape, context)
1551
- }
1552
- })
1553
- }
1554
-
1555
- /**
1556
- * Merge two shapes together. If the resulting shape has one of the "special merge" keys,
1557
- * then the special merge function for that key will be used to match that property
1558
- * @param shapeA AMF node
1559
- * @param shapeB AMF node
1560
- * @param context A context to use. If not set, it looks for the context of the passed model
1561
- * @returns Merged AMF node
1562
- */
1563
- _mergeShapes(shapeA: any, shapeB: any, context?: Record<string, string>): any {
1564
- const merged = { ...shapeA, ...shapeB }
1565
- const specialMerges = [
1566
- {
1567
- key: this._getAmfKey(ns.aml.vocabularies.docSourceMaps.sources, context),
1568
- merger: this._mergeSourceMapsSources.bind(this),
1569
- },
1570
- ]
1571
- specialMerges.forEach(({ key, merger }) => {
1572
- if (this._hasProperty(merged, key, context)) {
1573
- merged[key] = merger(shapeA, shapeB, context)
1574
- }
1575
- })
1576
- return Object.assign(shapeA, merged)
1577
- }
1578
-
1579
- /**
1580
- * Obtains source map sources value from two shapes and returns the merged result
1581
- * If neither shape has a sources node, then an empty object will be returned.
1582
- * Result is wrapped in an array as per AMF model standard
1583
- * @param shapeA AMF node
1584
- * @param shapeB AMF node
1585
- * @param context A context to use. If not set, it looks for the context of the passed model
1586
- * @returns Empty object or resulting merge, wrapped in an array
1587
- * @private
1588
- */
1589
- _mergeSourceMapsSources(shapeA: any, shapeB: any, context?: Record<string, string>): (any | object)[] {
1590
- const sourcesKey = this._getAmfKey(ns.aml.vocabularies.docSourceMaps.sources, context)
1591
- let aSources = shapeA[sourcesKey] || {}
1592
- if (Array.isArray(aSources)) {
1593
- aSources = aSources[0]
1594
- }
1595
- let bSources = shapeB[sourcesKey] || {}
1596
- if (Array.isArray(bSources)) {
1597
- bSources = bSources[0]
1598
- }
1599
- return [Object.assign(aSources, bSources)]
1600
- }
1601
-
1602
- /**
1603
- * Expands the key property from compacted mode to full mode.
1604
- * @param value The value to process
1605
- * @returns The expanded value.
1606
- */
1607
- _expandKey(value: string, context?: Record<string, string>): string {
1608
- let { amf } = this
1609
- if (!value || typeof value !== 'string' || (!amf && !context)) {
1610
- return value
1611
- }
1612
- if (Array.isArray(amf)) {
1613
- ;[amf] = amf
1614
- }
1615
- const ctx = context || (amf && amf['@context'])
1616
- if (!ctx) {
1617
- return value
1618
- }
1619
- const [root, key] = value.split(':')
1620
- if (!root || !key) {
1621
- return value
1622
- }
1623
- const prefix = ctx[root]
1624
- if (!prefix) {
1625
- return value
1626
- }
1627
- return `${prefix}${key}`
1628
- }
1629
-
1630
- /**
1631
- * Computes a security model from a reference (library for example).
1632
- * @param domainId Domain id of the security requirement to find.
1633
- * @param context A context to use. If not set, it looks for the context of the passed model
1634
- * @returns Type definition or undefined if not found.
1635
- */
1636
- findSecurityScheme(domainId: string, context?: Record<string, string>): IAmfSecurityScheme | undefined {
1637
- const { amf } = this
1638
- const declares = this._computeDeclares(amf, context)
1639
- let result
1640
- if (declares) {
1641
- result = declares.find((item) => item['@id'] === domainId)
1642
- }
1643
- if (result) {
1644
- result = this._resolve(result)
1645
- return result
1646
- }
1647
- const references = this._computeReferences(amf, context)
1648
- if (Array.isArray(references) && references.length) {
1649
- for (const ref of references) {
1650
- if (this._hasType(ref, ns.aml.vocabularies.document.Module, context)) {
1651
- result = this[computeReferenceSecurity](ref, domainId, context)
1652
- if (result) {
1653
- result = this._resolve(result)
1654
- return result
1655
- }
1656
- }
1657
- }
1658
- }
1659
- return undefined
1660
- }
1661
-
1662
- /**
1663
- * Computes a security model from a reference (library for example).
1664
- * @param reference AMF model for a reference to extract the data from
1665
- * @param selected Node ID to look for
1666
- * @param context A context to use. If not set, it looks for the context of the passed model
1667
- * @returns Type definition or undefined if not found.
1668
- */
1669
- [computeReferenceSecurity](
1670
- reference: IAmfDomainElement,
1671
- selected: string,
1672
- context?: Record<string, string>
1673
- ): IAmfSecurityScheme | undefined {
1674
- const declare = this._computeDeclares(reference, context)
1675
- if (!declare) {
1676
- return undefined
1677
- }
1678
- let result = declare.find((item) => {
1679
- let declared = item
1680
- if (Array.isArray(declared)) {
1681
- ;[declared] = declared
1682
- }
1683
- return declared['@id'] === selected
1684
- })
1685
- if (Array.isArray(result)) {
1686
- ;[result] = result
1687
- }
1688
- return this._resolve(result)
1689
- }
1690
-
1691
- /**
1692
- * Collects domain objects by a domain type.
1693
- * @param source The element to search for declare/encoded objects.
1694
- * @param type The domain type
1695
- * @param context A context to use. If not set, it looks for the context of the passed model
1696
- */
1697
- getByType(source: IAmfDomainElement, type: string, context?: Record<string, string>): IAmfDomainElement[] {
1698
- if (!source) {
1699
- return []
1700
- }
1701
- let result: IAmfDomainElement[] = []
1702
- const declares = this._computeDeclares(source)
1703
- const key = this._getAmfKey(type, context)
1704
- if (declares && declares.length) {
1705
- declares.forEach((declared) => {
1706
- if (this._hasType(declared, key)) {
1707
- result.push(declared as IAmfDomainElement)
1708
- }
1709
- })
1710
- }
1711
- const references = this._computeReferences(source)
1712
- if (Array.isArray(references) && references.length) {
1713
- for (const ref of references) {
1714
- if (this._hasType(ref, ns.aml.vocabularies.document.Module)) {
1715
- const items = this.getByType(ref as IAmfDomainElement, type, context)
1716
- if (items.length) {
1717
- result = result.concat(items)
1718
- }
1719
- }
1720
- }
1721
- }
1722
- return result
1723
- }
1724
- }
1725
- return AmfMixin as Constructor<AmfMixinInterface> & T
1726
- }