Skip to content

Commit b4a12d6

Browse files
authored
Fix circularRef in schema + examples OpenAPI (#2872)
1 parent a054554 commit b4a12d6

File tree

3 files changed

+31
-16
lines changed

3 files changed

+31
-16
lines changed

.changeset/itchy-crabs-explain.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@gitbook/react-openapi': patch
3+
---
4+
5+
Fix circularRef in schema + examples OpenAPI

packages/react-openapi/src/OpenAPISchema.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ export function OpenAPISchemaProperty(
5959
context={context}
6060
/>
6161
))}
62+
{parentCircularRef ? (
63+
<OpenAPISchemaCircularRef id={parentCircularRef} schema={schema} />
64+
) : null}
6265
</InteractiveSection>
6366
);
6467
}
@@ -76,6 +79,9 @@ export function OpenAPISchemaProperty(
7679
/>
7780
</OpenAPIDisclosure>
7881
) : null}
82+
{parentCircularRef ? (
83+
<OpenAPISchemaCircularRef id={parentCircularRef} schema={schema} />
84+
) : null}
7985
</InteractiveSection>
8086
);
8187
}

packages/react-openapi/src/generateSchemaExample.ts

+20-16
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,27 @@ export function generateSchemaExample(
1616
schema: OpenAPIV3.SchemaObject,
1717
options?: GenerateSchemaExampleOptions,
1818
): JSONValue | undefined {
19-
return getExampleFromSchema(schema, {
20-
emptyString: 'text',
21-
variables: {
22-
'date-time': new Date().toISOString(),
23-
date: new Date().toISOString().split('T')[0],
24-
25-
hostname: 'example.com',
26-
ipv4: '0.0.0.0',
27-
ipv6: '2001:0db8:85a3:0000:0000:8a2e:0370:7334',
28-
uri: 'https://example.com',
29-
uuid: '123e4567-e89b-12d3-a456-426614174000',
30-
binary: 'binary',
31-
byte: 'Ynl0ZXM=',
32-
password: 'password',
19+
return getExampleFromSchema(
20+
schema,
21+
{
22+
emptyString: 'text',
23+
variables: {
24+
'date-time': new Date().toISOString(),
25+
date: new Date().toISOString().split('T')[0],
26+
27+
hostname: 'example.com',
28+
ipv4: '0.0.0.0',
29+
ipv6: '2001:0db8:85a3:0000:0000:8a2e:0370:7334',
30+
uri: 'https://example.com',
31+
uuid: '123e4567-e89b-12d3-a456-426614174000',
32+
binary: 'binary',
33+
byte: 'Ynl0ZXM=',
34+
password: 'password',
35+
},
36+
...options,
3337
},
34-
...options,
35-
});
38+
3, // Max depth for circular references
39+
);
3640
}
3741

3842
/**

0 commit comments

Comments
 (0)