@swagger-api/apidom-ns-openapi-3-1 1.0.0-beta.9 → 1.0.0-rc.0

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 (54) hide show
  1. package/CHANGELOG.md +187 -0
  2. package/README.md +371 -1
  3. package/dist/apidom-ns-openapi-3-1.browser.js +29414 -24750
  4. package/dist/apidom-ns-openapi-3-1.browser.min.js +1 -1
  5. package/package.json +10 -9
  6. package/src/elements/Schema.cjs +2 -427
  7. package/src/elements/Schema.mjs +2 -427
  8. package/src/index.cjs +3 -1
  9. package/src/index.mjs +1 -0
  10. package/src/refractor/plugins/normalize-discriminator-mapping.cjs +173 -0
  11. package/src/refractor/plugins/normalize-discriminator-mapping.mjs +167 -0
  12. package/src/refractor/plugins/replace-empty-element.cjs +2 -1
  13. package/src/refractor/plugins/replace-empty-element.mjs +3 -2
  14. package/src/refractor/specification.cjs +55 -157
  15. package/src/refractor/specification.mjs +13 -115
  16. package/src/refractor/toolbox.cjs +2 -2
  17. package/src/refractor/toolbox.mjs +1 -1
  18. package/src/refractor/visitors/open-api-3-1/components/SchemasVisitor.cjs +13 -0
  19. package/src/refractor/visitors/open-api-3-1/components/SchemasVisitor.mjs +13 -2
  20. package/src/refractor/visitors/open-api-3-1/schema/$defsVisitor.cjs +2 -10
  21. package/src/refractor/visitors/open-api-3-1/schema/$defsVisitor.mjs +4 -9
  22. package/src/refractor/visitors/open-api-3-1/schema/AllOfVisitor.cjs +2 -25
  23. package/src/refractor/visitors/open-api-3-1/schema/AllOfVisitor.mjs +2 -23
  24. package/src/refractor/visitors/open-api-3-1/schema/AnyOfVisitor.cjs +2 -25
  25. package/src/refractor/visitors/open-api-3-1/schema/AnyOfVisitor.mjs +2 -23
  26. package/src/refractor/visitors/open-api-3-1/schema/DependentSchemasVisitor.cjs +2 -14
  27. package/src/refractor/visitors/open-api-3-1/schema/DependentSchemasVisitor.mjs +2 -12
  28. package/src/refractor/visitors/open-api-3-1/schema/OneOfVisitor.cjs +2 -25
  29. package/src/refractor/visitors/open-api-3-1/schema/OneOfVisitor.mjs +2 -23
  30. package/src/refractor/visitors/open-api-3-1/schema/PatternPropertiesVisitor.cjs +2 -14
  31. package/src/refractor/visitors/open-api-3-1/schema/PatternPropertiesVisitor.mjs +2 -12
  32. package/src/refractor/visitors/open-api-3-1/schema/PrefixItemsVisitor.cjs +2 -25
  33. package/src/refractor/visitors/open-api-3-1/schema/PrefixItemsVisitor.mjs +2 -23
  34. package/src/refractor/visitors/open-api-3-1/schema/PropertiesVisitor.cjs +2 -14
  35. package/src/refractor/visitors/open-api-3-1/schema/PropertiesVisitor.mjs +2 -12
  36. package/src/refractor/visitors/open-api-3-1/schema/index.cjs +10 -31
  37. package/src/refractor/visitors/open-api-3-1/schema/index.mjs +12 -33
  38. package/types/apidom-ns-openapi-3-1.d.ts +183 -408
  39. package/src/refractor/visitors/open-api-3-1/schema/$refVisitor.cjs +0 -16
  40. package/src/refractor/visitors/open-api-3-1/schema/$refVisitor.mjs +0 -12
  41. package/src/refractor/visitors/open-api-3-1/schema/$vocabularyVisitor.cjs +0 -16
  42. package/src/refractor/visitors/open-api-3-1/schema/$vocabularyVisitor.mjs +0 -12
  43. package/src/refractor/visitors/open-api-3-1/schema/DependentRequiredVisitor.cjs +0 -16
  44. package/src/refractor/visitors/open-api-3-1/schema/DependentRequiredVisitor.mjs +0 -12
  45. package/src/refractor/visitors/open-api-3-1/schema/EnumVisitor.cjs +0 -16
  46. package/src/refractor/visitors/open-api-3-1/schema/EnumVisitor.mjs +0 -12
  47. package/src/refractor/visitors/open-api-3-1/schema/ExamplesVisitor.cjs +0 -16
  48. package/src/refractor/visitors/open-api-3-1/schema/ExamplesVisitor.mjs +0 -12
  49. package/src/refractor/visitors/open-api-3-1/schema/ParentSchemaAwareVisitor.cjs +0 -17
  50. package/src/refractor/visitors/open-api-3-1/schema/ParentSchemaAwareVisitor.mjs +0 -13
  51. package/src/refractor/visitors/open-api-3-1/schema/RequiredVisitor.cjs +0 -16
  52. package/src/refractor/visitors/open-api-3-1/schema/RequiredVisitor.mjs +0 -12
  53. package/src/refractor/visitors/open-api-3-1/schema/TypeVisitor.cjs +0 -21
  54. package/src/refractor/visitors/open-api-3-1/schema/TypeVisitor.mjs +0 -17
package/CHANGELOG.md CHANGED
@@ -3,6 +3,193 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [1.0.0-rc.0](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.51...v1.0.0-rc.0) (2025-10-21)
7
+
8
+ ### Performance Improvements
9
+
10
+ - flatten sourceMap to improve memory usage ([#4964](https://github.com/swagger-api/apidom/issues/4964)) ([bda1edf](https://github.com/swagger-api/apidom/commit/bda1edf7b1b37adc728b8632337b22866e33fa4a))
11
+
12
+ # [1.0.0-beta.51](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.50...v1.0.0-beta.51) (2025-10-14)
13
+
14
+ **Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
15
+
16
+ # [1.0.0-beta.50](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.49...v1.0.0-beta.50) (2025-09-26)
17
+
18
+ **Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
19
+
20
+ # [1.0.0-beta.49](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.48...v1.0.0-beta.49) (2025-09-22)
21
+
22
+ **Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
23
+
24
+ # [1.0.0-beta.48](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.47...v1.0.0-beta.48) (2025-09-09)
25
+
26
+ **Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
27
+
28
+ # [1.0.0-beta.47](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.46...v1.0.0-beta.47) (2025-09-01)
29
+
30
+ ### Features
31
+
32
+ - **ls:** disable newly added rules for 3.1 spec ([#4997](https://github.com/swagger-api/apidom/issues/4997)) ([d5b16f8](https://github.com/swagger-api/apidom/commit/d5b16f82a916aea70929d2f3ff5be04769d8d8d3))
33
+
34
+ # [1.0.0-beta.46](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.45...v1.0.0-beta.46) (2025-08-19)
35
+
36
+ **Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
37
+
38
+ # [1.0.0-beta.45](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.44...v1.0.0-beta.45) (2025-08-01)
39
+
40
+ **Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
41
+
42
+ # [1.0.0-beta.44](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.43...v1.0.0-beta.44) (2025-07-07)
43
+
44
+ ### Features
45
+
46
+ - add PoC of handling discriminator for allOf case in OpenAPI 3.1 ([#4959](https://github.com/swagger-api/apidom/issues/4959)) ([4eee665](https://github.com/swagger-api/apidom/commit/4eee66574c9ff4ab08cbd3f89d32247d07cde7e2))
47
+ - add PoC of handling discriminator for oneOf/anyOf cases in OpenAPI 3.1 ([#4952](https://github.com/swagger-api/apidom/issues/4952)) ([e8ddbb7](https://github.com/swagger-api/apidom/commit/e8ddbb7522476903a153474cd6a00a2d505735db))
48
+
49
+ # [1.0.0-beta.43](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.42...v1.0.0-beta.43) (2025-06-13)
50
+
51
+ **Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
52
+
53
+ # [1.0.0-beta.42](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.41...v1.0.0-beta.42) (2025-06-06)
54
+
55
+ **Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
56
+
57
+ # [1.0.0-beta.41](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.40...v1.0.0-beta.41) (2025-06-04)
58
+
59
+ **Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
60
+
61
+ # [1.0.0-beta.40](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.39...v1.0.0-beta.40) (2025-05-30)
62
+
63
+ **Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
64
+
65
+ # [1.0.0-beta.39](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.38...v1.0.0-beta.39) (2025-05-20)
66
+
67
+ **Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
68
+
69
+ # [1.0.0-beta.38](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.37...v1.0.0-beta.38) (2025-05-16)
70
+
71
+ **Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
72
+
73
+ # [1.0.0-beta.37](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.36...v1.0.0-beta.37) (2025-05-12)
74
+
75
+ **Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
76
+
77
+ # [1.0.0-beta.36](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.35...v1.0.0-beta.36) (2025-05-06)
78
+
79
+ **Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
80
+
81
+ # [1.0.0-beta.35](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.34...v1.0.0-beta.35) (2025-05-02)
82
+
83
+ **Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
84
+
85
+ # [1.0.0-beta.34](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.33...v1.0.0-beta.34) (2025-05-02)
86
+
87
+ ### Bug Fixes
88
+
89
+ - **ns-openapi-3-1:** use spec compliant JSON Pointer implementation ([#4880](https://github.com/swagger-api/apidom/issues/4880)) ([9499aa8](https://github.com/swagger-api/apidom/commit/9499aa8733445f15ec7441c7f87b89dab8542c49)), closes [#4870](https://github.com/swagger-api/apidom/issues/4870)
90
+
91
+ # [1.0.0-beta.33](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.32...v1.0.0-beta.33) (2025-04-30)
92
+
93
+ **Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
94
+
95
+ # [1.0.0-beta.32](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.31...v1.0.0-beta.32) (2025-04-28)
96
+
97
+ **Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
98
+
99
+ # [1.0.0-beta.31](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.30...v1.0.0-beta.31) (2025-04-24)
100
+
101
+ **Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
102
+
103
+ # [1.0.0-beta.30](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.29...v1.0.0-beta.30) (2025-03-17)
104
+
105
+ **Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
106
+
107
+ # [1.0.0-beta.29](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.28...v1.0.0-beta.29) (2025-03-17)
108
+
109
+ ### Bug Fixes
110
+
111
+ - **security:** eliminate CVE-2025-27789 ([#4797](https://github.com/swagger-api/apidom/issues/4797)) ([af335c3](https://github.com/swagger-api/apidom/commit/af335c3d53616b7991acc74329e61d350398997a))
112
+
113
+ # [1.0.0-beta.28](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.27...v1.0.0-beta.28) (2025-03-12)
114
+
115
+ **Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
116
+
117
+ # [1.0.0-beta.27](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.26...v1.0.0-beta.27) (2025-03-12)
118
+
119
+ **Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
120
+
121
+ # [1.0.0-beta.26](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.25...v1.0.0-beta.26) (2025-03-12)
122
+
123
+ **Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
124
+
125
+ # [1.0.0-beta.25](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.24...v1.0.0-beta.25) (2025-03-12)
126
+
127
+ **Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
128
+
129
+ # [1.0.0-beta.24](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.23...v1.0.0-beta.24) (2025-03-12)
130
+
131
+ **Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
132
+
133
+ # [1.0.0-beta.23](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.22...v1.0.0-beta.23) (2025-03-12)
134
+
135
+ **Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
136
+
137
+ # [1.0.0-beta.22](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.21...v1.0.0-beta.22) (2025-03-12)
138
+
139
+ **Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
140
+
141
+ # [1.0.0-beta.21](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.20...v1.0.0-beta.21) (2025-03-12)
142
+
143
+ **Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
144
+
145
+ # [1.0.0-beta.20](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.19...v1.0.0-beta.20) (2025-03-12)
146
+
147
+ **Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
148
+
149
+ # [1.0.0-beta.19](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.18...v1.0.0-beta.19) (2025-03-12)
150
+
151
+ **Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
152
+
153
+ # [1.0.0-beta.18](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.17...v1.0.0-beta.18) (2025-03-12)
154
+
155
+ **Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
156
+
157
+ # [1.0.0-beta.17](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.16...v1.0.0-beta.17) (2025-03-12)
158
+
159
+ **Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
160
+
161
+ # [1.0.0-beta.16](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.15...v1.0.0-beta.16) (2025-03-12)
162
+
163
+ **Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
164
+
165
+ # [1.0.0-beta.15](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.14...v1.0.0-beta.15) (2025-03-11)
166
+
167
+ **Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
168
+
169
+ # [1.0.0-beta.14](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.13...v1.0.0-beta.14) (2025-03-11)
170
+
171
+ **Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
172
+
173
+ # [1.0.0-beta.13](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.12...v1.0.0-beta.13) (2025-03-10)
174
+
175
+ **Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
176
+
177
+ # [1.0.0-beta.12](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.11...v1.0.0-beta.12) (2025-02-11)
178
+
179
+ ### Bug Fixes
180
+
181
+ - **ns-openapi-3-1:** import only JSON Schema 2020-12 namespace ([#4716](https://github.com/swagger-api/apidom/issues/4716)) ([ab1ca15](https://github.com/swagger-api/apidom/commit/ab1ca15aeecc0d8e8621afb706ec76ee007183d1)), closes [#4705](https://github.com/swagger-api/apidom/issues/4705)
182
+
183
+ # [1.0.0-beta.11](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.10...v1.0.0-beta.11) (2025-01-27)
184
+
185
+ ### Features
186
+
187
+ - **ns-openapi-3-1:** use JSON Schema 2020-12 namespace ([#4691](https://github.com/swagger-api/apidom/issues/4691)) ([f68adb7](https://github.com/swagger-api/apidom/commit/f68adb7645b692152c80537828247e9ad71e5933)), closes [#1822](https://github.com/swagger-api/apidom/issues/1822)
188
+
189
+ # [1.0.0-beta.10](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.9...v1.0.0-beta.10) (2025-01-25)
190
+
191
+ **Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
192
+
6
193
  # [1.0.0-beta.9](https://github.com/swagger-api/apidom/compare/v1.0.0-beta.8...v1.0.0-beta.9) (2025-01-23)
7
194
 
8
195
  **Note:** Version bump only for package @swagger-api/apidom-ns-openapi-3-1
package/README.md CHANGED
@@ -52,7 +52,7 @@ isOpenApi3_1Element(openApiElement); // => true
52
52
 
53
53
  ## Traversal
54
54
 
55
- Traversing ApiDOM in this namespace is possible by using `visit` function from `apidom` package.
55
+ Traversing ApiDOM in this namespace is possible by using `visit` function from `apidom-core` package.
56
56
  This package comes with its own [keyMap](https://github.com/swagger-api/apidom/blob/main/packages/apidom-ns-openapi-3-1/src/traversal/visitor.ts#L11) and [nodeTypeGetter](https://github.com/swagger-api/apidom/blob/main/packages/apidom-ns-openapi-3-1/src/traversal/visitor.ts#L4).
57
57
  To learn more about these `visit` configuration options please refer to [@swagger-api/apidom-ast documentation](https://github.com/swagger-api/apidom/blob/main/packages/apidom-ast/README.md#visit).
58
58
 
@@ -139,6 +139,7 @@ InfoElement.refract(objectElement, { plugins: [plugin] }); // => InfoElement({ t
139
139
 
140
140
  You can define as many plugins as needed to enhance the resulting namespaced ApiDOM structure.
141
141
  If multiple plugins with the same visitor method are defined, they run in parallel (just like in Babel).
142
+ All the plugins available in `@swagger-api/apidom-ns-openapi-3-1` are idempotent and the normalization state is stored in the root `OpenApi3_1Element` in `<storageField>`. `<storageField>` can be customized in the plugin configuration (default: `x-normalized`).
142
143
 
143
144
  #### Replace Empty Element plugin
144
145
 
@@ -431,6 +432,375 @@ toValue(openApiElement);
431
432
  // }
432
433
  // }
433
434
  ```
435
+ #### Normalize Parameter examples plugin
436
+
437
+ `parameter.examples` and `parameter.example` override `parameter.schema.examples` and `parameter.schema.example` fields. The plugin overrides only the existing `parameter.schema.examples` and `parameter.schema.example`.
438
+
439
+ - Does not apply to parameters defined under `components`.
440
+ - `parameter.examples` has precedence over deprecated `parameter.example`.
441
+
442
+ ```js
443
+ import { toValue } from '@swagger-api/apidom-core';
444
+ import { OpenApi3_1Element, refractorPluginNormalizeParameterExamples } from '@swagger-api/apidom-ns-openapi-3-1';
445
+ import { parse } from '@swagger-api/apidom-parser-adapter-yaml-1-2';
446
+
447
+ const yamlDefinition = `
448
+ openapi: 3.1.0
449
+ paths:
450
+ /:
451
+ get:
452
+ parameters:
453
+ - in: query
454
+ name: idempotent
455
+ schema:
456
+ type: number
457
+ examples: [1]
458
+ examples:
459
+ example1:
460
+ value: 2`
461
+
462
+ const apiDOM = await parse(yamlDefinition);
463
+
464
+ //default
465
+ const openApiElement = OpenApi3_1Element.refract(apiDOM.result, {
466
+ plugins: [refractorPluginNormalizeParameterExamples()],
467
+ });
468
+ toValue(openApiElement);
469
+ // =>
470
+ // {
471
+ // openapi: '3.1.0',
472
+ // paths: {
473
+ // '/': {
474
+ // get: {
475
+ // parameters: [
476
+ // {
477
+ // in: 'query',
478
+ // name: 'idempotent',
479
+ // schema: { type: 'number', examples: [ 2 ] },
480
+ // examples: { example1: { value: 2 } }
481
+ // }
482
+ // ]
483
+ // }
484
+ // }
485
+ // },
486
+ // 'x-normalized': { 'parameter-examples': [ '/paths/~1/get/parameters/0' ] }
487
+ // }
488
+
489
+ // custom storage field name
490
+ const openApiElementWithCustomField = OpenApi3_1Element.refract(apiDOM.result, {
491
+ plugins: [refractorPluginNormalizeParameterExamples({ storageField: '$$my-normalized' })],
492
+ });
493
+ toValue(openApiElementWithCustomField);
494
+ // =>
495
+ // {
496
+ // openapi: '3.1.0',
497
+ // paths: {
498
+ // '/': {
499
+ // get: {
500
+ // parameters: [
501
+ // {
502
+ // in: 'query',
503
+ // name: 'idempotent',
504
+ // schema: { type: 'number', examples: [2] },
505
+ // examples: { example1: { value: 2 } }
506
+ // }
507
+ // ]
508
+ // }
509
+ // }
510
+ // },
511
+ // '$$my-normalized': { 'parameter-examples': [ '/paths/~1/get/parameters/0' ] }
512
+ // }
513
+ ```
514
+
515
+ #### Normalize Header examples plugin
516
+
517
+ `Header.examples` and `header.example` override `header.schema.examples` and `header.schema.example` fields. The plugin overrides only the existing `header.schema.examples` and `header.schema.example`.
518
+
519
+ - Does not apply to headers defined under `components`.
520
+ - `header.examples` has precedence over deprecated `header.example`.
521
+
522
+ ```js
523
+ import { toValue } from '@swagger-api/apidom-core';
524
+ import { OpenApi3_1Element, refractorPluginNormalizeHeaderExamples } from '@swagger-api/apidom-ns-openapi-3-1';
525
+ import { parse } from '@swagger-api/apidom-parser-adapter-yaml-1-2';
526
+
527
+ const yamlDefinition = `
528
+ openapi: 3.1.0
529
+ paths:
530
+ /:
531
+ get:
532
+ responses:
533
+ "200":
534
+ headers:
535
+ content-type:
536
+ schema:
537
+ type: number
538
+ example: 1
539
+ examples:
540
+ example1:
541
+ value: 2
542
+ `
543
+ const apiDOM = await parse(yamlDefinition);
544
+
545
+ // default
546
+ const openApiElement = OpenApi3_1Element.refract(apiDOM.result, {
547
+ plugins: [refractorPluginNormalizeHeaderExamples()],
548
+ });
549
+ toValue(openApiElement);
550
+ // =>
551
+ // {
552
+ // openapi: '3.1.0',
553
+ // paths: {
554
+ // '/': {
555
+ // get: {
556
+ // responses: {
557
+ // '200': {
558
+ // headers: {
559
+ // 'content-type': {
560
+ // schema: { type: 'number', example: 2 },
561
+ // examples: { example1: { value: 2 } }
562
+ // }
563
+ // }
564
+ // }
565
+ // }
566
+ // }
567
+ // }
568
+ // },
569
+ // 'x-normalized': {
570
+ // 'header-examples': [ '/paths/~1/get/responses/200/headers/content-type' ]
571
+ // }
572
+ // }
573
+
574
+ // custom storage field name
575
+
576
+ const openApiElementWithCustomField = OpenApi3_1Element.refract(apiDOM.result, {
577
+ plugins: [refractorPluginNormalizeHeaderExamples({ storageField: '$$normalized' })],
578
+ });
579
+ toValue(openApiElementWithCustomField);
580
+ // =>
581
+ // {
582
+ // openapi: '3.1.0',
583
+ // paths: {
584
+ // '/': {
585
+ // get: {
586
+ // responses: {
587
+ // '200': {
588
+ // headers: {
589
+ // 'content-type': {
590
+ // schema: { type: 'number', example: 2 },
591
+ // examples: { example1: { value: 2 } }
592
+ // }
593
+ // }
594
+ // }
595
+ // }
596
+ // }
597
+ // }
598
+ // },
599
+ // '$$normalized': {
600
+ // 'header-examples': [ '/paths/~1/get/responses/200/headers/content-type' ]
601
+ // }
602
+ // }
603
+ ```
604
+
605
+ #### Normalize Discriminator mapping plugin
606
+ This plugin normalizes the `discriminator.mapping` field in a Schema Object by:
607
+
608
+ - Converting mapping values into inline Schema Objects when possible.
609
+ - Adding missing mapping entries based on the schema's `oneOf`, `anyOf`, or a prepared `allOf` mapping. The `allOf` mapping
610
+ is created based on the schemas defined in `components.schemas` during dereferencing.
611
+
612
+ The `discriminator.mapping` field is not modified by the plugin.
613
+
614
+ This plugin is intended to run on dereferenced OpenAPI 3.1 documents. During dereferencing Schema Objects are annotated with meta properties and the `allOf` mapping is created for Schema Objects defined in `components.schemas`.
615
+
616
+ ```json
617
+
618
+ // fixture-example.json
619
+ {
620
+ "openapi": "3.1.0",
621
+ "components": {
622
+ "schemas": {
623
+ "MyResponse": {
624
+ "type": "object",
625
+ "oneOf": [
626
+ {
627
+ "$ref": "#/components/schemas/Cat"
628
+ },
629
+ {
630
+ "$ref": "#/components/schemas/Dog"
631
+ }
632
+ ],
633
+ "discriminator": {
634
+ "propertyName": "petType"
635
+ }
636
+ },
637
+ "Pet": {
638
+ "type": "object",
639
+ "properties": {
640
+ "petType": {
641
+ "type": "string"
642
+ }
643
+ }
644
+ },
645
+ "Cat": {
646
+ "allOf": [
647
+ {
648
+ "$ref": "#/components/schemas/Pet"
649
+ },
650
+ {
651
+ "type": "object",
652
+ "properties": {
653
+ "meows": {
654
+ "type": "boolean"
655
+ }
656
+ }
657
+ }
658
+ ]
659
+ },
660
+ "Dog": {
661
+ "allOf": [
662
+ {
663
+ "$ref": "#/components/schemas/Pet"
664
+ },
665
+ {
666
+ "type": "object",
667
+ "properties": {
668
+ "barks": {
669
+ "type": "boolean"
670
+ }
671
+ }
672
+ }
673
+ ]
674
+ }
675
+ }
676
+ }
677
+ }
678
+ ```
679
+
680
+ ```js
681
+ import { toValue, dispatchRefractorPlugins } from '@swagger-api/apidom-core';
682
+ import { dereference } from '@swagger-api/apidom-reference';
683
+ import FileResolver from '@swagger-api/apidom-reference/resolve/resolvers/file';
684
+ import {
685
+ createToolbox,
686
+ refractorPluginNormalizeDiscriminatorMapping,
687
+ keyMap,
688
+ getNodeType,
689
+ mediaTypes,
690
+ } from '@swagger-api/apidom-ns-openapi-3-1';
691
+ const uri = 'path/to/fixture-example.json'; // the arbitrary file name shown above
692
+
693
+ // 1) dereference the document to annotate schemas with required metadata
694
+ const dereferenced = await dereference(uri, {
695
+ parse: { mediaType: mediaTypes.latest('json') },
696
+ resolve: {
697
+ baseURI: uri,
698
+ resolvers: [ new FileResolver({ fileAllowList: [/\.json$/] }) ],
699
+ },
700
+ dereference: { strategyOpts: { 'openapi-3-1': { dereferenceDiscriminatorMapping: true } } },
701
+ });
702
+
703
+ // 2) dispatch the plugin and pass the same baseURI
704
+ const normalized = dispatchRefractorPlugins(
705
+ dereferenced.result,
706
+ [refractorPluginNormalizeDiscriminatorMapping({ baseURI: uri })],
707
+ { toolboxCreator: createToolbox, visitorOptions: { keyMap, nodeTypeGetter: getNodeType } }
708
+ );
709
+ toValue(normalized)
710
+
711
+ // =>
712
+ // {
713
+ // openapi: '3.1.0',
714
+ // components: {
715
+ // schemas: {
716
+ // MyResponse: {
717
+ // type: 'object',
718
+ // oneOf: [
719
+ // {
720
+ // allOf: [
721
+ // {
722
+ // type: 'object',
723
+ // properties: { petType: { type: 'string' } }
724
+ // },
725
+ // {
726
+ // type: 'object',
727
+ // properties: { meows: { type: 'boolean' } }
728
+ // }
729
+ // ]
730
+ // },
731
+ // {
732
+ // allOf: [
733
+ // {
734
+ // type: 'object',
735
+ // properties: { petType: { type: 'string' } }
736
+ // },
737
+ // {
738
+ // type: 'object',
739
+ // properties: { barks: { type: 'boolean' } }
740
+ // }
741
+ // ]
742
+ // }
743
+ // ],
744
+ // discriminator: {
745
+ // propertyName: 'petType',
746
+ // 'x-normalized-mapping': {
747
+ // Cat: {
748
+ // allOf: [
749
+ // {
750
+ // type: 'object',
751
+ // properties: { petType: { type: 'string' } }
752
+ // },
753
+ // {
754
+ // type: 'object',
755
+ // properties: { meows: { type: 'boolean' } }
756
+ // }
757
+ // ]
758
+ // },
759
+ // Dog: {
760
+ // allOf: [
761
+ // {
762
+ // type: 'object',
763
+ // properties: { petType: { type: 'string' } }
764
+ // },
765
+ // {
766
+ // type: 'object',
767
+ // properties: { barks: { type: 'boolean' } }
768
+ // }
769
+ // ]
770
+ // }
771
+ // }
772
+ // }
773
+ // },
774
+ // Pet: { type: 'object', properties: { petType: { type: 'string' } } },
775
+ // Cat: {
776
+ // allOf: [
777
+ // {
778
+ // type: 'object',
779
+ // properties: { petType: { type: 'string' } }
780
+ // },
781
+ // {
782
+ // type: 'object',
783
+ // properties: { meows: { type: 'boolean' } }
784
+ // }
785
+ // ]
786
+ // },
787
+ // Dog: {
788
+ // allOf: [
789
+ // {
790
+ // type: 'object',
791
+ // properties: { petType: { type: 'string' } }
792
+ // },
793
+ // {
794
+ // type: 'object',
795
+ // properties: { barks: { type: 'boolean' } }
796
+ // }
797
+ // ]
798
+ // }
799
+ // }
800
+ // },
801
+ // 'x-normalized': { 'discriminator-mapping': [ '/components/schemas/MyResponse' ] }
802
+ // }
803
+ ```
434
804
 
435
805
  ## Implementation progress
436
806