@kubb/adapter-oas 5.0.0-beta.106 → 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 +26 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +26 -5
- 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
|
@@ -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
|
/**
|
|
@@ -449,6 +449,24 @@ async function parseFromConfig(source) {
|
|
|
449
449
|
return parseDocument(resolved);
|
|
450
450
|
}
|
|
451
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
|
+
/**
|
|
452
470
|
* Validates an OpenAPI document using `@readme/openapi-parser` with colorized error output.
|
|
453
471
|
*
|
|
454
472
|
* @example
|
|
@@ -1623,9 +1641,9 @@ function convertObject({ schema, name, nullable, defaultValue, rawOptions, optio
|
|
|
1623
1641
|
/**
|
|
1624
1642
|
* Converts an OAS 3.1 `prefixItems` tuple into a `TupleSchemaNode`.
|
|
1625
1643
|
*/
|
|
1626
|
-
function convertTuple({ schema, name, nullable, defaultValue, rawOptions, parse }) {
|
|
1644
|
+
function convertTuple({ schema, name, nullable, defaultValue, rawOptions, options, parse }) {
|
|
1627
1645
|
const tupleItems = (schema.prefixItems ?? []).map((item) => parse({ schema: item }, rawOptions));
|
|
1628
|
-
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);
|
|
1629
1647
|
return createNode({
|
|
1630
1648
|
schema,
|
|
1631
1649
|
name,
|
|
@@ -2491,13 +2509,16 @@ const adapterOas = (0, _kubb_core.createAdapter)((options) => {
|
|
|
2491
2509
|
},
|
|
2492
2510
|
async validate(input, options) {
|
|
2493
2511
|
await assertInputExists(input);
|
|
2494
|
-
|
|
2512
|
+
const document = await parseDocument(input);
|
|
2513
|
+
assertDocument(document);
|
|
2514
|
+
await validateDocument(document, options);
|
|
2495
2515
|
},
|
|
2496
2516
|
async parse(source) {
|
|
2497
2517
|
const cached = inputCache.get(source);
|
|
2498
2518
|
if (cached) return cached;
|
|
2499
2519
|
const promise = (async () => {
|
|
2500
2520
|
const document = await parseFromConfig(source);
|
|
2521
|
+
assertDocument(document);
|
|
2501
2522
|
if (validate) await validateDocument(document);
|
|
2502
2523
|
parsedDocument = document;
|
|
2503
2524
|
const refs = createRefs(document);
|