@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.js
CHANGED
|
@@ -924,9 +924,7 @@ function getRequestContentType({ operation, refs }) {
|
|
|
924
924
|
refs
|
|
925
925
|
});
|
|
926
926
|
const mediaTypes = content ? Object.keys(content) : [];
|
|
927
|
-
|
|
928
|
-
for (const mt of mediaTypes) if (isJsonMimeType(mt)) result = mt;
|
|
929
|
-
return result;
|
|
927
|
+
return mediaTypes.findLast(isJsonMimeType) ?? mediaTypes[0] ?? "application/json";
|
|
930
928
|
}
|
|
931
929
|
/**
|
|
932
930
|
* Builds an `Operation` for every supported HTTP method on every path, in document order.
|
|
@@ -1482,7 +1480,11 @@ function createNullNode(schema, name, nullable) {
|
|
|
1482
1480
|
function convertConst({ schema, name, nullable, defaultValue }) {
|
|
1483
1481
|
const constValue = schema.const;
|
|
1484
1482
|
if (constValue === null) return createNullNode(schema, name);
|
|
1485
|
-
const constPrimitive = getPrimitiveType(
|
|
1483
|
+
const constPrimitive = getPrimitiveType((() => {
|
|
1484
|
+
if (typeof constValue === "number") return "number";
|
|
1485
|
+
if (typeof constValue === "boolean") return "boolean";
|
|
1486
|
+
return "string";
|
|
1487
|
+
})());
|
|
1486
1488
|
return createNode({
|
|
1487
1489
|
schema,
|
|
1488
1490
|
name,
|
|
@@ -1566,9 +1568,11 @@ function convertEnum({ schema, name, nullable, type, rawOptions, parse }) {
|
|
|
1566
1568
|
const extensionKey = enumExtensionKeys.find((key) => key in schema);
|
|
1567
1569
|
const descriptionKey = enumDescriptionKeys.find((key) => key in schema);
|
|
1568
1570
|
if (extensionKey || descriptionKey || enumPrimitive === "number" || enumPrimitive === "integer" || enumPrimitive === "boolean") {
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1571
|
+
const enumPrimitiveType = (() => {
|
|
1572
|
+
if (enumPrimitive === "boolean") return "boolean";
|
|
1573
|
+
if (enumPrimitive === "number" || enumPrimitive === "integer") return "number";
|
|
1574
|
+
return "string";
|
|
1575
|
+
})();
|
|
1572
1576
|
const rawEnumNames = extensionKey ? schema[extensionKey] : void 0;
|
|
1573
1577
|
const rawEnumDescriptions = descriptionKey ? schema[descriptionKey] : void 0;
|
|
1574
1578
|
const uniqueValues = [...new Set(filteredValues)];
|
|
@@ -1710,10 +1714,11 @@ function convertObject({ schema, name, nullable, defaultValue, rawOptions, optio
|
|
|
1710
1714
|
});
|
|
1711
1715
|
}) : [];
|
|
1712
1716
|
const additionalProperties = schema.additionalProperties;
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
+
const additionalPropertiesNode = (() => {
|
|
1718
|
+
if (additionalProperties === true) return true;
|
|
1719
|
+
if (additionalProperties) return resolveMapSchema(additionalProperties, options, parse, rawOptions);
|
|
1720
|
+
return additionalProperties;
|
|
1721
|
+
})();
|
|
1717
1722
|
const rawPatternProperties = "patternProperties" in schema ? schema.patternProperties : void 0;
|
|
1718
1723
|
const patternProperties = rawPatternProperties ? Object.fromEntries(Object.entries(rawPatternProperties).map(([pattern, patternSchema]) => [pattern, resolveMapSchema(patternSchema, options, parse, rawOptions)])) : void 0;
|
|
1719
1724
|
const objectNode = createNode({
|
|
@@ -2560,24 +2565,19 @@ const adapterOas = createAdapter((options) => {
|
|
|
2560
2565
|
const operationNode = parseOperation(parserOptions, operation);
|
|
2561
2566
|
if (operationNode) operationNodes.push(operationNode);
|
|
2562
2567
|
}
|
|
2563
|
-
|
|
2564
|
-
if (
|
|
2565
|
-
promotedEnums = collectInlineEnums([...parsedByName.values(), ...operationNodes], new Set(Object.keys(schemas)));
|
|
2566
|
-
for (const name of promotedEnums.keys()) enumNames.push(name);
|
|
2567
|
-
}
|
|
2568
|
+
const promotedEnums = enums === "root" ? collectInlineEnums([...parsedByName.values(), ...operationNodes], new Set(Object.keys(schemas))) : null;
|
|
2569
|
+
if (promotedEnums) for (const name of promotedEnums.keys()) enumNames.push(name);
|
|
2568
2570
|
const schemaNodes = promotedEnums ? [...promotedEnums.values()] : [];
|
|
2569
2571
|
for (const name of Object.keys(schemas)) {
|
|
2570
2572
|
const alias = refAliasMap.get(name);
|
|
2571
|
-
|
|
2572
|
-
if (alias?.name && parsedByName.has(alias.name)) node = {
|
|
2573
|
+
const node = alias?.name && parsedByName.has(alias.name) ? {
|
|
2573
2574
|
...parsedByName.get(alias.name),
|
|
2574
2575
|
name
|
|
2575
|
-
}
|
|
2576
|
-
else {
|
|
2576
|
+
} : (() => {
|
|
2577
2577
|
const parsed = parsedByName.get(name);
|
|
2578
2578
|
const child = discriminatorChildMap?.get(name);
|
|
2579
|
-
|
|
2580
|
-
}
|
|
2579
|
+
return child ? patchDiscriminatorNode(parsed, child) : parsed;
|
|
2580
|
+
})();
|
|
2581
2581
|
schemaNodes.push(promotedEnums ? refPromotedEnums(node, promotedEnums) : node);
|
|
2582
2582
|
}
|
|
2583
2583
|
const operations = promotedEnums ? operationNodes.map((node) => refPromotedEnums(node, promotedEnums)) : operationNodes;
|
|
@@ -2622,11 +2622,13 @@ const adapterOas = createAdapter((options) => {
|
|
|
2622
2622
|
assertDocument(document);
|
|
2623
2623
|
await validateDocument(document, options);
|
|
2624
2624
|
},
|
|
2625
|
-
async parse(source) {
|
|
2625
|
+
async parse(source, { signal } = {}) {
|
|
2626
|
+
signal?.throwIfAborted();
|
|
2626
2627
|
const cached = inputCache.get(source);
|
|
2627
2628
|
if (cached) return cached;
|
|
2628
2629
|
const promise = (async () => {
|
|
2629
2630
|
const document = await parseFromConfig(source);
|
|
2631
|
+
signal?.throwIfAborted();
|
|
2630
2632
|
assertDocument(document);
|
|
2631
2633
|
if (validate) await validateDocument(document);
|
|
2632
2634
|
parsedDocument = document;
|
|
@@ -2645,7 +2647,10 @@ const adapterOas = createAdapter((options) => {
|
|
|
2645
2647
|
});
|
|
2646
2648
|
})();
|
|
2647
2649
|
inputCache.set(source, promise);
|
|
2648
|
-
return promise
|
|
2650
|
+
return promise.catch((error) => {
|
|
2651
|
+
if (signal?.aborted) inputCache.delete(source);
|
|
2652
|
+
throw error;
|
|
2653
|
+
});
|
|
2649
2654
|
}
|
|
2650
2655
|
};
|
|
2651
2656
|
});
|