@kubb/adapter-oas 5.0.0-beta.42 → 5.0.0-beta.44
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 +23 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +23 -6
- package/dist/index.js.map +1 -1
- package/package.json +6 -5
- package/src/parser.ts +7 -6
package/dist/index.cjs
CHANGED
|
@@ -32,6 +32,7 @@ let oas_normalize = require("oas-normalize");
|
|
|
32
32
|
oas_normalize = __toESM(oas_normalize, 1);
|
|
33
33
|
let swagger2openapi = require("swagger2openapi");
|
|
34
34
|
swagger2openapi = __toESM(swagger2openapi, 1);
|
|
35
|
+
let _kubb_ast_utils = require("@kubb/ast/utils");
|
|
35
36
|
let oas_types = require("oas/types");
|
|
36
37
|
let oas_utils = require("oas/utils");
|
|
37
38
|
//#region src/constants.ts
|
|
@@ -400,6 +401,22 @@ const reservedWords = new Set([
|
|
|
400
401
|
*/
|
|
401
402
|
function isValidVarName(name) {
|
|
402
403
|
if (!name || reservedWords.has(name)) return false;
|
|
404
|
+
return isIdentifier(name);
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Returns `true` when `name` is syntactically a valid identifier, ignoring reserved words.
|
|
408
|
+
*
|
|
409
|
+
* Reserved words and globals (`class`, `name`, `Date`, …) are valid as bare object-literal keys
|
|
410
|
+
* even though they are not valid variable names, so use this (not {@link isValidVarName}) when
|
|
411
|
+
* deciding whether an object key needs quoting.
|
|
412
|
+
*
|
|
413
|
+
* @example
|
|
414
|
+
* ```ts
|
|
415
|
+
* isIdentifier('name') // true
|
|
416
|
+
* isIdentifier('x-total')// false
|
|
417
|
+
* ```
|
|
418
|
+
*/
|
|
419
|
+
function isIdentifier(name) {
|
|
403
420
|
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
|
|
404
421
|
}
|
|
405
422
|
//#endregion
|
|
@@ -1321,7 +1338,7 @@ function createSchemaParser(ctx, dialect = oasDialect) {
|
|
|
1321
1338
|
return _kubb_core.ast.createSchema({
|
|
1322
1339
|
...buildSchemaNode(schema, name, nullable, defaultValue),
|
|
1323
1340
|
type: "ref",
|
|
1324
|
-
name:
|
|
1341
|
+
name: (0, _kubb_ast_utils.extractRefName)(schema.$ref),
|
|
1325
1342
|
ref: schema.$ref,
|
|
1326
1343
|
schema: resolvedSchema
|
|
1327
1344
|
});
|
|
@@ -1365,7 +1382,7 @@ function createSchemaParser(ctx, dialect = oasDialect) {
|
|
|
1365
1382
|
const inOneOf = parentUnion.some((oneOfItem) => dialect.isReference(oneOfItem) && oneOfItem.$ref === childRef);
|
|
1366
1383
|
const inMapping = Object.values(deref.discriminator.mapping ?? {}).some((v) => v === childRef);
|
|
1367
1384
|
if (inOneOf || inMapping) {
|
|
1368
|
-
const discriminatorValue =
|
|
1385
|
+
const discriminatorValue = (0, _kubb_ast_utils.findDiscriminator)(deref.discriminator.mapping, childRef);
|
|
1369
1386
|
if (discriminatorValue) filteredDiscriminantValues.push({
|
|
1370
1387
|
propertyName: deref.discriminator.propertyName,
|
|
1371
1388
|
value: discriminatorValue
|
|
@@ -1444,7 +1461,7 @@ function createSchemaParser(ctx, dialect = oasDialect) {
|
|
|
1444
1461
|
if (sharedPropertiesNode || discriminator?.mapping) {
|
|
1445
1462
|
const members = unionMembers.map((s) => {
|
|
1446
1463
|
const ref = dialect.isReference(s) ? s.$ref : void 0;
|
|
1447
|
-
const discriminatorValue =
|
|
1464
|
+
const discriminatorValue = (0, _kubb_ast_utils.findDiscriminator)(discriminator?.mapping, ref);
|
|
1448
1465
|
const memberNode = parseSchema({
|
|
1449
1466
|
schema: s,
|
|
1450
1467
|
name
|
|
@@ -1647,7 +1664,7 @@ function createSchemaParser(ctx, dialect = oasDialect) {
|
|
|
1647
1664
|
const propNullable = dialect.isNullable(resolvedPropSchema);
|
|
1648
1665
|
const propNode = parseSchema({
|
|
1649
1666
|
schema: resolvedPropSchema,
|
|
1650
|
-
name:
|
|
1667
|
+
name: (0, _kubb_ast_utils.childName)(name, propName)
|
|
1651
1668
|
}, rawOptions);
|
|
1652
1669
|
const schemaNode = (() => {
|
|
1653
1670
|
const node = _kubb_core.ast.setEnumName(propNode, name, propName, options.enumSuffix);
|
|
@@ -1692,7 +1709,7 @@ function createSchemaParser(ctx, dialect = oasDialect) {
|
|
|
1692
1709
|
if (dialect.isDiscriminator(schema) && schema.discriminator.mapping) {
|
|
1693
1710
|
const discPropName = schema.discriminator.propertyName;
|
|
1694
1711
|
const values = Object.keys(schema.discriminator.mapping);
|
|
1695
|
-
const enumName = name ?
|
|
1712
|
+
const enumName = name ? (0, _kubb_ast_utils.enumPropName)(name, discPropName, options.enumSuffix) : void 0;
|
|
1696
1713
|
return _kubb_core.ast.setDiscriminatorEnum({
|
|
1697
1714
|
node: objectNode,
|
|
1698
1715
|
propertyName: discPropName,
|
|
@@ -1723,7 +1740,7 @@ function createSchemaParser(ctx, dialect = oasDialect) {
|
|
|
1723
1740
|
*/
|
|
1724
1741
|
function convertArray({ schema, name, nullable, defaultValue, rawOptions, options }) {
|
|
1725
1742
|
const rawItems = schema.items;
|
|
1726
|
-
const itemName = rawItems?.enum?.length && name ?
|
|
1743
|
+
const itemName = rawItems?.enum?.length && name ? (0, _kubb_ast_utils.enumPropName)(null, name, options.enumSuffix) : name;
|
|
1727
1744
|
const items = rawItems ? [parseSchema({
|
|
1728
1745
|
schema: rawItems,
|
|
1729
1746
|
name: itemName
|