@kubb/oas 4.5.8 → 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.
@@ -373,4 +373,4 @@ type JSONResponseSchema<TOAS extends OasTypes.OASDocument, TPath extends keyof P
373
373
  type Response<TOAS extends OasTypes.OASDocument, TPath extends keyof PathMap<TOAS>, TMethod extends keyof MethodMap<TOAS, TPath>, TStatusCode extends keyof StatusMap<TOAS, TPath, TMethod> = 200> = FromSchema<JSONResponseSchema<TOAS, TPath, TMethod, TStatusCode>>;
374
374
  //#endregion
375
375
  export { PathMap as a, HttpMethods as c, OpenAPIV3_1$1 as d, Operation$1 as f, Infer as h, MethodMap as i, OasTypes as l, contentType as m, RequestParams as n, StatusMap as o, SchemaObject$1 as p, Model as r, HttpMethod as s, Response as t, OpenAPIV3$1 as u };
376
- //# sourceMappingURL=index-C674urwx.d.cts.map
376
+ //# sourceMappingURL=index-BuoKUWab.d.cts.map
@@ -373,4 +373,4 @@ type JSONResponseSchema<TOAS extends OasTypes.OASDocument, TPath extends keyof P
373
373
  type Response<TOAS extends OasTypes.OASDocument, TPath extends keyof PathMap<TOAS>, TMethod extends keyof MethodMap<TOAS, TPath>, TStatusCode extends keyof StatusMap<TOAS, TPath, TMethod> = 200> = FromSchema<JSONResponseSchema<TOAS, TPath, TMethod, TStatusCode>>;
374
374
  //#endregion
375
375
  export { PathMap as a, HttpMethods as c, OpenAPIV3_1$1 as d, Operation$1 as f, Infer as h, MethodMap as i, OasTypes as l, contentType as m, RequestParams as n, StatusMap as o, SchemaObject$1 as p, Model as r, HttpMethod as s, Response as t, OpenAPIV3$1 as u };
376
- //# sourceMappingURL=index-BGlrm4xM.d.ts.map
376
+ //# sourceMappingURL=index-CT3Sz4Y8.d.ts.map
package/dist/index.cjs CHANGED
@@ -4409,7 +4409,11 @@ var Oas = class extends oas.default {
4409
4409
  this.document = oas$1;
4410
4410
  }
4411
4411
  setOptions(options) {
4412
- this.#options = options;
4412
+ this.#options = {
4413
+ ...this.#options,
4414
+ ...options
4415
+ };
4416
+ if (this.#options.discriminator === "inherit") this.#applyDiscriminatorInheritance();
4413
4417
  }
4414
4418
  get options() {
4415
4419
  return this.#options;
@@ -4436,8 +4440,7 @@ var Oas = class extends oas.default {
4436
4440
  jsonpointer.default.set(this.api, $ref, value);
4437
4441
  }
4438
4442
  }
4439
- getDiscriminator(schema$2) {
4440
- if (!isDiscriminator(schema$2)) return;
4443
+ #setDiscriminator(schema$2) {
4441
4444
  const { mapping = {}, propertyName } = schema$2.discriminator;
4442
4445
  if (this.#options.discriminator === "inherit") Object.entries(mapping).forEach(([mappingKey, mappingValue]) => {
4443
4446
  if (mappingValue) {
@@ -4449,11 +4452,15 @@ var Oas = class extends oas.default {
4449
4452
  ...childSchema.properties ? childSchema.properties[propertyName] : {},
4450
4453
  enum: [...property?.enum?.filter((value) => value !== mappingKey) ?? [], mappingKey]
4451
4454
  };
4452
- childSchema.required = [...childSchema.required ?? [], propertyName];
4455
+ childSchema.required = [...new Set([...childSchema.required ?? [], propertyName])];
4453
4456
  this.set(mappingValue, childSchema);
4454
4457
  }
4455
4458
  }
4456
4459
  });
4460
+ }
4461
+ getDiscriminator(schema$2) {
4462
+ if (!isDiscriminator(schema$2)) return;
4463
+ const { mapping = {}, propertyName } = schema$2.discriminator;
4457
4464
  if (schema$2.oneOf) schema$2.oneOf.forEach((schema$3) => {
4458
4465
  if (isReference(schema$3)) {
4459
4466
  const key = this.getKey(schema$3.$ref);
@@ -4485,6 +4492,39 @@ var Oas = class extends oas.default {
4485
4492
  };
4486
4493
  return schema$2;
4487
4494
  }
4495
+ #applyDiscriminatorInheritance() {
4496
+ const components = this.api.components;
4497
+ if (!components?.schemas) return;
4498
+ const visited = /* @__PURE__ */ new WeakSet();
4499
+ const enqueue = (value) => {
4500
+ if (!value) return;
4501
+ if (Array.isArray(value)) {
4502
+ for (const item of value) enqueue(item);
4503
+ return;
4504
+ }
4505
+ if (typeof value === "object") visit(value);
4506
+ };
4507
+ const visit = (schema$2) => {
4508
+ if (!schema$2 || typeof schema$2 !== "object") return;
4509
+ if (isReference(schema$2)) {
4510
+ visit(this.get(schema$2.$ref));
4511
+ return;
4512
+ }
4513
+ const schemaObject = schema$2;
4514
+ if (visited.has(schemaObject)) return;
4515
+ visited.add(schemaObject);
4516
+ if (isDiscriminator(schemaObject)) this.#setDiscriminator(schemaObject);
4517
+ if ("allOf" in schemaObject) enqueue(schemaObject.allOf);
4518
+ if ("oneOf" in schemaObject) enqueue(schemaObject.oneOf);
4519
+ if ("anyOf" in schemaObject) enqueue(schemaObject.anyOf);
4520
+ if ("not" in schemaObject) enqueue(schemaObject.not);
4521
+ if ("items" in schemaObject) enqueue(schemaObject.items);
4522
+ if ("prefixItems" in schemaObject) enqueue(schemaObject.prefixItems);
4523
+ if (schemaObject.properties) enqueue(Object.values(schemaObject.properties));
4524
+ if (schemaObject.additionalProperties && typeof schemaObject.additionalProperties === "object") enqueue(schemaObject.additionalProperties);
4525
+ };
4526
+ for (const schema$2 of Object.values(components.schemas)) visit(schema$2);
4527
+ }
4488
4528
  /**
4489
4529
  * Oas does not have a getResponseBody(contentType)
4490
4530
  */