mirror of
https://github.com/open-webui/open-webui.git
synced 2026-01-02 14:45:18 +00:00
fix: prevent crash when invalid OpenAPI spec is loaded for tool servers (#20257)
* enh * fix
This commit is contained in:
parent
935808f5ea
commit
697e94e935
2 changed files with 20 additions and 8 deletions
|
|
@ -379,6 +379,13 @@ export const getToolServersData = async (servers: object[]) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
|
if (!res.paths) {
|
||||||
|
return {
|
||||||
|
error: 'Invalid OpenAPI spec',
|
||||||
|
url: server?.url
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const { openapi, info, specs } = {
|
const { openapi, info, specs } = {
|
||||||
openapi: res,
|
openapi: res,
|
||||||
info: res.info,
|
info: res.info,
|
||||||
|
|
@ -1667,7 +1674,7 @@ export interface ModelMeta {
|
||||||
profile_image_url?: string;
|
profile_image_url?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ModelParams {}
|
export interface ModelParams { }
|
||||||
|
|
||||||
export type GlobalModelConfig = ModelConfig[];
|
export type GlobalModelConfig = ModelConfig[];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -357,9 +357,9 @@ export const generateInitialsImage = (name) => {
|
||||||
const initials =
|
const initials =
|
||||||
sanitizedName.length > 0
|
sanitizedName.length > 0
|
||||||
? sanitizedName[0] +
|
? sanitizedName[0] +
|
||||||
(sanitizedName.split(' ').length > 1
|
(sanitizedName.split(' ').length > 1
|
||||||
? sanitizedName[sanitizedName.lastIndexOf(' ') + 1]
|
? sanitizedName[sanitizedName.lastIndexOf(' ') + 1]
|
||||||
: '')
|
: '')
|
||||||
: '';
|
: '';
|
||||||
|
|
||||||
ctx.fillText(initials.toUpperCase(), canvas.width / 2, canvas.height / 2);
|
ctx.fillText(initials.toUpperCase(), canvas.width / 2, canvas.height / 2);
|
||||||
|
|
@ -515,10 +515,10 @@ export const compareVersion = (latest, current) => {
|
||||||
return current === '0.0.0'
|
return current === '0.0.0'
|
||||||
? false
|
? false
|
||||||
: current.localeCompare(latest, undefined, {
|
: current.localeCompare(latest, undefined, {
|
||||||
numeric: true,
|
numeric: true,
|
||||||
sensitivity: 'case',
|
sensitivity: 'case',
|
||||||
caseFirst: 'upper'
|
caseFirst: 'upper'
|
||||||
}) < 0;
|
}) < 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const extractCurlyBraceWords = (text) => {
|
export const extractCurlyBraceWords = (text) => {
|
||||||
|
|
@ -1249,6 +1249,11 @@ function resolveSchema(schemaRef, components, resolvedSchemas = new Set()) {
|
||||||
export const convertOpenApiToToolPayload = (openApiSpec) => {
|
export const convertOpenApiToToolPayload = (openApiSpec) => {
|
||||||
const toolPayload = [];
|
const toolPayload = [];
|
||||||
|
|
||||||
|
// Guard against invalid or non-OpenAPI specs (e.g., MCP-style configs)
|
||||||
|
if (!openApiSpec || !openApiSpec.paths) {
|
||||||
|
return toolPayload;
|
||||||
|
}
|
||||||
|
|
||||||
for (const [path, methods] of Object.entries(openApiSpec.paths)) {
|
for (const [path, methods] of Object.entries(openApiSpec.paths)) {
|
||||||
for (const [method, operation] of Object.entries(methods)) {
|
for (const [method, operation] of Object.entries(methods)) {
|
||||||
if (operation?.operationId) {
|
if (operation?.operationId) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue