@speclynx/apidom-ns-openapi-3-1 1.12.1

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 (198) hide show
  1. package/CHANGELOG.md +87 -0
  2. package/LICENSE +202 -0
  3. package/LICENSES/AFL-3.0.txt +182 -0
  4. package/LICENSES/Apache-2.0.txt +202 -0
  5. package/LICENSES/BSD-3-Clause.txt +26 -0
  6. package/LICENSES/MIT.txt +9 -0
  7. package/NOTICE +65 -0
  8. package/README.md +472 -0
  9. package/dist/apidom-ns-openapi-3-1.browser.js +36144 -0
  10. package/dist/apidom-ns-openapi-3-1.browser.min.js +1 -0
  11. package/package.json +70 -0
  12. package/src/elements/Callback.cjs +10 -0
  13. package/src/elements/Callback.mjs +7 -0
  14. package/src/elements/Components.cjs +17 -0
  15. package/src/elements/Components.mjs +14 -0
  16. package/src/elements/Contact.cjs +10 -0
  17. package/src/elements/Contact.mjs +7 -0
  18. package/src/elements/Discriminator.cjs +10 -0
  19. package/src/elements/Discriminator.mjs +7 -0
  20. package/src/elements/Encoding.cjs +10 -0
  21. package/src/elements/Encoding.mjs +7 -0
  22. package/src/elements/Example.cjs +10 -0
  23. package/src/elements/Example.mjs +7 -0
  24. package/src/elements/ExternalDocumentation.cjs +10 -0
  25. package/src/elements/ExternalDocumentation.mjs +7 -0
  26. package/src/elements/Header.cjs +17 -0
  27. package/src/elements/Header.mjs +13 -0
  28. package/src/elements/Info.cjs +23 -0
  29. package/src/elements/Info.mjs +19 -0
  30. package/src/elements/JsonSchemaDialect.cjs +16 -0
  31. package/src/elements/JsonSchemaDialect.mjs +13 -0
  32. package/src/elements/License.cjs +17 -0
  33. package/src/elements/License.mjs +14 -0
  34. package/src/elements/Link.cjs +10 -0
  35. package/src/elements/Link.mjs +7 -0
  36. package/src/elements/MediaType.cjs +17 -0
  37. package/src/elements/MediaType.mjs +13 -0
  38. package/src/elements/OAuthFlow.cjs +10 -0
  39. package/src/elements/OAuthFlow.mjs +7 -0
  40. package/src/elements/OAuthFlows.cjs +10 -0
  41. package/src/elements/OAuthFlows.mjs +7 -0
  42. package/src/elements/OpenApi3-1.cjs +77 -0
  43. package/src/elements/OpenApi3-1.mjs +73 -0
  44. package/src/elements/Openapi.cjs +10 -0
  45. package/src/elements/Openapi.mjs +7 -0
  46. package/src/elements/Operation.cjs +17 -0
  47. package/src/elements/Operation.mjs +13 -0
  48. package/src/elements/Parameter.cjs +17 -0
  49. package/src/elements/Parameter.mjs +13 -0
  50. package/src/elements/PathItem.cjs +59 -0
  51. package/src/elements/PathItem.mjs +55 -0
  52. package/src/elements/Paths.cjs +10 -0
  53. package/src/elements/Paths.mjs +7 -0
  54. package/src/elements/Reference.cjs +28 -0
  55. package/src/elements/Reference.mjs +25 -0
  56. package/src/elements/RequestBody.cjs +10 -0
  57. package/src/elements/RequestBody.mjs +7 -0
  58. package/src/elements/Response.cjs +10 -0
  59. package/src/elements/Response.mjs +7 -0
  60. package/src/elements/Responses.cjs +10 -0
  61. package/src/elements/Responses.mjs +7 -0
  62. package/src/elements/Schema.cjs +50 -0
  63. package/src/elements/Schema.mjs +46 -0
  64. package/src/elements/SecurityRequirement.cjs +10 -0
  65. package/src/elements/SecurityRequirement.mjs +7 -0
  66. package/src/elements/SecurityScheme.cjs +10 -0
  67. package/src/elements/SecurityScheme.mjs +7 -0
  68. package/src/elements/Server.cjs +10 -0
  69. package/src/elements/Server.mjs +7 -0
  70. package/src/elements/ServerVariable.cjs +10 -0
  71. package/src/elements/ServerVariable.mjs +7 -0
  72. package/src/elements/Tag.cjs +10 -0
  73. package/src/elements/Tag.mjs +7 -0
  74. package/src/elements/Xml.cjs +10 -0
  75. package/src/elements/Xml.mjs +7 -0
  76. package/src/elements/nces/ComponentsPathItems.cjs +16 -0
  77. package/src/elements/nces/ComponentsPathItems.mjs +13 -0
  78. package/src/elements/nces/Webhooks.cjs +16 -0
  79. package/src/elements/nces/Webhooks.mjs +13 -0
  80. package/src/index.cjs +158 -0
  81. package/src/index.mjs +28 -0
  82. package/src/media-types.cjs +34 -0
  83. package/src/media-types.mjs +30 -0
  84. package/src/namespace.cjs +82 -0
  85. package/src/namespace.mjs +76 -0
  86. package/src/predicates.cjs +365 -0
  87. package/src/predicates.mjs +357 -0
  88. package/src/refractor/index.cjs +45 -0
  89. package/src/refractor/index.mjs +39 -0
  90. package/src/refractor/plugins/normalize-header-examples/NormalizeStorage.cjs +38 -0
  91. package/src/refractor/plugins/normalize-header-examples/NormalizeStorage.mjs +34 -0
  92. package/src/refractor/plugins/normalize-header-examples/index.cjs +105 -0
  93. package/src/refractor/plugins/normalize-header-examples/index.mjs +99 -0
  94. package/src/refractor/plugins/normalize-operation-ids.cjs +159 -0
  95. package/src/refractor/plugins/normalize-operation-ids.mjs +154 -0
  96. package/src/refractor/plugins/normalize-parameter-examples.cjs +105 -0
  97. package/src/refractor/plugins/normalize-parameter-examples.mjs +99 -0
  98. package/src/refractor/plugins/normalize-parameters.cjs +103 -0
  99. package/src/refractor/plugins/normalize-parameters.mjs +97 -0
  100. package/src/refractor/plugins/normalize-security-requirements.cjs +71 -0
  101. package/src/refractor/plugins/normalize-security-requirements.mjs +65 -0
  102. package/src/refractor/plugins/normalize-servers.cjs +118 -0
  103. package/src/refractor/plugins/normalize-servers.mjs +112 -0
  104. package/src/refractor/plugins/replace-empty-element.cjs +665 -0
  105. package/src/refractor/plugins/replace-empty-element.mjs +658 -0
  106. package/src/refractor/registration.cjs +102 -0
  107. package/src/refractor/registration.mjs +66 -0
  108. package/src/refractor/specification.cjs +492 -0
  109. package/src/refractor/specification.mjs +487 -0
  110. package/src/refractor/toolbox.cjs +70 -0
  111. package/src/refractor/toolbox.mjs +60 -0
  112. package/src/refractor/visitors/open-api-3-1/JsonSchemaDialectVisitor.cjs +25 -0
  113. package/src/refractor/visitors/open-api-3-1/JsonSchemaDialectVisitor.mjs +19 -0
  114. package/src/refractor/visitors/open-api-3-1/WebhooksVisitor.cjs +44 -0
  115. package/src/refractor/visitors/open-api-3-1/WebhooksVisitor.mjs +38 -0
  116. package/src/refractor/visitors/open-api-3-1/callback/index.cjs +37 -0
  117. package/src/refractor/visitors/open-api-3-1/callback/index.mjs +32 -0
  118. package/src/refractor/visitors/open-api-3-1/components/PathItemsVisitor.cjs +34 -0
  119. package/src/refractor/visitors/open-api-3-1/components/PathItemsVisitor.mjs +28 -0
  120. package/src/refractor/visitors/open-api-3-1/components/SchemasVisitor.cjs +22 -0
  121. package/src/refractor/visitors/open-api-3-1/components/SchemasVisitor.mjs +19 -0
  122. package/src/refractor/visitors/open-api-3-1/components/index.cjs +21 -0
  123. package/src/refractor/visitors/open-api-3-1/components/index.mjs +16 -0
  124. package/src/refractor/visitors/open-api-3-1/contact/index.cjs +21 -0
  125. package/src/refractor/visitors/open-api-3-1/contact/index.mjs +16 -0
  126. package/src/refractor/visitors/open-api-3-1/distriminator/index.cjs +22 -0
  127. package/src/refractor/visitors/open-api-3-1/distriminator/index.mjs +17 -0
  128. package/src/refractor/visitors/open-api-3-1/encoding/index.cjs +21 -0
  129. package/src/refractor/visitors/open-api-3-1/encoding/index.mjs +16 -0
  130. package/src/refractor/visitors/open-api-3-1/example/index.cjs +21 -0
  131. package/src/refractor/visitors/open-api-3-1/example/index.mjs +16 -0
  132. package/src/refractor/visitors/open-api-3-1/external-documentation/index.cjs +21 -0
  133. package/src/refractor/visitors/open-api-3-1/external-documentation/index.mjs +16 -0
  134. package/src/refractor/visitors/open-api-3-1/header/index.cjs +21 -0
  135. package/src/refractor/visitors/open-api-3-1/header/index.mjs +16 -0
  136. package/src/refractor/visitors/open-api-3-1/index.cjs +31 -0
  137. package/src/refractor/visitors/open-api-3-1/index.mjs +25 -0
  138. package/src/refractor/visitors/open-api-3-1/info/index.cjs +21 -0
  139. package/src/refractor/visitors/open-api-3-1/info/index.mjs +16 -0
  140. package/src/refractor/visitors/open-api-3-1/license/index.cjs +21 -0
  141. package/src/refractor/visitors/open-api-3-1/license/index.mjs +16 -0
  142. package/src/refractor/visitors/open-api-3-1/link/index.cjs +21 -0
  143. package/src/refractor/visitors/open-api-3-1/link/index.mjs +16 -0
  144. package/src/refractor/visitors/open-api-3-1/media-type/index.cjs +21 -0
  145. package/src/refractor/visitors/open-api-3-1/media-type/index.mjs +16 -0
  146. package/src/refractor/visitors/open-api-3-1/oauth-flow/index.cjs +21 -0
  147. package/src/refractor/visitors/open-api-3-1/oauth-flow/index.mjs +16 -0
  148. package/src/refractor/visitors/open-api-3-1/oauth-flows/index.cjs +21 -0
  149. package/src/refractor/visitors/open-api-3-1/oauth-flows/index.mjs +16 -0
  150. package/src/refractor/visitors/open-api-3-1/operation/index.cjs +21 -0
  151. package/src/refractor/visitors/open-api-3-1/operation/index.mjs +16 -0
  152. package/src/refractor/visitors/open-api-3-1/parameter/index.cjs +21 -0
  153. package/src/refractor/visitors/open-api-3-1/parameter/index.mjs +16 -0
  154. package/src/refractor/visitors/open-api-3-1/path-item/index.cjs +21 -0
  155. package/src/refractor/visitors/open-api-3-1/path-item/index.mjs +16 -0
  156. package/src/refractor/visitors/open-api-3-1/paths/index.cjs +21 -0
  157. package/src/refractor/visitors/open-api-3-1/paths/index.mjs +16 -0
  158. package/src/refractor/visitors/open-api-3-1/reference/index.cjs +21 -0
  159. package/src/refractor/visitors/open-api-3-1/reference/index.mjs +16 -0
  160. package/src/refractor/visitors/open-api-3-1/request-body/index.cjs +21 -0
  161. package/src/refractor/visitors/open-api-3-1/request-body/index.mjs +16 -0
  162. package/src/refractor/visitors/open-api-3-1/response/index.cjs +21 -0
  163. package/src/refractor/visitors/open-api-3-1/response/index.mjs +16 -0
  164. package/src/refractor/visitors/open-api-3-1/responses/index.cjs +21 -0
  165. package/src/refractor/visitors/open-api-3-1/responses/index.mjs +16 -0
  166. package/src/refractor/visitors/open-api-3-1/schema/$defsVisitor.cjs +19 -0
  167. package/src/refractor/visitors/open-api-3-1/schema/$defsVisitor.mjs +16 -0
  168. package/src/refractor/visitors/open-api-3-1/schema/AllOfVisitor.cjs +15 -0
  169. package/src/refractor/visitors/open-api-3-1/schema/AllOfVisitor.mjs +11 -0
  170. package/src/refractor/visitors/open-api-3-1/schema/AnyOfVisitor.cjs +15 -0
  171. package/src/refractor/visitors/open-api-3-1/schema/AnyOfVisitor.mjs +11 -0
  172. package/src/refractor/visitors/open-api-3-1/schema/DependentSchemasVisitor.cjs +15 -0
  173. package/src/refractor/visitors/open-api-3-1/schema/DependentSchemasVisitor.mjs +11 -0
  174. package/src/refractor/visitors/open-api-3-1/schema/OneOfVisitor.cjs +15 -0
  175. package/src/refractor/visitors/open-api-3-1/schema/OneOfVisitor.mjs +11 -0
  176. package/src/refractor/visitors/open-api-3-1/schema/PatternPropertiesVisitor.cjs +15 -0
  177. package/src/refractor/visitors/open-api-3-1/schema/PatternPropertiesVisitor.mjs +11 -0
  178. package/src/refractor/visitors/open-api-3-1/schema/PrefixItemsVisitor.cjs +15 -0
  179. package/src/refractor/visitors/open-api-3-1/schema/PrefixItemsVisitor.mjs +11 -0
  180. package/src/refractor/visitors/open-api-3-1/schema/PropertiesVisitor.cjs +15 -0
  181. package/src/refractor/visitors/open-api-3-1/schema/PropertiesVisitor.mjs +11 -0
  182. package/src/refractor/visitors/open-api-3-1/schema/index.cjs +75 -0
  183. package/src/refractor/visitors/open-api-3-1/schema/index.mjs +69 -0
  184. package/src/refractor/visitors/open-api-3-1/security-requirement/index.cjs +21 -0
  185. package/src/refractor/visitors/open-api-3-1/security-requirement/index.mjs +16 -0
  186. package/src/refractor/visitors/open-api-3-1/security-scheme/index.cjs +21 -0
  187. package/src/refractor/visitors/open-api-3-1/security-scheme/index.mjs +16 -0
  188. package/src/refractor/visitors/open-api-3-1/server/index.cjs +21 -0
  189. package/src/refractor/visitors/open-api-3-1/server/index.mjs +16 -0
  190. package/src/refractor/visitors/open-api-3-1/server-variable/index.cjs +21 -0
  191. package/src/refractor/visitors/open-api-3-1/server-variable/index.mjs +16 -0
  192. package/src/refractor/visitors/open-api-3-1/tag/index.cjs +21 -0
  193. package/src/refractor/visitors/open-api-3-1/tag/index.mjs +16 -0
  194. package/src/refractor/visitors/open-api-3-1/xml/index.cjs +21 -0
  195. package/src/refractor/visitors/open-api-3-1/xml/index.mjs +16 -0
  196. package/src/traversal/visitor.cjs +57 -0
  197. package/src/traversal/visitor.mjs +54 -0
  198. package/types/apidom-ns-openapi-3-1.d.ts +2745 -0
package/README.md ADDED
@@ -0,0 +1,472 @@
1
+ # @speclynx/apidom-ns-openapi-3-1
2
+
3
+ `@speclynx/apidom-ns-openapi-3-1` contains ApiDOM namespace specific to **OpenAPI 3.1.x specification**, supporting the following versions:
4
+
5
+ - [OpenAPI 3.1.0](https://spec.openapis.org/oas/v3.1.0.html)
6
+ - [OpenAPI 3.1.1](https://spec.openapis.org/oas/v3.1.1.html)
7
+ - [OpenAPI 3.1.2](https://spec.openapis.org/oas/v3.1.2.html)
8
+
9
+ ## Installation
10
+
11
+ You can install this package via [npm CLI](https://docs.npmjs.com/cli) by running the following command:
12
+
13
+ ```sh
14
+ $ npm install @speclynx/apidom-ns-openapi-3-1
15
+ ```
16
+
17
+ ## OpenAPI 3.1.0 namespace
18
+
19
+ OpenAPI 3.1.0 namespace consists of [number of elements](https://github.com/speclynx/apidom/tree/main/packages/apidom-ns-openapi-3-1/src/elements) implemented on top
20
+ of [primitive ones](https://github.com/refractproject/minim/tree/master/lib/primitives).
21
+
22
+ ```js
23
+ import { createNamespace } from '@speclynx/apidom-core';
24
+ import openApi3_1Namespace from '@speclynx/apidom-ns-openapi-3-1';
25
+
26
+ const namespace = createNamespace(openApi3_1Namespace);
27
+
28
+ const objectElement = new namespace.elements.Object();
29
+ const openApiElement = new namespace.elements.OpenApi3_1();
30
+ ```
31
+
32
+ When namespace instance is created in this way, it will extend the base namespace
33
+ with the namespace provided as an argument.
34
+
35
+ Elements from the namespace can also be used directly by importing them.
36
+
37
+ ```js
38
+ import { OpenApi3_1Element, InfoElement } from '@speclynx/apidom-ns-openapi-3-1';
39
+
40
+ const infoElement = new InfoElement();
41
+ const openApiElement = new OpenApi3_1Element();
42
+ ```
43
+
44
+ ## Predicates
45
+
46
+ This package exposes [predicates](https://github.com/speclynx/apidom/blob/main/packages/apidom-ns-openapi-3-1/src/predicates.ts)
47
+ for all higher order elements that are part of this namespace.
48
+
49
+ ```js
50
+ import { isOpenApi3_1Element, OpenApi3_1Element } from '@speclynx/apidom-ns-openapi-3-1';
51
+
52
+ const openApiElement = new OpenApi3_1Element();
53
+
54
+ isOpenApi3_1Element(openApiElement); // => true
55
+ ```
56
+
57
+ ## Traversal
58
+
59
+ Traversing ApiDOM in this namespace is possible by using `visit` function from `apidom` package.
60
+ This package comes with its own [keyMap](https://github.com/speclynx/apidom/blob/main/packages/apidom-ns-openapi-3-1/src/traversal/visitor.ts#L11) and [nodeTypeGetter](https://github.com/speclynx/apidom/blob/main/packages/apidom-ns-openapi-3-1/src/traversal/visitor.ts#L4).
61
+ To learn more about these `visit` configuration options please refer to [@speclynx/apidom-ast documentation](https://github.com/speclynx/apidom/blob/main/packages/apidom-ast/README.md#visit).
62
+
63
+ ```js
64
+ import { visit } from '@speclynx/apidom-core';
65
+ import { OpenApi3_1Element, keyMap, getNodeType } from '@speclynx/apidom-ns-openapi-3-1';
66
+
67
+ const element = new OpenApi3_1Element();
68
+
69
+ const visitor = {
70
+ OpenApi3_1Element(openApiElement) {
71
+ console.dir(openApiElement);
72
+ },
73
+ };
74
+
75
+ visit(element, visitor, { keyMap, nodeTypeGetter: getNodeType });
76
+ ```
77
+
78
+ ## Refractors
79
+
80
+ Refractor is a special layer inside the namespace that can transform either JavaScript structures
81
+ or generic ApiDOM structures into structures built from elements of this namespace.
82
+
83
+ **Refracting JavaScript structures**:
84
+
85
+ ```js
86
+ import { InfoElement } from '@speclynx/apidom-ns-openapi-3-1';
87
+
88
+ const object = {
89
+ title: 'my title',
90
+ description: 'my description',
91
+ version: '0.1.0',
92
+ };
93
+
94
+ InfoElement.refract(object); // => InfoElement({ title, description, version })
95
+ ```
96
+
97
+ **Refracting generic ApiDOM structures**:
98
+
99
+ ```js
100
+ import { ObjectElement } from '@speclynx/apidom-core';
101
+ import { InfoElement } from '@speclynx/apidom-ns-openapi-3-1';
102
+
103
+ const objectElement = new ObjectElement({
104
+ title: 'my title',
105
+ description: 'my description',
106
+ version: '0.1.0',
107
+ });
108
+
109
+ InfoElement.refract(objectElement); // => InfoElement({ title = 'my title', description = 'my description', version = '0.1.0' })
110
+ ```
111
+
112
+ ### Refractor plugins
113
+
114
+ Refractors can accept plugins as a second argument of refract static method.
115
+
116
+ ```js
117
+ import { ObjectElement } from '@speclynx/apidom-core';
118
+ import { InfoElement } from '@speclynx/apidom-ns-openapi-3-1';
119
+
120
+ const objectElement = new ObjectElement({
121
+ title: 'my title',
122
+ description: 'my description',
123
+ version: '0.1.0',
124
+ });
125
+
126
+ const plugin = ({ predicates, namespace }) => ({
127
+ name: 'plugin',
128
+ pre() {
129
+ console.dir('runs before traversal');
130
+ },
131
+ visitor: {
132
+ InfoElement(infoElement) {
133
+ infoElement.version = '2.0.0';
134
+ },
135
+ },
136
+ post() {
137
+ console.dir('runs after traversal');
138
+ },
139
+ });
140
+
141
+ InfoElement.refract(objectElement, { plugins: [plugin] }); // => InfoElement({ title = 'my title', description = 'my description', version = '2.0.0' })
142
+ ```
143
+
144
+ You can define as many plugins as needed to enhance the resulting namespaced ApiDOM structure.
145
+ If multiple plugins with the same visitor method are defined, they run in parallel (just like in Babel).
146
+
147
+ #### Replace Empty Element plugin
148
+
149
+ This plugin is specific to YAML 1.2 format, which allows defining key-value pairs with empty key,
150
+ empty value, or both. If the value is not provided in YAML format, this plugin compensates for
151
+ this missing value with the most appropriate semantic element type.
152
+
153
+ ```js
154
+ import { parse } from '@speclynx/apidom-parser-adapter-yaml-1-2';
155
+ import { refractorPluginReplaceEmptyElement, OpenApi3_1Element } from '@speclynx/apidom-ns-openapi-3-1';
156
+
157
+ const yamlDefinition = `
158
+ openapi: 3.1.0
159
+ info:
160
+ `;
161
+ const apiDOM = await parse(yamlDefinition);
162
+ const openApiElement = OpenApi3_1Element.refract(apiDOM.result, {
163
+ plugins: [refractorPluginReplaceEmptyElement()],
164
+ });
165
+
166
+ // =>
167
+ // (OpenApi3_1Element
168
+ // (MemberElement
169
+ // (StringElement)
170
+ // (OpenapiElement))
171
+ // (MemberElement
172
+ // (StringElement)
173
+ // (InfoElement)))
174
+
175
+ // => without the plugin the result would be as follows:
176
+ // (OpenApi3_1Element
177
+ // (MemberElement
178
+ // (StringElement)
179
+ // (OpenapiElement))
180
+ // (MemberElement
181
+ // (StringElement)
182
+ // (StringElement)))
183
+ ```
184
+
185
+ #### Normalize Operation.operationId fields plugin
186
+
187
+ Existing `Operation.operationId` fields are normalized into snake case form.
188
+ Operation Objects, that do not define operationId field, are left untouched.
189
+ Original operationId is stored in meta and as new `__originalOperationId` field.
190
+ This plugin also guarantees the uniqueness of all defined Operation.operationId fields,
191
+ and make sure Link.operationId fields are pointing to correct and normalized Operation.operationId fields.
192
+
193
+ ```js
194
+ import { toValue } from '@speclynx/apidom-core';
195
+ import { parse } from '@speclynx/apidom-parser-adapter-yaml-1-2';
196
+ import { refractorPluginNormalizeOperationIds, OpenApi3_1Element } from '@speclynx/apidom-ns-openapi-3-1';
197
+
198
+ const yamlDefinition = `
199
+ openapi: 3.1.0
200
+ paths:
201
+ /:
202
+ get:
203
+ operationId: get operation ^
204
+ `;
205
+ const apiDOM = await parse(yamlDefinition);
206
+ const openApiElement = OpenApi3_1Element.refract(apiDOM.result, {
207
+ plugins: [refractorPluginNormalizeOperationIds()],
208
+ });
209
+
210
+ toValue(openApiElement);
211
+ // =>
212
+ // {
213
+ // "openapi": "3.1.0",
214
+ // "paths": {
215
+ // "/": {
216
+ // "get": {
217
+ // "operationId": "getoperation_"
218
+ // }
219
+ // }
220
+ // }
221
+ // }
222
+ ```
223
+ This plugin also accepts custom normalization function that will determine how normalized Operation.operationId fields
224
+ should look like.
225
+
226
+ ```typescript
227
+ import { toValue } from '@speclynx/apidom-core';
228
+ import { parse } from '@speclynx/apidom-parser-adapter-yaml-1-2';
229
+ import { refractorPluginNormalizeOperationIds, OpenApi3_1Element } from '@speclynx/apidom-ns-openapi-3-1';
230
+
231
+ const yamlDefinition = `
232
+ openapi: 3.1.0
233
+ paths:
234
+ /:
235
+ get:
236
+ operationId: get operation ^
237
+ `;
238
+ const apiDOM = await parse(yamlDefinition);
239
+ const openApiElement = OpenApi3_1Element.refract(apiDOM.result, {
240
+ plugins: [refractorPluginNormalizeOperationIds({
241
+ operationIdNormalizer: (operationId: string, path: string, method: string): string => {
242
+ // operationId - value of Original.operationId field
243
+ // path - field pattern of Paths Object under which Path Item containing this Operation is registered
244
+ // method - name of HTTP method under which the Operation is registered in Path Item
245
+ },
246
+ })],
247
+ });
248
+
249
+ toValue(openApiElement);
250
+ // =>
251
+ // {
252
+ // "openapi": "3.1.0",
253
+ // "paths": {
254
+ // "/": {
255
+ // "get": {
256
+ // "operationId": "<normalized-operation-id>"
257
+ // }
258
+ // }
259
+ // }
260
+ // }
261
+ ```
262
+
263
+ #### Normalize Parameter Objects plugin
264
+
265
+ Duplicates Parameters from Path Items to Operation Objects using following rules:
266
+
267
+ - If a parameter is already defined at the Path Item, the new definition will override it but can never remove it
268
+ - The list MUST NOT include duplicated parameters
269
+ - A unique parameter is defined by a combination of a name and location.
270
+
271
+ ```js
272
+ import { toValue } from '@speclynx/apidom-core';
273
+ import { parse } from '@speclynx/apidom-parser-adapter-yaml-1-2';
274
+ import { refractorPluginNormalizeParameters, OpenApi3_1Element } from '@speclynx/apidom-ns-openapi-3-1';
275
+
276
+ const yamlDefinition = `
277
+ openapi: 3.1.0
278
+ paths:
279
+ /:
280
+ parameters:
281
+ - name: param1
282
+ in: query
283
+ - name: param2
284
+ in: query
285
+ get: {}
286
+ `;
287
+ const apiDOM = await parse(yamlDefinition);
288
+ const openApiElement = OpenApi3_1Element.refract(apiDOM.result, {
289
+ plugins: [refractorPluginNormalizeParameters()],
290
+ });
291
+
292
+ toValue(openApiElement);
293
+ // =>
294
+ // {
295
+ // "openapi": "3.1.0",
296
+ // "paths": {
297
+ // "/": {
298
+ // "parameters": [
299
+ // {
300
+ // "name": "param1",
301
+ // "in": "query"
302
+ // },
303
+ // {
304
+ // "name": "param2",
305
+ // "in": "query"
306
+ // }
307
+ // ],
308
+ // "get": {
309
+ // "parameters": [
310
+ // {
311
+ // "name": "param1",
312
+ // "in": "query"
313
+ // },
314
+ // {
315
+ // "name": "param2",
316
+ // "in": "query"
317
+ // }
318
+ // ],
319
+ // }
320
+ // }
321
+ // }
322
+ ```
323
+
324
+ #### Normalize Security Requirements Objects plugin
325
+
326
+ `Operation.security` definition overrides any declared top-level security from OpenAPI.security field.
327
+ If Operation.security field is not defined, this field will inherit security from OpenAPI.security field.
328
+
329
+ ```js
330
+ import { toValue } from '@speclynx/apidom-core';
331
+ import { parse } from '@speclynx/apidom-parser-adapter-yaml-1-2';
332
+ import { refractorPluginNormalizeSecurityRequirements, OpenApi3_1Element } from '@speclynx/apidom-ns-openapi-3-1';
333
+
334
+ const yamlDefinition = `
335
+ openapi: 3.1.0
336
+ security:
337
+ - petstore_auth:
338
+ - write:pets
339
+ - read:pets
340
+ paths:
341
+ /:
342
+ get: {}
343
+ `;
344
+ const apiDOM = await parse(yamlDefinition);
345
+ const openApiElement = OpenApi3_1Element.refract(apiDOM.result, {
346
+ plugins: [refractorPluginNormalizeSecurityRequirements()],
347
+ });
348
+
349
+ toValue(openApiElement);
350
+ // =>
351
+ // {
352
+ // "openapi": "3.1.0",
353
+ // "security": [
354
+ // {
355
+ // "petstore_auth": [
356
+ // "write:pets",
357
+ // "read:pets"
358
+ // ]
359
+ // }
360
+ // ],
361
+ // "paths": {
362
+ // "/": {
363
+ // "get": {
364
+ // "security": [
365
+ // {
366
+ // "petstore_auth": [
367
+ // "write:pets",
368
+ // "read:pets"
369
+ // ]
370
+ // }
371
+ // ]
372
+ // }
373
+ // }
374
+ // }
375
+ // }
376
+ ```
377
+
378
+ #### Normalize Server Objects plugin
379
+
380
+ List of Server Objects can be defined in OpenAPI 3.1 on multiple levels:
381
+
382
+ - OpenAPI.servers
383
+ - PathItem.servers
384
+ - Operation.servers
385
+
386
+ If an alternative server object is specified at the Path Item Object level, it will override OpenAPI.servers.
387
+ If an alternative server object is specified at the Operation Object level, it will override PathItem.servers and OpenAPI.servers respectively.
388
+
389
+ ```js
390
+ import { toValue } from '@speclynx/apidom-core';
391
+ import { parse } from '@speclynx/apidom-parser-adapter-yaml-1-2';
392
+ import { refractorPluginNormalizeServers, OpenApi3_1Element } from '@speclynx/apidom-ns-openapi-3-1';
393
+
394
+ const yamlDefinition = `
395
+ openapi: 3.1.0
396
+ servers:
397
+ - url: https://example.com/
398
+ description: production server
399
+ paths:
400
+ /:
401
+ get: {}
402
+ `;
403
+ const apiDOM = await parse(yamlDefinition);
404
+ const openApiElement = OpenApi3_1Element.refract(apiDOM.result, {
405
+ plugins: [refractorPluginNormalizeServers()],
406
+ });
407
+
408
+ toValue(openApiElement);
409
+ // =>
410
+ // {
411
+ // "openapi": "3.1.0",
412
+ // "servers": [
413
+ // {
414
+ // "url": "https://example.com/",
415
+ // "description": "production server"
416
+ // }
417
+ // ],
418
+ // "paths": {
419
+ // "/": {
420
+ // "servers": [
421
+ // {
422
+ // "url": "https://example.com/",
423
+ // "description": "production server"
424
+ // }
425
+ // ],
426
+ // "get": {
427
+ // "servers": [
428
+ // {
429
+ // "url": "https://example.com/",
430
+ // "description": "production server"
431
+ // }
432
+ // ]
433
+ // }
434
+ // }
435
+ // }
436
+ // }
437
+ ```
438
+
439
+ ## Implementation progress
440
+
441
+ Only fully implemented specification objects should be checked here.
442
+
443
+ - [x] [OpenAPI Object](https://spec.openapis.org/oas/v3.1.2.html#openapi-object)
444
+ - [x] [Info Object](https://spec.openapis.org/oas/v3.1.2.html#info-object)
445
+ - [x] [Contact Object](https://spec.openapis.org/oas/v3.1.2.html#contact-object)
446
+ - [x] [License Object](https://spec.openapis.org/oas/v3.1.2.html#license-object)
447
+ - [x] [Server Object](https://spec.openapis.org/oas/v3.1.2.html#server-object)
448
+ - [x] [Server Variable Object](https://spec.openapis.org/oas/v3.1.2.html#server-variable-object)
449
+ - [x] [Components Object](https://spec.openapis.org/oas/v3.1.2.html#components-object)
450
+ - [x] [Paths Object](https://spec.openapis.org/oas/v3.1.2.html#paths-object)
451
+ - [x] [Path Item Object](https://spec.openapis.org/oas/v3.1.2.html#path-item-object)
452
+ - [x] [Operation Object](https://spec.openapis.org/oas/v3.1.2.html#operation-object)
453
+ - [x] [External Documentation Object](https://spec.openapis.org/oas/v3.1.2.html#external-documentation-object)
454
+ - [x] [Parameter Object](https://spec.openapis.org/oas/v3.1.2.html#parameter-object)
455
+ - [x] [Request Body Object](https://spec.openapis.org/oas/v3.1.2.html#request-body-object)
456
+ - [x] [Media Type Object](https://spec.openapis.org/oas/v3.1.2.html#media-type-object)
457
+ - [x] [Encoding Object](https://spec.openapis.org/oas/v3.1.2.html#encoding-object)
458
+ - [x] [Responses Object](https://spec.openapis.org/oas/v3.1.2.html#responses-object)
459
+ - [x] [Callback Object](https://spec.openapis.org/oas/v3.1.2.html#callback-object)
460
+ - [x] [Example Object](https://spec.openapis.org/oas/v3.1.2.html#example-object)
461
+ - [x] [Link Object](https://spec.openapis.org/oas/v3.1.2.html#link-object)
462
+ - [x] [Header Object](https://spec.openapis.org/oas/v3.1.2.html#header-object)
463
+ - [x] [Tag Object](https://spec.openapis.org/oas/v3.1.2.html#tag-object)
464
+ - [x] [Reference Object](https://spec.openapis.org/oas/v3.1.2.html#reference-object)
465
+ - [x] [Schema Object](https://spec.openapis.org/oas/v3.1.2.html#schema-object)
466
+ - [x] [Discriminator Object](https://spec.openapis.org/oas/v3.1.2.html#discriminator-object)
467
+ - [x] [XML Object](https://spec.openapis.org/oas/v3.1.2.html#xml-object)
468
+ - [x] [Security Scheme Object](https://spec.openapis.org/oas/v3.1.2.html#security-scheme-object)
469
+ - [x] [OAuth Flows Object](https://spec.openapis.org/oas/v3.1.2.html#oauth-flows-object)
470
+ - [x] [OAuth Flow Object](https://spec.openapis.org/oas/v3.1.2.html#oauth-flow-object)
471
+ - [x] [Security Requirement Object](https://spec.openapis.org/oas/v3.1.2.html#security-requirement-object)
472
+ - [x] [Specification Extensions](https://spec.openapis.org/oas/v3.1.2.html#specification-extensions)