Skip to content

Commit

Permalink
Fix configuration flow
Browse files Browse the repository at this point in the history
  • Loading branch information
SamyPesse committed Feb 4, 2025
1 parent d73c393 commit 160e132
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion integrations/openapi/gitbook-manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
38 changes: 24 additions & 14 deletions integrations/openapi/src/components/configureSource.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createComponent, InstallationConfigurationProps } from '@gitbook/runtime';
import { createComponent, ExposableError, InstallationConfigurationProps } from '@gitbook/runtime';

import type {
OpenAPIRuntimeEnvironment,
Expand All @@ -13,7 +13,7 @@ export const configureComponent = createComponent<
{
specURL: string;
},
void,
{ action: 'submit' },
OpenAPIRuntimeContext
>({
componentId: 'configureSource',
Expand All @@ -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 (
<block>
<configuration>
<input
label="Spec URL"
hint="Enter the URL of the OpenAPI specification."
Expand All @@ -37,19 +56,10 @@ export const configureComponent = createComponent<
style="primary"
label="Continue"
onPress={{
action: '@ui.submit',
returnValue: {
props: {
specURL: element.state.specURL,
},
dependencies: {
// Align with GenerateContentSourceDependencies
// spec: { kind: 'openapi', spec: element.dynamicState('spec') }
},
},
action: 'submit',
}}
/>
</block>
</configuration>
);
},
});

0 comments on commit 160e132

Please sign in to comment.