diff --git a/packages/gitbook/src/app/(space)/(content)/[[...pathname]]/page.tsx b/packages/gitbook/src/app/(space)/(content)/[[...pathname]]/page.tsx index 4b126ee90..176bb07e2 100644 --- a/packages/gitbook/src/app/(space)/(content)/[[...pathname]]/page.tsx +++ b/packages/gitbook/src/app/(space)/(content)/[[...pathname]]/page.tsx @@ -93,6 +93,7 @@ export default async function Page(props: { // Display the page feedback in the page footer if the aside is not visible withPageFeedback && !page.layout.outline } + searchParams={searchParams} /> {page.layout.outline ? ( boolean; + + searchParams?: Record; } export interface DocumentContextProps { diff --git a/packages/gitbook/src/components/DocumentView/OpenAPI/OpenAPI.tsx b/packages/gitbook/src/components/DocumentView/OpenAPI/OpenAPI.tsx index 08fe0be58..e2a2256c7 100644 --- a/packages/gitbook/src/components/DocumentView/OpenAPI/OpenAPI.tsx +++ b/packages/gitbook/src/components/DocumentView/OpenAPI/OpenAPI.tsx @@ -1,6 +1,6 @@ import { DocumentBlockSwagger } from '@gitbook/api'; import { Icon } from '@gitbook/icons'; -import { OpenAPIOperation } from '@gitbook/react-openapi'; +import { OpenAPIOperation, OpenAPIOperationData } from '@gitbook/react-openapi'; import React from 'react'; import { LoadingPane } from '@/components/primitives'; @@ -100,3 +100,27 @@ function OpenAPIFallback() { ); } + +function parseModifiers(data: OpenAPIOperationData, params: Record) { + if (!data) { + return; + } + const { servers } = params; + const serverIndex = + servers && !isNaN(Number(servers)) + ? Math.min(0, Math.max(Number(servers), servers.length - 1)) + : 0; + const server = data.servers[serverIndex]; + if (server && server.variables) { + return Object.keys(server.variables).reduce>( + (result, key) => { + const selection = Number(params[key]); + if (!isNaN(selection)) { + result[key] = selection; + } + return result; + }, + { servers: serverIndex }, + ); + } +} diff --git a/packages/gitbook/src/components/PageBody/PageBody.tsx b/packages/gitbook/src/components/PageBody/PageBody.tsx index 052d9abb2..98dd20f97 100644 --- a/packages/gitbook/src/components/PageBody/PageBody.tsx +++ b/packages/gitbook/src/components/PageBody/PageBody.tsx @@ -34,6 +34,7 @@ export function PageBody(props: { document: JSONDocument | null; context: ContentRefContext; withPageFeedback: boolean; + searchParams: Record; }) { const { space, @@ -44,6 +45,7 @@ export function PageBody(props: { page, document, withPageFeedback, + searchParams, } = props; const asFullWidth = document ? hasFullWidthBlock(document) : false; @@ -96,6 +98,7 @@ export function PageBody(props: { resolveContentRef: (ref, options) => resolveContentRef(ref, context, options), shouldHighlightCode, + searchParams, }} /> ) : ( diff --git a/packages/react-openapi/src/OpenAPIOperation.tsx b/packages/react-openapi/src/OpenAPIOperation.tsx index e4a643303..48d9e9390 100644 --- a/packages/react-openapi/src/OpenAPIOperation.tsx +++ b/packages/react-openapi/src/OpenAPIOperation.tsx @@ -5,7 +5,7 @@ import { OpenAPIOperationData, toJSON } from './fetchOpenAPIOperation'; import { Markdown } from './Markdown'; import { OpenAPICodeSample } from './OpenAPICodeSample'; import { OpenAPIResponseExample } from './OpenAPIResponseExample'; -import { OpenAPIServerURL } from './OpenAPIServerURL'; +import { getServersURL, OpenAPIServerURL } from './OpenAPIServerURL'; import { OpenAPISpec } from './OpenAPISpec'; import { OpenAPIClientContext, OpenAPIContextProps } from './types'; import { ScalarApiClient } from './ScalarApiButton'; @@ -25,8 +25,10 @@ export async function OpenAPIOperation(props: { defaultInteractiveOpened: context.defaultInteractiveOpened, icons: context.icons, blockKey: context.blockKey, + enumSelectors: context.enumSelectors, }; + const config = await getConfiguration(context); return (
@@ -70,3 +72,17 @@ export async function OpenAPIOperation(props: { ); } + +async function getConfiguration(context: OpenAPIContextProps) { + const response = await fetch(context.specUrl); + const doc = await response.json(); + + return { + spec: { + content: { + ...doc, + servers: [{ url: getServersURL(doc.servers, context.enumSelectors) }], + }, + }, + }; +} diff --git a/packages/react-openapi/src/OpenAPIServerURLVariable.tsx b/packages/react-openapi/src/OpenAPIServerURLVariable.tsx index 27e82a00c..eae2732e4 100644 --- a/packages/react-openapi/src/OpenAPIServerURLVariable.tsx +++ b/packages/react-openapi/src/OpenAPIServerURLVariable.tsx @@ -1,7 +1,9 @@ 'use client'; import * as React from 'react'; +import { useRouter } from 'next/navigation'; import classNames from 'classnames'; import { OpenAPIV3 } from 'openapi-types'; +import { OpenAPIClientContext } from './types'; /** * Interactive component to show the value of a server variable and let the user change it.