@kubb/adapter-oas 5.0.0-beta.21 → 5.0.0-beta.23
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.cjs +18 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +35 -17
- package/dist/index.js +18 -9
- package/dist/index.js.map +1 -1
- package/extension.yaml +144 -57
- package/package.json +2 -2
- package/src/adapter.ts +14 -6
- package/src/types.ts +21 -11
package/dist/index.d.ts
CHANGED
|
@@ -418,8 +418,9 @@ type ResponseObject$1 = ResponseObject$2;
|
|
|
418
418
|
*/
|
|
419
419
|
type MediaTypeObject$1 = MediaTypeObject$2;
|
|
420
420
|
/**
|
|
421
|
-
* Configuration options for the OpenAPI adapter.
|
|
422
|
-
*
|
|
421
|
+
* Configuration options for the OpenAPI adapter. Controls spec validation,
|
|
422
|
+
* content-type selection, server URL resolution, and how types are derived
|
|
423
|
+
* from the spec.
|
|
423
424
|
*
|
|
424
425
|
* @example
|
|
425
426
|
* ```ts
|
|
@@ -433,23 +434,28 @@ type MediaTypeObject$1 = MediaTypeObject$2;
|
|
|
433
434
|
*/
|
|
434
435
|
type AdapterOasOptions = {
|
|
435
436
|
/**
|
|
436
|
-
* Validate the OpenAPI spec before parsing.
|
|
437
|
+
* Validate the OpenAPI spec with `@readme/openapi-parser` before parsing.
|
|
438
|
+
* Set to `false` only when you have a known-invalid spec you still want to
|
|
439
|
+
* generate from.
|
|
440
|
+
*
|
|
437
441
|
* @default true
|
|
438
442
|
*/
|
|
439
443
|
validate?: boolean;
|
|
440
444
|
/**
|
|
441
|
-
* Preferred
|
|
442
|
-
*
|
|
445
|
+
* Preferred media type when an operation defines several. Defaults to the
|
|
446
|
+
* first JSON-compatible media type found in the spec.
|
|
443
447
|
*/
|
|
444
448
|
contentType?: ContentType;
|
|
445
449
|
/**
|
|
446
|
-
* Index into `
|
|
447
|
-
*
|
|
450
|
+
* Index into the `servers` array from your OpenAPI spec. Used to compute the
|
|
451
|
+
* base URL for plugins that need it. Most projects pick `0` for the primary
|
|
452
|
+
* server. Omit to leave `baseURL` undefined.
|
|
448
453
|
*/
|
|
449
454
|
serverIndex?: number;
|
|
450
455
|
/**
|
|
451
456
|
* Override values for `{variable}` placeholders in the selected server URL.
|
|
452
|
-
* Only used when `serverIndex` is set.
|
|
457
|
+
* Only used when `serverIndex` is set. Variables you do not provide use
|
|
458
|
+
* their `default` value from the spec.
|
|
453
459
|
*
|
|
454
460
|
* @example
|
|
455
461
|
* ```ts
|
|
@@ -460,9 +466,13 @@ type AdapterOasOptions = {
|
|
|
460
466
|
*/
|
|
461
467
|
serverVariables?: Record<string, string>;
|
|
462
468
|
/**
|
|
463
|
-
* How the discriminator field is interpreted.
|
|
464
|
-
* - `'strict'`
|
|
465
|
-
*
|
|
469
|
+
* How the `discriminator` field on `oneOf`/`anyOf` schemas is interpreted.
|
|
470
|
+
* - `'strict'` — child schemas stay exactly as written; the discriminator
|
|
471
|
+
* narrows types at the call site but child shapes are not modified.
|
|
472
|
+
* - `'inherit'` — Kubb propagates the discriminator property as a literal
|
|
473
|
+
* value into each child schema, so each branch's discriminator field is
|
|
474
|
+
* precisely typed.
|
|
475
|
+
*
|
|
466
476
|
* @default 'strict'
|
|
467
477
|
*/
|
|
468
478
|
discriminator?: 'strict' | 'inherit';
|
|
@@ -500,14 +510,17 @@ type AdapterOas = AdapterFactoryOptions<'oas', AdapterOasOptions, AdapterOasReso
|
|
|
500
510
|
//#endregion
|
|
501
511
|
//#region src/adapter.d.ts
|
|
502
512
|
/**
|
|
503
|
-
*
|
|
513
|
+
* Canonical adapter name for `@kubb/adapter-oas`. Used for driver lookups.
|
|
504
514
|
*/
|
|
505
515
|
declare const adapterOasName = "oas";
|
|
506
516
|
/**
|
|
507
|
-
*
|
|
517
|
+
* Default Kubb adapter for OpenAPI 2.0, 3.0, and 3.1 specifications. Reads the
|
|
518
|
+
* file at `input.path`, validates it, resolves the base URL, and converts every
|
|
519
|
+
* schema and operation into the universal AST that every downstream plugin
|
|
520
|
+
* consumes.
|
|
508
521
|
*
|
|
509
|
-
*
|
|
510
|
-
*
|
|
522
|
+
* Configure once on `defineConfig`. The adapter's choices (date representation,
|
|
523
|
+
* integer width, server URL) apply to every plugin in the build.
|
|
511
524
|
*
|
|
512
525
|
* @example
|
|
513
526
|
* ```ts
|
|
@@ -516,8 +529,13 @@ declare const adapterOasName = "oas";
|
|
|
516
529
|
* import { pluginTs } from '@kubb/plugin-ts'
|
|
517
530
|
*
|
|
518
531
|
* export default defineConfig({
|
|
519
|
-
*
|
|
520
|
-
*
|
|
532
|
+
* input: { path: './petStore.yaml' },
|
|
533
|
+
* output: { path: './src/gen' },
|
|
534
|
+
* adapter: adapterOas({
|
|
535
|
+
* serverIndex: 0,
|
|
536
|
+
* discriminator: 'inherit',
|
|
537
|
+
* dateType: 'date',
|
|
538
|
+
* }),
|
|
521
539
|
* plugins: [pluginTs()],
|
|
522
540
|
* })
|
|
523
541
|
* ```
|
package/dist/index.js
CHANGED
|
@@ -340,12 +340,13 @@ var URLPath = class {
|
|
|
340
340
|
* @example
|
|
341
341
|
* new URLPath('/pet/{petId}').toTemplateString() // '`/pet/${petId}`'
|
|
342
342
|
*/
|
|
343
|
-
toTemplateString({ prefix
|
|
344
|
-
|
|
343
|
+
toTemplateString({ prefix, replacer } = {}) {
|
|
344
|
+
const result = this.path.split(/\{([^}]+)\}/).map((part, i) => {
|
|
345
345
|
if (i % 2 === 0) return part;
|
|
346
346
|
const param = this.#transformParam(part);
|
|
347
347
|
return `\${${replacer ? replacer(param) : param}}`;
|
|
348
|
-
}).join("")
|
|
348
|
+
}).join("");
|
|
349
|
+
return `\`${prefix ?? ""}${result}\``;
|
|
349
350
|
}
|
|
350
351
|
/**
|
|
351
352
|
* Extracts all `{param}` segments from the path and returns them as a key-value map.
|
|
@@ -2004,14 +2005,17 @@ function createInputStream({ schemas, parseSchema, parseOperation, baseOas, pars
|
|
|
2004
2005
|
//#endregion
|
|
2005
2006
|
//#region src/adapter.ts
|
|
2006
2007
|
/**
|
|
2007
|
-
*
|
|
2008
|
+
* Canonical adapter name for `@kubb/adapter-oas`. Used for driver lookups.
|
|
2008
2009
|
*/
|
|
2009
2010
|
const adapterOasName = "oas";
|
|
2010
2011
|
/**
|
|
2011
|
-
*
|
|
2012
|
+
* Default Kubb adapter for OpenAPI 2.0, 3.0, and 3.1 specifications. Reads the
|
|
2013
|
+
* file at `input.path`, validates it, resolves the base URL, and converts every
|
|
2014
|
+
* schema and operation into the universal AST that every downstream plugin
|
|
2015
|
+
* consumes.
|
|
2012
2016
|
*
|
|
2013
|
-
*
|
|
2014
|
-
*
|
|
2017
|
+
* Configure once on `defineConfig`. The adapter's choices (date representation,
|
|
2018
|
+
* integer width, server URL) apply to every plugin in the build.
|
|
2015
2019
|
*
|
|
2016
2020
|
* @example
|
|
2017
2021
|
* ```ts
|
|
@@ -2020,8 +2024,13 @@ const adapterOasName = "oas";
|
|
|
2020
2024
|
* import { pluginTs } from '@kubb/plugin-ts'
|
|
2021
2025
|
*
|
|
2022
2026
|
* export default defineConfig({
|
|
2023
|
-
*
|
|
2024
|
-
*
|
|
2027
|
+
* input: { path: './petStore.yaml' },
|
|
2028
|
+
* output: { path: './src/gen' },
|
|
2029
|
+
* adapter: adapterOas({
|
|
2030
|
+
* serverIndex: 0,
|
|
2031
|
+
* discriminator: 'inherit',
|
|
2032
|
+
* dateType: 'date',
|
|
2033
|
+
* }),
|
|
2025
2034
|
* plugins: [pluginTs()],
|
|
2026
2035
|
* })
|
|
2027
2036
|
* ```
|