Handle Errors from Unresolved Refs (#2810)

This commit is contained in:
Scott Cazan
2025-02-05 11:52:35 +01:00
committed by GitHub
parent 18953b2d6b
commit a6529584a5
3 changed files with 11 additions and 3 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@gitbook/react-openapi': patch
---
Fix error on unresolvable refs by replacing with property name and any type
+5 -2
View File
@@ -5,7 +5,7 @@ import React, { useId } from 'react';
import { InteractiveSection } from './InteractiveSection';
import { Markdown } from './Markdown';
import { OpenAPIClientContext } from './types';
import { noReference } from './utils';
import { checkIsReference, noReference } from './utils';
import { stringifyOpenAPI } from './stringifyOpenAPI';
type CircularRefsIds = Map<OpenAPIV3.SchemaObject, string>;
@@ -278,7 +278,10 @@ function getSchemaProperties(schema: OpenAPIV3.SchemaObject): null | OpenAPISche
if (schema.properties) {
Object.entries(schema.properties).forEach(([propertyName, rawPropertySchema]) => {
const propertySchema = noReference(rawPropertySchema);
const isReference = checkIsReference(rawPropertySchema);
const propertySchema: OpenAPIV3.SchemaObject = isReference
? { propertyName }
: rawPropertySchema;
if (propertySchema.deprecated) {
return;
}
+1 -1
View File
@@ -8,7 +8,7 @@ export function noReference<T>(input: T | OpenAPIV3.ReferenceObject): T {
return input;
}
function checkIsReference(input: unknown): input is OpenAPIV3.ReferenceObject {
export function checkIsReference(input: unknown): input is OpenAPIV3.ReferenceObject {
return typeof input === 'object' && !!input && '$ref' in input;
}