diff --git a/packages/docusaurus-theme-openapi-docs/src/theme/Schema/index.tsx b/packages/docusaurus-theme-openapi-docs/src/theme/Schema/index.tsx index 106aabcd1..4d850932a 100644 --- a/packages/docusaurus-theme-openapi-docs/src/theme/Schema/index.tsx +++ b/packages/docusaurus-theme-openapi-docs/src/theme/Schema/index.tsx @@ -129,17 +129,32 @@ interface SchemaProps { const AnyOneOf: React.FC = ({ schema, schemaType }) => { const key = schema.oneOf ? "oneOf" : "anyOf"; - const type = schema.oneOf + const groupLabel = schema.oneOf ? translate({ id: OPENAPI_SCHEMA_ITEM.ONE_OF, message: "oneOf" }) : translate({ id: OPENAPI_SCHEMA_ITEM.ANY_OF, message: "anyOf" }); + return ( <> - {type} + {groupLabel} {schema[key]?.map((anyOneSchema: any, index: number) => { - const label = anyOneSchema.title || anyOneSchema.type; + // Prefer explicit title, then inferred name, then raw type, finally fallback MOD{n} + const computedSchemaName = getSchemaName(anyOneSchema); + const label = + anyOneSchema.title || + computedSchemaName || + anyOneSchema.type || + `MOD${index + 1}`; + const isPrimitiveArm = + isPrimitive(anyOneSchema) || anyOneSchema.const; + const emptyObjectPrimitive = + anyOneSchema.type === "object" && + !anyOneSchema.properties && + !anyOneSchema.allOf && + !anyOneSchema.oneOf && + !anyOneSchema.anyOf; return ( // @ts-ignore = ({ schema, schemaType }) => { label={label} value={`${index}-item-properties`} > - {/* Handle primitive types directly */} - {(isPrimitive(anyOneSchema) || anyOneSchema.const) && ( + {isPrimitiveArm && ( + )} + {emptyObjectPrimitive && ( + )} - - {/* Handle empty object as a primitive type */} - {anyOneSchema.type === "object" && - !anyOneSchema.properties && - !anyOneSchema.allOf && - !anyOneSchema.oneOf && - !anyOneSchema.anyOf && ( - - )} - - {/* Handle actual object types with properties or nested schemas */} {anyOneSchema.type === "object" && anyOneSchema.properties && ( )}