OpenAPI: Improve error message

This commit is contained in:
Fuma Nama
2025-05-15 20:11:26 +08:00
parent c25d67821c
commit 623610a79d
3 changed files with 10 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'fumadocs-openapi': patch
---
Improve error message
+1 -1
View File
@@ -135,7 +135,7 @@ function getAuthorizationField(
if (!item) {
console.warn(
`Cannot find suitable security schema for API Playground from ${JSON.stringify(security, null, 2)}. Only one requirement is allowed`,
`Cannot find suitable security scheme for API Playground from ${JSON.stringify(security, null, 2)}. Only schemes with one requirement are allowed.`,
);
return;
}
+4 -1
View File
@@ -17,7 +17,10 @@ export function getSecurities(
const schemas = document.components?.securitySchemes ?? {};
for (const [key, scopes] of Object.entries(requirement)) {
if (!(key in schemas)) return [];
if (!(key in schemas))
throw new Error(
`Security scheme with name ${key} is not found, make sure to define referenced schemes.`,
);
const schema = schemas[key];
results.push({