@kubb/adapter-oas 5.0.0-beta.63 → 5.0.0-beta.65
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 +86 -194
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +8 -8
- package/dist/index.js +87 -195
- package/dist/index.js.map +1 -1
- package/package.json +4 -6
- package/src/adapter.bench.ts +0 -60
- package/src/adapter.ts +0 -207
- package/src/bundler.ts +0 -71
- package/src/constants.ts +0 -135
- package/src/dedupe.ts +0 -237
- package/src/dialect.ts +0 -42
- package/src/discriminator.ts +0 -132
- package/src/factory.ts +0 -180
- package/src/guards.ts +0 -68
- package/src/index.ts +0 -15
- package/src/mime.ts +0 -21
- package/src/operation.ts +0 -194
- package/src/parser.ts +0 -1129
- package/src/refs.ts +0 -86
- package/src/resolvers.ts +0 -590
- package/src/schemaDiagnostics.ts +0 -76
- package/src/stream.ts +0 -221
- package/src/types.ts +0 -235
- /package/dist/{chunk-C0LytTxp.js → rolldown-runtime-C0LytTxp.js} +0 -0
package/src/schemaDiagnostics.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { Diagnostics } from '@kubb/core'
|
|
2
|
-
import type { ast } from '@kubb/core'
|
|
3
|
-
import { isHandledFormat } from './resolvers.ts'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Reports the advisory diagnostics (`KUBB_UNSUPPORTED_FORMAT`, `KUBB_DEPRECATED`) for one
|
|
7
|
-
* top-level schema. Walks the node the parser produced during `preScan`, threading the RFC 6901
|
|
8
|
-
* pointer as it descends so a nested field reports against its full path
|
|
9
|
-
* (`#/components/schemas/Pet/properties/owner/properties/name`). Refs are not followed, so the
|
|
10
|
-
* resolved schema is reported under its own walk. Reports land in the active build run, are a
|
|
11
|
-
* no-op outside one, and repeats are deduped by the build.
|
|
12
|
-
*/
|
|
13
|
-
export function reportSchemaDiagnostics({ node, name }: { node: ast.SchemaNode; name: string }): void {
|
|
14
|
-
visit(node, `#/components/schemas/${escapePointerToken(name)}`)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Escapes a single JSON pointer reference token per RFC 6901 (`~` → `~0`, `/` → `~1`), so a
|
|
19
|
-
* property name with those characters maps to a distinct pointer instead of colliding in the dedupe.
|
|
20
|
-
*/
|
|
21
|
-
function escapePointerToken(token: string): string {
|
|
22
|
-
return token.replace(/~/g, '~0').replace(/\//g, '~1')
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function visit(node: ast.SchemaNode, pointer: string): void {
|
|
26
|
-
if (node.deprecated) {
|
|
27
|
-
Diagnostics.report({
|
|
28
|
-
code: Diagnostics.code.deprecated,
|
|
29
|
-
severity: 'info',
|
|
30
|
-
message: 'This schema is marked as deprecated.',
|
|
31
|
-
location: { kind: 'schema', pointer },
|
|
32
|
-
})
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (typeof node.format === 'string' && !isHandledFormat(node.format)) {
|
|
36
|
-
Diagnostics.report({
|
|
37
|
-
code: Diagnostics.code.unsupportedFormat,
|
|
38
|
-
severity: 'warning',
|
|
39
|
-
message: `Kubb does not map the format "${node.format}" to a specific type, so it falls back to the base type.`,
|
|
40
|
-
help: `Use a format Kubb supports, or handle "${node.format}" with a custom parser or plugin.`,
|
|
41
|
-
location: { kind: 'schema', pointer },
|
|
42
|
-
})
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (node.type === 'object') {
|
|
46
|
-
for (const property of node.properties) {
|
|
47
|
-
visit(property.schema, `${pointer}/properties/${escapePointerToken(property.name)}`)
|
|
48
|
-
}
|
|
49
|
-
if (node.additionalProperties && typeof node.additionalProperties === 'object') {
|
|
50
|
-
visit(node.additionalProperties, `${pointer}/additionalProperties`)
|
|
51
|
-
}
|
|
52
|
-
return
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (node.type === 'array') {
|
|
56
|
-
for (const item of node.items ?? []) {
|
|
57
|
-
visit(item, `${pointer}/items`)
|
|
58
|
-
}
|
|
59
|
-
return
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (node.type === 'tuple') {
|
|
63
|
-
// Each tuple position has its own pointer, so index them. A shared `/items` would collapse
|
|
64
|
-
// distinct diagnostics in the dedupe.
|
|
65
|
-
for (const [index, item] of (node.items ?? []).entries()) {
|
|
66
|
-
visit(item, `${pointer}/items/${index}`)
|
|
67
|
-
}
|
|
68
|
-
return
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (node.type === 'union' || node.type === 'intersection') {
|
|
72
|
-
for (const [index, member] of (node.members ?? []).entries()) {
|
|
73
|
-
visit(member, `${pointer}/members/${index}`)
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
package/src/stream.ts
DELETED
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
import { findCircularSchemas } from '@kubb/ast/utils'
|
|
2
|
-
import { ast } from '@kubb/core'
|
|
3
|
-
import type { Plan } from './dedupe.ts'
|
|
4
|
-
import { oasDialect } from './dialect.ts'
|
|
5
|
-
import { buildDiscriminatorChildMap, patchDiscriminatorNode } from './discriminator.ts'
|
|
6
|
-
import { getOperations } from './operation.ts'
|
|
7
|
-
import type { SchemaParser } from './parser.ts'
|
|
8
|
-
import { resolveServerUrl } from './resolvers.ts'
|
|
9
|
-
import { reportSchemaDiagnostics } from './schemaDiagnostics.ts'
|
|
10
|
-
import type { DiscriminatorTarget } from './discriminator.ts'
|
|
11
|
-
import type { AdapterOas, Document, SchemaObject } from './types.ts'
|
|
12
|
-
|
|
13
|
-
export type PreScanResult = {
|
|
14
|
-
refAliasMap: Map<string, ast.SchemaNode>
|
|
15
|
-
enumNames: Array<string>
|
|
16
|
-
circularNames: Array<string>
|
|
17
|
-
discriminatorChildMap: Map<string, DiscriminatorTarget> | null
|
|
18
|
-
dedupePlan: Plan | null
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Reads the server URL from the document's `servers` array at `serverIndex`,
|
|
23
|
-
* interpolating any `serverVariables` into the URL template.
|
|
24
|
-
*
|
|
25
|
-
* Returns `null` when `serverIndex` is omitted or out of range.
|
|
26
|
-
*
|
|
27
|
-
* @example Resolve the first server
|
|
28
|
-
* `resolveBaseUrl({ document, serverIndex: 0 })`
|
|
29
|
-
*
|
|
30
|
-
* @example Override a path variable
|
|
31
|
-
* `resolveBaseUrl({ document, serverIndex: 0, serverVariables: { version: 'v2' } })`
|
|
32
|
-
*/
|
|
33
|
-
export function resolveBaseUrl({
|
|
34
|
-
document,
|
|
35
|
-
serverIndex,
|
|
36
|
-
serverVariables,
|
|
37
|
-
}: {
|
|
38
|
-
document: Document
|
|
39
|
-
serverIndex?: number
|
|
40
|
-
serverVariables?: Record<string, string>
|
|
41
|
-
}): string | null {
|
|
42
|
-
const server = serverIndex !== undefined ? document.servers?.at(serverIndex) : undefined
|
|
43
|
-
return server?.url ? resolveServerUrl(server, serverVariables) : null
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Parses every schema once to build the lookup structures that streaming needs upfront.
|
|
48
|
-
*
|
|
49
|
-
* Three things happen in this single pass:
|
|
50
|
-
* - `refAliasMap` records schemas that are pure `$ref` aliases so the streaming pass can inline them.
|
|
51
|
-
* - `enumNames` collects the names of every enum schema so plugins skip re-scanning the stream.
|
|
52
|
-
* - `circularNames` runs cycle detection, which requires all nodes in memory simultaneously.
|
|
53
|
-
* The `allNodes` array is local and drops out of scope as soon as this function returns.
|
|
54
|
-
*
|
|
55
|
-
* After this call, only `refAliasMap` and `discriminatorChildMap` stay alive in the adapter closure.
|
|
56
|
-
* Both are proportional to the number of aliases or discriminator parents, not total schema count.
|
|
57
|
-
*
|
|
58
|
-
* Each schema is parsed again during the streaming pass. This is intentional.
|
|
59
|
-
* Holding the parsed nodes in memory here would defeat the streaming memory benefit.
|
|
60
|
-
*
|
|
61
|
-
* @example
|
|
62
|
-
* ```ts
|
|
63
|
-
* const { refAliasMap, enumNames, circularNames } = preScan({
|
|
64
|
-
* schemas,
|
|
65
|
-
* parseSchema,
|
|
66
|
-
* parserOptions,
|
|
67
|
-
* discriminator: 'strict',
|
|
68
|
-
* })
|
|
69
|
-
* ```
|
|
70
|
-
*/
|
|
71
|
-
export function preScan({
|
|
72
|
-
schemas,
|
|
73
|
-
parseSchema,
|
|
74
|
-
parseOperation,
|
|
75
|
-
document,
|
|
76
|
-
parserOptions,
|
|
77
|
-
discriminator,
|
|
78
|
-
dedupe,
|
|
79
|
-
}: {
|
|
80
|
-
schemas: Record<string, SchemaObject>
|
|
81
|
-
parseSchema: (entry: { schema: SchemaObject; name: string }, options: ast.ParserOptions) => ast.SchemaNode
|
|
82
|
-
parseOperation: SchemaParser['parseOperation']
|
|
83
|
-
document: Document
|
|
84
|
-
parserOptions: ast.ParserOptions
|
|
85
|
-
discriminator: AdapterOas['options']['discriminator']
|
|
86
|
-
dedupe: boolean
|
|
87
|
-
}): PreScanResult {
|
|
88
|
-
const allNodes: Array<ast.SchemaNode> = []
|
|
89
|
-
const refAliasMap = new Map<string, ast.SchemaNode>()
|
|
90
|
-
const enumNames: Array<string> = []
|
|
91
|
-
const discriminatorParentNodes: Array<ast.SchemaNode> = []
|
|
92
|
-
|
|
93
|
-
for (const [name, schema] of Object.entries(schemas)) {
|
|
94
|
-
const node = parseSchema({ schema, name }, parserOptions)
|
|
95
|
-
allNodes.push(node)
|
|
96
|
-
reportSchemaDiagnostics({ node, name })
|
|
97
|
-
if (node.type === 'ref' && node.name && node.name !== name) {
|
|
98
|
-
refAliasMap.set(name, node)
|
|
99
|
-
}
|
|
100
|
-
if (ast.narrowSchema(node, ast.schemaTypes.enum) && node.name) {
|
|
101
|
-
enumNames.push(node.name)
|
|
102
|
-
}
|
|
103
|
-
if (discriminator === 'inherit' && (schema.oneOf ?? schema.anyOf) && schema.discriminator?.propertyName) {
|
|
104
|
-
discriminatorParentNodes.push(node)
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const circularNames = [...findCircularSchemas(allNodes)]
|
|
109
|
-
const discriminatorChildMap = discriminatorParentNodes.length > 0 ? buildDiscriminatorChildMap(discriminatorParentNodes) : null
|
|
110
|
-
|
|
111
|
-
let dedupePlan: Plan | null = null
|
|
112
|
-
if (dedupe) {
|
|
113
|
-
// One extra parse pass over operations so duplicates in request/response bodies are seen.
|
|
114
|
-
// Reuses the already-parsed `allNodes` for schemas, no second schema parse.
|
|
115
|
-
const operationNodes: Array<ast.OperationNode> = []
|
|
116
|
-
for (const operation of getOperations(document)) {
|
|
117
|
-
const operationNode = parseOperation(parserOptions, operation)
|
|
118
|
-
if (operationNode) operationNodes.push(operationNode)
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const circularSchemas = new Set(circularNames)
|
|
122
|
-
const usedNames = new Set(Object.keys(schemas))
|
|
123
|
-
|
|
124
|
-
dedupePlan = oasDialect.dedupe.plan([...allNodes, ...operationNodes], { circularSchemas, usedNames })
|
|
125
|
-
|
|
126
|
-
for (const definition of dedupePlan.extracted) {
|
|
127
|
-
if (definition.type === 'enum' && definition.name) enumNames.push(definition.name)
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// Enum names that duplicate an earlier schema's content are never emitted, so they are not
|
|
132
|
-
// advertised to plugins either.
|
|
133
|
-
const emittedEnumNames = dedupePlan ? enumNames.filter((name) => !dedupePlan.isAlias(name)) : enumNames
|
|
134
|
-
|
|
135
|
-
return { refAliasMap, enumNames: emittedEnumNames, circularNames, discriminatorChildMap, dedupePlan }
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Creates a lazy `InputNode<true>` from already-resolved adapter state.
|
|
140
|
-
*
|
|
141
|
-
* The schema and operation iterables each start a fresh parse pass on every
|
|
142
|
-
* `[Symbol.asyncIterator]()` call. This lets multiple plugins consume the same
|
|
143
|
-
* stream object independently without sharing a cursor or holding all nodes in memory.
|
|
144
|
-
*
|
|
145
|
-
* Ref aliases in `refAliasMap` are inlined during iteration: an alias entry is replaced
|
|
146
|
-
* with its target's parsed node (but keeps the alias name) so plugins never receive bare `ref` nodes.
|
|
147
|
-
*
|
|
148
|
-
* @example
|
|
149
|
-
* ```ts
|
|
150
|
-
* const streamNode = createInputStream({ schemas, parseSchema, parseOperation, document, parserOptions, refAliasMap, discriminatorChildMap, meta })
|
|
151
|
-
* for await (const schema of streamNode.schemas) {
|
|
152
|
-
* // each call to for-await restarts from the first schema
|
|
153
|
-
* }
|
|
154
|
-
* ```
|
|
155
|
-
*/
|
|
156
|
-
export function createInputStream({
|
|
157
|
-
schemas,
|
|
158
|
-
parseSchema,
|
|
159
|
-
parseOperation,
|
|
160
|
-
document,
|
|
161
|
-
parserOptions,
|
|
162
|
-
refAliasMap,
|
|
163
|
-
discriminatorChildMap,
|
|
164
|
-
dedupePlan,
|
|
165
|
-
meta,
|
|
166
|
-
}: {
|
|
167
|
-
schemas: Record<string, SchemaObject>
|
|
168
|
-
parseSchema: SchemaParser['parseSchema']
|
|
169
|
-
parseOperation: SchemaParser['parseOperation']
|
|
170
|
-
document: Document
|
|
171
|
-
parserOptions: ast.ParserOptions
|
|
172
|
-
refAliasMap: Map<string, ast.SchemaNode>
|
|
173
|
-
discriminatorChildMap: Map<string, DiscriminatorTarget> | null
|
|
174
|
-
dedupePlan: Plan | null
|
|
175
|
-
meta: ast.InputMeta
|
|
176
|
-
}): ast.InputNode<true> {
|
|
177
|
-
const schemasIterable: AsyncIterable<ast.SchemaNode> = {
|
|
178
|
-
[Symbol.asyncIterator]() {
|
|
179
|
-
return (async function* () {
|
|
180
|
-
// Extracted shared definitions are emitted first so the schema list owns the shared shapes.
|
|
181
|
-
if (dedupePlan) {
|
|
182
|
-
for (const definition of dedupePlan.extracted) yield definition
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
for (const [name, schema] of Object.entries(schemas)) {
|
|
186
|
-
// A top-level schema whose content duplicates an earlier one is not emitted: every
|
|
187
|
-
// ref to it is repointed at the first schema with that content, so its model would
|
|
188
|
-
// be dead code.
|
|
189
|
-
if (dedupePlan?.isAlias(name)) continue
|
|
190
|
-
|
|
191
|
-
// Inline ref aliases: replace the alias entry with its target's parsed node
|
|
192
|
-
// (keeping the alias name). Skip the first parse entirely for alias entries
|
|
193
|
-
// since that result is never used.
|
|
194
|
-
const alias = refAliasMap.get(name)
|
|
195
|
-
if (alias?.name && schemas[alias.name]) {
|
|
196
|
-
const aliasNode = { ...parseSchema({ schema: schemas[alias.name]!, name: alias.name }, parserOptions), name }
|
|
197
|
-
yield dedupePlan ? dedupePlan.applyTopLevel(aliasNode) : aliasNode
|
|
198
|
-
continue
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
const parsed = parseSchema({ schema, name }, parserOptions)
|
|
202
|
-
const node = discriminatorChildMap?.get(name) ? patchDiscriminatorNode(parsed, discriminatorChildMap.get(name)!) : parsed
|
|
203
|
-
yield dedupePlan ? dedupePlan.applyTopLevel(node) : node
|
|
204
|
-
}
|
|
205
|
-
})()
|
|
206
|
-
},
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
const operationsIterable: AsyncIterable<ast.OperationNode> = {
|
|
210
|
-
[Symbol.asyncIterator]() {
|
|
211
|
-
return (async function* () {
|
|
212
|
-
for (const operation of getOperations(document)) {
|
|
213
|
-
const node = parseOperation(parserOptions, operation)
|
|
214
|
-
if (node) yield dedupePlan ? dedupePlan.apply(node) : node
|
|
215
|
-
}
|
|
216
|
-
})()
|
|
217
|
-
},
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
return ast.factory.createInput({ stream: true, schemas: schemasIterable, operations: operationsIterable, meta })
|
|
221
|
-
}
|
package/src/types.ts
DELETED
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
import type { AdapterFactoryOptions } from '@kubb/core'
|
|
2
|
-
import type { ast } from '@kubb/core'
|
|
3
|
-
import type { JSONSchema4, JSONSchema6, JSONSchema7 } from 'json-schema'
|
|
4
|
-
import type { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'
|
|
5
|
-
import type { Operation } from './operation.ts'
|
|
6
|
-
|
|
7
|
-
export type { Operation }
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Media type used to pick a schema from an operation's request or response.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```ts
|
|
14
|
-
* const ct: ContentType = 'application/vnd.api+json'
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
export type ContentType = 'application/json' | (string & {})
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Extended OpenAPI 3.0 schema object that includes OpenAPI 3.1 and JSON Schema fields.
|
|
21
|
-
* The parser uses these additional fields to handle newer spec versions.
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```ts
|
|
25
|
-
* const schema: SchemaObject = {
|
|
26
|
-
* type: 'string',
|
|
27
|
-
* const: 'dog',
|
|
28
|
-
* contentMediaType: 'application/octet-stream',
|
|
29
|
-
* }
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
export type SchemaObject = {
|
|
33
|
-
externalDocs?: unknown
|
|
34
|
-
xml?: unknown
|
|
35
|
-
$schema?: string
|
|
36
|
-
deprecated?: boolean
|
|
37
|
-
example?: unknown
|
|
38
|
-
examples?: Array<unknown>
|
|
39
|
-
nullable?: boolean
|
|
40
|
-
readOnly?: boolean
|
|
41
|
-
writeOnly?: boolean
|
|
42
|
-
discriminator?: DiscriminatorObject
|
|
43
|
-
'x-readme-ref-name'?: string
|
|
44
|
-
/**
|
|
45
|
-
* OAS 3.0 vendor extension: marks a schema as nullable without using `type: ['null', ...]`.
|
|
46
|
-
*/
|
|
47
|
-
'x-nullable'?: boolean
|
|
48
|
-
/**
|
|
49
|
-
* OAS 3.1: constrains the schema to a single fixed value (equivalent to a one-item `enum`).
|
|
50
|
-
*/
|
|
51
|
-
const?: string | number | boolean | null
|
|
52
|
-
/**
|
|
53
|
-
* OAS 3.1: media type of the schema content. `'application/octet-stream'` on a `string` schema maps to `blob`.
|
|
54
|
-
*/
|
|
55
|
-
contentMediaType?: string
|
|
56
|
-
$ref?: string
|
|
57
|
-
/**
|
|
58
|
-
* OAS 3.1: positional tuple items, replacing the multi-item `items` array from OAS 3.0.
|
|
59
|
-
*/
|
|
60
|
-
prefixItems?: Array<SchemaObject | ReferenceObject>
|
|
61
|
-
/**
|
|
62
|
-
* JSON Schema: maps regex patterns to sub-schemas for validating additional properties.
|
|
63
|
-
*/
|
|
64
|
-
patternProperties?: Record<string, SchemaObject | boolean>
|
|
65
|
-
/**
|
|
66
|
-
* Single-schema form of `items`. Narrowed from the base type to take precedence over the tuple overload.
|
|
67
|
-
*/
|
|
68
|
-
items?: SchemaObject | ReferenceObject
|
|
69
|
-
/**
|
|
70
|
-
* Allowed values for this schema.
|
|
71
|
-
*/
|
|
72
|
-
enum?: Array<string | number | boolean | null>
|
|
73
|
-
} & (OpenAPIV3.SchemaObject | OpenAPIV3_1.SchemaObject | JSONSchema4 | JSONSchema6 | JSONSchema7)
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* HTTP method in the lowercase form an OpenAPI path item uses for its keys.
|
|
77
|
-
*/
|
|
78
|
-
export type HttpMethod = Lowercase<ast.HttpMethod>
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Normalized OpenAPI document after parsing.
|
|
82
|
-
*/
|
|
83
|
-
export type Document = (OpenAPIV3.Document | OpenAPIV3_1.Document) & Record<string, unknown>
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Single operation object (the `get`/`post`/… entry on a path item) plus any vendor extensions.
|
|
87
|
-
*/
|
|
88
|
-
export type OperationObject = (OpenAPIV3.OperationObject | OpenAPIV3_1.OperationObject) & Record<string, unknown>
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Path item object holding the operations and shared parameters for a single URL path.
|
|
92
|
-
*/
|
|
93
|
-
export type PathItemObject = OpenAPIV3.PathItemObject | OpenAPIV3_1.PathItemObject
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Discriminator object for `oneOf`/`anyOf` schemas in OpenAPI.
|
|
97
|
-
*/
|
|
98
|
-
export type DiscriminatorObject = OpenAPIV3.DiscriminatorObject | OpenAPIV3_1.DiscriminatorObject
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* OpenAPI reference object pointing to a schema definition via `$ref`.
|
|
102
|
-
*/
|
|
103
|
-
export type ReferenceObject = OpenAPIV3.ReferenceObject
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* OpenAPI response object holding the content and headers for one status code.
|
|
107
|
-
*/
|
|
108
|
-
export type ResponseObject = OpenAPIV3.ResponseObject | OpenAPIV3_1.ResponseObject
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* OpenAPI request body object that maps content types to their media type objects.
|
|
112
|
-
*/
|
|
113
|
-
export type RequestBodyObject = OpenAPIV3.RequestBodyObject | OpenAPIV3_1.RequestBodyObject
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* OpenAPI media type object that maps a content-type string to its schema.
|
|
117
|
-
*/
|
|
118
|
-
export type MediaTypeObject = OpenAPIV3.MediaTypeObject | OpenAPIV3_1.MediaTypeObject
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* OpenAPI parameter object, narrowed so `in` is always one of the four valid locations.
|
|
122
|
-
*/
|
|
123
|
-
export type ParameterObject = {
|
|
124
|
-
in: 'cookie' | 'header' | 'path' | 'query'
|
|
125
|
-
} & (OpenAPIV3.ParameterObject | OpenAPIV3_1.ParameterObject)
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* OpenAPI server object describing a base URL and its `{variable}` substitutions.
|
|
129
|
-
*/
|
|
130
|
-
export type ServerObject = OpenAPIV3.ServerObject | OpenAPIV3_1.ServerObject
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Configuration for the OpenAPI adapter: spec validation, content-type selection,
|
|
134
|
-
* server URL resolution, and how schema types are derived.
|
|
135
|
-
*
|
|
136
|
-
* @example
|
|
137
|
-
* ```ts
|
|
138
|
-
* adapterOas({
|
|
139
|
-
* validate: false,
|
|
140
|
-
* dateType: 'date',
|
|
141
|
-
* serverIndex: 0,
|
|
142
|
-
* serverVariables: { env: 'prod' },
|
|
143
|
-
* })
|
|
144
|
-
* ```
|
|
145
|
-
*/
|
|
146
|
-
export type AdapterOasOptions = {
|
|
147
|
-
/**
|
|
148
|
-
* Validate the OpenAPI spec with `@readme/openapi-parser` before parsing.
|
|
149
|
-
* Set to `false` only when you have a known-invalid spec you still want to
|
|
150
|
-
* generate from.
|
|
151
|
-
*
|
|
152
|
-
* @default true
|
|
153
|
-
*/
|
|
154
|
-
validate?: boolean
|
|
155
|
-
/**
|
|
156
|
-
* Preferred media type when an operation defines several. Defaults to the
|
|
157
|
-
* first JSON-compatible media type found in the spec.
|
|
158
|
-
*/
|
|
159
|
-
contentType?: ContentType
|
|
160
|
-
/**
|
|
161
|
-
* Index into the `servers` array from your OpenAPI spec. Used to compute the
|
|
162
|
-
* base URL for plugins that need it. Most projects pick `0` for the primary
|
|
163
|
-
* server. Omit to leave `baseURL` undefined.
|
|
164
|
-
*/
|
|
165
|
-
serverIndex?: number
|
|
166
|
-
/**
|
|
167
|
-
* Override values for `{variable}` placeholders in the selected server URL.
|
|
168
|
-
* Only used when `serverIndex` is set. Variables you do not provide use
|
|
169
|
-
* their `default` value from the spec.
|
|
170
|
-
*
|
|
171
|
-
* @example
|
|
172
|
-
* ```ts
|
|
173
|
-
* // spec server: "https://api.{env}.example.com"
|
|
174
|
-
* serverVariables: { env: 'prod' }
|
|
175
|
-
* // → baseURL: "https://api.prod.example.com"
|
|
176
|
-
* ```
|
|
177
|
-
*/
|
|
178
|
-
serverVariables?: Record<string, string>
|
|
179
|
-
/**
|
|
180
|
-
* How the `discriminator` field on `oneOf`/`anyOf` schemas is interpreted.
|
|
181
|
-
* - `'strict'` child schemas stay exactly as written. The discriminator
|
|
182
|
-
* narrows types at the call site but child shapes are not modified.
|
|
183
|
-
* - `'inherit'` Kubb propagates the discriminator property as a literal
|
|
184
|
-
* value into each child schema, so each branch's discriminator field is
|
|
185
|
-
* precisely typed.
|
|
186
|
-
*
|
|
187
|
-
* @default 'strict'
|
|
188
|
-
*/
|
|
189
|
-
discriminator?: 'strict' | 'inherit'
|
|
190
|
-
/**
|
|
191
|
-
* Collapse structurally identical schemas and enums into a single shared definition.
|
|
192
|
-
*
|
|
193
|
-
* Duplicated inline shapes (especially enums repeated across many properties) are hoisted
|
|
194
|
-
* into one named schema. Every other occurrence, and any structurally identical top-level
|
|
195
|
-
* component, becomes a `ref` to it. Equality is shape-only, so documentation such as
|
|
196
|
-
* `description` and `example` is ignored. Set to `false` to keep every occurrence inline
|
|
197
|
-
* and produce byte-for-byte identical output to earlier versions.
|
|
198
|
-
*
|
|
199
|
-
* @default true
|
|
200
|
-
*/
|
|
201
|
-
dedupe?: boolean
|
|
202
|
-
} & Partial<ast.ParserOptions>
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* Adapter options after defaults have been applied and schema name collisions resolved.
|
|
206
|
-
*/
|
|
207
|
-
export type AdapterOasResolvedOptions = {
|
|
208
|
-
validate: boolean
|
|
209
|
-
contentType: AdapterOasOptions['contentType']
|
|
210
|
-
serverIndex: AdapterOasOptions['serverIndex']
|
|
211
|
-
serverVariables: AdapterOasOptions['serverVariables']
|
|
212
|
-
discriminator: NonNullable<AdapterOasOptions['discriminator']>
|
|
213
|
-
dedupe: NonNullable<AdapterOasOptions['dedupe']>
|
|
214
|
-
dateType: NonNullable<AdapterOasOptions['dateType']>
|
|
215
|
-
integerType: NonNullable<AdapterOasOptions['integerType']>
|
|
216
|
-
unknownType: NonNullable<AdapterOasOptions['unknownType']>
|
|
217
|
-
emptySchemaType: NonNullable<AdapterOasOptions['emptySchemaType']>
|
|
218
|
-
enumSuffix: AdapterOasOptions['enumSuffix']
|
|
219
|
-
/**
|
|
220
|
-
* Map from original `$ref` paths to their collision-resolved schema names.
|
|
221
|
-
* Populated once the adapter resolves a spec's schemas, on the first `stream()` or `parse()`.
|
|
222
|
-
*
|
|
223
|
-
* @example
|
|
224
|
-
* ```ts
|
|
225
|
-
* nameMapping.get('#/components/schemas/Order') // 'Order'
|
|
226
|
-
* nameMapping.get('#/components/responses/Order') // 'OrderResponse'
|
|
227
|
-
* ```
|
|
228
|
-
*/
|
|
229
|
-
nameMapping: Map<string, string>
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* `@kubb/core` adapter factory type for the OpenAPI adapter.
|
|
234
|
-
*/
|
|
235
|
-
export type AdapterOas = AdapterFactoryOptions<'oas', AdapterOasOptions, AdapterOasResolvedOptions, Document>
|
|
File without changes
|