diff --git a/.changeset/spicy-ravens-live.md b/.changeset/spicy-ravens-live.md new file mode 100644 index 000000000..68b671baa --- /dev/null +++ b/.changeset/spicy-ravens-live.md @@ -0,0 +1,5 @@ +--- +'@gitbook/react-openapi': patch +--- + +Fix error on unresolvable refs by replacing with property name and any type diff --git a/packages/react-openapi/src/OpenAPISchema.tsx b/packages/react-openapi/src/OpenAPISchema.tsx index 6f2b396db..ec875242f 100644 --- a/packages/react-openapi/src/OpenAPISchema.tsx +++ b/packages/react-openapi/src/OpenAPISchema.tsx @@ -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; @@ -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; } diff --git a/packages/react-openapi/src/utils.ts b/packages/react-openapi/src/utils.ts index 7b2ae87d4..49e7ef3ca 100644 --- a/packages/react-openapi/src/utils.ts +++ b/packages/react-openapi/src/utils.ts @@ -8,7 +8,7 @@ export function noReference(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; }