Skip to content

Fix schema generation for $ref with sibling description (OpenAPI 3.1) - #381

Merged
jemacineiras merged 1 commit into
sngular:mainfrom
joseegman-idoneea:fix/ref-with-description-main
Jul 23, 2026
Merged

Fix schema generation for $ref with sibling description (OpenAPI 3.1)#381
jemacineiras merged 1 commit into
sngular:mainfrom
joseegman-idoneea:fix/ref-with-description-main

Conversation

@joseegman-idoneea

Copy link
Copy Markdown
Contributor

Problem

In OpenAPI 3.1 / JSON Schema 2020-12 a $ref may carry sibling keywords such as description, and their ordering is not significant. When a property combines $ref + description, schema generation breaks and produces a field with an empty type (or fails).

Root cause

ApiTool.hasRef only treated a node as a reference when $ref was the first field:

return (hasNode(schema, "$ref") || schema.fieldNames().hasNext()) && schema.fieldNames().next().equals("$ref");

If description appears before $ref (the usual ordering), hasRef returns false, the node falls through to the isBasicType branch and a field with an empty type is generated.

Changes

  • hasRef now detects a top-level $ref regardless of field ordering.
  • New regression test testRefWithDescription covering both orderings (description before and after $ref), with its assets.
  • Version bump 6.4.16.4.2 (engine, maven-plugin, gradle-plugin).

Verification

multiapi-engine OpenAPI generator suite: 51/51 passing on top of main (mvn test -Dtest=OpenApiGeneratorTest#processFileSpec).

Example that reproduces the bug

Order:
  type: object
  properties:
    customer:
      description: The customer that placed the order
      $ref: "#/components/schemas/Customer"

🤖 Generated with Claude Code

OpenAPI 3.1 / JSON Schema 2020-12 allow sibling keywords (e.g. `description`)
next to `$ref`, and their ordering is not significant. `ApiTool.hasRef` only
treated a node as a reference when `$ref` was the *first* field, so a property
declaring `description` before `$ref` was not recognised as a reference: it fell
through to the basic-type branch and generated a field with an empty type,
breaking generation.

`hasRef` now detects a top-level `$ref` regardless of field ordering. Adds a
regression test (`testRefWithDescription`) covering both orderings.

Bumps version 6.4.1 -> 6.4.2.

Closes #1

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@jemacineiras jemacineiras added the enhancement New feature or request label Jul 23, 2026
@jemacineiras
jemacineiras merged commit 7164d96 into sngular:main Jul 23, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants