mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-25 04:20:02 +00:00
OpenAPI: Fix allOf schema display problem
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'fumadocs-openapi': patch
|
||||
---
|
||||
|
||||
Fix `allOf` schema display problem
|
||||
+11
-1
@@ -175,7 +175,17 @@ paths:
|
||||
content:
|
||||
multipart/form-data:
|
||||
schema:
|
||||
$ref: '#/components/schemas/BuyMuseumTicketsRequest'
|
||||
allOf:
|
||||
- $ref: '#/components/schemas/BuyMuseumTicketsRequest'
|
||||
- type: object
|
||||
properties:
|
||||
test:
|
||||
type: string
|
||||
enum:
|
||||
- general
|
||||
- gold
|
||||
- platinum
|
||||
- vip
|
||||
examples:
|
||||
general_entry:
|
||||
$ref: '#/components/examples/BuyGeneralTicketsRequestExample'
|
||||
|
||||
@@ -118,6 +118,16 @@ export function Schema({
|
||||
return child;
|
||||
}
|
||||
|
||||
if (schema.allOf && parseObject) {
|
||||
return (
|
||||
<Schema
|
||||
name={name}
|
||||
schema={combineSchema(noRef(schema.allOf))}
|
||||
ctx={ctx}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
if (schema.description)
|
||||
child.push(<Markdown key="description" text={schema.description} />);
|
||||
|
||||
@@ -156,7 +166,7 @@ export function Schema({
|
||||
</p>,
|
||||
);
|
||||
|
||||
if (isObject(schema) && !parseObject) {
|
||||
if ((isObject(schema) || schema.allOf) && !parseObject) {
|
||||
child.push(
|
||||
<renderer.ObjectCollapsible key="attributes" name="Attributes">
|
||||
<Schema
|
||||
@@ -170,20 +180,6 @@ export function Schema({
|
||||
/>
|
||||
</renderer.ObjectCollapsible>,
|
||||
);
|
||||
} else if (schema.allOf) {
|
||||
child.push(
|
||||
<renderer.ObjectCollapsible key="attributes" name={name}>
|
||||
<Schema
|
||||
name={name}
|
||||
schema={combineSchema(noRef(schema.allOf))}
|
||||
ctx={{
|
||||
...ctx,
|
||||
parseObject: true,
|
||||
required: false,
|
||||
}}
|
||||
/>
|
||||
</renderer.ObjectCollapsible>,
|
||||
);
|
||||
} else {
|
||||
const mentionedObjectTypes = [
|
||||
...(schema.anyOf ?? schema.oneOf ?? []),
|
||||
@@ -237,24 +233,23 @@ function combineSchema(schema: OpenAPI.SchemaObject[]): OpenAPI.SchemaObject {
|
||||
};
|
||||
|
||||
function add(s: OpenAPI.SchemaObject): void {
|
||||
result.properties ??= {};
|
||||
|
||||
if (s.properties) {
|
||||
result.properties ??= {};
|
||||
Object.assign(result.properties, s.properties);
|
||||
}
|
||||
|
||||
result.additionalProperties ??= {};
|
||||
if (s.additionalProperties === true) {
|
||||
result.additionalProperties = true;
|
||||
} else if (
|
||||
s.additionalProperties &&
|
||||
typeof result.additionalProperties !== 'boolean'
|
||||
) {
|
||||
result.additionalProperties ??= {};
|
||||
Object.assign(result.additionalProperties, s.additionalProperties);
|
||||
}
|
||||
|
||||
if (s.allOf) {
|
||||
add(combineSchema(noRef(s.allOf)));
|
||||
noRef(s.allOf).forEach(add);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user