mirror of
https://github.com/open-webui/open-webui
synced 2025-06-15 19:05:04 +00:00
enh: allow custom openapi json url
This commit is contained in:
parent
a38e44e870
commit
2c7ccc69fe
@ -490,8 +490,17 @@ async def get_tool_servers_data(
|
|||||||
server_entries = []
|
server_entries = []
|
||||||
for idx, server in enumerate(servers):
|
for idx, server in enumerate(servers):
|
||||||
if server.get("config", {}).get("enable"):
|
if server.get("config", {}).get("enable"):
|
||||||
url_path = server.get("path", "openapi.json")
|
# Path (to OpenAPI spec URL) can be either a full URL or a path to append to the base URL
|
||||||
full_url = f"{server.get('url')}/{url_path}"
|
openapi_path = server.get("path", "openapi.json")
|
||||||
|
if "://" in openapi_path:
|
||||||
|
# If it contains "://", it's a full URL
|
||||||
|
full_url = openapi_path
|
||||||
|
else:
|
||||||
|
if not openapi_path.startswith("/"):
|
||||||
|
# Ensure the path starts with a slash
|
||||||
|
openapi_path = f"/{openapi_path}"
|
||||||
|
|
||||||
|
full_url = f"{server.get('url')}{openapi_path}"
|
||||||
|
|
||||||
info = server.get("info", {})
|
info = server.get("info", {})
|
||||||
|
|
||||||
|
@ -346,11 +346,15 @@ export const getToolServersData = async (i18n, servers: object[]) => {
|
|||||||
.map(async (server) => {
|
.map(async (server) => {
|
||||||
const data = await getToolServerData(
|
const data = await getToolServerData(
|
||||||
(server?.auth_type ?? 'bearer') === 'bearer' ? server?.key : localStorage.token,
|
(server?.auth_type ?? 'bearer') === 'bearer' ? server?.key : localStorage.token,
|
||||||
server?.url + '/' + (server?.path ?? 'openapi.json')
|
(server?.path ?? '').includes('://')
|
||||||
|
? server?.path
|
||||||
|
: `${server?.url}${(server?.path ?? '').startsWith('/') ? '' : '/'}${server?.path}`
|
||||||
).catch((err) => {
|
).catch((err) => {
|
||||||
toast.error(
|
toast.error(
|
||||||
i18n.t(`Failed to connect to {{URL}} OpenAPI tool server`, {
|
i18n.t(`Failed to connect to {{URL}} OpenAPI tool server`, {
|
||||||
URL: server?.url + '/' + (server?.path ?? 'openapi.json')
|
URL: (server?.path ?? '').includes('://')
|
||||||
|
? server?.path
|
||||||
|
: `${server?.url}${(server?.path ?? '').startsWith('/') ? '' : '/'}${server?.path}`
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
return null;
|
return null;
|
||||||
|
@ -53,7 +53,7 @@
|
|||||||
if (direct) {
|
if (direct) {
|
||||||
const res = await getToolServerData(
|
const res = await getToolServerData(
|
||||||
auth_type === 'bearer' ? key : localStorage.token,
|
auth_type === 'bearer' ? key : localStorage.token,
|
||||||
`${url}/${path}`
|
path.includes('://') ? path : `${url}${path.startsWith('/') ? '' : '/'}${path}`
|
||||||
).catch((err) => {
|
).catch((err) => {
|
||||||
toast.error($i18n.t('Connection failed'));
|
toast.error($i18n.t('Connection failed'));
|
||||||
});
|
});
|
||||||
@ -237,12 +237,11 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex-1 flex items-center">
|
<div class="flex-1 flex items-center">
|
||||||
<div class="text-sm">/</div>
|
|
||||||
<input
|
<input
|
||||||
class="w-full text-sm bg-transparent placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-hidden"
|
class="w-full text-sm bg-transparent placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-hidden"
|
||||||
type="text"
|
type="text"
|
||||||
bind:value={path}
|
bind:value={path}
|
||||||
placeholder={$i18n.t('openapi.json Path')}
|
placeholder={$i18n.t('openapi.json URL or Path')}
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
@ -252,7 +251,7 @@
|
|||||||
|
|
||||||
<div class="text-xs text-gray-500 mt-1">
|
<div class="text-xs text-gray-500 mt-1">
|
||||||
{$i18n.t(`WebUI will make requests to "{{url}}"`, {
|
{$i18n.t(`WebUI will make requests to "{{url}}"`, {
|
||||||
url: `${url}/${path}`
|
url: path.includes('://') ? path : `${url}${path.startsWith('/') ? '' : '/'}${path}`
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user