@kubb/oas 4.15.1 → 4.16.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/index.cjs +14 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +14 -1
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/index.ts +1 -0
- package/src/utils.ts +29 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/oas",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.16.0",
|
|
4
4
|
"description": "OpenAPI Specification (OAS) utilities and helpers for Kubb, providing parsing, normalization, and manipulation of OpenAPI/Swagger schemas.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"openapi",
|
|
@@ -48,15 +48,15 @@
|
|
|
48
48
|
}
|
|
49
49
|
],
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@redocly/openapi-core": "^2.14.
|
|
51
|
+
"@redocly/openapi-core": "^2.14.5",
|
|
52
52
|
"json-schema-to-ts": "^3.1.1",
|
|
53
53
|
"jsonpointer": "^5.0.1",
|
|
54
54
|
"oas": "^28.8.3",
|
|
55
55
|
"oas-normalize": "^15.7.0",
|
|
56
56
|
"openapi-types": "^12.1.3",
|
|
57
|
-
"remeda": "^2.33.
|
|
57
|
+
"remeda": "^2.33.2",
|
|
58
58
|
"swagger2openapi": "^7.0.8",
|
|
59
|
-
"@kubb/core": "4.
|
|
59
|
+
"@kubb/core": "4.16.0"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@stoplight/yaml": "^4.3.0",
|
package/src/index.ts
CHANGED
package/src/utils.ts
CHANGED
|
@@ -76,6 +76,35 @@ export function isRequired(schema?: SchemaObject): boolean {
|
|
|
76
76
|
return Array.isArray(schema.required) ? !!schema.required?.length : !!schema.required
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
// Helper to determine if a schema (and its composed children) has no required fields
|
|
80
|
+
// This prefers structural optionality over top-level optional flag
|
|
81
|
+
type JSONSchemaLike =
|
|
82
|
+
| {
|
|
83
|
+
required?: readonly string[]
|
|
84
|
+
allOf?: readonly unknown[]
|
|
85
|
+
anyOf?: readonly unknown[]
|
|
86
|
+
oneOf?: readonly unknown[]
|
|
87
|
+
}
|
|
88
|
+
| undefined
|
|
89
|
+
|
|
90
|
+
//TODO make isAllOptional more like isOptional with better typings
|
|
91
|
+
export function isAllOptional(schema: unknown): boolean {
|
|
92
|
+
// If completely absent, consider it optional in context of defaults
|
|
93
|
+
if (!schema) return true
|
|
94
|
+
// If the entire schema itself is optional, it's safe to default
|
|
95
|
+
if (isOptional(schema)) return true
|
|
96
|
+
|
|
97
|
+
const s = schema as JSONSchemaLike
|
|
98
|
+
const hasRequired = Array.isArray(s?.required) && s?.required.length > 0
|
|
99
|
+
if (hasRequired) return false
|
|
100
|
+
|
|
101
|
+
const groups = [s?.allOf, s?.anyOf, s?.oneOf].filter((g): g is readonly unknown[] => Array.isArray(g))
|
|
102
|
+
if (groups.length === 0) return true
|
|
103
|
+
|
|
104
|
+
// Be conservative: only when all composed parts are all-optional we treat it as all-optional
|
|
105
|
+
return groups.every((arr) => arr.every((child) => isAllOptional(child)))
|
|
106
|
+
}
|
|
107
|
+
|
|
79
108
|
export function isOptional(schema?: SchemaObject): boolean {
|
|
80
109
|
return !isRequired(schema)
|
|
81
110
|
}
|