@speclynx/apidom-ns-openapi-2 4.0.3 → 4.0.4

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 (112) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/apidom-ns-openapi-2.browser.js +7 -7
  3. package/dist/apidom-ns-openapi-2.browser.min.js +1 -1
  4. package/package.json +9 -8
  5. package/src/elements/Contact.ts +0 -42
  6. package/src/elements/Definitions.ts +0 -13
  7. package/src/elements/Example.ts +0 -13
  8. package/src/elements/ExternalDocumentation.ts +0 -34
  9. package/src/elements/Header.ts +0 -261
  10. package/src/elements/Headers.ts +0 -13
  11. package/src/elements/Info.ts +0 -70
  12. package/src/elements/Items.ts +0 -264
  13. package/src/elements/License.ts +0 -34
  14. package/src/elements/Operation.ts +0 -106
  15. package/src/elements/Parameter.ts +0 -326
  16. package/src/elements/ParametersDefinitions.ts +0 -13
  17. package/src/elements/PathItem.ts +0 -93
  18. package/src/elements/Paths.ts +0 -13
  19. package/src/elements/Reference.ts +0 -27
  20. package/src/elements/Response.ts +0 -54
  21. package/src/elements/Responses.ts +0 -24
  22. package/src/elements/ResponsesDefinitions.ts +0 -13
  23. package/src/elements/Schema.ts +0 -204
  24. package/src/elements/Scopes.ts +0 -13
  25. package/src/elements/SecurityDefinitions.ts +0 -13
  26. package/src/elements/SecurityRequirement.ts +0 -13
  27. package/src/elements/SecurityScheme.ts +0 -83
  28. package/src/elements/Swagger.ts +0 -149
  29. package/src/elements/SwaggerVersion.ts +0 -15
  30. package/src/elements/Tag.ts +0 -44
  31. package/src/elements/Xml.ts +0 -59
  32. package/src/elements/nces/OperationConsumes.ts +0 -15
  33. package/src/elements/nces/OperationParameters.ts +0 -16
  34. package/src/elements/nces/OperationProduces.ts +0 -15
  35. package/src/elements/nces/OperationSchemes.ts +0 -15
  36. package/src/elements/nces/OperationSecurity.ts +0 -16
  37. package/src/elements/nces/OperationTags.ts +0 -16
  38. package/src/elements/nces/PathItemParameters.ts +0 -16
  39. package/src/elements/nces/SwaggerConsumes.ts +0 -15
  40. package/src/elements/nces/SwaggerProduces.ts +0 -15
  41. package/src/elements/nces/SwaggerSchemes.ts +0 -15
  42. package/src/elements/nces/SwaggerSecurity.ts +0 -16
  43. package/src/elements/nces/SwaggerTags.ts +0 -15
  44. package/src/index.ts +0 -368
  45. package/src/media-types.ts +0 -42
  46. package/src/namespace.ts +0 -70
  47. package/src/predicates.ts +0 -194
  48. package/src/refractor/index.ts +0 -330
  49. package/src/refractor/inspect.ts +0 -181
  50. package/src/refractor/plugins/replace-empty-element.ts +0 -389
  51. package/src/refractor/predicates.ts +0 -29
  52. package/src/refractor/specification.ts +0 -444
  53. package/src/refractor/toolbox.ts +0 -24
  54. package/src/refractor/visitors/FallbackVisitor.ts +0 -25
  55. package/src/refractor/visitors/SpecificationExtensionVisitor.ts +0 -22
  56. package/src/refractor/visitors/SpecificationVisitor.ts +0 -83
  57. package/src/refractor/visitors/Visitor.ts +0 -47
  58. package/src/refractor/visitors/generics/AlternatingVisitor.ts +0 -45
  59. package/src/refractor/visitors/generics/FixedFieldsVisitor.ts +0 -109
  60. package/src/refractor/visitors/generics/MapVisitor.ts +0 -25
  61. package/src/refractor/visitors/generics/MixedFieldsVisitor.ts +0 -77
  62. package/src/refractor/visitors/generics/PatternedFieldsVisitor.ts +0 -99
  63. package/src/refractor/visitors/open-api-2/BasePathVisitor.ts +0 -20
  64. package/src/refractor/visitors/open-api-2/ConsumesVisitor.ts +0 -29
  65. package/src/refractor/visitors/open-api-2/HostVisitor.ts +0 -20
  66. package/src/refractor/visitors/open-api-2/ProducesVisitor.ts +0 -29
  67. package/src/refractor/visitors/open-api-2/SchemesVisitor.ts +0 -29
  68. package/src/refractor/visitors/open-api-2/SecurityVisitor.ts +0 -34
  69. package/src/refractor/visitors/open-api-2/SwaggerVisitor.ts +0 -29
  70. package/src/refractor/visitors/open-api-2/TagsVisitor.ts +0 -34
  71. package/src/refractor/visitors/open-api-2/bases.ts +0 -82
  72. package/src/refractor/visitors/open-api-2/contact/index.ts +0 -27
  73. package/src/refractor/visitors/open-api-2/definitions/index.ts +0 -48
  74. package/src/refractor/visitors/open-api-2/example/index.ts +0 -27
  75. package/src/refractor/visitors/open-api-2/external-documentation/index.ts +0 -27
  76. package/src/refractor/visitors/open-api-2/header/index.ts +0 -27
  77. package/src/refractor/visitors/open-api-2/headers/index.ts +0 -27
  78. package/src/refractor/visitors/open-api-2/index.ts +0 -28
  79. package/src/refractor/visitors/open-api-2/info/VersionVisitor.ts +0 -21
  80. package/src/refractor/visitors/open-api-2/info/index.ts +0 -27
  81. package/src/refractor/visitors/open-api-2/items/index.ts +0 -27
  82. package/src/refractor/visitors/open-api-2/license/index.ts +0 -27
  83. package/src/refractor/visitors/open-api-2/operation/ConsumesVisitor.ts +0 -29
  84. package/src/refractor/visitors/open-api-2/operation/ParametersVisitor.ts +0 -44
  85. package/src/refractor/visitors/open-api-2/operation/ProducesVisitor.ts +0 -29
  86. package/src/refractor/visitors/open-api-2/operation/SchemesVisitor.ts +0 -29
  87. package/src/refractor/visitors/open-api-2/operation/SecurityVisitor.ts +0 -34
  88. package/src/refractor/visitors/open-api-2/operation/TagsVisitor.ts +0 -29
  89. package/src/refractor/visitors/open-api-2/operation/index.ts +0 -24
  90. package/src/refractor/visitors/open-api-2/parameter/index.ts +0 -27
  91. package/src/refractor/visitors/open-api-2/parameters-definitions/index.ts +0 -24
  92. package/src/refractor/visitors/open-api-2/path-item/$RefVisitor.ts +0 -20
  93. package/src/refractor/visitors/open-api-2/path-item/ParametersVisitor.ts +0 -44
  94. package/src/refractor/visitors/open-api-2/path-item/index.ts +0 -48
  95. package/src/refractor/visitors/open-api-2/paths/index.ts +0 -48
  96. package/src/refractor/visitors/open-api-2/reference/$RefVisitor.ts +0 -20
  97. package/src/refractor/visitors/open-api-2/reference/index.ts +0 -38
  98. package/src/refractor/visitors/open-api-2/response/index.ts +0 -27
  99. package/src/refractor/visitors/open-api-2/responses/DefaultVisitor.ts +0 -36
  100. package/src/refractor/visitors/open-api-2/responses/index.ts +0 -64
  101. package/src/refractor/visitors/open-api-2/responses-definitions/index.ts +0 -24
  102. package/src/refractor/visitors/open-api-2/schema/AllOfVisitor.ts +0 -35
  103. package/src/refractor/visitors/open-api-2/schema/ItemsVisitor.ts +0 -38
  104. package/src/refractor/visitors/open-api-2/schema/PropertiesVisitor.ts +0 -35
  105. package/src/refractor/visitors/open-api-2/schema/SchemaOrJSONReferenceVisitor.ts +0 -37
  106. package/src/refractor/visitors/open-api-2/schema/index.ts +0 -27
  107. package/src/refractor/visitors/open-api-2/scopes/index.ts +0 -27
  108. package/src/refractor/visitors/open-api-2/security-definitions/index.ts +0 -24
  109. package/src/refractor/visitors/open-api-2/security-requirement/index.ts +0 -24
  110. package/src/refractor/visitors/open-api-2/security-scheme/index.ts +0 -27
  111. package/src/refractor/visitors/open-api-2/tag/index.ts +0 -27
  112. package/src/refractor/visitors/open-api-2/xml/index.ts +0 -27
package/src/predicates.ts DELETED
@@ -1,194 +0,0 @@
1
- import SwaggerElement from './elements/Swagger.ts';
2
- import SwaggerVersionElement from './elements/SwaggerVersion.ts';
3
- import InfoElement from './elements/Info.ts';
4
- import ContactElement from './elements/Contact.ts';
5
- import LicenseElement from './elements/License.ts';
6
- import PathsElement from './elements/Paths.ts';
7
- import PathItemElement from './elements/PathItem.ts';
8
- import OperationElement from './elements/Operation.ts';
9
- import ExternalDocumentationElement from './elements/ExternalDocumentation.ts';
10
- import ParameterElement from './elements/Parameter.ts';
11
- import ItemsElement from './elements/Items.ts';
12
- import ExampleElement from './elements/Example.ts';
13
- import ResponsesElement from './elements/Responses.ts';
14
- import ResponseElement from './elements/Response.ts';
15
- import HeadersElement from './elements/Headers.ts';
16
- import HeaderElement from './elements/Header.ts';
17
- import TagElement from './elements/Tag.ts';
18
- import ReferenceElement from './elements/Reference.ts';
19
- import SchemaElement from './elements/Schema.ts';
20
- import XmlElement from './elements/Xml.ts';
21
- import DefinitionsElement from './elements/Definitions.ts';
22
- import ParametersDefinitionsElement from './elements/ParametersDefinitions.ts';
23
- import ResponsesDefinitionsElement from './elements/ResponsesDefinitions.ts';
24
- import SecurityDefinitionsElement from './elements/SecurityDefinitions.ts';
25
- import SecuritySchemeElement from './elements/SecurityScheme.ts';
26
- import SecurityRequirementElement from './elements/SecurityRequirement.ts';
27
- import ScopesElement from './elements/Scopes.ts';
28
-
29
- /**
30
- * @public
31
- */
32
- export const isSwaggerElement = (element: unknown): element is SwaggerElement =>
33
- element instanceof SwaggerElement;
34
-
35
- /**
36
- * @public
37
- */
38
- export const isSwaggerVersionElement = (element: unknown): element is SwaggerVersionElement =>
39
- element instanceof SwaggerVersionElement;
40
-
41
- /**
42
- * @public
43
- */
44
- export const isInfoElement = (element: unknown): element is InfoElement =>
45
- element instanceof InfoElement;
46
-
47
- /**
48
- * @public
49
- */
50
- export const isLicenseElement = (element: unknown): element is LicenseElement =>
51
- element instanceof LicenseElement;
52
-
53
- /**
54
- * @public
55
- */
56
- export const isContactElement = (element: unknown): element is ContactElement =>
57
- element instanceof ContactElement;
58
-
59
- /**
60
- * @public
61
- */
62
- export const isPathsElement = (element: unknown): element is PathsElement =>
63
- element instanceof PathsElement;
64
-
65
- /**
66
- * @public
67
- */
68
- export const isPathItemElement = (element: unknown): element is PathItemElement =>
69
- element instanceof PathItemElement;
70
-
71
- /**
72
- * @public
73
- */
74
- export const isOperationElement = (element: unknown): element is OperationElement =>
75
- element instanceof OperationElement;
76
-
77
- /**
78
- * @public
79
- */
80
- export const isExternalDocumentationElement = (
81
- element: unknown,
82
- ): element is ExternalDocumentationElement => element instanceof ExternalDocumentationElement;
83
-
84
- /**
85
- * @public
86
- */
87
- export const isParameterElement = (element: unknown): element is ParameterElement =>
88
- element instanceof ParameterElement;
89
-
90
- /**
91
- * @public
92
- */
93
- export const isItemsElement = (element: unknown): element is ItemsElement =>
94
- element instanceof ItemsElement;
95
-
96
- /**
97
- * @public
98
- */
99
- export const isResponsesElement = (element: unknown): element is ResponsesElement =>
100
- element instanceof ResponsesElement;
101
-
102
- /**
103
- * @public
104
- */
105
- export const isResponseElement = (element: unknown): element is ResponseElement =>
106
- element instanceof ResponseElement;
107
-
108
- /**
109
- * @public
110
- */
111
- export const isHeadersElement = (element: unknown): element is HeadersElement =>
112
- element instanceof HeadersElement;
113
-
114
- /**
115
- * @public
116
- */
117
- export const isExampleElement = (element: unknown): element is ExampleElement =>
118
- element instanceof ExampleElement;
119
-
120
- /**
121
- * @public
122
- */
123
- export const isHeaderElement = (element: unknown): element is HeaderElement =>
124
- element instanceof HeaderElement;
125
-
126
- /**
127
- * @public
128
- */
129
- export const isTagElement = (element: unknown): element is TagElement =>
130
- element instanceof TagElement;
131
-
132
- /**
133
- * @public
134
- */
135
- export const isReferenceElement = (element: unknown): element is ReferenceElement =>
136
- element instanceof ReferenceElement;
137
-
138
- /**
139
- * @public
140
- */
141
- export const isSchemaElement = (element: unknown): element is SchemaElement =>
142
- element instanceof SchemaElement;
143
-
144
- /**
145
- * @public
146
- */
147
- export const isXmlElement = (element: unknown): element is XmlElement =>
148
- element instanceof XmlElement;
149
-
150
- /**
151
- * @public
152
- */
153
- export const isResponsesDefinitionsElement = (
154
- element: unknown,
155
- ): element is ResponsesDefinitionsElement => element instanceof ResponsesDefinitionsElement;
156
-
157
- /**
158
- * @public
159
- */
160
- export const isSecurityDefinitionsElement = (
161
- element: unknown,
162
- ): element is SecurityDefinitionsElement => element instanceof SecurityDefinitionsElement;
163
-
164
- /**
165
- * @public
166
- */
167
- export const isDefinitionsElement = (element: unknown): element is DefinitionsElement =>
168
- element instanceof DefinitionsElement;
169
-
170
- /**
171
- * @public
172
- */
173
- export const isParametersDefinitionsElement = (
174
- element: unknown,
175
- ): element is ParametersDefinitionsElement => element instanceof ParametersDefinitionsElement;
176
-
177
- /**
178
- * @public
179
- */
180
- export const isSecuritySchemeElement = (element: unknown): element is SecuritySchemeElement =>
181
- element instanceof SecuritySchemeElement;
182
-
183
- /**
184
- * @public
185
- */
186
- export const isScopesElement = (element: unknown): element is ScopesElement =>
187
- element instanceof ScopesElement;
188
-
189
- /**
190
- * @public
191
- */
192
- export const isSecurityRequirementElement = (
193
- element: unknown,
194
- ): element is SecurityRequirementElement => element instanceof SecurityRequirementElement;
@@ -1,330 +0,0 @@
1
- import { resolveSpecification, dispatchRefractorPlugins } from '@speclynx/apidom-core';
2
- import { Element, refract as baseRefract } from '@speclynx/apidom-datamodel';
3
- import { traverse } from '@speclynx/apidom-traverse';
4
- import { path } from 'ramda';
5
-
6
- import type VisitorClass from './visitors/Visitor.ts';
7
- import specification from './specification.ts';
8
- import createToolbox, { type Toolbox } from './toolbox.ts';
9
- import type SwaggerElement from '../elements/Swagger.ts';
10
- import type InfoElement from '../elements/Info.ts';
11
- import type ContactElement from '../elements/Contact.ts';
12
- import type LicenseElement from '../elements/License.ts';
13
- import type PathsElement from '../elements/Paths.ts';
14
- import type PathItemElement from '../elements/PathItem.ts';
15
- import type OperationElement from '../elements/Operation.ts';
16
- import type ExternalDocumentationElement from '../elements/ExternalDocumentation.ts';
17
- import type ParameterElement from '../elements/Parameter.ts';
18
- import type ItemsElement from '../elements/Items.ts';
19
- import type ResponsesElement from '../elements/Responses.ts';
20
- import type ResponseElement from '../elements/Response.ts';
21
- import type HeadersElement from '../elements/Headers.ts';
22
- import type ExampleElement from '../elements/Example.ts';
23
- import type HeaderElement from '../elements/Header.ts';
24
- import type TagElement from '../elements/Tag.ts';
25
- import type ReferenceElement from '../elements/Reference.ts';
26
- import type SchemaElement from '../elements/Schema.ts';
27
- import type XmlElement from '../elements/Xml.ts';
28
- import type DefinitionsElement from '../elements/Definitions.ts';
29
- import type ParametersDefinitionsElement from '../elements/ParametersDefinitions.ts';
30
- import type ResponsesDefinitionsElement from '../elements/ResponsesDefinitions.ts';
31
- import type SecurityDefinitionsElement from '../elements/SecurityDefinitions.ts';
32
- import type SecuritySchemeElement from '../elements/SecurityScheme.ts';
33
- import type ScopesElement from '../elements/Scopes.ts';
34
- import type SecurityRequirementElement from '../elements/SecurityRequirement.ts';
35
-
36
- /**
37
- * @public
38
- */
39
- export type RefractorPlugin = (toolbox: Toolbox) => {
40
- visitor?: object;
41
- pre?: () => void;
42
- post?: () => void;
43
- };
44
-
45
- /**
46
- * @public
47
- */
48
- export interface RefractorOptions {
49
- readonly element?: string;
50
- readonly plugins?: RefractorPlugin[];
51
- readonly specificationObj?: typeof specification;
52
- readonly consume?: boolean;
53
- }
54
-
55
- /**
56
- * @public
57
- */
58
- const refract = <T extends Element>(
59
- value: unknown,
60
- {
61
- element = 'swagger',
62
- plugins = [],
63
- specificationObj = specification,
64
- consume = false,
65
- }: RefractorOptions = {},
66
- ): T => {
67
- const genericElement = baseRefract(value);
68
- const resolvedSpec = resolveSpecification(specificationObj);
69
- const elementMap = resolvedSpec.elementMap as Record<string, string[]>;
70
- const specPath = elementMap[element];
71
-
72
- if (!specPath) {
73
- throw new Error(`Unknown element type: "${element}"`);
74
- }
75
-
76
- /**
77
- * This is where generic ApiDOM becomes semantic (namespace applied).
78
- * We don't allow consumers to hook into this translation.
79
- * Though we allow consumers to define their own plugins on already transformed ApiDOM.
80
- */
81
- const RootVisitorClass = path(specPath, resolvedSpec) as new (
82
- options: Record<string, unknown>,
83
- ) => InstanceType<typeof VisitorClass>;
84
- const rootVisitor = new RootVisitorClass({ specObj: resolvedSpec, consume });
85
-
86
- traverse(genericElement, rootVisitor);
87
-
88
- /**
89
- * Running plugins visitors means extra single traversal === performance hit.
90
- */
91
- return dispatchRefractorPlugins(rootVisitor.element, plugins, {
92
- toolboxCreator: createToolbox,
93
- }) as T;
94
- };
95
-
96
- /**
97
- * Refracts a value into a SwaggerElement.
98
- * @public
99
- */
100
- export const refractSwagger = <T extends Element = SwaggerElement>(
101
- value: unknown,
102
- options: Omit<RefractorOptions, 'element'> = {},
103
- ): T => refract(value, { ...options, element: 'swagger' });
104
-
105
- /**
106
- * Refracts a value into an InfoElement.
107
- * @public
108
- */
109
- export const refractInfo = <T extends Element = InfoElement>(
110
- value: unknown,
111
- options: Omit<RefractorOptions, 'element'> = {},
112
- ): T => refract(value, { ...options, element: 'info' });
113
-
114
- /**
115
- * Refracts a value into a ContactElement.
116
- * @public
117
- */
118
- export const refractContact = <T extends Element = ContactElement>(
119
- value: unknown,
120
- options: Omit<RefractorOptions, 'element'> = {},
121
- ): T => refract(value, { ...options, element: 'contact' });
122
-
123
- /**
124
- * Refracts a value into a LicenseElement.
125
- * @public
126
- */
127
- export const refractLicense = <T extends Element = LicenseElement>(
128
- value: unknown,
129
- options: Omit<RefractorOptions, 'element'> = {},
130
- ): T => refract(value, { ...options, element: 'license' });
131
-
132
- /**
133
- * Refracts a value into a PathsElement.
134
- * @public
135
- */
136
- export const refractPaths = <T extends Element = PathsElement>(
137
- value: unknown,
138
- options: Omit<RefractorOptions, 'element'> = {},
139
- ): T => refract(value, { ...options, element: 'paths' });
140
-
141
- /**
142
- * Refracts a value into a PathItemElement.
143
- * @public
144
- */
145
- export const refractPathItem = <T extends Element = PathItemElement>(
146
- value: unknown,
147
- options: Omit<RefractorOptions, 'element'> = {},
148
- ): T => refract(value, { ...options, element: 'pathItem' });
149
-
150
- /**
151
- * Refracts a value into an OperationElement.
152
- * @public
153
- */
154
- export const refractOperation = <T extends Element = OperationElement>(
155
- value: unknown,
156
- options: Omit<RefractorOptions, 'element'> = {},
157
- ): T => refract(value, { ...options, element: 'operation' });
158
-
159
- /**
160
- * Refracts a value into an ExternalDocumentationElement.
161
- * @public
162
- */
163
- export const refractExternalDocumentation = <T extends Element = ExternalDocumentationElement>(
164
- value: unknown,
165
- options: Omit<RefractorOptions, 'element'> = {},
166
- ): T => refract(value, { ...options, element: 'externalDocumentation' });
167
-
168
- /**
169
- * Refracts a value into a ParameterElement.
170
- * @public
171
- */
172
- export const refractParameter = <T extends Element = ParameterElement>(
173
- value: unknown,
174
- options: Omit<RefractorOptions, 'element'> = {},
175
- ): T => refract(value, { ...options, element: 'parameter' });
176
-
177
- /**
178
- * Refracts a value into an ItemsElement.
179
- * @public
180
- */
181
- export const refractItems = <T extends Element = ItemsElement>(
182
- value: unknown,
183
- options: Omit<RefractorOptions, 'element'> = {},
184
- ): T => refract(value, { ...options, element: 'items' });
185
-
186
- /**
187
- * Refracts a value into a ResponsesElement.
188
- * @public
189
- */
190
- export const refractResponses = <T extends Element = ResponsesElement>(
191
- value: unknown,
192
- options: Omit<RefractorOptions, 'element'> = {},
193
- ): T => refract(value, { ...options, element: 'responses' });
194
-
195
- /**
196
- * Refracts a value into a ResponseElement.
197
- * @public
198
- */
199
- export const refractResponse = <T extends Element = ResponseElement>(
200
- value: unknown,
201
- options: Omit<RefractorOptions, 'element'> = {},
202
- ): T => refract(value, { ...options, element: 'response' });
203
-
204
- /**
205
- * Refracts a value into a HeadersElement.
206
- * @public
207
- */
208
- export const refractHeaders = <T extends Element = HeadersElement>(
209
- value: unknown,
210
- options: Omit<RefractorOptions, 'element'> = {},
211
- ): T => refract(value, { ...options, element: 'headers' });
212
-
213
- /**
214
- * Refracts a value into an ExampleElement.
215
- * @public
216
- */
217
- export const refractExample = <T extends Element = ExampleElement>(
218
- value: unknown,
219
- options: Omit<RefractorOptions, 'element'> = {},
220
- ): T => refract(value, { ...options, element: 'example' });
221
-
222
- /**
223
- * Refracts a value into a HeaderElement.
224
- * @public
225
- */
226
- export const refractHeader = <T extends Element = HeaderElement>(
227
- value: unknown,
228
- options: Omit<RefractorOptions, 'element'> = {},
229
- ): T => refract(value, { ...options, element: 'header' });
230
-
231
- /**
232
- * Refracts a value into a TagElement.
233
- * @public
234
- */
235
- export const refractTag = <T extends Element = TagElement>(
236
- value: unknown,
237
- options: Omit<RefractorOptions, 'element'> = {},
238
- ): T => refract(value, { ...options, element: 'tag' });
239
-
240
- /**
241
- * Refracts a value into a ReferenceElement.
242
- * @public
243
- */
244
- export const refractReference = <T extends Element = ReferenceElement>(
245
- value: unknown,
246
- options: Omit<RefractorOptions, 'element'> = {},
247
- ): T => refract(value, { ...options, element: 'reference' });
248
-
249
- /**
250
- * Refracts a value into a SchemaElement.
251
- * @public
252
- */
253
- export const refractSchema = <T extends Element = SchemaElement>(
254
- value: unknown,
255
- options: Omit<RefractorOptions, 'element'> = {},
256
- ): T => refract(value, { ...options, element: 'schema' });
257
-
258
- /**
259
- * Refracts a value into an XmlElement.
260
- * @public
261
- */
262
- export const refractXml = <T extends Element = XmlElement>(
263
- value: unknown,
264
- options: Omit<RefractorOptions, 'element'> = {},
265
- ): T => refract(value, { ...options, element: 'xml' });
266
-
267
- /**
268
- * Refracts a value into a DefinitionsElement.
269
- * @public
270
- */
271
- export const refractDefinitions = <T extends Element = DefinitionsElement>(
272
- value: unknown,
273
- options: Omit<RefractorOptions, 'element'> = {},
274
- ): T => refract(value, { ...options, element: 'definitions' });
275
-
276
- /**
277
- * Refracts a value into a ParametersDefinitionsElement.
278
- * @public
279
- */
280
- export const refractParametersDefinitions = <T extends Element = ParametersDefinitionsElement>(
281
- value: unknown,
282
- options: Omit<RefractorOptions, 'element'> = {},
283
- ): T => refract(value, { ...options, element: 'parametersDefinitions' });
284
-
285
- /**
286
- * Refracts a value into a ResponsesDefinitionsElement.
287
- * @public
288
- */
289
- export const refractResponsesDefinitions = <T extends Element = ResponsesDefinitionsElement>(
290
- value: unknown,
291
- options: Omit<RefractorOptions, 'element'> = {},
292
- ): T => refract(value, { ...options, element: 'responsesDefinitions' });
293
-
294
- /**
295
- * Refracts a value into a SecurityDefinitionsElement.
296
- * @public
297
- */
298
- export const refractSecurityDefinitions = <T extends Element = SecurityDefinitionsElement>(
299
- value: unknown,
300
- options: Omit<RefractorOptions, 'element'> = {},
301
- ): T => refract(value, { ...options, element: 'securityDefinitions' });
302
-
303
- /**
304
- * Refracts a value into a SecuritySchemeElement.
305
- * @public
306
- */
307
- export const refractSecurityScheme = <T extends Element = SecuritySchemeElement>(
308
- value: unknown,
309
- options: Omit<RefractorOptions, 'element'> = {},
310
- ): T => refract(value, { ...options, element: 'securityScheme' });
311
-
312
- /**
313
- * Refracts a value into a ScopesElement.
314
- * @public
315
- */
316
- export const refractScopes = <T extends Element = ScopesElement>(
317
- value: unknown,
318
- options: Omit<RefractorOptions, 'element'> = {},
319
- ): T => refract(value, { ...options, element: 'scopes' });
320
-
321
- /**
322
- * Refracts a value into a SecurityRequirementElement.
323
- * @public
324
- */
325
- export const refractSecurityRequirement = <T extends Element = SecurityRequirementElement>(
326
- value: unknown,
327
- options: Omit<RefractorOptions, 'element'> = {},
328
- ): T => refract(value, { ...options, element: 'securityRequirement' });
329
-
330
- export default refract;
@@ -1,181 +0,0 @@
1
- import { resolveSpecification, type ResolvedSpecification } from '@speclynx/apidom-core';
2
- import { isPlainObject } from 'ramda-adjunct';
3
-
4
- /**
5
- * OpenAPI 2.0 specification elements.
6
- */
7
- import SwaggerElement from '../elements/Swagger.ts';
8
- import SwaggerVersionElement from '../elements/SwaggerVersion.ts';
9
- import InfoElement from '../elements/Info.ts';
10
- import ContactElement from '../elements/Contact.ts';
11
- import LicenseElement from '../elements/License.ts';
12
- import PathsElement from '../elements/Paths.ts';
13
- import PathItemElement from '../elements/PathItem.ts';
14
- import OperationElement from '../elements/Operation.ts';
15
- import ExternalDocumentationElement from '../elements/ExternalDocumentation.ts';
16
- import ParameterElement from '../elements/Parameter.ts';
17
- import ItemsElement from '../elements/Items.ts';
18
- import ResponsesElement from '../elements/Responses.ts';
19
- import ResponseElement from '../elements/Response.ts';
20
- import HeadersElement from '../elements/Headers.ts';
21
- import ExampleElement from '../elements/Example.ts';
22
- import HeaderElement from '../elements/Header.ts';
23
- import TagElement from '../elements/Tag.ts';
24
- import ReferenceElement from '../elements/Reference.ts';
25
- import SchemaElement from '../elements/Schema.ts';
26
- import XmlElement from '../elements/Xml.ts';
27
- import DefinitionsElement from '../elements/Definitions.ts';
28
- import ParametersDefinitionsElement from '../elements/ParametersDefinitions.ts';
29
- import ResponsesDefinitionsElement from '../elements/ResponsesDefinitions.ts';
30
- import SecurityDefinitionsElement from '../elements/SecurityDefinitions.ts';
31
- import SecuritySchemeElement from '../elements/SecurityScheme.ts';
32
- import ScopesElement from '../elements/Scopes.ts';
33
- import SecurityRequirementElement from '../elements/SecurityRequirement.ts';
34
- import specification from './specification.ts';
35
-
36
- /**
37
- * @public
38
- */
39
- export interface FixedField {
40
- name: string;
41
- alias?: string;
42
- $visitor: unknown;
43
- }
44
-
45
- interface ResolvedSpec extends ResolvedSpecification {
46
- visitors: {
47
- document: {
48
- objects: Record<string, { fixedFields: Record<string, unknown> }>;
49
- };
50
- };
51
- }
52
-
53
- // Resolve specification to dereference $ref pointers
54
- const resolvedSpec = resolveSpecification<ResolvedSpec>(specification);
55
-
56
- // Extract fixed fields as list of { name, alias?, $visitor }
57
- const getFixedFields = (fixedFieldsSpec: Record<string, unknown>): FixedField[] => {
58
- return Object.entries(fixedFieldsSpec).map(([name, fieldSpec]) => {
59
- if (isPlainObject(fieldSpec)) {
60
- return { name, ...fieldSpec } as FixedField;
61
- }
62
- return { name, $visitor: fieldSpec };
63
- });
64
- };
65
-
66
- // OpenAPI 2.0 specification elements
67
- Object.defineProperty(SwaggerElement, 'fixedFields', {
68
- get: () => getFixedFields(resolvedSpec.visitors.document.objects.Swagger.fixedFields),
69
- enumerable: true,
70
- });
71
-
72
- Object.defineProperty(InfoElement, 'fixedFields', {
73
- get: () => getFixedFields(resolvedSpec.visitors.document.objects.Info.fixedFields),
74
- enumerable: true,
75
- });
76
-
77
- Object.defineProperty(ContactElement, 'fixedFields', {
78
- get: () => getFixedFields(resolvedSpec.visitors.document.objects.Contact.fixedFields),
79
- enumerable: true,
80
- });
81
-
82
- Object.defineProperty(LicenseElement, 'fixedFields', {
83
- get: () => getFixedFields(resolvedSpec.visitors.document.objects.License.fixedFields),
84
- enumerable: true,
85
- });
86
-
87
- Object.defineProperty(PathItemElement, 'fixedFields', {
88
- get: () => getFixedFields(resolvedSpec.visitors.document.objects.PathItem.fixedFields),
89
- enumerable: true,
90
- });
91
-
92
- Object.defineProperty(OperationElement, 'fixedFields', {
93
- get: () => getFixedFields(resolvedSpec.visitors.document.objects.Operation.fixedFields),
94
- enumerable: true,
95
- });
96
-
97
- Object.defineProperty(ExternalDocumentationElement, 'fixedFields', {
98
- get: () =>
99
- getFixedFields(resolvedSpec.visitors.document.objects.ExternalDocumentation.fixedFields),
100
- enumerable: true,
101
- });
102
-
103
- Object.defineProperty(ParameterElement, 'fixedFields', {
104
- get: () => getFixedFields(resolvedSpec.visitors.document.objects.Parameter.fixedFields),
105
- enumerable: true,
106
- });
107
-
108
- Object.defineProperty(ItemsElement, 'fixedFields', {
109
- get: () => getFixedFields(resolvedSpec.visitors.document.objects.Items.fixedFields),
110
- enumerable: true,
111
- });
112
-
113
- Object.defineProperty(ResponsesElement, 'fixedFields', {
114
- get: () => getFixedFields(resolvedSpec.visitors.document.objects.Responses.fixedFields),
115
- enumerable: true,
116
- });
117
-
118
- Object.defineProperty(ResponseElement, 'fixedFields', {
119
- get: () => getFixedFields(resolvedSpec.visitors.document.objects.Response.fixedFields),
120
- enumerable: true,
121
- });
122
-
123
- Object.defineProperty(HeaderElement, 'fixedFields', {
124
- get: () => getFixedFields(resolvedSpec.visitors.document.objects.Header.fixedFields),
125
- enumerable: true,
126
- });
127
-
128
- Object.defineProperty(TagElement, 'fixedFields', {
129
- get: () => getFixedFields(resolvedSpec.visitors.document.objects.Tag.fixedFields),
130
- enumerable: true,
131
- });
132
-
133
- Object.defineProperty(ReferenceElement, 'fixedFields', {
134
- get: () => getFixedFields(resolvedSpec.visitors.document.objects.Reference.fixedFields),
135
- enumerable: true,
136
- });
137
-
138
- Object.defineProperty(SchemaElement, 'fixedFields', {
139
- get: () => getFixedFields(resolvedSpec.visitors.document.objects.Schema.fixedFields),
140
- enumerable: true,
141
- });
142
-
143
- Object.defineProperty(XmlElement, 'fixedFields', {
144
- get: () => getFixedFields(resolvedSpec.visitors.document.objects.XML.fixedFields),
145
- enumerable: true,
146
- });
147
-
148
- Object.defineProperty(SecuritySchemeElement, 'fixedFields', {
149
- get: () => getFixedFields(resolvedSpec.visitors.document.objects.SecurityScheme.fixedFields),
150
- enumerable: true,
151
- });
152
-
153
- export {
154
- SwaggerElement,
155
- SwaggerVersionElement,
156
- InfoElement,
157
- ContactElement,
158
- LicenseElement,
159
- PathsElement,
160
- PathItemElement,
161
- OperationElement,
162
- ExternalDocumentationElement,
163
- ParameterElement,
164
- ItemsElement,
165
- ResponsesElement,
166
- ResponseElement,
167
- HeadersElement,
168
- ExampleElement,
169
- HeaderElement,
170
- TagElement,
171
- ReferenceElement,
172
- SchemaElement,
173
- XmlElement,
174
- DefinitionsElement,
175
- ParametersDefinitionsElement,
176
- ResponsesDefinitionsElement,
177
- SecurityDefinitionsElement,
178
- SecuritySchemeElement,
179
- ScopesElement,
180
- SecurityRequirementElement,
181
- };