@kubb/adapter-oas 5.3.5 → 5.3.7
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 +29 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +29 -24
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -947,9 +947,7 @@ function getRequestContentType({ operation, refs }) {
|
|
|
947
947
|
refs
|
|
948
948
|
});
|
|
949
949
|
const mediaTypes = content ? Object.keys(content) : [];
|
|
950
|
-
|
|
951
|
-
for (const mt of mediaTypes) if (isJsonMimeType(mt)) result = mt;
|
|
952
|
-
return result;
|
|
950
|
+
return mediaTypes.findLast(isJsonMimeType) ?? mediaTypes[0] ?? "application/json";
|
|
953
951
|
}
|
|
954
952
|
/**
|
|
955
953
|
* Builds an `Operation` for every supported HTTP method on every path, in document order.
|
|
@@ -1505,7 +1503,11 @@ function createNullNode(schema, name, nullable) {
|
|
|
1505
1503
|
function convertConst({ schema, name, nullable, defaultValue }) {
|
|
1506
1504
|
const constValue = schema.const;
|
|
1507
1505
|
if (constValue === null) return createNullNode(schema, name);
|
|
1508
|
-
const constPrimitive = getPrimitiveType(
|
|
1506
|
+
const constPrimitive = getPrimitiveType((() => {
|
|
1507
|
+
if (typeof constValue === "number") return "number";
|
|
1508
|
+
if (typeof constValue === "boolean") return "boolean";
|
|
1509
|
+
return "string";
|
|
1510
|
+
})());
|
|
1509
1511
|
return createNode({
|
|
1510
1512
|
schema,
|
|
1511
1513
|
name,
|
|
@@ -1589,9 +1591,11 @@ function convertEnum({ schema, name, nullable, type, rawOptions, parse }) {
|
|
|
1589
1591
|
const extensionKey = enumExtensionKeys.find((key) => key in schema);
|
|
1590
1592
|
const descriptionKey = enumDescriptionKeys.find((key) => key in schema);
|
|
1591
1593
|
if (extensionKey || descriptionKey || enumPrimitive === "number" || enumPrimitive === "integer" || enumPrimitive === "boolean") {
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1594
|
+
const enumPrimitiveType = (() => {
|
|
1595
|
+
if (enumPrimitive === "boolean") return "boolean";
|
|
1596
|
+
if (enumPrimitive === "number" || enumPrimitive === "integer") return "number";
|
|
1597
|
+
return "string";
|
|
1598
|
+
})();
|
|
1595
1599
|
const rawEnumNames = extensionKey ? schema[extensionKey] : void 0;
|
|
1596
1600
|
const rawEnumDescriptions = descriptionKey ? schema[descriptionKey] : void 0;
|
|
1597
1601
|
const uniqueValues = [...new Set(filteredValues)];
|
|
@@ -1733,10 +1737,11 @@ function convertObject({ schema, name, nullable, defaultValue, rawOptions, optio
|
|
|
1733
1737
|
});
|
|
1734
1738
|
}) : [];
|
|
1735
1739
|
const additionalProperties = schema.additionalProperties;
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
+
const additionalPropertiesNode = (() => {
|
|
1741
|
+
if (additionalProperties === true) return true;
|
|
1742
|
+
if (additionalProperties) return resolveMapSchema(additionalProperties, options, parse, rawOptions);
|
|
1743
|
+
return additionalProperties;
|
|
1744
|
+
})();
|
|
1740
1745
|
const rawPatternProperties = "patternProperties" in schema ? schema.patternProperties : void 0;
|
|
1741
1746
|
const patternProperties = rawPatternProperties ? Object.fromEntries(Object.entries(rawPatternProperties).map(([pattern, patternSchema]) => [pattern, resolveMapSchema(patternSchema, options, parse, rawOptions)])) : void 0;
|
|
1742
1747
|
const objectNode = createNode({
|
|
@@ -2583,24 +2588,19 @@ const adapterOas = (0, _kubb_core.createAdapter)((options) => {
|
|
|
2583
2588
|
const operationNode = parseOperation(parserOptions, operation);
|
|
2584
2589
|
if (operationNode) operationNodes.push(operationNode);
|
|
2585
2590
|
}
|
|
2586
|
-
|
|
2587
|
-
if (
|
|
2588
|
-
promotedEnums = collectInlineEnums([...parsedByName.values(), ...operationNodes], new Set(Object.keys(schemas)));
|
|
2589
|
-
for (const name of promotedEnums.keys()) enumNames.push(name);
|
|
2590
|
-
}
|
|
2591
|
+
const promotedEnums = enums === "root" ? collectInlineEnums([...parsedByName.values(), ...operationNodes], new Set(Object.keys(schemas))) : null;
|
|
2592
|
+
if (promotedEnums) for (const name of promotedEnums.keys()) enumNames.push(name);
|
|
2591
2593
|
const schemaNodes = promotedEnums ? [...promotedEnums.values()] : [];
|
|
2592
2594
|
for (const name of Object.keys(schemas)) {
|
|
2593
2595
|
const alias = refAliasMap.get(name);
|
|
2594
|
-
|
|
2595
|
-
if (alias?.name && parsedByName.has(alias.name)) node = {
|
|
2596
|
+
const node = alias?.name && parsedByName.has(alias.name) ? {
|
|
2596
2597
|
...parsedByName.get(alias.name),
|
|
2597
2598
|
name
|
|
2598
|
-
}
|
|
2599
|
-
else {
|
|
2599
|
+
} : (() => {
|
|
2600
2600
|
const parsed = parsedByName.get(name);
|
|
2601
2601
|
const child = discriminatorChildMap?.get(name);
|
|
2602
|
-
|
|
2603
|
-
}
|
|
2602
|
+
return child ? patchDiscriminatorNode(parsed, child) : parsed;
|
|
2603
|
+
})();
|
|
2604
2604
|
schemaNodes.push(promotedEnums ? refPromotedEnums(node, promotedEnums) : node);
|
|
2605
2605
|
}
|
|
2606
2606
|
const operations = promotedEnums ? operationNodes.map((node) => refPromotedEnums(node, promotedEnums)) : operationNodes;
|
|
@@ -2645,11 +2645,13 @@ const adapterOas = (0, _kubb_core.createAdapter)((options) => {
|
|
|
2645
2645
|
assertDocument(document);
|
|
2646
2646
|
await validateDocument(document, options);
|
|
2647
2647
|
},
|
|
2648
|
-
async parse(source) {
|
|
2648
|
+
async parse(source, { signal } = {}) {
|
|
2649
|
+
signal?.throwIfAborted();
|
|
2649
2650
|
const cached = inputCache.get(source);
|
|
2650
2651
|
if (cached) return cached;
|
|
2651
2652
|
const promise = (async () => {
|
|
2652
2653
|
const document = await parseFromConfig(source);
|
|
2654
|
+
signal?.throwIfAborted();
|
|
2653
2655
|
assertDocument(document);
|
|
2654
2656
|
if (validate) await validateDocument(document);
|
|
2655
2657
|
parsedDocument = document;
|
|
@@ -2668,7 +2670,10 @@ const adapterOas = (0, _kubb_core.createAdapter)((options) => {
|
|
|
2668
2670
|
});
|
|
2669
2671
|
})();
|
|
2670
2672
|
inputCache.set(source, promise);
|
|
2671
|
-
return promise
|
|
2673
|
+
return promise.catch((error) => {
|
|
2674
|
+
if (signal?.aborted) inputCache.delete(source);
|
|
2675
|
+
throw error;
|
|
2676
|
+
});
|
|
2672
2677
|
}
|
|
2673
2678
|
};
|
|
2674
2679
|
});
|