From b4a12d606e02048061e4f024d1b4c60b0ce30919 Mon Sep 17 00:00:00 2001
From: "Nolann B." <100787331+nolannbiron@users.noreply.github.com>
Date: Mon, 24 Feb 2025 21:26:26 +0100
Subject: [PATCH] Fix circularRef in schema + examples OpenAPI (#2872)
---
.changeset/itchy-crabs-explain.md | 5 +++
packages/react-openapi/src/OpenAPISchema.tsx | 6 ++++
.../src/generateSchemaExample.ts | 36 ++++++++++---------
3 files changed, 31 insertions(+), 16 deletions(-)
create mode 100644 .changeset/itchy-crabs-explain.md
diff --git a/.changeset/itchy-crabs-explain.md b/.changeset/itchy-crabs-explain.md
new file mode 100644
index 000000000..49030b483
--- /dev/null
+++ b/.changeset/itchy-crabs-explain.md
@@ -0,0 +1,5 @@
+---
+'@gitbook/react-openapi': patch
+---
+
+Fix circularRef in schema + examples OpenAPI
diff --git a/packages/react-openapi/src/OpenAPISchema.tsx b/packages/react-openapi/src/OpenAPISchema.tsx
index 8c7c9bf5e..30c49ff55 100644
--- a/packages/react-openapi/src/OpenAPISchema.tsx
+++ b/packages/react-openapi/src/OpenAPISchema.tsx
@@ -59,6 +59,9 @@ export function OpenAPISchemaProperty(
context={context}
/>
))}
+ {parentCircularRef ? (
+
+ ) : null}
);
}
@@ -76,6 +79,9 @@ export function OpenAPISchemaProperty(
/>
) : null}
+ {parentCircularRef ? (
+
+ ) : null}
);
}
diff --git a/packages/react-openapi/src/generateSchemaExample.ts b/packages/react-openapi/src/generateSchemaExample.ts
index c00cb55d3..c8c72a99c 100644
--- a/packages/react-openapi/src/generateSchemaExample.ts
+++ b/packages/react-openapi/src/generateSchemaExample.ts
@@ -16,23 +16,27 @@ export function generateSchemaExample(
schema: OpenAPIV3.SchemaObject,
options?: GenerateSchemaExampleOptions,
): JSONValue | undefined {
- return getExampleFromSchema(schema, {
- emptyString: 'text',
- variables: {
- 'date-time': new Date().toISOString(),
- date: new Date().toISOString().split('T')[0],
- email: 'name@gmail.com',
- hostname: 'example.com',
- ipv4: '0.0.0.0',
- ipv6: '2001:0db8:85a3:0000:0000:8a2e:0370:7334',
- uri: 'https://example.com',
- uuid: '123e4567-e89b-12d3-a456-426614174000',
- binary: 'binary',
- byte: 'Ynl0ZXM=',
- password: 'password',
+ return getExampleFromSchema(
+ schema,
+ {
+ emptyString: 'text',
+ variables: {
+ 'date-time': new Date().toISOString(),
+ date: new Date().toISOString().split('T')[0],
+ email: 'name@gmail.com',
+ hostname: 'example.com',
+ ipv4: '0.0.0.0',
+ ipv6: '2001:0db8:85a3:0000:0000:8a2e:0370:7334',
+ uri: 'https://example.com',
+ uuid: '123e4567-e89b-12d3-a456-426614174000',
+ binary: 'binary',
+ byte: 'Ynl0ZXM=',
+ password: 'password',
+ },
+ ...options,
},
- ...options,
- });
+ 3, // Max depth for circular references
+ );
}
/**