mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-21 01:53:26 +00:00
Handle Errors from Unresolved Refs (#2810)
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'@gitbook/react-openapi': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix error on unresolvable refs by replacing with property name and any type
|
||||||
@@ -5,7 +5,7 @@ import React, { useId } from 'react';
|
|||||||
import { InteractiveSection } from './InteractiveSection';
|
import { InteractiveSection } from './InteractiveSection';
|
||||||
import { Markdown } from './Markdown';
|
import { Markdown } from './Markdown';
|
||||||
import { OpenAPIClientContext } from './types';
|
import { OpenAPIClientContext } from './types';
|
||||||
import { noReference } from './utils';
|
import { checkIsReference, noReference } from './utils';
|
||||||
import { stringifyOpenAPI } from './stringifyOpenAPI';
|
import { stringifyOpenAPI } from './stringifyOpenAPI';
|
||||||
|
|
||||||
type CircularRefsIds = Map<OpenAPIV3.SchemaObject, string>;
|
type CircularRefsIds = Map<OpenAPIV3.SchemaObject, string>;
|
||||||
@@ -278,7 +278,10 @@ function getSchemaProperties(schema: OpenAPIV3.SchemaObject): null | OpenAPISche
|
|||||||
|
|
||||||
if (schema.properties) {
|
if (schema.properties) {
|
||||||
Object.entries(schema.properties).forEach(([propertyName, rawPropertySchema]) => {
|
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) {
|
if (propertySchema.deprecated) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ export function noReference<T>(input: T | OpenAPIV3.ReferenceObject): T {
|
|||||||
return input;
|
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;
|
return typeof input === 'object' && !!input && '$ref' in input;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user