@kubb/adapter-oas 5.0.0-alpha.1 → 5.0.0-alpha.11
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 +432 -220
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +71 -27
- package/dist/index.js +433 -221
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/adapter.ts +28 -8
- package/src/constants.ts +19 -9
- package/src/oas/Oas.ts +16 -9
- package/src/oas/types.ts +19 -0
- package/src/oas/utils.ts +1 -1
- package/src/parser.ts +209 -228
- package/src/types.ts +41 -19
- package/src/utils.ts +168 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
2
|
import * as _kubb_core0 from "@kubb/core";
|
|
3
3
|
import { AdapterFactoryOptions } from "@kubb/core";
|
|
4
|
-
import { DiscriminatorObject, OASDocument, SchemaObject } from "oas/types";
|
|
4
|
+
import { DiscriminatorObject, OASDocument, ParameterObject, SchemaObject } from "oas/types";
|
|
5
5
|
import BaseOas from "oas";
|
|
6
6
|
import * as oas_normalize_lib_types0 from "oas-normalize/lib/types";
|
|
7
7
|
import { Operation } from "oas/operation";
|
|
8
|
+
import { OpenAPIV3 } from "openapi-types";
|
|
8
9
|
|
|
9
10
|
//#region src/oas/types.d.ts
|
|
10
11
|
type contentType = 'application/json' | (string & {});
|
|
@@ -24,10 +25,30 @@ type SchemaObject$1 = SchemaObject & {
|
|
|
24
25
|
*/
|
|
25
26
|
contentMediaType?: string;
|
|
26
27
|
$ref?: string;
|
|
28
|
+
/**
|
|
29
|
+
* OAS 3.1 / JSON Schema: positional items in a tuple schema.
|
|
30
|
+
* Replaces the OAS 3.0 multi-item `items` array syntax.
|
|
31
|
+
*/
|
|
32
|
+
prefixItems?: Array<SchemaObject$1 | ReferenceObject>;
|
|
33
|
+
/**
|
|
34
|
+
* JSON Schema: maps regex patterns to sub-schemas for additional property validation.
|
|
35
|
+
*/
|
|
36
|
+
patternProperties?: Record<string, SchemaObject$1 | boolean>;
|
|
37
|
+
/**
|
|
38
|
+
* OAS 3.0 / JSON Schema: single-schema form.
|
|
39
|
+
* The OAS base type already includes this, but we re-declare it here to ensure
|
|
40
|
+
* the single-schema overload takes precedence over the multi-schema tuple form.
|
|
41
|
+
*/
|
|
42
|
+
items?: SchemaObject$1 | ReferenceObject;
|
|
43
|
+
/**
|
|
44
|
+
* Enum values for this schema (narrowed from `unknown[]` in the base type).
|
|
45
|
+
*/
|
|
46
|
+
enum?: Array<string | number | boolean | null>;
|
|
27
47
|
};
|
|
28
48
|
type Document = OASDocument;
|
|
29
49
|
type Operation$1 = Operation;
|
|
30
50
|
type DiscriminatorObject$1 = DiscriminatorObject;
|
|
51
|
+
type ReferenceObject = OpenAPIV3.ReferenceObject;
|
|
31
52
|
//#endregion
|
|
32
53
|
//#region src/oas/Oas.d.ts
|
|
33
54
|
type OasOptions = {
|
|
@@ -52,6 +73,15 @@ declare class Oas extends BaseOas {
|
|
|
52
73
|
dereferenceWithRef<T = unknown>(schema?: T): T;
|
|
53
74
|
getResponseSchema(operation: Operation$1, statusCode: string | number): SchemaObject$1;
|
|
54
75
|
getRequestSchema(operation: Operation$1): SchemaObject$1 | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* Returns all resolved parameters for an operation, merging path-level and operation-level
|
|
78
|
+
* parameters and deduplicating by `in:name` (operation-level takes precedence).
|
|
79
|
+
*
|
|
80
|
+
* oas v31+ filters out `$ref` parameters in `getParameters()`, so this method accesses the
|
|
81
|
+
* raw `operation.schema.parameters` and path-item parameters directly and resolves `$ref`
|
|
82
|
+
* pointers via `dereferenceWithRef` to preserve backward compatibility.
|
|
83
|
+
*/
|
|
84
|
+
getParameters(operation: Operation$1): Array<ParameterObject>;
|
|
55
85
|
getParametersSchema(operation: Operation$1, inKey: 'path' | 'query' | 'header'): SchemaObject$1 | null;
|
|
56
86
|
validate(): Promise<oas_normalize_lib_types0.ValidationResult>;
|
|
57
87
|
flattenSchema(schema: SchemaObject$1 | null): SchemaObject$1 | null;
|
|
@@ -70,6 +100,31 @@ declare class Oas extends BaseOas {
|
|
|
70
100
|
}
|
|
71
101
|
//#endregion
|
|
72
102
|
//#region src/types.d.ts
|
|
103
|
+
/**
|
|
104
|
+
* Controls how various OAS constructs are mapped to Kubb AST nodes.
|
|
105
|
+
*/
|
|
106
|
+
type ParserOptions = {
|
|
107
|
+
/**
|
|
108
|
+
* How `format: 'date-time'` schemas are represented. `false` falls through to a plain string.
|
|
109
|
+
*/
|
|
110
|
+
dateType: false | 'string' | 'stringOffset' | 'stringLocal' | 'date';
|
|
111
|
+
/**
|
|
112
|
+
* Whether `type: 'integer'` and `format: 'int64'` produce `number` or `bigint` nodes.
|
|
113
|
+
*/
|
|
114
|
+
integerType?: 'number' | 'bigint';
|
|
115
|
+
/**
|
|
116
|
+
* AST type used when no schema type can be inferred.
|
|
117
|
+
*/
|
|
118
|
+
unknownType: 'any' | 'unknown' | 'void';
|
|
119
|
+
/**
|
|
120
|
+
* AST type used for completely empty schemas (`{}`).
|
|
121
|
+
*/
|
|
122
|
+
emptySchemaType: 'any' | 'unknown' | 'void';
|
|
123
|
+
/**
|
|
124
|
+
* Suffix appended to derived enum names when building property schema names.
|
|
125
|
+
*/
|
|
126
|
+
enumSuffix: 'enum' | (string & {});
|
|
127
|
+
};
|
|
73
128
|
type OasAdapterOptions = {
|
|
74
129
|
/**
|
|
75
130
|
* Validate the OpenAPI spec before parsing.
|
|
@@ -109,34 +164,16 @@ type OasAdapterOptions = {
|
|
|
109
164
|
*/
|
|
110
165
|
discriminator?: 'strict' | 'inherit';
|
|
111
166
|
/**
|
|
112
|
-
*
|
|
113
|
-
*
|
|
167
|
+
* Enable collision detection for inline enum and schema type names.
|
|
168
|
+
* When `true` (default), full-path names are used and name collisions
|
|
169
|
+
* across schema components are automatically resolved (e.g. `OrderParamsStatusEnum`).
|
|
170
|
+
* When `false`, enum names use only the immediate property context
|
|
171
|
+
* (e.g. `ParamsStatusEnum`) matching the v4 naming conventions, with numeric
|
|
172
|
+
* suffixes for deduplication (e.g. `ParamsStatusEnum2`).
|
|
173
|
+
* @default true
|
|
114
174
|
*/
|
|
115
175
|
collisionDetection?: boolean;
|
|
116
|
-
|
|
117
|
-
* How `format: 'date-time'` schemas are represented in the AST.
|
|
118
|
-
* - `'string'` maps to a `datetime` string node.
|
|
119
|
-
* - `'date'` maps to a JavaScript `Date` node.
|
|
120
|
-
* - `false` falls through to a plain `string` node.
|
|
121
|
-
* @default 'string'
|
|
122
|
-
*/
|
|
123
|
-
dateType?: false | 'string' | 'stringOffset' | 'stringLocal' | 'date';
|
|
124
|
-
/**
|
|
125
|
-
* Whether `type: 'integer'` / `format: 'int64'` produces `number` or `bigint` nodes.
|
|
126
|
-
* @default 'number'
|
|
127
|
-
*/
|
|
128
|
-
integerType?: 'number' | 'bigint';
|
|
129
|
-
/**
|
|
130
|
-
* AST type used when no schema type can be inferred.
|
|
131
|
-
* @default 'any'
|
|
132
|
-
*/
|
|
133
|
-
unknownType?: 'any' | 'unknown' | 'void';
|
|
134
|
-
/**
|
|
135
|
-
* AST type used for completely empty schemas (`{}`).
|
|
136
|
-
* @default `unknownType`
|
|
137
|
-
*/
|
|
138
|
-
emptySchemaType?: 'any' | 'unknown' | 'void';
|
|
139
|
-
};
|
|
176
|
+
} & Partial<ParserOptions>;
|
|
140
177
|
type OasAdapterResolvedOptions = {
|
|
141
178
|
validate: boolean;
|
|
142
179
|
oasClass: OasAdapterOptions['oasClass'];
|
|
@@ -149,6 +186,13 @@ type OasAdapterResolvedOptions = {
|
|
|
149
186
|
integerType: NonNullable<OasAdapterOptions['integerType']>;
|
|
150
187
|
unknownType: NonNullable<OasAdapterOptions['unknownType']>;
|
|
151
188
|
emptySchemaType: NonNullable<OasAdapterOptions['emptySchemaType']>;
|
|
189
|
+
enumSuffix: OasAdapterOptions['enumSuffix'];
|
|
190
|
+
/**
|
|
191
|
+
* Map from original `$ref` paths to their collision-resolved schema names.
|
|
192
|
+
* Populated by the adapter after each `parse()` call.
|
|
193
|
+
* e.g. `'#/components/schemas/Order'` → `'OrderSchema'`
|
|
194
|
+
*/
|
|
195
|
+
nameMapping: Map<string, string>;
|
|
152
196
|
};
|
|
153
197
|
type OasAdapter = AdapterFactoryOptions<'oas', OasAdapterOptions, OasAdapterResolvedOptions>;
|
|
154
198
|
//#endregion
|