Skip to content

Commit a652958

Browse files
authored
Handle Errors from Unresolved Refs (#2810)
1 parent 18953b2 commit a652958

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

.changeset/spicy-ravens-live.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@gitbook/react-openapi': patch
3+
---
4+
5+
Fix error on unresolvable refs by replacing with property name and any type

packages/react-openapi/src/OpenAPISchema.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import React, { useId } from 'react';
55
import { InteractiveSection } from './InteractiveSection';
66
import { Markdown } from './Markdown';
77
import { OpenAPIClientContext } from './types';
8-
import { noReference } from './utils';
8+
import { checkIsReference, noReference } from './utils';
99
import { stringifyOpenAPI } from './stringifyOpenAPI';
1010

1111
type CircularRefsIds = Map<OpenAPIV3.SchemaObject, string>;
@@ -278,7 +278,10 @@ function getSchemaProperties(schema: OpenAPIV3.SchemaObject): null | OpenAPISche
278278

279279
if (schema.properties) {
280280
Object.entries(schema.properties).forEach(([propertyName, rawPropertySchema]) => {
281-
const propertySchema = noReference(rawPropertySchema);
281+
const isReference = checkIsReference(rawPropertySchema);
282+
const propertySchema: OpenAPIV3.SchemaObject = isReference
283+
? { propertyName }
284+
: rawPropertySchema;
282285
if (propertySchema.deprecated) {
283286
return;
284287
}

packages/react-openapi/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export function noReference<T>(input: T | OpenAPIV3.ReferenceObject): T {
88
return input;
99
}
1010

11-
function checkIsReference(input: unknown): input is OpenAPIV3.ReferenceObject {
11+
export function checkIsReference(input: unknown): input is OpenAPIV3.ReferenceObject {
1212
return typeof input === 'object' && !!input && '$ref' in input;
1313
}
1414

0 commit comments

Comments
 (0)