@kubb/adapter-oas 5.0.0-alpha.13 → 5.0.0-alpha.15
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 +19 -75
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +0 -17
- package/dist/index.js +19 -75
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/adapter.ts +2 -4
- package/src/oas/Oas.ts +2 -10
- package/src/oas/utils.ts +7 -8
- package/src/parser.ts +8 -27
- package/src/types.ts +0 -11
package/dist/index.d.ts
CHANGED
|
@@ -54,11 +54,6 @@ type ReferenceObject = OpenAPIV3.ReferenceObject;
|
|
|
54
54
|
type OasOptions = {
|
|
55
55
|
contentType?: contentType;
|
|
56
56
|
discriminator?: 'strict' | 'inherit';
|
|
57
|
-
/**
|
|
58
|
-
* Resolve name collisions when schemas from different components share the same name (case-insensitive).
|
|
59
|
-
* @default false
|
|
60
|
-
*/
|
|
61
|
-
collisionDetection?: boolean;
|
|
62
57
|
};
|
|
63
58
|
declare class Oas extends BaseOas {
|
|
64
59
|
#private;
|
|
@@ -92,7 +87,6 @@ declare class Oas extends BaseOas {
|
|
|
92
87
|
getSchemas(options?: {
|
|
93
88
|
contentType?: contentType;
|
|
94
89
|
includes?: Array<'schemas' | 'responses' | 'requestBodies'>;
|
|
95
|
-
collisionDetection?: boolean;
|
|
96
90
|
}): {
|
|
97
91
|
schemas: Record<string, SchemaObject$1>;
|
|
98
92
|
nameMapping: Map<string, string>;
|
|
@@ -163,16 +157,6 @@ type OasAdapterOptions = {
|
|
|
163
157
|
* @default 'strict'
|
|
164
158
|
*/
|
|
165
159
|
discriminator?: 'strict' | 'inherit';
|
|
166
|
-
/**
|
|
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
|
|
174
|
-
*/
|
|
175
|
-
collisionDetection?: boolean;
|
|
176
160
|
} & Partial<ParserOptions>;
|
|
177
161
|
type OasAdapterResolvedOptions = {
|
|
178
162
|
validate: boolean;
|
|
@@ -181,7 +165,6 @@ type OasAdapterResolvedOptions = {
|
|
|
181
165
|
serverIndex: OasAdapterOptions['serverIndex'];
|
|
182
166
|
serverVariables: OasAdapterOptions['serverVariables'];
|
|
183
167
|
discriminator: NonNullable<OasAdapterOptions['discriminator']>;
|
|
184
|
-
collisionDetection: boolean;
|
|
185
168
|
dateType: NonNullable<OasAdapterOptions['dateType']>;
|
|
186
169
|
integerType: NonNullable<OasAdapterOptions['integerType']>;
|
|
187
170
|
unknownType: NonNullable<OasAdapterOptions['unknownType']>;
|
package/dist/index.js
CHANGED
|
@@ -196,27 +196,6 @@ function pascalCase(text, { isFile, prefix = "", suffix = "" } = {}) {
|
|
|
196
196
|
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
|
|
197
197
|
}
|
|
198
198
|
//#endregion
|
|
199
|
-
//#region ../../internals/utils/src/names.ts
|
|
200
|
-
/**
|
|
201
|
-
* Returns a unique name by appending an incrementing numeric suffix when the name has already been used.
|
|
202
|
-
* Mutates `data` in-place as a usage counter so subsequent calls remain consistent.
|
|
203
|
-
*
|
|
204
|
-
* @example
|
|
205
|
-
* const seen: Record<string, number> = {}
|
|
206
|
-
* getUniqueName('Foo', seen) // 'Foo'
|
|
207
|
-
* getUniqueName('Foo', seen) // 'Foo2'
|
|
208
|
-
* getUniqueName('Foo', seen) // 'Foo3'
|
|
209
|
-
*/
|
|
210
|
-
function getUniqueName(originalName, data) {
|
|
211
|
-
let used = data[originalName] || 0;
|
|
212
|
-
if (used) {
|
|
213
|
-
data[originalName] = ++used;
|
|
214
|
-
originalName += used;
|
|
215
|
-
}
|
|
216
|
-
data[originalName] = 1;
|
|
217
|
-
return originalName;
|
|
218
|
-
}
|
|
219
|
-
//#endregion
|
|
220
199
|
//#region ../../internals/utils/src/reserved.ts
|
|
221
200
|
/**
|
|
222
201
|
* Returns `true` when `name` is a syntactically valid JavaScript variable name.
|
|
@@ -620,7 +599,6 @@ var Oas = class extends BaseOas {
|
|
|
620
599
|
"requestBodies",
|
|
621
600
|
"responses"
|
|
622
601
|
];
|
|
623
|
-
const shouldResolveCollisions = options.collisionDetection ?? this.#options.collisionDetection ?? false;
|
|
624
602
|
const components = this.getDefinition().components;
|
|
625
603
|
const schemasWithMeta = [];
|
|
626
604
|
if (includes.includes("schemas")) {
|
|
@@ -674,7 +652,7 @@ var Oas = class extends BaseOas {
|
|
|
674
652
|
}
|
|
675
653
|
}
|
|
676
654
|
}
|
|
677
|
-
const { schemas, nameMapping } =
|
|
655
|
+
const { schemas, nameMapping } = resolveCollisions(schemasWithMeta);
|
|
678
656
|
return {
|
|
679
657
|
schemas: sortSchemas(schemas),
|
|
680
658
|
nameMapping
|
|
@@ -886,29 +864,13 @@ function extractSchemaFromContent(content, preferredContentType) {
|
|
|
886
864
|
* Returns the PascalCase suffix appended to a component name when resolving
|
|
887
865
|
* cross-source name collisions (schemas vs. responses vs. requestBodies).
|
|
888
866
|
*/
|
|
867
|
+
const semanticSuffixes = {
|
|
868
|
+
schemas: "Schema",
|
|
869
|
+
responses: "Response",
|
|
870
|
+
requestBodies: "Request"
|
|
871
|
+
};
|
|
889
872
|
function getSemanticSuffix(source) {
|
|
890
|
-
|
|
891
|
-
case "schemas": return "Schema";
|
|
892
|
-
case "responses": return "Response";
|
|
893
|
-
case "requestBodies": return "Request";
|
|
894
|
-
}
|
|
895
|
-
}
|
|
896
|
-
/**
|
|
897
|
-
* Builds `GetSchemasResult` without any collision detection.
|
|
898
|
-
* Each schema is registered under its original component name and its full
|
|
899
|
-
* `#/components/<source>/<name>` ref path.
|
|
900
|
-
*/
|
|
901
|
-
function legacyResolve(schemasWithMeta) {
|
|
902
|
-
const schemas = {};
|
|
903
|
-
const nameMapping = /* @__PURE__ */ new Map();
|
|
904
|
-
for (const item of schemasWithMeta) {
|
|
905
|
-
schemas[item.originalName] = item.schema;
|
|
906
|
-
nameMapping.set(`#/components/${item.source}/${item.originalName}`, item.originalName);
|
|
907
|
-
}
|
|
908
|
-
return {
|
|
909
|
-
schemas,
|
|
910
|
-
nameMapping
|
|
911
|
-
};
|
|
873
|
+
return semanticSuffixes[source];
|
|
912
874
|
}
|
|
913
875
|
/**
|
|
914
876
|
* Builds `GetSchemasResult` with automatic name-collision resolution.
|
|
@@ -1129,13 +1091,8 @@ function toMediaType(contentType) {
|
|
|
1129
1091
|
* const root = parser.parse({ emptySchemaType: 'unknown' })
|
|
1130
1092
|
* ```
|
|
1131
1093
|
*/
|
|
1132
|
-
function createOasParser(oas, { contentType
|
|
1133
|
-
const { schemas: schemaObjects, nameMapping } = oas.getSchemas({
|
|
1134
|
-
contentType,
|
|
1135
|
-
collisionDetection
|
|
1136
|
-
});
|
|
1137
|
-
const usedEnumNames = {};
|
|
1138
|
-
const isLegacyNaming = collisionDetection === false;
|
|
1094
|
+
function createOasParser(oas, { contentType } = {}) {
|
|
1095
|
+
const { schemas: schemaObjects, nameMapping } = oas.getSchemas({ contentType });
|
|
1139
1096
|
/**
|
|
1140
1097
|
* Maps an `'any' | 'unknown' | 'void'` option string to the corresponding `SchemaType` constant.
|
|
1141
1098
|
* Used for both `unknownType` (unannotated schemas) and `emptySchemaType` (empty `{}` schemas).
|
|
@@ -1334,7 +1291,7 @@ function createOasParser(oas, { contentType, collisionDetection } = {}) {
|
|
|
1334
1291
|
const discriminator = isDiscriminator(schema) ? schema.discriminator : void 0;
|
|
1335
1292
|
const sharedPropertiesNode = convertSchema({
|
|
1336
1293
|
schema: discriminator ? Object.fromEntries(Object.entries(schemaWithoutUnion).filter(([key]) => key !== "discriminator")) : schemaWithoutUnion,
|
|
1337
|
-
name
|
|
1294
|
+
name
|
|
1338
1295
|
}, options);
|
|
1339
1296
|
return createSchema({
|
|
1340
1297
|
type: "union",
|
|
@@ -1557,29 +1514,24 @@ function createOasParser(oas, { contentType, collisionDetection } = {}) {
|
|
|
1557
1514
|
/**
|
|
1558
1515
|
* Builds the propagation name for a child property during recursive schema conversion.
|
|
1559
1516
|
*
|
|
1560
|
-
*
|
|
1561
|
-
* (e.g. `Params` for property `params`), keeping nested names short.
|
|
1562
|
-
* - **Default naming**: the parent name is prepended so the full path is encoded
|
|
1517
|
+
* The parent name is prepended so the full path is encoded
|
|
1563
1518
|
* (e.g. `OrderParams` when parent is `Order`).
|
|
1564
1519
|
*/
|
|
1565
1520
|
function resolveChildName(parentName, propName) {
|
|
1566
|
-
if (isLegacyNaming) return pascalCase(propName);
|
|
1567
1521
|
return parentName ? pascalCase([parentName, propName].join(" ")) : void 0;
|
|
1568
1522
|
}
|
|
1569
1523
|
/**
|
|
1570
1524
|
* Derives the final name for an enum property schema node.
|
|
1571
1525
|
*
|
|
1572
|
-
* The
|
|
1573
|
-
*
|
|
1574
|
-
* when the same name has already been used (e.g. `ParamsStatusEnum2`).
|
|
1526
|
+
* The resulting name always includes the enum suffix and full parent path context
|
|
1527
|
+
* (e.g. `OrderParamsStatusEnum`).
|
|
1575
1528
|
*/
|
|
1576
1529
|
function resolveEnumPropName(parentName, propName, enumSuffix) {
|
|
1577
|
-
|
|
1530
|
+
return pascalCase([
|
|
1578
1531
|
parentName,
|
|
1579
1532
|
propName,
|
|
1580
1533
|
enumSuffix
|
|
1581
1534
|
].filter(Boolean).join(" "));
|
|
1582
|
-
return isLegacyNaming ? getUniqueName(raw, usedEnumNames) : raw;
|
|
1583
1535
|
}
|
|
1584
1536
|
/**
|
|
1585
1537
|
* Given a freshly-converted property schema, returns the node with a correct
|
|
@@ -1619,9 +1571,7 @@ function createOasParser(oas, { contentType, collisionDetection } = {}) {
|
|
|
1619
1571
|
name: propName,
|
|
1620
1572
|
schema: {
|
|
1621
1573
|
...schemaNode,
|
|
1622
|
-
nullable: schemaNode.type === "null" ? void 0 : propNullable || void 0
|
|
1623
|
-
optional: !required && !propNullable ? true : void 0,
|
|
1624
|
-
nullish: !required && propNullable ? true : void 0
|
|
1574
|
+
nullable: schemaNode.type === "null" ? void 0 : propNullable || void 0
|
|
1625
1575
|
},
|
|
1626
1576
|
required
|
|
1627
1577
|
});
|
|
@@ -1843,8 +1793,7 @@ function createOasParser(oas, { contentType, collisionDetection } = {}) {
|
|
|
1843
1793
|
in: param["in"],
|
|
1844
1794
|
schema: {
|
|
1845
1795
|
...schema,
|
|
1846
|
-
description: param["description"] ?? schema.description
|
|
1847
|
-
optional: !required || !!schema.optional ? true : void 0
|
|
1796
|
+
description: param["description"] ?? schema.description
|
|
1848
1797
|
},
|
|
1849
1798
|
required
|
|
1850
1799
|
});
|
|
@@ -1969,7 +1918,7 @@ const adapterOasName = "oas";
|
|
|
1969
1918
|
* ```
|
|
1970
1919
|
*/
|
|
1971
1920
|
const adapterOas = createAdapter((options) => {
|
|
1972
|
-
const { validate = true, oasClass, contentType, serverIndex, serverVariables, discriminator = "strict",
|
|
1921
|
+
const { validate = true, oasClass, contentType, serverIndex, serverVariables, discriminator = "strict", dateType = DEFAULT_PARSER_OPTIONS.dateType, integerType = DEFAULT_PARSER_OPTIONS.integerType, unknownType = DEFAULT_PARSER_OPTIONS.unknownType, enumSuffix = DEFAULT_PARSER_OPTIONS.enumSuffix, emptySchemaType = unknownType || DEFAULT_PARSER_OPTIONS.emptySchemaType } = options;
|
|
1973
1922
|
const nameMapping = /* @__PURE__ */ new Map();
|
|
1974
1923
|
return {
|
|
1975
1924
|
name: "oas",
|
|
@@ -1980,7 +1929,6 @@ const adapterOas = createAdapter((options) => {
|
|
|
1980
1929
|
serverIndex,
|
|
1981
1930
|
serverVariables,
|
|
1982
1931
|
discriminator,
|
|
1983
|
-
collisionDetection,
|
|
1984
1932
|
dateType,
|
|
1985
1933
|
integerType,
|
|
1986
1934
|
unknownType,
|
|
@@ -1999,18 +1947,14 @@ const adapterOas = createAdapter((options) => {
|
|
|
1999
1947
|
const oas = await parseFromConfig(sourceToFakeConfig(source), oasClass);
|
|
2000
1948
|
oas.setOptions({
|
|
2001
1949
|
contentType,
|
|
2002
|
-
discriminator
|
|
2003
|
-
collisionDetection
|
|
1950
|
+
discriminator
|
|
2004
1951
|
});
|
|
2005
1952
|
if (validate) try {
|
|
2006
1953
|
await oas.validate();
|
|
2007
1954
|
} catch (_err) {}
|
|
2008
1955
|
const server = serverIndex !== void 0 ? oas.api.servers?.at(serverIndex) : void 0;
|
|
2009
1956
|
const baseURL = server?.url ? resolveServerUrl(server, serverVariables) : void 0;
|
|
2010
|
-
const parser = createOasParser(oas, {
|
|
2011
|
-
contentType,
|
|
2012
|
-
collisionDetection
|
|
2013
|
-
});
|
|
1957
|
+
const parser = createOasParser(oas, { contentType });
|
|
2014
1958
|
const root = parser.parse({
|
|
2015
1959
|
dateType,
|
|
2016
1960
|
integerType,
|