@kubb/adapter-oas 5.0.0-alpha.38 → 5.0.0-alpha.39

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.ts CHANGED
@@ -1,7 +1,10 @@
1
1
  import { t as __name } from "./chunk--u3MIqq1.js";
2
2
  import * as _$_kubb_core0 from "@kubb/core";
3
- import { AdapterFactoryOptions, ast } from "@kubb/core";
4
- import { OASDocument } from "oas/types";
3
+ import { AdapterFactoryOptions, AdapterSource, ast } from "@kubb/core";
4
+ import { DiscriminatorObject as DiscriminatorObject$1, MediaTypeObject as MediaTypeObject$1, OASDocument, ResponseObject as ResponseObject$1, SchemaObject as SchemaObject$1 } from "oas/types";
5
+ import { Operation as Operation$1 } from "oas/operation";
6
+ import { OpenAPIV3 } from "openapi-types";
7
+
5
8
  //#region src/types.d.ts
6
9
  /**
7
10
  * Content-type string used when selecting request/response schemas from a spec.
@@ -14,10 +17,87 @@ import { OASDocument } from "oas/types";
14
17
  * ```
15
18
  */
16
19
  type ContentType = 'application/json' | (string & {});
20
+ /**
21
+ * Augments `oas`'s `SchemaObject` with OAS 3.1 / JSON Schema fields the parser needs.
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * const schema: SchemaObject = {
26
+ * type: 'string',
27
+ * const: 'dog',
28
+ * contentMediaType: 'application/octet-stream',
29
+ * }
30
+ * ```
31
+ */
32
+ type SchemaObject = SchemaObject$1 & {
33
+ /**
34
+ * OAS 3.0 vendor extension: marks a schema as nullable without using `type: ['null', ...]`.
35
+ */
36
+ 'x-nullable'?: boolean;
37
+ /**
38
+ * OAS 3.1: constrains the schema to a single fixed value (equivalent to a one-item `enum`).
39
+ */
40
+ const?: string | number | boolean | null;
41
+ /**
42
+ * OAS 3.1: media type of the schema content. `'application/octet-stream'` on a `string` schema maps to `blob`.
43
+ */
44
+ contentMediaType?: string;
45
+ $ref?: string;
46
+ /**
47
+ * OAS 3.1: positional tuple items, replacing the multi-item `items` array from OAS 3.0.
48
+ */
49
+ prefixItems?: Array<SchemaObject | ReferenceObject>;
50
+ /**
51
+ * JSON Schema: maps regex patterns to sub-schemas for validating additional properties.
52
+ */
53
+ patternProperties?: Record<string, SchemaObject | boolean>;
54
+ /**
55
+ * Single-schema form of `items`. Narrowed from the base type to take precedence over the tuple overload.
56
+ */
57
+ items?: SchemaObject | ReferenceObject;
58
+ /**
59
+ * Enum values for this schema (narrowed from `unknown[]`).
60
+ */
61
+ enum?: Array<string | number | boolean | null>;
62
+ };
63
+ /**
64
+ * Uppercase → lowercase HTTP method map, re-exported for backwards compatibility.
65
+ *
66
+ * @example
67
+ * ```ts
68
+ * HttpMethods['GET'] // 'get'
69
+ * HttpMethods['POST'] // 'post'
70
+ * ```
71
+ */
72
+ declare const HttpMethods: Record<Uppercase<ast.HttpMethod>, Lowercase<ast.HttpMethod>>;
73
+ /**
74
+ * Lowercase HTTP method string as used by the `oas` package (`'get' | 'post' | ...`).
75
+ */
76
+ type HttpMethod = Lowercase<ast.HttpMethod>;
17
77
  /**
18
78
  * Normalized OpenAPI document type used throughout the adapter.
19
79
  */
20
80
  type Document = OASDocument;
81
+ /**
82
+ * Operation wrapper type returned by the `oas` package.
83
+ */
84
+ type Operation = Operation$1;
85
+ /**
86
+ * OpenAPI `discriminator` object attached to a `oneOf`/`anyOf` schema.
87
+ */
88
+ type DiscriminatorObject = DiscriminatorObject$1;
89
+ /**
90
+ * OpenAPI `$ref` pointer object (`{ $ref: string }`).
91
+ */
92
+ type ReferenceObject = OpenAPIV3.ReferenceObject;
93
+ /**
94
+ * OpenAPI response object type (may contain `content`, `description`, `headers`).
95
+ */
96
+ type ResponseObject = ResponseObject$1;
97
+ /**
98
+ * OpenAPI media type object that maps a content-type to a schema.
99
+ */
100
+ type MediaTypeObject = MediaTypeObject$1;
21
101
  /**
22
102
  * User-facing options for `adapterOas(...)`.
23
103
  *
@@ -127,5 +207,69 @@ declare const adapterOasName = "oas";
127
207
  */
128
208
  declare const adapterOas: (options?: AdapterOasOptions | undefined) => _$_kubb_core0.Adapter<AdapterOas>;
129
209
  //#endregion
130
- export { type AdapterOas, adapterOas, adapterOasName };
210
+ //#region src/factory.d.ts
211
+ type ParseOptions = {
212
+ canBundle?: boolean;
213
+ enablePaths?: boolean;
214
+ };
215
+ type ValidateDocumentOptions = {
216
+ throwOnError?: boolean;
217
+ };
218
+ /**
219
+ * Loads and dereferences an OpenAPI document, returning the raw `Document`.
220
+ *
221
+ * Accepts a file path string or an already-parsed document object. File paths are bundled via
222
+ * Redocly to resolve external `$ref`s. Swagger 2.0 documents are automatically up-converted
223
+ * to OpenAPI 3.0 via `swagger2openapi`.
224
+ *
225
+ * @example
226
+ * ```ts
227
+ * const document = await parseDocument('./openapi.yaml')
228
+ * const document = await parse(rawDocumentObject, { canBundle: false })
229
+ * ```
230
+ */
231
+ declare function parseDocument(pathOrApi: string | Document, {
232
+ canBundle,
233
+ enablePaths
234
+ }?: ParseOptions): Promise<Document>;
235
+ /**
236
+ * Deep-merges multiple OpenAPI documents into a single `Document`.
237
+ *
238
+ * Each document is parsed independently then recursively merged with `remeda`'s `mergeDeep`.
239
+ * Throws when the input array is empty.
240
+ *
241
+ * @example
242
+ * ```ts
243
+ * const document = await mergeDocuments(['./pets.yaml', './orders.yaml'])
244
+ * ```
245
+ */
246
+ declare function mergeDocuments(pathOrApi: Array<string | Document>): Promise<Document>;
247
+ /**
248
+ * Creates a `Document` from an `AdapterSource`.
249
+ *
250
+ * Handles all three source types:
251
+ * - `{ type: 'path' }` — resolves and bundles a local file path or remote URL.
252
+ * - `{ type: 'paths' }` — merges multiple file paths into a single document.
253
+ * - `{ type: 'data' }` — parses an inline string (YAML/JSON) or raw object.
254
+ *
255
+ * @example
256
+ * ```ts
257
+ * const document = await parseFromConfig({ type: 'path', path: './openapi.yaml' })
258
+ * const document = await parseFromConfig({ type: 'data', data: '{"openapi":"3.0.0",...}' })
259
+ * ```
260
+ */
261
+ declare function parseFromConfig(source: AdapterSource): Promise<Document>;
262
+ /**
263
+ * Validates an OpenAPI document using `oas-normalize` with colorized error output.
264
+ *
265
+ * @example
266
+ * ```ts
267
+ * await validateDocument(document)
268
+ * ```
269
+ */
270
+ declare function validateDocument(document: Document, {
271
+ throwOnError
272
+ }?: ValidateDocumentOptions): Promise<void>;
273
+ //#endregion
274
+ export { type AdapterOas, type AdapterOasOptions, type AdapterOasResolvedOptions, type ContentType, type DiscriminatorObject, type Document, type HttpMethod, HttpMethods, type MediaTypeObject, type Operation, type ParseOptions, type ReferenceObject, type ResponseObject, type SchemaObject, type ValidateDocumentOptions, adapterOas, adapterOasName, mergeDocuments, parseDocument, parseFromConfig, validateDocument };
131
275
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -581,13 +581,15 @@ function parseFromConfig(source) {
581
581
  * await validateDocument(document)
582
582
  * ```
583
583
  */
584
- async function validateDocument(document) {
584
+ async function validateDocument(document, { throwOnError = false } = {}) {
585
585
  try {
586
586
  await new OASNormalize(document, {
587
587
  enablePaths: true,
588
588
  colorizeErrors: true
589
589
  }).validate({ parser: { validate: { errors: { colorize: true } } } });
590
- } catch (_err) {}
590
+ } catch (error) {
591
+ if (throwOnError) throw error;
592
+ }
591
593
  }
592
594
  //#endregion
593
595
  //#region src/refs.ts
@@ -1745,6 +1747,18 @@ const adapterOas = createAdapter((options) => {
1745
1747
  };
1746
1748
  });
1747
1749
  //#endregion
1748
- export { adapterOas, adapterOasName };
1750
+ //#region src/types.ts
1751
+ /**
1752
+ * Uppercase → lowercase HTTP method map, re-exported for backwards compatibility.
1753
+ *
1754
+ * @example
1755
+ * ```ts
1756
+ * HttpMethods['GET'] // 'get'
1757
+ * HttpMethods['POST'] // 'post'
1758
+ * ```
1759
+ */
1760
+ const HttpMethods = Object.fromEntries(Object.entries(ast.httpMethods).map(([lower, upper]) => [upper, lower]));
1761
+ //#endregion
1762
+ export { HttpMethods, adapterOas, adapterOasName, mergeDocuments, parseDocument, parseFromConfig, validateDocument };
1749
1763
 
1750
1764
  //# sourceMappingURL=index.js.map