@kubb/adapter-oas 5.0.0-beta.104 → 5.0.0-beta.106
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 +23 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +22 -5
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -16,7 +16,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
}
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
20
20
|
value: mod,
|
|
21
21
|
enumerable: true
|
|
22
22
|
}) : target, mod));
|
|
@@ -84,17 +84,32 @@ const structuralKeys = /* @__PURE__ */ new Set([
|
|
|
84
84
|
]);
|
|
85
85
|
/**
|
|
86
86
|
* Formats `convertFormat` maps to a dedicated type without going through `formatMap`:
|
|
87
|
-
* `int64` and the date/time family. Keep this in sync with the `convertFormat`
|
|
87
|
+
* `int64`, `uint64` and the date/time family. Keep this in sync with the `convertFormat`
|
|
88
88
|
* special-cases in `parser.ts`. `isHandledFormat` reads it so the
|
|
89
89
|
* `KUBB_UNSUPPORTED_FORMAT` diagnostic and the parser agree on what is handled.
|
|
90
90
|
*/
|
|
91
91
|
const specialCasedFormats = /* @__PURE__ */ new Set([
|
|
92
92
|
"int64",
|
|
93
|
+
"uint64",
|
|
93
94
|
"date-time",
|
|
94
95
|
"date",
|
|
95
96
|
"time"
|
|
96
97
|
]);
|
|
97
98
|
/**
|
|
99
|
+
* Formats that describe a number, whether they resolve through `formatMap` or through the
|
|
100
|
+
* `convertFormat` special cases. On a `type: 'string'` schema these do not make the value a
|
|
101
|
+
* number: gRPC-gateway and other ProtoJSON producers send 64-bit integers as JSON strings.
|
|
102
|
+
*
|
|
103
|
+
* @see https://protobuf.dev/programming-guides/json/#int64-strings
|
|
104
|
+
*/
|
|
105
|
+
const numericFormats = /* @__PURE__ */ new Set([
|
|
106
|
+
"int32",
|
|
107
|
+
"int64",
|
|
108
|
+
"uint64",
|
|
109
|
+
"float",
|
|
110
|
+
"double"
|
|
111
|
+
]);
|
|
112
|
+
/**
|
|
98
113
|
* Static map from OAS `format` strings to Kubb `SchemaType` values.
|
|
99
114
|
*
|
|
100
115
|
* Only formats whose AST type differs from the OAS `type` field appear here.
|
|
@@ -844,14 +859,14 @@ function getOperations(document, refs) {
|
|
|
844
859
|
//#region src/emit/schemaShape.ts
|
|
845
860
|
/**
|
|
846
861
|
* Returns the Kubb `SchemaType` for a given OAS `format` string, or `null` if not found.
|
|
847
|
-
* Formats not in `formatMap` (e.g., `int64`, `date-time`) are handled separately by parser options.
|
|
862
|
+
* Formats not in `formatMap` (e.g., `int64`, `uint64`, `date-time`) are handled separately by parser options.
|
|
848
863
|
*/
|
|
849
864
|
function getSchemaType(format) {
|
|
850
865
|
return formatMap[format] ?? null;
|
|
851
866
|
}
|
|
852
867
|
/**
|
|
853
868
|
* Whether the parser maps `format` to a dedicated type. True for any `formatMap` entry, plus the
|
|
854
|
-
* `specialCasedFormats` that `convertFormat` handles directly. False means the format falls back to
|
|
869
|
+
* `specialCasedFormats` that `convertFormat` handles directly (int64, uint64, date-time, date, time). False means the format falls back to
|
|
855
870
|
* the base type, which is what `KUBB_UNSUPPORTED_FORMAT` flags. Reading both sources keeps the
|
|
856
871
|
* diagnostic in step with the parser as `formatMap` grows.
|
|
857
872
|
*/
|
|
@@ -1362,14 +1377,16 @@ function convertConst({ schema, name, nullable, defaultValue }) {
|
|
|
1362
1377
|
* `format` rule's `match` has confirmed the format is handled (see `isHandledFormat`) and, for
|
|
1363
1378
|
* a date-ish format, that `dateType` is not `false`.
|
|
1364
1379
|
*/
|
|
1365
|
-
function convertFormat(
|
|
1380
|
+
function convertFormat(context) {
|
|
1381
|
+
const { schema, name, nullable, defaultValue, options, type } = context;
|
|
1366
1382
|
const ctx = {
|
|
1367
1383
|
schema,
|
|
1368
1384
|
name,
|
|
1369
1385
|
nullable,
|
|
1370
1386
|
defaultValue
|
|
1371
1387
|
};
|
|
1372
|
-
if (
|
|
1388
|
+
if (type === "string" && numericFormats.has(schema.format)) return convertString(context);
|
|
1389
|
+
if (schema.format === "int64" || schema.format === "uint64") return createNode(ctx, {
|
|
1373
1390
|
type: options.integerType === "bigint" ? "bigint" : "integer",
|
|
1374
1391
|
primitive: "integer",
|
|
1375
1392
|
min: schema.minimum,
|