Skip to content

Commit 7d0b422

Browse files
authored
Handle grouped OpenAPISchemas (#3071)
1 parent fb90eb0 commit 7d0b422

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

.changeset/fuzzy-buckets-talk.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@gitbook/react-openapi': patch
3+
'gitbook': patch
4+
---
5+
6+
Handle grouped OpenAPISchemas

packages/gitbook/src/components/DocumentView/OpenAPI/OpenAPISchemas.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ async function OpenAPISchemasBody(props: BlockProps<OpenAPISchemasBlock>) {
5050
return (
5151
<BaseOpenAPISchemas
5252
data={data}
53+
grouped={block.data.grouped}
5354
context={{
5455
specUrl,
5556
icons: {

packages/react-openapi/src/schemas/OpenAPISchemas.tsx

+10-5
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ export function OpenAPISchemas(props: {
1616
className?: string;
1717
data: OpenAPISchemasData;
1818
context: OpenAPISchemasContextProps;
19+
/**
20+
* Whether to show the schema directly if there is only one.
21+
*/
22+
grouped?: boolean;
1923
}) {
20-
const { className, data, context } = props;
24+
const { className, data, context, grouped } = props;
2125
const { schemas } = data;
2226

2327
const clientContext: OpenAPIClientContext = {
@@ -32,7 +36,7 @@ export function OpenAPISchemas(props: {
3236

3337
return (
3438
<div className={clsx('openapi-schemas', className)}>
35-
<OpenAPIRootSchemasSchema schemas={schemas} context={clientContext} />
39+
<OpenAPIRootSchemasSchema grouped={grouped} schemas={schemas} context={clientContext} />
3640
</div>
3741
);
3842
}
@@ -44,11 +48,12 @@ export function OpenAPISchemas(props: {
4448
function OpenAPIRootSchemasSchema(props: {
4549
schemas: OpenAPISchemasData['schemas'];
4650
context: OpenAPIClientContext;
51+
grouped?: boolean;
4752
}) {
48-
const { schemas, context } = props;
53+
const { schemas, context, grouped } = props;
4954

50-
// If there is only one model, we show it directly.
51-
if (schemas.length === 1) {
55+
// If there is only one model and we are not grouping, we show it directly.
56+
if (schemas.length === 1 && !grouped) {
5257
const schema = schemas?.[0]?.schema;
5358

5459
if (!schema) {

0 commit comments

Comments
 (0)