@kubb/oas 4.5.7 → 4.5.9

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.
package/dist/infer.d.cts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as PathMap, h as Infer, i as MethodMap, n as RequestParams, o as StatusMap, r as Model, t as Response } from "./index-C674urwx.cjs";
1
+ import { a as PathMap, h as Infer, i as MethodMap, n as RequestParams, o as StatusMap, r as Model, t as Response } from "./index-BuoKUWab.cjs";
2
2
  export { Infer, MethodMap, Model, PathMap, RequestParams, Response, StatusMap };
package/dist/infer.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as PathMap, h as Infer, i as MethodMap, n as RequestParams, o as StatusMap, r as Model, t as Response } from "./index-BGlrm4xM.js";
1
+ import { a as PathMap, h as Infer, i as MethodMap, n as RequestParams, o as StatusMap, r as Model, t as Response } from "./index-CT3Sz4Y8.js";
2
2
  export { Infer, MethodMap, Model, PathMap, RequestParams, Response, StatusMap };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/oas",
3
- "version": "4.5.7",
3
+ "version": "4.5.9",
4
4
  "description": "OpenAPI Specification (OAS) utilities and helpers for Kubb, providing parsing, normalization, and manipulation of OpenAPI/Swagger schemas.",
5
5
  "keywords": [
6
6
  "openapi",
@@ -56,12 +56,12 @@
56
56
  }
57
57
  ],
58
58
  "dependencies": {
59
- "@redocly/openapi-core": "^2.11.0",
59
+ "@redocly/openapi-core": "^2.11.1",
60
60
  "hotscript": "^1.0.13",
61
61
  "json-schema-to-ts": "^3.1.1",
62
62
  "jsonpointer": "^5.0.1",
63
- "oas": "^28.5.0",
64
- "oas-normalize": "^15.2.0",
63
+ "oas": "^28.5.1",
64
+ "oas-normalize": "^15.4.0",
65
65
  "openapi-types": "^12.1.3",
66
66
  "remeda": "^2.32.0",
67
67
  "swagger2openapi": "^7.0.8",
package/src/Oas.ts CHANGED
@@ -31,7 +31,14 @@ export class Oas<const TOAS = unknown> extends BaseOas {
31
31
  }
32
32
 
33
33
  setOptions(options: Options) {
34
- this.#options = options
34
+ this.#options = {
35
+ ...this.#options,
36
+ ...options,
37
+ }
38
+
39
+ if (this.#options.discriminator === 'inherit') {
40
+ this.#applyDiscriminatorInheritance()
41
+ }
35
42
  }
36
43
 
37
44
  get options(): Options {
@@ -73,11 +80,7 @@ export class Oas<const TOAS = unknown> extends BaseOas {
73
80
  }
74
81
  }
75
82
 
76
- getDiscriminator(schema: OasTypes.SchemaObject): OpenAPIV3.DiscriminatorObject | undefined {
77
- if (!isDiscriminator(schema)) {
78
- return undefined
79
- }
80
-
83
+ #setDiscriminator(schema: OasTypes.SchemaObject & { discriminator: OpenAPIV3.DiscriminatorObject }): void {
81
84
  const { mapping = {}, propertyName } = schema.discriminator
82
85
 
83
86
  if (this.#options.discriminator === 'inherit') {
@@ -96,13 +99,21 @@ export class Oas<const TOAS = unknown> extends BaseOas {
96
99
  enum: [...(property?.enum?.filter((value) => value !== mappingKey) ?? []), mappingKey],
97
100
  }
98
101
 
99
- childSchema.required = [...(childSchema.required ?? []), propertyName]
102
+ childSchema.required = [...new Set([...(childSchema.required ?? []), propertyName])]
100
103
 
101
104
  this.set(mappingValue, childSchema)
102
105
  }
103
106
  }
104
107
  })
105
108
  }
109
+ }
110
+
111
+ getDiscriminator(schema: OasTypes.SchemaObject): OpenAPIV3.DiscriminatorObject | undefined {
112
+ if (!isDiscriminator(schema)) {
113
+ return undefined
114
+ }
115
+
116
+ const { mapping = {}, propertyName } = schema.discriminator
106
117
 
107
118
  // loop over oneOf and add default mapping when none is defined
108
119
  if (schema.oneOf) {
@@ -160,6 +171,85 @@ export class Oas<const TOAS = unknown> extends BaseOas {
160
171
  return schema
161
172
  }
162
173
 
174
+ #applyDiscriminatorInheritance() {
175
+ const components = this.api.components
176
+ if (!components?.schemas) {
177
+ return
178
+ }
179
+
180
+ const visited = new WeakSet<object>()
181
+ const enqueue = (value: unknown) => {
182
+ if (!value) {
183
+ return
184
+ }
185
+
186
+ if (Array.isArray(value)) {
187
+ for (const item of value) {
188
+ enqueue(item)
189
+ }
190
+ return
191
+ }
192
+
193
+ if (typeof value === 'object') {
194
+ visit(value as SchemaObject)
195
+ }
196
+ }
197
+
198
+ const visit = (schema?: SchemaObject | OpenAPIV3.ReferenceObject | null) => {
199
+ if (!schema || typeof schema !== 'object') {
200
+ return
201
+ }
202
+
203
+ if (isReference(schema)) {
204
+ visit(this.get(schema.$ref) as OpenAPIV3.SchemaObject)
205
+ return
206
+ }
207
+
208
+ const schemaObject = schema as OpenAPIV3.SchemaObject
209
+
210
+ if (visited.has(schemaObject as object)) {
211
+ return
212
+ }
213
+
214
+ visited.add(schemaObject as object)
215
+
216
+ if (isDiscriminator(schemaObject)) {
217
+ this.#setDiscriminator(schemaObject)
218
+ }
219
+
220
+ if ('allOf' in schemaObject) {
221
+ enqueue(schemaObject.allOf)
222
+ }
223
+ if ('oneOf' in schemaObject) {
224
+ enqueue(schemaObject.oneOf)
225
+ }
226
+ if ('anyOf' in schemaObject) {
227
+ enqueue(schemaObject.anyOf)
228
+ }
229
+ if ('not' in schemaObject) {
230
+ enqueue(schemaObject.not)
231
+ }
232
+ if ('items' in schemaObject) {
233
+ enqueue(schemaObject.items)
234
+ }
235
+ if ('prefixItems' in schemaObject) {
236
+ enqueue(schemaObject.prefixItems)
237
+ }
238
+
239
+ if (schemaObject.properties) {
240
+ enqueue(Object.values(schemaObject.properties))
241
+ }
242
+
243
+ if (schemaObject.additionalProperties && typeof schemaObject.additionalProperties === 'object') {
244
+ enqueue(schemaObject.additionalProperties)
245
+ }
246
+ }
247
+
248
+ for (const schema of Object.values(components.schemas)) {
249
+ visit(schema as SchemaObject)
250
+ }
251
+ }
252
+
163
253
  /**
164
254
  * Oas does not have a getResponseBody(contentType)
165
255
  */