@kubb/adapter-oas 5.0.0-alpha.73 → 5.0.0-alpha.74
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 +34 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +16 -18
- package/dist/index.js +34 -30
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/parser.ts +37 -18
- package/src/resolvers.ts +13 -21
- package/src/types.ts +16 -18
package/dist/index.d.ts
CHANGED
|
@@ -326,18 +326,18 @@ declare namespace OpenAPIV3 {
|
|
|
326
326
|
//#endregion
|
|
327
327
|
//#region src/types.d.ts
|
|
328
328
|
/**
|
|
329
|
-
* Content-type string
|
|
330
|
-
*
|
|
331
|
-
* Accepts `'application/json'` or any arbitrary media type string.
|
|
329
|
+
* Content-type string for selecting request/response schemas from an OpenAPI spec.
|
|
330
|
+
* Supports `'application/json'` or any other media type.
|
|
332
331
|
*
|
|
333
332
|
* @example
|
|
334
333
|
* ```ts
|
|
335
|
-
* const ct:
|
|
334
|
+
* const ct: ContentType = 'application/vnd.api+json'
|
|
336
335
|
* ```
|
|
337
336
|
*/
|
|
338
337
|
type ContentType = 'application/json' | (string & {});
|
|
339
338
|
/**
|
|
340
|
-
*
|
|
339
|
+
* Extended OpenAPI 3.0 schema object that includes OpenAPI 3.1 and JSON Schema fields.
|
|
340
|
+
* The parser uses these additional fields to handle newer spec versions.
|
|
341
341
|
*
|
|
342
342
|
* @example
|
|
343
343
|
* ```ts
|
|
@@ -380,7 +380,7 @@ type SchemaObject$1 = SchemaObject$2 & {
|
|
|
380
380
|
enum?: Array<string | number | boolean | null>;
|
|
381
381
|
};
|
|
382
382
|
/**
|
|
383
|
-
*
|
|
383
|
+
* Maps uppercase HTTP method names to lowercase for backwards compatibility.
|
|
384
384
|
*
|
|
385
385
|
* @example
|
|
386
386
|
* ```ts
|
|
@@ -390,38 +390,36 @@ type SchemaObject$1 = SchemaObject$2 & {
|
|
|
390
390
|
*/
|
|
391
391
|
declare const HttpMethods$1: Record<Uppercase<ast.HttpMethod>, Lowercase<ast.HttpMethod>>;
|
|
392
392
|
/**
|
|
393
|
-
*
|
|
393
|
+
* HTTP method as a lowercase string (`'get' | 'post' | ...`).
|
|
394
394
|
*/
|
|
395
395
|
type HttpMethod = Lowercase<ast.HttpMethod>;
|
|
396
396
|
/**
|
|
397
|
-
* Normalized OpenAPI document
|
|
397
|
+
* Normalized OpenAPI document after parsing.
|
|
398
398
|
*/
|
|
399
399
|
type Document = OASDocument;
|
|
400
400
|
/**
|
|
401
|
-
*
|
|
401
|
+
* API operation extracted from an OpenAPI document.
|
|
402
402
|
*/
|
|
403
403
|
type Operation = Operation$1;
|
|
404
404
|
/**
|
|
405
|
-
*
|
|
405
|
+
* Discriminator object for `oneOf`/`anyOf` schemas in OpenAPI.
|
|
406
406
|
*/
|
|
407
407
|
type DiscriminatorObject$1 = DiscriminatorObject$2;
|
|
408
408
|
/**
|
|
409
|
-
* OpenAPI
|
|
409
|
+
* OpenAPI reference object pointing to a schema definition via `$ref`.
|
|
410
410
|
*/
|
|
411
411
|
type ReferenceObject$1 = OpenAPIV3.ReferenceObject;
|
|
412
412
|
/**
|
|
413
|
-
* OpenAPI response object
|
|
413
|
+
* OpenAPI response object from a spec that contains schema, status code, and headers.
|
|
414
414
|
*/
|
|
415
415
|
type ResponseObject$1 = ResponseObject$2;
|
|
416
416
|
/**
|
|
417
|
-
* OpenAPI media type object that maps a content-type to
|
|
417
|
+
* OpenAPI media type object that maps a content-type string to its schema.
|
|
418
418
|
*/
|
|
419
419
|
type MediaTypeObject$1 = MediaTypeObject$2;
|
|
420
420
|
/**
|
|
421
|
-
*
|
|
422
|
-
*
|
|
423
|
-
* Extends `ParserOptions` from `@kubb/ast` with adapter-specific controls
|
|
424
|
-
* like spec validation and server URL selection.
|
|
421
|
+
* Configuration options for the OpenAPI adapter.
|
|
422
|
+
* Controls spec validation, content-type selection, and server URL resolution.
|
|
425
423
|
*
|
|
426
424
|
* @example
|
|
427
425
|
* ```ts
|
|
@@ -470,7 +468,7 @@ type AdapterOasOptions = {
|
|
|
470
468
|
discriminator?: 'strict' | 'inherit';
|
|
471
469
|
} & Partial<ast.ParserOptions>;
|
|
472
470
|
/**
|
|
473
|
-
*
|
|
471
|
+
* Adapter options after defaults have been applied and schema name collisions resolved.
|
|
474
472
|
*/
|
|
475
473
|
type AdapterOasResolvedOptions = {
|
|
476
474
|
validate: boolean;
|
package/dist/index.js
CHANGED
|
@@ -764,10 +764,9 @@ function dereferenceWithRef(document, schema) {
|
|
|
764
764
|
//#endregion
|
|
765
765
|
//#region src/resolvers.ts
|
|
766
766
|
/**
|
|
767
|
-
*
|
|
768
|
-
*
|
|
769
|
-
*
|
|
770
|
-
* Throws when an override value is not in the variable's allowed `enum` list.
|
|
767
|
+
* Replaces `{variable}` placeholders in an OpenAPI server URL with provided values.
|
|
768
|
+
* Resolution order: `overrides[key]` → `variable.default` → left unreplaced.
|
|
769
|
+
* Throws if an override value is not in the variable's `enum` list.
|
|
771
770
|
*
|
|
772
771
|
* @example
|
|
773
772
|
* ```ts
|
|
@@ -790,17 +789,15 @@ function resolveServerUrl(server, overrides) {
|
|
|
790
789
|
return url;
|
|
791
790
|
}
|
|
792
791
|
/**
|
|
793
|
-
*
|
|
794
|
-
*
|
|
795
|
-
* which are handled separately because their output depends on parser options.
|
|
792
|
+
* Returns the Kubb `SchemaType` for a given OAS `format` string, or `null` if not found.
|
|
793
|
+
* Formats not in `formatMap` (e.g., `int64`, `date-time`) are handled separately by parser options.
|
|
796
794
|
*/
|
|
797
795
|
function getSchemaType(format) {
|
|
798
796
|
return formatMap[format] ?? null;
|
|
799
797
|
}
|
|
800
798
|
/**
|
|
801
|
-
*
|
|
802
|
-
* Numeric types (`number`, `integer`, `bigint`)
|
|
803
|
-
* `boolean` maps to `'boolean'`; everything else defaults to `'string'`.
|
|
799
|
+
* Converts an OAS primitive type string to its `PrimitiveSchemaType` equivalent.
|
|
800
|
+
* Numeric types (`number`, `integer`, `bigint`) pass through unchanged. `boolean` maps to `'boolean'`. Everything else becomes `'string'`.
|
|
804
801
|
*/
|
|
805
802
|
function getPrimitiveType(type) {
|
|
806
803
|
if (type === "number" || type === "integer" || type === "bigint") return type;
|
|
@@ -808,18 +805,15 @@ function getPrimitiveType(type) {
|
|
|
808
805
|
return "string";
|
|
809
806
|
}
|
|
810
807
|
/**
|
|
811
|
-
* Narrows a
|
|
812
|
-
* Returns `undefined` for content types not present in `KNOWN_MEDIA_TYPES`.
|
|
808
|
+
* Narrows a content-type string to the `MediaType` union Kubb recognizes, or returns `null`.
|
|
813
809
|
*/
|
|
814
810
|
function getMediaType(contentType) {
|
|
815
811
|
return Object.values(ast.mediaTypes).includes(contentType) ? contentType : null;
|
|
816
812
|
}
|
|
817
813
|
/**
|
|
818
|
-
* Returns all
|
|
819
|
-
*
|
|
820
|
-
*
|
|
821
|
-
* `$ref` parameters are resolved via `dereferenceWithRef` to restore backward compatibility
|
|
822
|
-
* with `oas` v31+ which otherwise filters them out.
|
|
814
|
+
* Returns all parameters for an operation, merging path-level and operation-level entries.
|
|
815
|
+
* Operation-level parameters override path-level ones with the same `in:name` key.
|
|
816
|
+
* `$ref` parameters resolve via `dereferenceWithRef` for backward compatibility.
|
|
823
817
|
*
|
|
824
818
|
* @example
|
|
825
819
|
* ```ts
|
|
@@ -886,7 +880,7 @@ function getResponseSchema(document, operation, statusCode, options = {}) {
|
|
|
886
880
|
return dereferenceWithRef(document, schema);
|
|
887
881
|
}
|
|
888
882
|
/**
|
|
889
|
-
* Returns the request body schema for an operation, or `
|
|
883
|
+
* Returns the request body schema for an operation, or `null` when absent.
|
|
890
884
|
*
|
|
891
885
|
* @example
|
|
892
886
|
* ```ts
|
|
@@ -1149,9 +1143,12 @@ function getRequestBodyContentTypes(document, operation) {
|
|
|
1149
1143
|
//#endregion
|
|
1150
1144
|
//#region src/parser.ts
|
|
1151
1145
|
/**
|
|
1152
|
-
*
|
|
1153
|
-
*
|
|
1154
|
-
* but appears in
|
|
1146
|
+
* Normalizes malformed `{ type: 'array', enum: [...] }` schemas by moving enum values into items.
|
|
1147
|
+
*
|
|
1148
|
+
* This pattern violates the OpenAPI spec but appears in real specs. The fix moves enum values
|
|
1149
|
+
* from the array to its items sub-schema, making them valid for downstream processing.
|
|
1150
|
+
*
|
|
1151
|
+
* @note This is a defensive measure for robustness with non-compliant specs.
|
|
1155
1152
|
*/
|
|
1156
1153
|
function normalizeArrayEnum(schema) {
|
|
1157
1154
|
const normalizedItems = {
|
|
@@ -1165,10 +1162,13 @@ function normalizeArrayEnum(schema) {
|
|
|
1165
1162
|
};
|
|
1166
1163
|
}
|
|
1167
1164
|
/**
|
|
1168
|
-
*
|
|
1165
|
+
* Factory function that creates schema and operation converters for a given OpenAPI context.
|
|
1169
1166
|
*
|
|
1170
|
-
*
|
|
1171
|
-
*
|
|
1167
|
+
* Returns closures that share mutable state (`resolvingRefs` set for cycle detection).
|
|
1168
|
+
* Each converter branch (`convertRef`, `convertAllOf`, etc.) mutually recursively calls `parseSchema`,
|
|
1169
|
+
* made possible by hoisting of function declarations.
|
|
1170
|
+
*
|
|
1171
|
+
* @note Not exported; called internally by `parseOas()` and `parseSchema()`.
|
|
1172
1172
|
*/
|
|
1173
1173
|
function createSchemaParser(ctx) {
|
|
1174
1174
|
const document = ctx.document;
|
|
@@ -1826,16 +1826,20 @@ function createSchemaParser(ctx) {
|
|
|
1826
1826
|
};
|
|
1827
1827
|
}
|
|
1828
1828
|
/**
|
|
1829
|
-
*
|
|
1829
|
+
* Parses an OpenAPI specification into Kubb's universal `InputNode` AST.
|
|
1830
|
+
*
|
|
1831
|
+
* This is the main entry point for `@kubb/adapter-oas`. It converts OpenAPI/Swagger specs into a spec-agnostic tree
|
|
1832
|
+
* that downstream plugins (`plugin-ts`, `plugin-zod`, etc.) consume for code generation. No code is generated here —
|
|
1833
|
+
* the tree is a pure data structure representing all schemas and operations.
|
|
1830
1834
|
*
|
|
1831
|
-
*
|
|
1832
|
-
* No code is generated here — the resulting tree is spec-agnostic and consumed by
|
|
1833
|
-
* downstream plugins (`plugin-ts`, `plugin-zod`, …).
|
|
1835
|
+
* Returns the AST root and a `nameMapping` for resolving schema references.
|
|
1834
1836
|
*
|
|
1835
1837
|
* @example
|
|
1836
1838
|
* ```ts
|
|
1839
|
+
* import { parseOas } from '@kubb/adapter-oas'
|
|
1840
|
+
*
|
|
1837
1841
|
* const document = await parseFromConfig(config)
|
|
1838
|
-
* const root = parseOas(document, { dateType: 'date', contentType: 'application/json' })
|
|
1842
|
+
* const { root, nameMapping } = parseOas(document, { dateType: 'date', contentType: 'application/json' })
|
|
1839
1843
|
* ```
|
|
1840
1844
|
*/
|
|
1841
1845
|
function parseOas(document, options = {}) {
|
|
@@ -1962,7 +1966,7 @@ const adapterOas = createAdapter((options) => {
|
|
|
1962
1966
|
//#endregion
|
|
1963
1967
|
//#region src/types.ts
|
|
1964
1968
|
/**
|
|
1965
|
-
*
|
|
1969
|
+
* Maps uppercase HTTP method names to lowercase for backwards compatibility.
|
|
1966
1970
|
*
|
|
1967
1971
|
* @example
|
|
1968
1972
|
* ```ts
|