Skip to content

Commit 3b6db9a

Browse files
committed
Pass recursive from server to client
1 parent e987108 commit 3b6db9a

File tree

7 files changed

+71
-6
lines changed

7 files changed

+71
-6
lines changed

bun.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@
241241
"@scalar/oas-utils": "^0.2.120",
242242
"clsx": "^2.1.1",
243243
"flatted": "^3.2.9",
244+
"json-decycle": "^4.0.0",
244245
"json-xml-parse": "^1.3.0",
245246
"react-aria": "^3.37.0",
246247
"react-aria-components": "^1.6.0",
@@ -2069,6 +2070,8 @@
20692070

20702071
"json-buffer": ["[email protected]", "", {}, "sha512-CuUqjv0FUZIdXkHPI8MezCnFCdaTAacej1TZYulLoAg1h/PhwkdXFN4V/gzY4g+fMBCOV2xF+rp7t2XD2ns/NQ=="],
20712072

2073+
"json-decycle": ["[email protected]", "", {}, "sha512-3GFL/vWazCbMu1kw+NdIfAHh6Ugq5pxkKcSUnK1f/Fw1nDtt1i+BiBfRJs0iPEKscYAz4k4+osvgjY95hmuJXQ=="],
2074+
20722075
"json-parse-even-better-errors": ["[email protected]", "", {}, "sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w=="],
20732076

20742077
"json-schema": ["[email protected]", "", {}, "sha512-es94M3nTIfsEPisRafak+HDLfHXnKBhV3vU5eqPcS3flIWqcxJWgXHXiey3YrpaNsanY5ei1VoYEbOzijuq9BA=="],

packages/react-openapi/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"@scalar/oas-utils": "^0.2.120",
1717
"clsx": "^2.1.1",
1818
"flatted": "^3.2.9",
19+
"json-decycle": "^4.0.0",
1920
"json-xml-parse": "^1.3.0",
2021
"react-aria-components": "^1.6.0",
2122
"react-aria": "^3.37.0",

packages/react-openapi/src/OpenAPIRequestBody.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { OpenAPIV3 } from '@gitbook/openapi-parser';
22
import { InteractiveSection } from './InteractiveSection';
3-
import { OpenAPIRootSchema } from './OpenAPISchema';
3+
import { OpenAPIRootSchema } from './OpenAPISchemaServer';
44
import type { OpenAPIClientContext } from './types';
55
import { checkIsReference } from './utils';
66

packages/react-openapi/src/OpenAPIResponse.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { OpenAPIV3 } from '@gitbook/openapi-parser';
22
import { OpenAPIDisclosure } from './OpenAPIDisclosure';
3-
import { OpenAPISchemaProperties } from './OpenAPISchema';
3+
import { OpenAPISchemaProperties } from './OpenAPISchemaServer';
44
import type { OpenAPIClientContext } from './types';
55
import { parameterToProperty, resolveDescription } from './utils';
66

packages/react-openapi/src/OpenAPISchema.tsx

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type { OpenAPIV3 } from '@gitbook/openapi-parser';
66
import { useId } from 'react';
77

88
import clsx from 'clsx';
9+
import { retrocycle } from 'json-decycle';
910
import { Markdown } from './Markdown';
1011
import { OpenAPIDisclosure } from './OpenAPIDisclosure';
1112
import { OpenAPISchemaName } from './OpenAPISchemaName';
@@ -14,7 +15,7 @@ import { checkIsReference, resolveDescription, resolveFirstExample } from './uti
1415

1516
type CircularRefsIds = Map<OpenAPIV3.SchemaObject, string>;
1617

17-
interface OpenAPISchemaPropertyEntry {
18+
export interface OpenAPISchemaPropertyEntry {
1819
propertyName?: string | undefined;
1920
required?: boolean | undefined;
2021
schema: OpenAPIV3.SchemaObject;
@@ -84,7 +85,7 @@ function OpenAPISchemaProperty(props: {
8485
/**
8586
* Render a set of properties of an OpenAPI schema.
8687
*/
87-
export function OpenAPISchemaProperties(props: {
88+
function OpenAPISchemaProperties(props: {
8889
id?: string;
8990
properties: OpenAPISchemaPropertyEntry[];
9091
circularRefs?: CircularRefsIds;
@@ -113,10 +114,24 @@ export function OpenAPISchemaProperties(props: {
113114
);
114115
}
115116

117+
export function OpenAPISchemaPropertiesFromServer(props: {
118+
id?: string;
119+
properties: string;
120+
context: OpenAPIClientContext;
121+
}) {
122+
return (
123+
<OpenAPISchemaProperties
124+
id={props.id}
125+
properties={JSON.parse(props.properties, retrocycle())}
126+
context={props.context}
127+
/>
128+
);
129+
}
130+
116131
/**
117132
* Render a root schema (such as the request body or response body).
118133
*/
119-
export function OpenAPIRootSchema(props: {
134+
function OpenAPIRootSchema(props: {
120135
schema: OpenAPIV3.SchemaObject;
121136
context: OpenAPIClientContext;
122137
circularRefs?: CircularRefsIds;
@@ -153,6 +168,18 @@ export function OpenAPIRootSchema(props: {
153168
);
154169
}
155170

171+
export function OpenAPIRootSchemaFromServer(props: {
172+
schema: string;
173+
context: OpenAPIClientContext;
174+
}) {
175+
return (
176+
<OpenAPIRootSchema
177+
schema={JSON.parse(props.schema, retrocycle())}
178+
context={props.context}
179+
/>
180+
);
181+
}
182+
156183
/**
157184
* Render a tab for an alternative schema.
158185
* It renders directly the properties if relevant;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import type { OpenAPIV3 } from '@gitbook/openapi-parser';
2+
import { decycle } from 'json-decycle';
3+
import {
4+
OpenAPIRootSchemaFromServer,
5+
OpenAPISchemaPropertiesFromServer,
6+
type OpenAPISchemaPropertyEntry,
7+
} from './OpenAPISchema';
8+
import type { OpenAPIClientContext } from './types';
9+
10+
export function OpenAPISchemaProperties(props: {
11+
id?: string;
12+
properties: OpenAPISchemaPropertyEntry[];
13+
context: OpenAPIClientContext;
14+
}) {
15+
return (
16+
<OpenAPISchemaPropertiesFromServer
17+
id={props.id}
18+
properties={JSON.stringify(props.properties, decycle())}
19+
context={props.context}
20+
/>
21+
);
22+
}
23+
24+
export function OpenAPIRootSchema(props: {
25+
schema: OpenAPIV3.SchemaObject;
26+
context: OpenAPIClientContext;
27+
}) {
28+
return (
29+
<OpenAPIRootSchemaFromServer
30+
schema={JSON.stringify(props.schema, decycle())}
31+
context={props.context}
32+
/>
33+
);
34+
}

packages/react-openapi/src/OpenAPISpec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { OpenAPI } from '@gitbook/openapi-parser';
22

33
import { OpenAPIRequestBody } from './OpenAPIRequestBody';
44
import { OpenAPIResponses } from './OpenAPIResponses';
5-
import { OpenAPISchemaProperties } from './OpenAPISchema';
5+
import { OpenAPISchemaProperties } from './OpenAPISchemaServer';
66
import { OpenAPISecurities } from './OpenAPISecurities';
77
import { StaticSection } from './StaticSection';
88
import type { OpenAPIClientContext, OpenAPIOperationData } from './types';

0 commit comments

Comments
 (0)