Skip to content

A description from "oneOf: $ref: schemas" is not rendered #1540

Description

@Compaurum

Describe the bug

When a request/response schema uses oneOf (with or without a discriminator), the description of each individual branch/variant schema is silently dropped by the Schema theme component (@theme/Schema). Only the branch's properties table is rendered — the branch's own description never appears, even though it is present in the OpenAPI document and correctly preserved all the way through to the generated schema JSON used by RequestSchema/ResponseSchema.

Expected behavior

For a schema like:

Cat:
  type: object
  description: A domesticated feline that likes to nap and knock things off tables.
  properties:
    petType:
      type: string
      enum: [cat]
    huntingSkill:
      type: string

referenced from a oneOf (directly, or via a discriminator.mapping), the rendered page should show the "A domesticated feline that likes to nap and knock things off tables." text for that branch/tab, in addition to its property list.

Current behavior

The branch's description is not rendered anywhere. Only the property list shows up under each oneOf/discriminator tab — the description text is missing entirely, with no error or warning.

Possible solution

Root cause is in docusaurus-theme-openapi-docs's theme/Schema/index.tsx:

  • In AnyOneOf (used for oneOf/anyOf without a discriminator), the branch with properties is rendered via <Properties schema={anyOneSchema} .../> directly — anyOneSchema.description is never read or rendered anywhere in that code path.
  • In PropertyDiscriminator (used for oneOf + discriminator), each discriminator.mapping[key] is rendered via <SchemaNode schema={discriminator.mapping[key]} .../> inside its TabItem — again, discriminator.mapping[key].description is never read.

Both are missing the same pattern already used elsewhere in the same file (e.g. SchemaNodeDetails, and PropertyDiscriminator's own top-level schema.description): wrap the branch's description in the existing MarkdownWrapper helper before rendering its properties/children.

Minimal fix (both in docusaurus-theme-openapi-docs/src/theme/Schema/index.tsx):

// AnyOneOf — inside the "object with properties" branch:
{(anyOneSchema.type === "object" || !anyOneSchema.type) &&
  anyOneSchema.properties && (
    <>
      {anyOneSchema.description && (
        <div style={{ marginLeft: "1rem" }}>
          <MarkdownWrapper text={anyOneSchema.description} />
        </div>
      )}
      <Properties schema={anyOneSchema} schemaType={schemaType} schemaPath={childSchemaPath} />
    </>
  )}
// PropertyDiscriminator — inside the DiscriminatorTabs TabItem loop:
<TabItem key={index} label={key} value={`${index}-item-discriminator`}>
  {discriminator.mapping[key].description && (
    <div style={{ marginLeft: "1rem" }}>
      <MarkdownWrapper text={discriminator.mapping[key].description} />
    </div>
  )}
  <SchemaNode schema={discriminator.mapping[key]} schemaType={schemaType} />
</TabItem>

Steps to reproduce

  1. Define an OpenAPI schema with a oneOf (with a discriminator) whose branches each have their own description, e.g.:
    Pet:
      oneOf:
        - $ref: "#/components/schemas/Cat"
        - $ref: "#/components/schemas/Dog"
      discriminator:
        propertyName: petType
        mapping:
          cat: "#/components/schemas/Cat"
          dog: "#/components/schemas/Dog"
    Cat:
      type: object
      description: A domesticated feline that likes to nap and knock things off tables.
      properties:
        petType:
          type: string
          enum: [cat]
        huntingSkill:
          type: string
    Dog:
      type: object
      description: A domesticated canine known for loyalty and fetching things.
      properties:
        petType:
          type: string
          enum: [dog]
        breed:
          type: string
  2. Run docusaurus gen-api-docs to generate the API docs for the endpoint using this schema.
  3. Open the generated page in the browser and expand the request body schema.
  4. Select the "cat" tab under the discriminator selector.
  5. Observe that only the property list is shown — the schema's own description ("A domesticated feline that likes to nap and knock things off tables.") never renders.

Screenshots

Image

Context

We generate API reference docs from an OpenAPI spec with several polymorphic (oneOf + discriminator) request/response schemas. Each variant has its own human-written description explaining what that variant represents, which is important context for API consumers choosing between variants. Because the description was silently dropped, readers only saw a bare property list per variant with no explanation of what the variant represents — this went unnoticed for a while since there's no error, just missing content.

Your Environment

  • Version used: docusaurus-theme-openapi-docs and docusaurus-plugin-openapi-docs ^5.1.0
  • Environment name and version: Node.js v22.16.0, @docusaurus/core ^3.10.0, React ^19.2.7
  • Operating System and version (desktop or mobile): macOS 15, desktop (Chrome)
  • Link to your project: internal/private repository (not publicly linkable)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions