'use client'; import type { OpenAPIClientContext } from './context'; import { formatPath } from './formatPath'; import type { OpenAPIPathProps } from './OpenAPIPath'; import { OpenAPIPathItem } from './OpenAPIPathItem'; import { OpenAPISelect, useSelectState } from './OpenAPISelect'; import type { OpenAPIServerWithCustomProperties } from './types'; import { getDefaultServerURL, interpolateServerURL } from './util/server'; import { createStateKey } from './utils'; export const serversStateKey = createStateKey('servers'); /** * Display the path of an operation. */ export function OpenAPIPathMultipleServers( props: OpenAPIPathProps & { context: OpenAPIClientContext } ) { const { data, withServer = true, context } = props; const { path, servers } = data; const defaultServer = getDefaultServerURL(servers); const { key, setKey } = useSelectState(serversStateKey, defaultServer); const formattedPath = formatPath(path); const items = servers .filter( (server): server is OpenAPIServerWithCustomProperties & { url: string } => !!server.url ) .map((server) => { const url = interpolateServerURL(server); return { key: url, label: url, description: server.description, }; }); return ( {withServer ? ( {(item) => ( <> {item.label} {item.description ? ( {item.description} ) : null} )} ) : null} {formattedPath} ); }