@kubb/oas 4.33.4 → 4.34.0
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/chunk--u3MIqq1.js +8 -0
- package/dist/index.cjs +251 -4390
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +95 -24
- package/dist/index.js +246 -4379
- package/dist/index.js.map +1 -1
- package/package.json +8 -10
- package/src/Oas.ts +33 -3
- package/src/constants.ts +88 -0
- package/src/index.ts +1 -0
- package/src/parser.ts +1163 -0
- package/src/types.ts +15 -10
- package/src/utils.ts +34 -17
- package/dist/chunk-OuPHjz6n.js +0 -41
package/src/types.ts
CHANGED
|
@@ -19,20 +19,25 @@ export type { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'
|
|
|
19
19
|
export type contentType = 'application/json' | (string & {})
|
|
20
20
|
|
|
21
21
|
export type SchemaObject = OASSchemaObject & {
|
|
22
|
+
/**
|
|
23
|
+
* OAS 3.1 extension: allows marking a schema as nullable even when `type` does not include `'null'`.
|
|
24
|
+
*/
|
|
22
25
|
'x-nullable'?: boolean
|
|
26
|
+
/**
|
|
27
|
+
* OAS 3.1: constrains the schema to a single fixed value.
|
|
28
|
+
* Semantically equivalent to a one-item `enum`.
|
|
29
|
+
*/
|
|
30
|
+
const?: string | number | boolean | null
|
|
31
|
+
/**
|
|
32
|
+
* OAS 3.1: specifies the media type of the schema content.
|
|
33
|
+
* When set to `'application/octet-stream'` on a `string` schema, the schema is treated as binary (`blob`).
|
|
34
|
+
*/
|
|
35
|
+
contentMediaType?: string
|
|
23
36
|
$ref?: string
|
|
24
37
|
}
|
|
25
38
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
POST: 'post',
|
|
29
|
-
PUT: 'put',
|
|
30
|
-
PATCH: 'patch',
|
|
31
|
-
DELETE: 'delete',
|
|
32
|
-
HEAD: 'head',
|
|
33
|
-
OPTIONS: 'options',
|
|
34
|
-
TRACE: 'trace',
|
|
35
|
-
} satisfies Record<Uppercase<OASHttpMethods>, OASHttpMethods>
|
|
39
|
+
/** Re-exported from `constants.ts` for backwards compatibility. */
|
|
40
|
+
export { httpMethods as HttpMethods } from './constants.ts'
|
|
36
41
|
|
|
37
42
|
export type HttpMethod = OASHttpMethods
|
|
38
43
|
|
package/src/utils.ts
CHANGED
|
@@ -3,34 +3,49 @@ import { pascalCase, URLPath } from '@internals/utils'
|
|
|
3
3
|
import type { Config } from '@kubb/core'
|
|
4
4
|
import { bundle, loadConfig } from '@redocly/openapi-core'
|
|
5
5
|
import yaml from '@stoplight/yaml'
|
|
6
|
-
import type { ParameterObject
|
|
6
|
+
import type { ParameterObject } from 'oas/types'
|
|
7
7
|
import { isRef, isSchema } from 'oas/types'
|
|
8
8
|
import OASNormalize from 'oas-normalize'
|
|
9
9
|
import type { OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'
|
|
10
10
|
import { isPlainObject, mergeDeep } from 'remeda'
|
|
11
11
|
import swagger2openapi from 'swagger2openapi'
|
|
12
|
+
import { STRUCTURAL_KEYS } from './constants.ts'
|
|
12
13
|
import { Oas } from './Oas.ts'
|
|
13
|
-
import type { contentType, Document } from './types.ts'
|
|
14
|
+
import type { contentType, Document, SchemaObject } from './types.ts'
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Returns `true` when `doc` looks like a Swagger 2.0 document (no `openapi` key).
|
|
18
|
+
*/
|
|
19
|
+
export function isOpenApiV2Document(doc: unknown): doc is OpenAPIV2.Document {
|
|
20
|
+
return !!doc && isPlainObject(doc) && !('openapi' in doc)
|
|
19
21
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Returns `true` when `doc` looks like an OpenAPI 3.x document (has `openapi` key).
|
|
25
|
+
*/
|
|
26
|
+
export function isOpenApiV3Document(doc: unknown): doc is OpenAPIV3.Document {
|
|
27
|
+
return !!doc && isPlainObject(doc) && 'openapi' in doc
|
|
22
28
|
}
|
|
23
29
|
|
|
24
|
-
|
|
25
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Returns `true` when `doc` is an OpenAPI 3.1 document.
|
|
32
|
+
*/
|
|
33
|
+
export function isOpenApiV3_1Document(doc: unknown): doc is OpenAPIV3_1.Document {
|
|
34
|
+
return !!doc && isPlainObject(doc) && 'openapi' in (doc as object) && (doc as { openapi: string }).openapi.startsWith('3.1')
|
|
26
35
|
}
|
|
27
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Returns `true` when `obj` is a JSON Schema object recognized by the `oas` library.
|
|
39
|
+
*/
|
|
28
40
|
export function isJSONSchema(obj?: unknown): obj is SchemaObject {
|
|
29
41
|
return !!obj && isSchema(obj)
|
|
30
42
|
}
|
|
31
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Returns `true` when `obj` is a parameter object (has an `in` field distinguishing it from a schema).
|
|
46
|
+
*/
|
|
32
47
|
export function isParameterObject(obj: ParameterObject | SchemaObject): obj is ParameterObject {
|
|
33
|
-
return obj && 'in' in obj
|
|
48
|
+
return !!obj && 'in' in obj
|
|
34
49
|
}
|
|
35
50
|
|
|
36
51
|
/**
|
|
@@ -56,17 +71,19 @@ export function isNullable(schema?: SchemaObject & { 'x-nullable'?: boolean }):
|
|
|
56
71
|
}
|
|
57
72
|
|
|
58
73
|
/**
|
|
59
|
-
*
|
|
74
|
+
* Returns `true` when `obj` is an OpenAPI `$ref` pointer object.
|
|
60
75
|
*/
|
|
61
|
-
export function isReference(obj?:
|
|
62
|
-
return !!obj && isRef(obj)
|
|
76
|
+
export function isReference(obj?: unknown): obj is OpenAPIV3.ReferenceObject | OpenAPIV3_1.ReferenceObject {
|
|
77
|
+
return !!obj && isRef(obj as object)
|
|
63
78
|
}
|
|
64
79
|
|
|
65
80
|
/**
|
|
66
|
-
*
|
|
81
|
+
* Returns `true` when `obj` is a schema that carries a structured `discriminator` object
|
|
82
|
+
* (as opposed to a plain string discriminator used in some older specs).
|
|
67
83
|
*/
|
|
68
|
-
export function isDiscriminator(obj?:
|
|
69
|
-
|
|
84
|
+
export function isDiscriminator(obj?: unknown): obj is SchemaObject & { discriminator: OpenAPIV3.DiscriminatorObject } {
|
|
85
|
+
const record = obj as Record<string, unknown>
|
|
86
|
+
return !!obj && !!record['discriminator'] && typeof record['discriminator'] !== 'string'
|
|
70
87
|
}
|
|
71
88
|
|
|
72
89
|
/**
|
package/dist/chunk-OuPHjz6n.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
|
-
//#region \0rolldown/runtime.js
|
|
3
|
-
var __create = Object.create;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __name = (target, value) => __defProp(target, "name", {
|
|
6
|
-
value,
|
|
7
|
-
configurable: true
|
|
8
|
-
});
|
|
9
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
12
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
13
|
-
var __esmMin = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
14
|
-
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
15
|
-
var __exportAll = (all, no_symbols) => {
|
|
16
|
-
let target = {};
|
|
17
|
-
for (var name in all) __defProp(target, name, {
|
|
18
|
-
get: all[name],
|
|
19
|
-
enumerable: true
|
|
20
|
-
});
|
|
21
|
-
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
22
|
-
return target;
|
|
23
|
-
};
|
|
24
|
-
var __copyProps = (to, from, except, desc) => {
|
|
25
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
26
|
-
key = keys[i];
|
|
27
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
28
|
-
get: ((k) => from[k]).bind(null, key),
|
|
29
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
return to;
|
|
33
|
-
};
|
|
34
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
35
|
-
value: mod,
|
|
36
|
-
enumerable: true
|
|
37
|
-
}) : target, mod));
|
|
38
|
-
var __toCommonJS = (mod) => __hasOwnProp.call(mod, "module.exports") ? mod["module.exports"] : __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
39
|
-
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
40
|
-
//#endregion
|
|
41
|
-
export { __require as a, __name as i, __esmMin as n, __toCommonJS as o, __exportAll as r, __toESM as s, __commonJSMin as t };
|