@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.cjs
CHANGED
|
@@ -790,10 +790,9 @@ function dereferenceWithRef(document, schema) {
|
|
|
790
790
|
//#endregion
|
|
791
791
|
//#region src/resolvers.ts
|
|
792
792
|
/**
|
|
793
|
-
*
|
|
794
|
-
*
|
|
795
|
-
*
|
|
796
|
-
* Throws when an override value is not in the variable's allowed `enum` list.
|
|
793
|
+
* Replaces `{variable}` placeholders in an OpenAPI server URL with provided values.
|
|
794
|
+
* Resolution order: `overrides[key]` → `variable.default` → left unreplaced.
|
|
795
|
+
* Throws if an override value is not in the variable's `enum` list.
|
|
797
796
|
*
|
|
798
797
|
* @example
|
|
799
798
|
* ```ts
|
|
@@ -816,17 +815,15 @@ function resolveServerUrl(server, overrides) {
|
|
|
816
815
|
return url;
|
|
817
816
|
}
|
|
818
817
|
/**
|
|
819
|
-
*
|
|
820
|
-
*
|
|
821
|
-
* which are handled separately because their output depends on parser options.
|
|
818
|
+
* Returns the Kubb `SchemaType` for a given OAS `format` string, or `null` if not found.
|
|
819
|
+
* Formats not in `formatMap` (e.g., `int64`, `date-time`) are handled separately by parser options.
|
|
822
820
|
*/
|
|
823
821
|
function getSchemaType(format) {
|
|
824
822
|
return formatMap[format] ?? null;
|
|
825
823
|
}
|
|
826
824
|
/**
|
|
827
|
-
*
|
|
828
|
-
* Numeric types (`number`, `integer`, `bigint`)
|
|
829
|
-
* `boolean` maps to `'boolean'`; everything else defaults to `'string'`.
|
|
825
|
+
* Converts an OAS primitive type string to its `PrimitiveSchemaType` equivalent.
|
|
826
|
+
* Numeric types (`number`, `integer`, `bigint`) pass through unchanged. `boolean` maps to `'boolean'`. Everything else becomes `'string'`.
|
|
830
827
|
*/
|
|
831
828
|
function getPrimitiveType(type) {
|
|
832
829
|
if (type === "number" || type === "integer" || type === "bigint") return type;
|
|
@@ -834,18 +831,15 @@ function getPrimitiveType(type) {
|
|
|
834
831
|
return "string";
|
|
835
832
|
}
|
|
836
833
|
/**
|
|
837
|
-
* Narrows a
|
|
838
|
-
* Returns `undefined` for content types not present in `KNOWN_MEDIA_TYPES`.
|
|
834
|
+
* Narrows a content-type string to the `MediaType` union Kubb recognizes, or returns `null`.
|
|
839
835
|
*/
|
|
840
836
|
function getMediaType(contentType) {
|
|
841
837
|
return Object.values(_kubb_core.ast.mediaTypes).includes(contentType) ? contentType : null;
|
|
842
838
|
}
|
|
843
839
|
/**
|
|
844
|
-
* Returns all
|
|
845
|
-
*
|
|
846
|
-
*
|
|
847
|
-
* `$ref` parameters are resolved via `dereferenceWithRef` to restore backward compatibility
|
|
848
|
-
* with `oas` v31+ which otherwise filters them out.
|
|
840
|
+
* Returns all parameters for an operation, merging path-level and operation-level entries.
|
|
841
|
+
* Operation-level parameters override path-level ones with the same `in:name` key.
|
|
842
|
+
* `$ref` parameters resolve via `dereferenceWithRef` for backward compatibility.
|
|
849
843
|
*
|
|
850
844
|
* @example
|
|
851
845
|
* ```ts
|
|
@@ -912,7 +906,7 @@ function getResponseSchema(document, operation, statusCode, options = {}) {
|
|
|
912
906
|
return dereferenceWithRef(document, schema);
|
|
913
907
|
}
|
|
914
908
|
/**
|
|
915
|
-
* Returns the request body schema for an operation, or `
|
|
909
|
+
* Returns the request body schema for an operation, or `null` when absent.
|
|
916
910
|
*
|
|
917
911
|
* @example
|
|
918
912
|
* ```ts
|
|
@@ -1175,9 +1169,12 @@ function getRequestBodyContentTypes(document, operation) {
|
|
|
1175
1169
|
//#endregion
|
|
1176
1170
|
//#region src/parser.ts
|
|
1177
1171
|
/**
|
|
1178
|
-
*
|
|
1179
|
-
*
|
|
1180
|
-
* but appears in
|
|
1172
|
+
* Normalizes malformed `{ type: 'array', enum: [...] }` schemas by moving enum values into items.
|
|
1173
|
+
*
|
|
1174
|
+
* This pattern violates the OpenAPI spec but appears in real specs. The fix moves enum values
|
|
1175
|
+
* from the array to its items sub-schema, making them valid for downstream processing.
|
|
1176
|
+
*
|
|
1177
|
+
* @note This is a defensive measure for robustness with non-compliant specs.
|
|
1181
1178
|
*/
|
|
1182
1179
|
function normalizeArrayEnum(schema) {
|
|
1183
1180
|
const normalizedItems = {
|
|
@@ -1191,10 +1188,13 @@ function normalizeArrayEnum(schema) {
|
|
|
1191
1188
|
};
|
|
1192
1189
|
}
|
|
1193
1190
|
/**
|
|
1194
|
-
*
|
|
1191
|
+
* Factory function that creates schema and operation converters for a given OpenAPI context.
|
|
1195
1192
|
*
|
|
1196
|
-
*
|
|
1197
|
-
*
|
|
1193
|
+
* Returns closures that share mutable state (`resolvingRefs` set for cycle detection).
|
|
1194
|
+
* Each converter branch (`convertRef`, `convertAllOf`, etc.) mutually recursively calls `parseSchema`,
|
|
1195
|
+
* made possible by hoisting of function declarations.
|
|
1196
|
+
*
|
|
1197
|
+
* @note Not exported; called internally by `parseOas()` and `parseSchema()`.
|
|
1198
1198
|
*/
|
|
1199
1199
|
function createSchemaParser(ctx) {
|
|
1200
1200
|
const document = ctx.document;
|
|
@@ -1852,16 +1852,20 @@ function createSchemaParser(ctx) {
|
|
|
1852
1852
|
};
|
|
1853
1853
|
}
|
|
1854
1854
|
/**
|
|
1855
|
-
*
|
|
1855
|
+
* Parses an OpenAPI specification into Kubb's universal `InputNode` AST.
|
|
1856
|
+
*
|
|
1857
|
+
* This is the main entry point for `@kubb/adapter-oas`. It converts OpenAPI/Swagger specs into a spec-agnostic tree
|
|
1858
|
+
* that downstream plugins (`plugin-ts`, `plugin-zod`, etc.) consume for code generation. No code is generated here —
|
|
1859
|
+
* the tree is a pure data structure representing all schemas and operations.
|
|
1856
1860
|
*
|
|
1857
|
-
*
|
|
1858
|
-
* No code is generated here — the resulting tree is spec-agnostic and consumed by
|
|
1859
|
-
* downstream plugins (`plugin-ts`, `plugin-zod`, …).
|
|
1861
|
+
* Returns the AST root and a `nameMapping` for resolving schema references.
|
|
1860
1862
|
*
|
|
1861
1863
|
* @example
|
|
1862
1864
|
* ```ts
|
|
1865
|
+
* import { parseOas } from '@kubb/adapter-oas'
|
|
1866
|
+
*
|
|
1863
1867
|
* const document = await parseFromConfig(config)
|
|
1864
|
-
* const root = parseOas(document, { dateType: 'date', contentType: 'application/json' })
|
|
1868
|
+
* const { root, nameMapping } = parseOas(document, { dateType: 'date', contentType: 'application/json' })
|
|
1865
1869
|
* ```
|
|
1866
1870
|
*/
|
|
1867
1871
|
function parseOas(document, options = {}) {
|
|
@@ -1988,7 +1992,7 @@ const adapterOas = (0, _kubb_core.createAdapter)((options) => {
|
|
|
1988
1992
|
//#endregion
|
|
1989
1993
|
//#region src/types.ts
|
|
1990
1994
|
/**
|
|
1991
|
-
*
|
|
1995
|
+
* Maps uppercase HTTP method names to lowercase for backwards compatibility.
|
|
1992
1996
|
*
|
|
1993
1997
|
* @example
|
|
1994
1998
|
* ```ts
|