@kubb/adapter-oas 5.0.0-beta.105 → 5.0.0-beta.107
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/README.md +10 -8
- package/dist/index.cjs +44 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +43 -6
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -45,29 +45,31 @@ import { defineConfig } from 'kubb'
|
|
|
45
45
|
import { adapterOas } from '@kubb/adapter-oas'
|
|
46
46
|
|
|
47
47
|
export default defineConfig({
|
|
48
|
-
input:
|
|
49
|
-
path: './openapi.yaml',
|
|
50
|
-
},
|
|
48
|
+
input: './openapi.yaml',
|
|
51
49
|
output: {
|
|
52
50
|
path: './src/gen',
|
|
53
51
|
},
|
|
54
|
-
|
|
52
|
+
adapter: adapterOas(),
|
|
55
53
|
})
|
|
56
54
|
```
|
|
57
55
|
|
|
56
|
+
`input` accepts a file path, a URL, an inline JSON or YAML string, or a parsed spec object.
|
|
57
|
+
|
|
58
58
|
## API
|
|
59
59
|
|
|
60
60
|
### `adapterOas(options?)`
|
|
61
61
|
|
|
62
|
-
Creates the OAS adapter instance. Pass it
|
|
62
|
+
Creates the OAS adapter instance. Pass it as `adapter` in `defineConfig`.
|
|
63
63
|
|
|
64
|
-
### `
|
|
64
|
+
### `adapterOasName`
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
The adapter's name, `'oas'`. Use it to identify this adapter in a Kubb config.
|
|
67
67
|
|
|
68
68
|
### Types
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
The package re-exports the OpenAPI types it works with: `ContentType`, `DiscriminatorObject`, `Document`,
|
|
71
|
+
`MediaTypeObject`, `Operation`, `ReferenceObject`, `ResponseObject`, and `SchemaObject`. Its own option types are
|
|
72
|
+
`AdapterOas`, `AdapterOasOptions`, and `AdapterOasResolvedOptions`.
|
|
71
73
|
|
|
72
74
|
## Supporting Kubb
|
|
73
75
|
|
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));
|
|
@@ -38,8 +38,8 @@ let _kubb_kit = require("@kubb/kit");
|
|
|
38
38
|
const DEFAULT_PARSER_OPTIONS = {
|
|
39
39
|
dateType: "string",
|
|
40
40
|
integerType: "bigint",
|
|
41
|
-
unknownType: "
|
|
42
|
-
emptySchemaType: "
|
|
41
|
+
unknownType: "unknown",
|
|
42
|
+
emptySchemaType: "unknown",
|
|
43
43
|
enumSuffix: "enum"
|
|
44
44
|
};
|
|
45
45
|
/**
|
|
@@ -96,6 +96,20 @@ const specialCasedFormats = /* @__PURE__ */ new Set([
|
|
|
96
96
|
"time"
|
|
97
97
|
]);
|
|
98
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
|
+
/**
|
|
99
113
|
* Static map from OAS `format` strings to Kubb `SchemaType` values.
|
|
100
114
|
*
|
|
101
115
|
* Only formats whose AST type differs from the OAS `type` field appear here.
|
|
@@ -435,6 +449,24 @@ async function parseFromConfig(source) {
|
|
|
435
449
|
return parseDocument(resolved);
|
|
436
450
|
}
|
|
437
451
|
/**
|
|
452
|
+
* Asserts the parsed input is an OpenAPI or Swagger document.
|
|
453
|
+
*
|
|
454
|
+
* {@link validateDocument} keeps spec violations non-fatal so imperfect but usable documents still
|
|
455
|
+
* generate. That leniency also swallowed input that is not a document at all, which then produced
|
|
456
|
+
* an empty build with a success exit code. A missing version field is the one failure that cannot
|
|
457
|
+
* be a usable document, so it is fatal regardless of the `validate` option.
|
|
458
|
+
*/
|
|
459
|
+
function assertDocument(document) {
|
|
460
|
+
if (document && ("openapi" in document || "swagger" in document)) return;
|
|
461
|
+
throw new _kubb_core.Diagnostics.Error({
|
|
462
|
+
code: _kubb_core.Diagnostics.code.invalidDocument,
|
|
463
|
+
severity: "error",
|
|
464
|
+
message: "The resolved `input` is not an OpenAPI or Swagger document: it declares no `openapi` or `swagger` version.",
|
|
465
|
+
help: "Point `input` at a document that declares `openapi` or `swagger`. If you pass an object, pass the spec itself rather than a wrapper such as `{ path }` or `{ data }`.",
|
|
466
|
+
location: { kind: "config" }
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
438
470
|
* Validates an OpenAPI document using `@readme/openapi-parser` with colorized error output.
|
|
439
471
|
*
|
|
440
472
|
* @example
|
|
@@ -1363,13 +1395,15 @@ function convertConst({ schema, name, nullable, defaultValue }) {
|
|
|
1363
1395
|
* `format` rule's `match` has confirmed the format is handled (see `isHandledFormat`) and, for
|
|
1364
1396
|
* a date-ish format, that `dateType` is not `false`.
|
|
1365
1397
|
*/
|
|
1366
|
-
function convertFormat(
|
|
1398
|
+
function convertFormat(context) {
|
|
1399
|
+
const { schema, name, nullable, defaultValue, options, type } = context;
|
|
1367
1400
|
const ctx = {
|
|
1368
1401
|
schema,
|
|
1369
1402
|
name,
|
|
1370
1403
|
nullable,
|
|
1371
1404
|
defaultValue
|
|
1372
1405
|
};
|
|
1406
|
+
if (type === "string" && numericFormats.has(schema.format)) return convertString(context);
|
|
1373
1407
|
if (schema.format === "int64" || schema.format === "uint64") return createNode(ctx, {
|
|
1374
1408
|
type: options.integerType === "bigint" ? "bigint" : "integer",
|
|
1375
1409
|
primitive: "integer",
|
|
@@ -1607,9 +1641,9 @@ function convertObject({ schema, name, nullable, defaultValue, rawOptions, optio
|
|
|
1607
1641
|
/**
|
|
1608
1642
|
* Converts an OAS 3.1 `prefixItems` tuple into a `TupleSchemaNode`.
|
|
1609
1643
|
*/
|
|
1610
|
-
function convertTuple({ schema, name, nullable, defaultValue, rawOptions, parse }) {
|
|
1644
|
+
function convertTuple({ schema, name, nullable, defaultValue, rawOptions, options, parse }) {
|
|
1611
1645
|
const tupleItems = (schema.prefixItems ?? []).map((item) => parse({ schema: item }, rawOptions));
|
|
1612
|
-
const rest = schema.items === false ? void 0 : !schema.items || schema.items === true ? _kubb_ast.ast.factory.createSchema({ type:
|
|
1646
|
+
const rest = schema.items === false ? void 0 : !schema.items || schema.items === true ? _kubb_ast.ast.factory.createSchema({ type: options.unknownType }) : parse({ schema: schema.items }, rawOptions);
|
|
1613
1647
|
return createNode({
|
|
1614
1648
|
schema,
|
|
1615
1649
|
name,
|
|
@@ -2475,13 +2509,16 @@ const adapterOas = (0, _kubb_core.createAdapter)((options) => {
|
|
|
2475
2509
|
},
|
|
2476
2510
|
async validate(input, options) {
|
|
2477
2511
|
await assertInputExists(input);
|
|
2478
|
-
|
|
2512
|
+
const document = await parseDocument(input);
|
|
2513
|
+
assertDocument(document);
|
|
2514
|
+
await validateDocument(document, options);
|
|
2479
2515
|
},
|
|
2480
2516
|
async parse(source) {
|
|
2481
2517
|
const cached = inputCache.get(source);
|
|
2482
2518
|
if (cached) return cached;
|
|
2483
2519
|
const promise = (async () => {
|
|
2484
2520
|
const document = await parseFromConfig(source);
|
|
2521
|
+
assertDocument(document);
|
|
2485
2522
|
if (validate) await validateDocument(document);
|
|
2486
2523
|
parsedDocument = document;
|
|
2487
2524
|
const refs = createRefs(document);
|