@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.js
CHANGED
|
@@ -61,17 +61,32 @@ const structuralKeys = /* @__PURE__ */ new Set([
|
|
|
61
61
|
]);
|
|
62
62
|
/**
|
|
63
63
|
* Formats `convertFormat` maps to a dedicated type without going through `formatMap`:
|
|
64
|
-
* `int64` and the date/time family. Keep this in sync with the `convertFormat`
|
|
64
|
+
* `int64`, `uint64` and the date/time family. Keep this in sync with the `convertFormat`
|
|
65
65
|
* special-cases in `parser.ts`. `isHandledFormat` reads it so the
|
|
66
66
|
* `KUBB_UNSUPPORTED_FORMAT` diagnostic and the parser agree on what is handled.
|
|
67
67
|
*/
|
|
68
68
|
const specialCasedFormats = /* @__PURE__ */ new Set([
|
|
69
69
|
"int64",
|
|
70
|
+
"uint64",
|
|
70
71
|
"date-time",
|
|
71
72
|
"date",
|
|
72
73
|
"time"
|
|
73
74
|
]);
|
|
74
75
|
/**
|
|
76
|
+
* Formats that describe a number, whether they resolve through `formatMap` or through the
|
|
77
|
+
* `convertFormat` special cases. On a `type: 'string'` schema these do not make the value a
|
|
78
|
+
* number: gRPC-gateway and other ProtoJSON producers send 64-bit integers as JSON strings.
|
|
79
|
+
*
|
|
80
|
+
* @see https://protobuf.dev/programming-guides/json/#int64-strings
|
|
81
|
+
*/
|
|
82
|
+
const numericFormats = /* @__PURE__ */ new Set([
|
|
83
|
+
"int32",
|
|
84
|
+
"int64",
|
|
85
|
+
"uint64",
|
|
86
|
+
"float",
|
|
87
|
+
"double"
|
|
88
|
+
]);
|
|
89
|
+
/**
|
|
75
90
|
* Static map from OAS `format` strings to Kubb `SchemaType` values.
|
|
76
91
|
*
|
|
77
92
|
* Only formats whose AST type differs from the OAS `type` field appear here.
|
|
@@ -821,14 +836,14 @@ function getOperations(document, refs) {
|
|
|
821
836
|
//#region src/emit/schemaShape.ts
|
|
822
837
|
/**
|
|
823
838
|
* Returns the Kubb `SchemaType` for a given OAS `format` string, or `null` if not found.
|
|
824
|
-
* Formats not in `formatMap` (e.g., `int64`, `date-time`) are handled separately by parser options.
|
|
839
|
+
* Formats not in `formatMap` (e.g., `int64`, `uint64`, `date-time`) are handled separately by parser options.
|
|
825
840
|
*/
|
|
826
841
|
function getSchemaType(format) {
|
|
827
842
|
return formatMap[format] ?? null;
|
|
828
843
|
}
|
|
829
844
|
/**
|
|
830
845
|
* Whether the parser maps `format` to a dedicated type. True for any `formatMap` entry, plus the
|
|
831
|
-
* `specialCasedFormats` that `convertFormat` handles directly. False means the format falls back to
|
|
846
|
+
* `specialCasedFormats` that `convertFormat` handles directly (int64, uint64, date-time, date, time). False means the format falls back to
|
|
832
847
|
* the base type, which is what `KUBB_UNSUPPORTED_FORMAT` flags. Reading both sources keeps the
|
|
833
848
|
* diagnostic in step with the parser as `formatMap` grows.
|
|
834
849
|
*/
|
|
@@ -1339,14 +1354,16 @@ function convertConst({ schema, name, nullable, defaultValue }) {
|
|
|
1339
1354
|
* `format` rule's `match` has confirmed the format is handled (see `isHandledFormat`) and, for
|
|
1340
1355
|
* a date-ish format, that `dateType` is not `false`.
|
|
1341
1356
|
*/
|
|
1342
|
-
function convertFormat(
|
|
1357
|
+
function convertFormat(context) {
|
|
1358
|
+
const { schema, name, nullable, defaultValue, options, type } = context;
|
|
1343
1359
|
const ctx = {
|
|
1344
1360
|
schema,
|
|
1345
1361
|
name,
|
|
1346
1362
|
nullable,
|
|
1347
1363
|
defaultValue
|
|
1348
1364
|
};
|
|
1349
|
-
if (
|
|
1365
|
+
if (type === "string" && numericFormats.has(schema.format)) return convertString(context);
|
|
1366
|
+
if (schema.format === "int64" || schema.format === "uint64") return createNode(ctx, {
|
|
1350
1367
|
type: options.integerType === "bigint" ? "bigint" : "integer",
|
|
1351
1368
|
primitive: "integer",
|
|
1352
1369
|
min: schema.minimum,
|