@kubb/oas 4.27.2 → 4.27.3

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/index.d.cts CHANGED
@@ -1,5 +1,4 @@
1
- import { findSchemaDefinition, matchesMimeType } from "oas/utils";
2
- import * as oas_normalize_lib_types0 from "oas-normalize/lib/types";
1
+ import * as _readme_openapi_parser0 from "@readme/openapi-parser";
3
2
  import BaseOas from "oas";
4
3
  import { Operation as Operation$1 } from "oas/operation";
5
4
  import * as OasTypes from "oas/types";
@@ -57,7 +56,7 @@ declare class Oas extends BaseOas {
57
56
  getResponseSchema(operation: Operation, statusCode: string | number): SchemaObject;
58
57
  getRequestSchema(operation: Operation): SchemaObject | undefined;
59
58
  getParametersSchema(operation: Operation, inKey: 'path' | 'query' | 'header'): SchemaObject | null;
60
- validate(): Promise<oas_normalize_lib_types0.ValidationResult>;
59
+ validate(): Promise<_readme_openapi_parser0.ValidationResult>;
61
60
  flattenSchema(schema: SchemaObject | null): SchemaObject | null;
62
61
  /**
63
62
  * Get schemas from OpenAPI components (schemas, responses, requestBodies).
@@ -115,7 +114,6 @@ declare function isOptional(schema?: SchemaObject$1): boolean;
115
114
  declare function getDefaultValue(schema?: SchemaObject$1): string | undefined;
116
115
  declare function parse(pathOrApi: string | Document, {
117
116
  oasClass,
118
- canBundle,
119
117
  enablePaths
120
118
  }?: {
121
119
  oasClass?: typeof Oas;
@@ -131,7 +129,7 @@ declare function parseFromConfig(config: Config, oasClass?: typeof Oas): Promise
131
129
  /**
132
130
  * Validate an OpenAPI document using oas-normalize.
133
131
  */
134
- declare function validate(document: Document): Promise<oas_normalize_lib_types0.ValidationResult>;
132
+ declare function validate(document: Document): Promise<_readme_openapi_parser0.ValidationResult>;
135
133
  //#endregion
136
- export { DiscriminatorObject, Document, HttpMethod, HttpMethods, MediaTypeObject, Oas, type OasTypes, type OpenAPIV3, type OpenAPIV3_1, Operation, ReferenceObject, ResponseObject, SchemaObject, contentType, findSchemaDefinition, getDefaultValue, isAllOptional, isDiscriminator, isNullable, isOpenApiV3_1Document, isOptional, isParameterObject, isReference, isRequired, matchesMimeType, merge, parse, parseFromConfig, validate };
134
+ export { DiscriminatorObject, Document, HttpMethod, HttpMethods, MediaTypeObject, Oas, type OasTypes, type OpenAPIV3, type OpenAPIV3_1, Operation, ReferenceObject, ResponseObject, SchemaObject, contentType, getDefaultValue, isAllOptional, isDiscriminator, isNullable, isOpenApiV3_1Document, isOptional, isParameterObject, isReference, isRequired, merge, parse, parseFromConfig, validate };
137
135
  //# sourceMappingURL=index.d.cts.map
package/dist/index.d.ts CHANGED
@@ -1,9 +1,8 @@
1
1
  import { i as __name } from "./chunk-BdfDOGov.js";
2
- import { findSchemaDefinition, matchesMimeType } from "oas/utils";
3
2
  import BaseOas from "oas";
3
+ import * as _readme_openapi_parser0 from "@readme/openapi-parser";
4
4
  import * as OasTypes from "oas/types";
5
5
  import { DiscriminatorObject as DiscriminatorObject$1, HttpMethods as HttpMethods$1, MediaTypeObject as MediaTypeObject$1, OASDocument, ParameterObject, ResponseObject as ResponseObject$1, SchemaObject as SchemaObject$1 } from "oas/types";
6
- import * as oas_normalize_lib_types0 from "oas-normalize/lib/types";
7
6
  import { Operation as Operation$1 } from "oas/operation";
8
7
  import { OpenAPIV3, OpenAPIV3 as OpenAPIV3$1, OpenAPIV3_1, OpenAPIV3_1 as OpenAPIV3_1$1 } from "openapi-types";
9
8
  import { Config } from "@kubb/core";
@@ -56,7 +55,7 @@ declare class Oas extends BaseOas {
56
55
  getResponseSchema(operation: Operation, statusCode: string | number): SchemaObject;
57
56
  getRequestSchema(operation: Operation): SchemaObject | undefined;
58
57
  getParametersSchema(operation: Operation, inKey: 'path' | 'query' | 'header'): SchemaObject | null;
59
- validate(): Promise<oas_normalize_lib_types0.ValidationResult>;
58
+ validate(): Promise<_readme_openapi_parser0.ValidationResult>;
60
59
  flattenSchema(schema: SchemaObject | null): SchemaObject | null;
61
60
  /**
62
61
  * Get schemas from OpenAPI components (schemas, responses, requestBodies).
@@ -114,7 +113,6 @@ declare function isOptional(schema?: SchemaObject$1): boolean;
114
113
  declare function getDefaultValue(schema?: SchemaObject$1): string | undefined;
115
114
  declare function parse(pathOrApi: string | Document, {
116
115
  oasClass,
117
- canBundle,
118
116
  enablePaths
119
117
  }?: {
120
118
  oasClass?: typeof Oas;
@@ -130,7 +128,7 @@ declare function parseFromConfig(config: Config, oasClass?: typeof Oas): Promise
130
128
  /**
131
129
  * Validate an OpenAPI document using oas-normalize.
132
130
  */
133
- declare function validate(document: Document): Promise<oas_normalize_lib_types0.ValidationResult>;
131
+ declare function validate(document: Document): Promise<_readme_openapi_parser0.ValidationResult>;
134
132
  //#endregion
135
- export { DiscriminatorObject, Document, HttpMethod, HttpMethods, MediaTypeObject, Oas, type OasTypes, type OpenAPIV3, type OpenAPIV3_1, Operation, ReferenceObject, ResponseObject, SchemaObject, contentType, findSchemaDefinition, getDefaultValue, isAllOptional, isDiscriminator, isNullable, isOpenApiV3_1Document, isOptional, isParameterObject, isReference, isRequired, matchesMimeType, merge, parse, parseFromConfig, validate };
133
+ export { DiscriminatorObject, Document, HttpMethod, HttpMethods, MediaTypeObject, Oas, type OasTypes, type OpenAPIV3, type OpenAPIV3_1, Operation, ReferenceObject, ResponseObject, SchemaObject, contentType, getDefaultValue, isAllOptional, isDiscriminator, isNullable, isOpenApiV3_1Document, isOptional, isParameterObject, isReference, isRequired, merge, parse, parseFromConfig, validate };
136
134
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import { a as __require, i as __name, n as __esmMin, o as __toCommonJS, r as __exportAll, s as __toESM, t as __commonJSMin } from "./chunk-BdfDOGov.js";
2
- import { findSchemaDefinition, matchesMimeType, matchesMimeType as matchesMimeType$1 } from "oas/utils";
3
2
  import jsonpointer from "jsonpointer";
4
3
  import BaseOas from "oas";
4
+ import { matchesMimeType } from "oas/utils";
5
5
  import path from "node:path";
6
6
  import { pascalCase } from "@kubb/core/transformers";
7
7
  import { URLPath } from "@kubb/core/utils";
8
- import { bundle, loadConfig } from "@redocly/openapi-core";
8
+ import { bundle } from "@readme/openapi-parser";
9
9
  import { isRef } from "oas/types";
10
10
  import OASNormalize from "oas-normalize";
11
11
  import { isPlainObject, mergeDeep } from "remeda";
@@ -4390,16 +4390,15 @@ function getDefaultValue(schema) {
4390
4390
  }
4391
4391
  if (schema.type === "object" || schema.properties) return "{}";
4392
4392
  }
4393
- async function parse(pathOrApi, { oasClass = Oas, canBundle = true, enablePaths = true } = {}) {
4394
- if (typeof pathOrApi === "string" && canBundle) return parse((await bundle({
4395
- ref: pathOrApi,
4396
- config: await loadConfig(),
4397
- base: pathOrApi
4398
- })).bundle.parsed, {
4399
- oasClass,
4400
- canBundle,
4401
- enablePaths
4402
- });
4393
+ async function parse(pathOrApi, { oasClass = Oas, enablePaths = true } = {}) {
4394
+ if (typeof pathOrApi === "string" && !pathOrApi.match(/\n/) && !pathOrApi.match(/^\s*\{/) && enablePaths) try {
4395
+ return parse(await bundle(pathOrApi), {
4396
+ oasClass,
4397
+ enablePaths
4398
+ });
4399
+ } catch (e) {
4400
+ console.warn(`[kubb] Failed to bundle external $refs in "${pathOrApi}": ${e.message}. Falling back to plain load.`);
4401
+ }
4403
4402
  const document = await new OASNormalize(pathOrApi, {
4404
4403
  enablePaths,
4405
4404
  colorizeErrors: true
@@ -4413,8 +4412,7 @@ async function parse(pathOrApi, { oasClass = Oas, canBundle = true, enablePaths
4413
4412
  async function merge(pathOrApi, { oasClass = Oas } = {}) {
4414
4413
  const instances = await Promise.all(pathOrApi.map((p) => parse(p, {
4415
4414
  oasClass,
4416
- enablePaths: false,
4417
- canBundle: false
4415
+ enablePaths: false
4418
4416
  })));
4419
4417
  if (instances.length === 0) throw new Error("No OAS instances provided for merging.");
4420
4418
  return parse(instances.reduce((acc, current) => {
@@ -4756,7 +4754,7 @@ var Oas = class extends BaseOas {
4756
4754
  let availableContentType;
4757
4755
  const contentTypes = Object.keys(responseBody.content);
4758
4756
  contentTypes.forEach((mt) => {
4759
- if (!availableContentType && matchesMimeType$1.json(mt)) availableContentType = mt;
4757
+ if (!availableContentType && matchesMimeType.json(mt)) availableContentType = mt;
4760
4758
  });
4761
4759
  if (!availableContentType) contentTypes.forEach((mt) => {
4762
4760
  if (!availableContentType) availableContentType = mt;
@@ -4907,5 +4905,5 @@ const HttpMethods = {
4907
4905
  };
4908
4906
 
4909
4907
  //#endregion
4910
- export { HttpMethods, Oas, findSchemaDefinition, getDefaultValue, isAllOptional, isDiscriminator, isNullable, isOpenApiV3_1Document, isOptional, isParameterObject, isReference, isRequired, matchesMimeType, merge, parse, parseFromConfig, validate };
4908
+ export { HttpMethods, Oas, getDefaultValue, isAllOptional, isDiscriminator, isNullable, isOpenApiV3_1Document, isOptional, isParameterObject, isReference, isRequired, merge, parse, parseFromConfig, validate };
4911
4909
  //# sourceMappingURL=index.js.map