@kubb/adapter-oas 5.0.0-beta.43 → 5.0.0-beta.45
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/extension.yaml +5 -5
- package/package.json +3 -2
- package/src/parser.ts +7 -6
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import { access } from "node:fs/promises";
|
|
|
6
6
|
import { bundle, loadConfig } from "@redocly/openapi-core";
|
|
7
7
|
import OASNormalize from "oas-normalize";
|
|
8
8
|
import swagger2openapi from "swagger2openapi";
|
|
9
|
+
import { childName, enumPropName, extractRefName, findDiscriminator } from "@kubb/ast/utils";
|
|
9
10
|
import { isRef } from "oas/types";
|
|
10
11
|
import { matchesMimeType } from "oas/utils";
|
|
11
12
|
//#region src/constants.ts
|
|
@@ -374,6 +375,22 @@ const reservedWords = new Set([
|
|
|
374
375
|
*/
|
|
375
376
|
function isValidVarName(name) {
|
|
376
377
|
if (!name || reservedWords.has(name)) return false;
|
|
378
|
+
return isIdentifier(name);
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Returns `true` when `name` is syntactically a valid identifier, ignoring reserved words.
|
|
382
|
+
*
|
|
383
|
+
* Reserved words and globals (`class`, `name`, `Date`, …) are valid as bare object-literal keys
|
|
384
|
+
* even though they are not valid variable names, so use this (not {@link isValidVarName}) when
|
|
385
|
+
* deciding whether an object key needs quoting.
|
|
386
|
+
*
|
|
387
|
+
* @example
|
|
388
|
+
* ```ts
|
|
389
|
+
* isIdentifier('name') // true
|
|
390
|
+
* isIdentifier('x-total')// false
|
|
391
|
+
* ```
|
|
392
|
+
*/
|
|
393
|
+
function isIdentifier(name) {
|
|
377
394
|
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
|
|
378
395
|
}
|
|
379
396
|
//#endregion
|
|
@@ -1295,7 +1312,7 @@ function createSchemaParser(ctx, dialect = oasDialect) {
|
|
|
1295
1312
|
return ast.createSchema({
|
|
1296
1313
|
...buildSchemaNode(schema, name, nullable, defaultValue),
|
|
1297
1314
|
type: "ref",
|
|
1298
|
-
name:
|
|
1315
|
+
name: extractRefName(schema.$ref),
|
|
1299
1316
|
ref: schema.$ref,
|
|
1300
1317
|
schema: resolvedSchema
|
|
1301
1318
|
});
|
|
@@ -1339,7 +1356,7 @@ function createSchemaParser(ctx, dialect = oasDialect) {
|
|
|
1339
1356
|
const inOneOf = parentUnion.some((oneOfItem) => dialect.isReference(oneOfItem) && oneOfItem.$ref === childRef);
|
|
1340
1357
|
const inMapping = Object.values(deref.discriminator.mapping ?? {}).some((v) => v === childRef);
|
|
1341
1358
|
if (inOneOf || inMapping) {
|
|
1342
|
-
const discriminatorValue =
|
|
1359
|
+
const discriminatorValue = findDiscriminator(deref.discriminator.mapping, childRef);
|
|
1343
1360
|
if (discriminatorValue) filteredDiscriminantValues.push({
|
|
1344
1361
|
propertyName: deref.discriminator.propertyName,
|
|
1345
1362
|
value: discriminatorValue
|
|
@@ -1418,7 +1435,7 @@ function createSchemaParser(ctx, dialect = oasDialect) {
|
|
|
1418
1435
|
if (sharedPropertiesNode || discriminator?.mapping) {
|
|
1419
1436
|
const members = unionMembers.map((s) => {
|
|
1420
1437
|
const ref = dialect.isReference(s) ? s.$ref : void 0;
|
|
1421
|
-
const discriminatorValue =
|
|
1438
|
+
const discriminatorValue = findDiscriminator(discriminator?.mapping, ref);
|
|
1422
1439
|
const memberNode = parseSchema({
|
|
1423
1440
|
schema: s,
|
|
1424
1441
|
name
|
|
@@ -1621,7 +1638,7 @@ function createSchemaParser(ctx, dialect = oasDialect) {
|
|
|
1621
1638
|
const propNullable = dialect.isNullable(resolvedPropSchema);
|
|
1622
1639
|
const propNode = parseSchema({
|
|
1623
1640
|
schema: resolvedPropSchema,
|
|
1624
|
-
name:
|
|
1641
|
+
name: childName(name, propName)
|
|
1625
1642
|
}, rawOptions);
|
|
1626
1643
|
const schemaNode = (() => {
|
|
1627
1644
|
const node = ast.setEnumName(propNode, name, propName, options.enumSuffix);
|
|
@@ -1666,7 +1683,7 @@ function createSchemaParser(ctx, dialect = oasDialect) {
|
|
|
1666
1683
|
if (dialect.isDiscriminator(schema) && schema.discriminator.mapping) {
|
|
1667
1684
|
const discPropName = schema.discriminator.propertyName;
|
|
1668
1685
|
const values = Object.keys(schema.discriminator.mapping);
|
|
1669
|
-
const enumName = name ?
|
|
1686
|
+
const enumName = name ? enumPropName(name, discPropName, options.enumSuffix) : void 0;
|
|
1670
1687
|
return ast.setDiscriminatorEnum({
|
|
1671
1688
|
node: objectNode,
|
|
1672
1689
|
propertyName: discPropName,
|
|
@@ -1697,7 +1714,7 @@ function createSchemaParser(ctx, dialect = oasDialect) {
|
|
|
1697
1714
|
*/
|
|
1698
1715
|
function convertArray({ schema, name, nullable, defaultValue, rawOptions, options }) {
|
|
1699
1716
|
const rawItems = schema.items;
|
|
1700
|
-
const itemName = rawItems?.enum?.length && name ?
|
|
1717
|
+
const itemName = rawItems?.enum?.length && name ? enumPropName(null, name, options.enumSuffix) : name;
|
|
1701
1718
|
const items = rawItems ? [parseSchema({
|
|
1702
1719
|
schema: rawItems,
|
|
1703
1720
|
name: itemName
|