Skip to content

fix(rapidoc): keep fields when allOf wraps a single composed schema - #1172

Merged
mrin9 merged 1 commit into
rapi-doc:masterfrom
thelastbackspace:fix/1170-allof-single-composed-ref
Nov 8, 2026
Merged

mrin9 merged 1 commit into
rapi-doc:masterfrom
thelastbackspace:fix/1170-allof-single-composed-ref

Conversation

@thelastbackspace

Copy link
Copy Markdown
Contributor

Fixes #1170

Base branch: master

A one-member allOf was handled as a "primitive" shortcut whenever the member had no properties or items. That's also true when the member is itself an allOf / oneOf / anyOf, which is the common allOf: [$ref] + description pattern pointing at a composed schema. In schemaToAST the shortcut spreads the outer schema over the member, so the member's own allOf gets replaced and then deleted, and the field renders as {missing-type-info}. In schemaToSampleObj the same check returns nothing, so the field is missing from the generated example. handleAllOfSchema (object notation) had the same condition.

The three checks now go through one small helper that also requires the member to have no allOf / oneOf / anyOf, so composed members fall through to the normal merge path, which already handles them.

Tests: added two cases to tests/unit/schema-ast.test.js using the schema from the issue. Both fail on master (kind is primitive, example fields are undefined) and pass with the change. npm run test:unit (474 pass), npm run lint and npm run format are clean. test:portal has the same 13 failures with and without the change here, and test:component needs Chrome, which I don't have locally.

A one-member allOf was treated as a primitive whenever the member had no
properties or items. When that member is itself an allOf/oneOf/anyOf
(e.g. a $ref to a composed schema next to a description), the schema
table showed {missing-type-info} and the example dropped the field.

Fixes rapi-doc#1170
@mrin9

mrin9 commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the clear write-up and the tests. The diagnosis matches #1170, and moving the three checks into one helper is a nice cleanup.

There's one change I'd like before merging. isSingleNonComposedAllOf also excludes members that have oneOf/anyOf. For schemaToSampleObj and handleAllOfSchema that's an improvement, because those fields were dropped from the example before. In composeSchemaAST, though, it changes how the schema table renders this case:

value:
  description: Amount or label
  allOf:
    - oneOf:
        - type: string
        - type: integer

Before, the shortcut merged the member into the outer schema, so the field rendered as a union row with the outer description. With this PR it goes through the merge path: the union ends up in unions of a node with kind: "object", so the row is labelled object even though the options are primitives.

Could you limit the composeSchemaAST check to the allOf case, for example by passing a flag to the helper or by checking !schema.allOf[0].allOf there? The full check can stay for the other two call sites. A test for the single-oneOf case in schema-ast.test.js would cover it.

Two smaller notes:

  • Please add a changeset (npm run changeset): a patch for rapidoc and for @rapidoc/prerender, which bundles schema-utils.js. If you'd rather not, I can add it when I merge.
  • The failing "Check Language" check isn't caused by this PR. It flags existing files, and I'll fix it separately.

@mrin9
mrin9 merged commit 3066dda into rapi-doc:master Nov 8, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

allOf with a single $ref to a composed schema renders {missing-type-info}` and an empty example

2 participants