@kubb/adapter-oas 5.0.0-beta.5 → 5.0.0-beta.51
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/LICENSE +17 -10
- package/README.md +100 -0
- package/dist/index.cjs +947 -344
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +52 -96
- package/dist/index.js +948 -339
- package/dist/index.js.map +1 -1
- package/extension.yaml +145 -58
- package/package.json +9 -6
- package/src/adapter.bench.ts +60 -0
- package/src/adapter.ts +139 -50
- package/src/constants.ts +8 -0
- package/src/dialect.ts +38 -0
- package/src/discriminator.ts +31 -47
- package/src/factory.ts +44 -26
- package/src/index.ts +0 -3
- package/src/parser.ts +239 -142
- package/src/refs.ts +31 -5
- package/src/resolvers.ts +77 -38
- package/src/schemaDiagnostics.ts +76 -0
- package/src/stream.ts +278 -0
- package/src/types.ts +34 -11
- /package/dist/{chunk--u3MIqq1.js → chunk-C0LytTxp.js} +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { t as __name } from "./chunk
|
|
2
|
-
import
|
|
3
|
-
import { AdapterFactoryOptions, AdapterSource, ast } from "@kubb/core";
|
|
1
|
+
import { t as __name } from "./chunk-C0LytTxp.js";
|
|
2
|
+
import { AdapterFactoryOptions, ast } from "@kubb/core";
|
|
4
3
|
import { DiscriminatorObject as DiscriminatorObject$2, MediaTypeObject as MediaTypeObject$2, OASDocument, ResponseObject as ResponseObject$2, SchemaObject as SchemaObject$2 } from "oas/types";
|
|
5
4
|
import { Operation as Operation$1 } from "oas/operation";
|
|
6
5
|
|
|
@@ -379,16 +378,6 @@ type SchemaObject$1 = SchemaObject$2 & {
|
|
|
379
378
|
*/
|
|
380
379
|
enum?: Array<string | number | boolean | null>;
|
|
381
380
|
};
|
|
382
|
-
/**
|
|
383
|
-
* Maps uppercase HTTP method names to lowercase for backwards compatibility.
|
|
384
|
-
*
|
|
385
|
-
* @example
|
|
386
|
-
* ```ts
|
|
387
|
-
* HttpMethods['GET'] // 'get'
|
|
388
|
-
* HttpMethods['POST'] // 'post'
|
|
389
|
-
* ```
|
|
390
|
-
*/
|
|
391
|
-
declare const HttpMethods$1: Record<Uppercase<ast.HttpMethod>, Lowercase<ast.HttpMethod>>;
|
|
392
381
|
/**
|
|
393
382
|
* HTTP method as a lowercase string (`'get' | 'post' | ...`).
|
|
394
383
|
*/
|
|
@@ -418,8 +407,9 @@ type ResponseObject$1 = ResponseObject$2;
|
|
|
418
407
|
*/
|
|
419
408
|
type MediaTypeObject$1 = MediaTypeObject$2;
|
|
420
409
|
/**
|
|
421
|
-
* Configuration options for the OpenAPI adapter.
|
|
422
|
-
*
|
|
410
|
+
* Configuration options for the OpenAPI adapter. Controls spec validation,
|
|
411
|
+
* content-type selection, server URL resolution, and how types are derived
|
|
412
|
+
* from the spec.
|
|
423
413
|
*
|
|
424
414
|
* @example
|
|
425
415
|
* ```ts
|
|
@@ -433,23 +423,28 @@ type MediaTypeObject$1 = MediaTypeObject$2;
|
|
|
433
423
|
*/
|
|
434
424
|
type AdapterOasOptions = {
|
|
435
425
|
/**
|
|
436
|
-
* Validate the OpenAPI spec before parsing.
|
|
426
|
+
* Validate the OpenAPI spec with `@readme/openapi-parser` before parsing.
|
|
427
|
+
* Set to `false` only when you have a known-invalid spec you still want to
|
|
428
|
+
* generate from.
|
|
429
|
+
*
|
|
437
430
|
* @default true
|
|
438
431
|
*/
|
|
439
432
|
validate?: boolean;
|
|
440
433
|
/**
|
|
441
|
-
* Preferred
|
|
442
|
-
*
|
|
434
|
+
* Preferred media type when an operation defines several. Defaults to the
|
|
435
|
+
* first JSON-compatible media type found in the spec.
|
|
443
436
|
*/
|
|
444
437
|
contentType?: ContentType;
|
|
445
438
|
/**
|
|
446
|
-
* Index into `
|
|
447
|
-
*
|
|
439
|
+
* Index into the `servers` array from your OpenAPI spec. Used to compute the
|
|
440
|
+
* base URL for plugins that need it. Most projects pick `0` for the primary
|
|
441
|
+
* server. Omit to leave `baseURL` undefined.
|
|
448
442
|
*/
|
|
449
443
|
serverIndex?: number;
|
|
450
444
|
/**
|
|
451
445
|
* Override values for `{variable}` placeholders in the selected server URL.
|
|
452
|
-
* Only used when `serverIndex` is set.
|
|
446
|
+
* Only used when `serverIndex` is set. Variables you do not provide use
|
|
447
|
+
* their `default` value from the spec.
|
|
453
448
|
*
|
|
454
449
|
* @example
|
|
455
450
|
* ```ts
|
|
@@ -460,12 +455,28 @@ type AdapterOasOptions = {
|
|
|
460
455
|
*/
|
|
461
456
|
serverVariables?: Record<string, string>;
|
|
462
457
|
/**
|
|
463
|
-
* How the discriminator field is interpreted.
|
|
464
|
-
* - `'strict'`
|
|
465
|
-
*
|
|
458
|
+
* How the `discriminator` field on `oneOf`/`anyOf` schemas is interpreted.
|
|
459
|
+
* - `'strict'` child schemas stay exactly as written. The discriminator
|
|
460
|
+
* narrows types at the call site but child shapes are not modified.
|
|
461
|
+
* - `'inherit'` Kubb propagates the discriminator property as a literal
|
|
462
|
+
* value into each child schema, so each branch's discriminator field is
|
|
463
|
+
* precisely typed.
|
|
464
|
+
*
|
|
466
465
|
* @default 'strict'
|
|
467
466
|
*/
|
|
468
467
|
discriminator?: 'strict' | 'inherit';
|
|
468
|
+
/**
|
|
469
|
+
* Collapse structurally identical schemas and enums into a single shared definition.
|
|
470
|
+
*
|
|
471
|
+
* Duplicated inline shapes (especially enums repeated across many properties) are hoisted
|
|
472
|
+
* into one named schema. Every other occurrence, and any structurally identical top-level
|
|
473
|
+
* component, becomes a `ref` to it. Equality is shape-only: documentation such as
|
|
474
|
+
* `description` and `example` is ignored. Enabled by default. Set to `false` to keep every
|
|
475
|
+
* occurrence inline and produce byte-for-byte identical output to earlier versions.
|
|
476
|
+
*
|
|
477
|
+
* @default true
|
|
478
|
+
*/
|
|
479
|
+
dedupe?: boolean;
|
|
469
480
|
} & Partial<ast.ParserOptions>;
|
|
470
481
|
/**
|
|
471
482
|
* Adapter options after defaults have been applied and schema name collisions resolved.
|
|
@@ -476,6 +487,7 @@ type AdapterOasResolvedOptions = {
|
|
|
476
487
|
serverIndex: AdapterOasOptions['serverIndex'];
|
|
477
488
|
serverVariables: AdapterOasOptions['serverVariables'];
|
|
478
489
|
discriminator: NonNullable<AdapterOasOptions['discriminator']>;
|
|
490
|
+
dedupe: NonNullable<AdapterOasOptions['dedupe']>;
|
|
479
491
|
dateType: NonNullable<AdapterOasOptions['dateType']>;
|
|
480
492
|
integerType: NonNullable<AdapterOasOptions['integerType']>;
|
|
481
493
|
unknownType: NonNullable<AdapterOasOptions['unknownType']>;
|
|
@@ -500,14 +512,17 @@ type AdapterOas = AdapterFactoryOptions<'oas', AdapterOasOptions, AdapterOasReso
|
|
|
500
512
|
//#endregion
|
|
501
513
|
//#region src/adapter.d.ts
|
|
502
514
|
/**
|
|
503
|
-
*
|
|
515
|
+
* Canonical adapter name for `@kubb/adapter-oas`. Used for driver lookups.
|
|
504
516
|
*/
|
|
505
517
|
declare const adapterOasName = "oas";
|
|
506
518
|
/**
|
|
507
|
-
*
|
|
519
|
+
* Default Kubb adapter for OpenAPI 2.0, 3.0, and 3.1 specifications. Reads the
|
|
520
|
+
* file at `input.path`, validates it, resolves the base URL, and converts every
|
|
521
|
+
* schema and operation into the universal AST that every downstream plugin
|
|
522
|
+
* consumes.
|
|
508
523
|
*
|
|
509
|
-
*
|
|
510
|
-
*
|
|
524
|
+
* Configure once on `defineConfig`. The adapter's choices (date representation,
|
|
525
|
+
* integer width, server URL) apply to every plugin in the build.
|
|
511
526
|
*
|
|
512
527
|
* @example
|
|
513
528
|
* ```ts
|
|
@@ -516,77 +531,18 @@ declare const adapterOasName = "oas";
|
|
|
516
531
|
* import { pluginTs } from '@kubb/plugin-ts'
|
|
517
532
|
*
|
|
518
533
|
* export default defineConfig({
|
|
519
|
-
*
|
|
520
|
-
*
|
|
534
|
+
* input: { path: './petStore.yaml' },
|
|
535
|
+
* output: { path: './src/gen' },
|
|
536
|
+
* adapter: adapterOas({
|
|
537
|
+
* serverIndex: 0,
|
|
538
|
+
* discriminator: 'inherit',
|
|
539
|
+
* dateType: 'date',
|
|
540
|
+
* }),
|
|
521
541
|
* plugins: [pluginTs()],
|
|
522
542
|
* })
|
|
523
543
|
* ```
|
|
524
544
|
*/
|
|
525
|
-
declare const adapterOas: (options?: AdapterOasOptions | undefined) =>
|
|
526
|
-
//#endregion
|
|
527
|
-
//#region src/factory.d.ts
|
|
528
|
-
type ParseOptions = {
|
|
529
|
-
canBundle?: boolean;
|
|
530
|
-
enablePaths?: boolean;
|
|
531
|
-
};
|
|
532
|
-
type ValidateDocumentOptions = {
|
|
533
|
-
throwOnError?: boolean;
|
|
534
|
-
};
|
|
535
|
-
/**
|
|
536
|
-
* Loads and dereferences an OpenAPI document, returning the raw `Document`.
|
|
537
|
-
*
|
|
538
|
-
* Accepts a file path string or an already-parsed document object. File paths are bundled via
|
|
539
|
-
* Redocly to resolve external `$ref`s. Swagger 2.0 documents are automatically up-converted
|
|
540
|
-
* to OpenAPI 3.0 via `swagger2openapi`.
|
|
541
|
-
*
|
|
542
|
-
* @example
|
|
543
|
-
* ```ts
|
|
544
|
-
* const document = await parseDocument('./openapi.yaml')
|
|
545
|
-
* const document = await parse(rawDocumentObject, { canBundle: false })
|
|
546
|
-
* ```
|
|
547
|
-
*/
|
|
548
|
-
declare function parseDocument(pathOrApi: string | Document, {
|
|
549
|
-
canBundle,
|
|
550
|
-
enablePaths
|
|
551
|
-
}?: ParseOptions): Promise<Document>;
|
|
552
|
-
/**
|
|
553
|
-
* Deep-merges multiple OpenAPI documents into a single `Document`.
|
|
554
|
-
*
|
|
555
|
-
* Each document is parsed independently then recursively merged via `mergeDeep` from `@internals/utils`.
|
|
556
|
-
* Throws when the input array is empty.
|
|
557
|
-
*
|
|
558
|
-
* @example
|
|
559
|
-
* ```ts
|
|
560
|
-
* const document = await mergeDocuments(['./pets.yaml', './orders.yaml'])
|
|
561
|
-
* ```
|
|
562
|
-
*/
|
|
563
|
-
declare function mergeDocuments(pathOrApi: Array<string | Document>): Promise<Document>;
|
|
564
|
-
/**
|
|
565
|
-
* Creates a `Document` from an `AdapterSource`.
|
|
566
|
-
*
|
|
567
|
-
* Handles all three source types:
|
|
568
|
-
* - `{ type: 'path' }` — resolves and bundles a local file path or remote URL.
|
|
569
|
-
* - `{ type: 'paths' }` — merges multiple file paths into a single document.
|
|
570
|
-
* - `{ type: 'data' }` — parses an inline string (YAML/JSON) or raw object.
|
|
571
|
-
*
|
|
572
|
-
* @example
|
|
573
|
-
* ```ts
|
|
574
|
-
* const document = await parseFromConfig({ type: 'path', path: './openapi.yaml' })
|
|
575
|
-
* const document = await parseFromConfig({ type: 'data', data: '{"openapi":"3.0.0",...}' })
|
|
576
|
-
* ```
|
|
577
|
-
*/
|
|
578
|
-
declare function parseFromConfig(source: AdapterSource): Promise<Document>;
|
|
579
|
-
/**
|
|
580
|
-
* Validates an OpenAPI document using `oas-normalize` with colorized error output.
|
|
581
|
-
*
|
|
582
|
-
* @example
|
|
583
|
-
* ```ts
|
|
584
|
-
* await validateDocument(document)
|
|
585
|
-
* ```
|
|
586
|
-
*/
|
|
587
|
-
declare function validateDocument(document: Document, {
|
|
588
|
-
throwOnError
|
|
589
|
-
}?: ValidateDocumentOptions): Promise<void>;
|
|
545
|
+
declare const adapterOas: (options?: AdapterOasOptions | undefined) => import("@kubb/core").Adapter<AdapterOas>;
|
|
590
546
|
//#endregion
|
|
591
|
-
export { type AdapterOas, type AdapterOasOptions, type AdapterOasResolvedOptions, type ContentType, type DiscriminatorObject$1 as DiscriminatorObject, type Document, type HttpMethod,
|
|
547
|
+
export { type AdapterOas, type AdapterOasOptions, type AdapterOasResolvedOptions, type ContentType, type DiscriminatorObject$1 as DiscriminatorObject, type Document, type HttpMethod, type MediaTypeObject$1 as MediaTypeObject, type Operation, type ReferenceObject$1 as ReferenceObject, type ResponseObject$1 as ResponseObject, type SchemaObject$1 as SchemaObject, adapterOas, adapterOasName };
|
|
592
548
|
//# sourceMappingURL=index.d.ts.map
|