mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-16 23:55:20 +00:00
Handle OpenAPI alternatives from schema.items (#3235)
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'@gitbook/react-openapi': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Handle OpenAPI alternatives from schema.items
|
||||||
@@ -80,11 +80,10 @@ function OpenAPISchemaProperty(
|
|||||||
context={context}
|
context={context}
|
||||||
/>
|
/>
|
||||||
{index < alternatives.length - 1 ? (
|
{index < alternatives.length - 1 ? (
|
||||||
<span className="openapi-schema-alternative-separator">
|
<OpenAPISchemaAlternativeSeparator
|
||||||
{(schema.anyOf || schema.oneOf) &&
|
schema={schema}
|
||||||
tString(context.translation, 'or')}
|
context={context}
|
||||||
{schema.allOf && tString(context.translation, 'and')}
|
/>
|
||||||
</span>
|
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
@@ -256,6 +255,28 @@ function OpenAPISchemaAlternative(props: {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function OpenAPISchemaAlternativeSeparator(props: {
|
||||||
|
schema: OpenAPIV3.SchemaObject;
|
||||||
|
context: OpenAPIClientContext;
|
||||||
|
}) {
|
||||||
|
const { schema, context } = props;
|
||||||
|
|
||||||
|
const anyOf = schema.anyOf || schema.items?.anyOf;
|
||||||
|
const oneOf = schema.oneOf || schema.items?.oneOf;
|
||||||
|
const allOf = schema.allOf || schema.items?.allOf;
|
||||||
|
|
||||||
|
if (!anyOf && !oneOf && !allOf) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<span className="openapi-schema-alternative-separator">
|
||||||
|
{(anyOf || oneOf) && tString(context.translation, 'or')}
|
||||||
|
{allOf && tString(context.translation, 'and')}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render a circular reference to a schema.
|
* Render a circular reference to a schema.
|
||||||
*/
|
*/
|
||||||
@@ -457,6 +478,14 @@ export function getSchemaAlternatives(
|
|||||||
schema: OpenAPIV3.SchemaObject,
|
schema: OpenAPIV3.SchemaObject,
|
||||||
ancestors: Set<OpenAPIV3.SchemaObject> = new Set()
|
ancestors: Set<OpenAPIV3.SchemaObject> = new Set()
|
||||||
): OpenAPIV3.SchemaObject[] | null {
|
): OpenAPIV3.SchemaObject[] | null {
|
||||||
|
// Search for alternatives in the items property if it exists
|
||||||
|
if (
|
||||||
|
schema.items &&
|
||||||
|
('oneOf' in schema.items || 'allOf' in schema.items || 'anyOf' in schema.items)
|
||||||
|
) {
|
||||||
|
return getSchemaAlternatives(schema.items, ancestors);
|
||||||
|
}
|
||||||
|
|
||||||
const alternatives:
|
const alternatives:
|
||||||
| [AlternativeType, (OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject)[]]
|
| [AlternativeType, (OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject)[]]
|
||||||
| null = (() => {
|
| null = (() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user