Handle grouped OpenAPISchemas (#3071)

This commit is contained in:
Nolann B.
2025-04-01 17:24:43 +02:00
committed by GitHub
parent fb90eb0acc
commit 7d0b422200
3 changed files with 17 additions and 5 deletions
+6
View File
@@ -0,0 +1,6 @@
---
'@gitbook/react-openapi': patch
'gitbook': patch
---
Handle grouped OpenAPISchemas
@@ -50,6 +50,7 @@ async function OpenAPISchemasBody(props: BlockProps<OpenAPISchemasBlock>) {
return ( return (
<BaseOpenAPISchemas <BaseOpenAPISchemas
data={data} data={data}
grouped={block.data.grouped}
context={{ context={{
specUrl, specUrl,
icons: { icons: {
@@ -16,8 +16,12 @@ export function OpenAPISchemas(props: {
className?: string; className?: string;
data: OpenAPISchemasData; data: OpenAPISchemasData;
context: OpenAPISchemasContextProps; context: OpenAPISchemasContextProps;
/**
* Whether to show the schema directly if there is only one.
*/
grouped?: boolean;
}) { }) {
const { className, data, context } = props; const { className, data, context, grouped } = props;
const { schemas } = data; const { schemas } = data;
const clientContext: OpenAPIClientContext = { const clientContext: OpenAPIClientContext = {
@@ -32,7 +36,7 @@ export function OpenAPISchemas(props: {
return ( return (
<div className={clsx('openapi-schemas', className)}> <div className={clsx('openapi-schemas', className)}>
<OpenAPIRootSchemasSchema schemas={schemas} context={clientContext} /> <OpenAPIRootSchemasSchema grouped={grouped} schemas={schemas} context={clientContext} />
</div> </div>
); );
} }
@@ -44,11 +48,12 @@ export function OpenAPISchemas(props: {
function OpenAPIRootSchemasSchema(props: { function OpenAPIRootSchemasSchema(props: {
schemas: OpenAPISchemasData['schemas']; schemas: OpenAPISchemasData['schemas'];
context: OpenAPIClientContext; context: OpenAPIClientContext;
grouped?: boolean;
}) { }) {
const { schemas, context } = props; const { schemas, context, grouped } = props;
// If there is only one model, we show it directly. // If there is only one model and we are not grouping, we show it directly.
if (schemas.length === 1) { if (schemas.length === 1 && !grouped) {
const schema = schemas?.[0]?.schema; const schema = schemas?.[0]?.schema;
if (!schema) { if (!schema) {