@kubb/oas 4.32.4 → 4.33.1
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 +201 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +24 -1
- package/dist/index.js +198 -4
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
- package/src/Oas.ts +8 -1
- package/src/index.ts +2 -1
- package/src/resolveServerUrl.ts +37 -0
- package/src/utils.ts +1 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/oas",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.33.1",
|
|
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",
|
|
@@ -59,11 +59,12 @@
|
|
|
59
59
|
"openapi-types": "^12.1.3",
|
|
60
60
|
"remeda": "^2.33.6",
|
|
61
61
|
"swagger2openapi": "^7.0.8",
|
|
62
|
-
"@kubb/core": "4.
|
|
62
|
+
"@kubb/core": "4.33.1"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"@stoplight/yaml": "^4.3.0",
|
|
66
|
-
"@types/swagger2openapi": "^7.0.4"
|
|
66
|
+
"@types/swagger2openapi": "^7.0.4",
|
|
67
|
+
"@internals/utils": "0.0.0"
|
|
67
68
|
},
|
|
68
69
|
"engines": {
|
|
69
70
|
"node": ">=20"
|
package/src/Oas.ts
CHANGED
|
@@ -14,6 +14,13 @@ import {
|
|
|
14
14
|
validate,
|
|
15
15
|
} from './utils.ts'
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Prefix used to create synthetic `$ref` values for anonymous (inline) discriminator schemas.
|
|
19
|
+
* The suffix is the schema index within the discriminator's `oneOf`/`anyOf` array.
|
|
20
|
+
* @example `#kubb-inline-0`
|
|
21
|
+
*/
|
|
22
|
+
export const KUBB_INLINE_REF_PREFIX = '#kubb-inline-'
|
|
23
|
+
|
|
17
24
|
type OasOptions = {
|
|
18
25
|
contentType?: contentType
|
|
19
26
|
discriminator?: 'strict' | 'inherit'
|
|
@@ -197,7 +204,7 @@ export class Oas extends BaseOas {
|
|
|
197
204
|
if (discriminatorValue) {
|
|
198
205
|
// Create a synthetic ref for inline schemas using index
|
|
199
206
|
// The value points to the inline schema itself via a special marker
|
|
200
|
-
existingMapping[discriminatorValue] =
|
|
207
|
+
existingMapping[discriminatorValue] = `${KUBB_INLINE_REF_PREFIX}${index}`
|
|
201
208
|
}
|
|
202
209
|
}
|
|
203
210
|
})
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
type ServerVariable = {
|
|
2
|
+
default?: string | number
|
|
3
|
+
enum?: (string | number)[]
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
type ServerObject = {
|
|
7
|
+
url: string
|
|
8
|
+
variables?: Record<string, ServerVariable>
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Resolves an OpenAPI server URL by substituting `{variable}` placeholders
|
|
13
|
+
* with values from `overrides` (user-provided) or the spec-defined defaults.
|
|
14
|
+
*
|
|
15
|
+
* Throws if an override value is not in the variable's `enum` list.
|
|
16
|
+
*/
|
|
17
|
+
export function resolveServerUrl(server: ServerObject, overrides?: Record<string, string>): string {
|
|
18
|
+
if (!server.variables) {
|
|
19
|
+
return server.url
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let url = server.url
|
|
23
|
+
for (const [key, variable] of Object.entries(server.variables)) {
|
|
24
|
+
const value = overrides?.[key] ?? (variable.default != null ? String(variable.default) : undefined)
|
|
25
|
+
if (value === undefined) {
|
|
26
|
+
continue
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (variable.enum?.length && !variable.enum.some((e) => String(e) === value)) {
|
|
30
|
+
throw new Error(`Invalid server variable value '${value}' for '${key}' when resolving ${server.url}. Valid values are: ${variable.enum.join(', ')}.`)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
url = url.replaceAll(`{${key}}`, value)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return url
|
|
37
|
+
}
|
package/src/utils.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs'
|
|
2
2
|
import path from 'node:path'
|
|
3
|
+
import { pascalCase, URLPath } from '@internals/utils'
|
|
3
4
|
import type { Config } from '@kubb/core'
|
|
4
|
-
import { pascalCase } from '@kubb/core/transformers'
|
|
5
|
-
import { URLPath } from '@kubb/core/utils'
|
|
6
5
|
import { bundle } from '@readme/openapi-parser'
|
|
7
6
|
import yaml from '@stoplight/yaml'
|
|
8
7
|
import type { ParameterObject, SchemaObject } from 'oas/types'
|