From 160e1324568ad1fb2dd165a5e0088d292cb86830 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Tue, 4 Feb 2025 10:32:46 +0100 Subject: [PATCH] Fix configuration flow --- integrations/openapi/gitbook-manifest.yaml | 2 +- .../src/components/configureSource.tsx | 38 ++++++++++++------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/integrations/openapi/gitbook-manifest.yaml b/integrations/openapi/gitbook-manifest.yaml index 374ae0fe3..9fed77219 100644 --- a/integrations/openapi/gitbook-manifest.yaml +++ b/integrations/openapi/gitbook-manifest.yaml @@ -19,6 +19,6 @@ target: space contentSources: - id: generate title: Generate API documentation - description: Generate and keep documentation from OpenAPI. + description: Auto-generate an API reference from an OpenAPI specification configuration: componentId: configureSource diff --git a/integrations/openapi/src/components/configureSource.tsx b/integrations/openapi/src/components/configureSource.tsx index 323b6f62d..9041f5af7 100644 --- a/integrations/openapi/src/components/configureSource.tsx +++ b/integrations/openapi/src/components/configureSource.tsx @@ -1,4 +1,4 @@ -import { createComponent, InstallationConfigurationProps } from '@gitbook/runtime'; +import { createComponent, ExposableError, InstallationConfigurationProps } from '@gitbook/runtime'; import type { OpenAPIRuntimeEnvironment, @@ -13,7 +13,7 @@ export const configureComponent = createComponent< { specURL: string; }, - void, + { action: 'submit' }, OpenAPIRuntimeContext >({ componentId: 'configureSource', @@ -23,11 +23,30 @@ export const configureComponent = createComponent< }; }, action: async (element, action, ctx) => { + if (action.action === 'submit') { + if (!element.state.specURL) { + throw new ExposableError('Invalid spec URL'); + } + + return { + type: 'complete', + returnValue: { + props: { + specURL: element.state.specURL, + }, + dependencies: { + // Align with GenerateContentSourceDependencies + // spec: { kind: 'openapi', spec: element.dynamicState('spec') } + }, + } + } + } + return element; }, render: async (element, context) => { return ( - + - + ); }, }); \ No newline at end of file