Skip to content

Conversation

@numbata
Copy link
Collaborator

@numbata numbata commented Jan 28, 2026

Summary

Fixes #44

In OpenAPI/Swagger 2.0 and 3.0.x, $ref cannot have sibling properties - they are ignored by tools like Swagger-UI. This caused:

  • desc (description) on non-array entity references to not be displayed
  • readOnly flags to be ignored

The fix wraps $ref in allOf when description or readOnly is present:

Before (invalid - siblings ignored):

{ "$ref": "#/definitions/Address", "description": "Client address" }

After (valid OpenAPI):

{ "allOf": [{ "$ref": "#/definitions/Address" }], "description": "Client address" }

Array entity references were not affected because the description is a sibling to type and items, not $ref.

In OpenAPI/Swagger 2.0 and 3.0.x, $ref cannot have sibling properties -
they are ignored by tools like Swagger-UI. This caused descriptions and
readOnly flags on non-array entity references to not be displayed.

The fix wraps $ref in allOf when description or readOnly is present:
- Before: { "$ref": "...", "description": "..." } (description ignored)
- After: { "allOf": [{"$ref": "..."}], "description": "..." } (works)

Array entity references were not affected because the description is a
sibling to "type" and "items", not "$ref".
@numbata numbata linked an issue Jan 28, 2026 that may be closed by this pull request
@github-actions
Copy link

github-actions bot commented Jan 28, 2026

Danger Report

No issues found.

View run

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes Swagger/OpenAPI rendering for entity properties that reference another schema via $ref by ensuring description and readOnly are not ignored by tooling.

Changes:

  • Wraps $ref in allOf when desc (description) or read_only is provided for non-array entity references.
  • Adds a dedicated regression spec for issue #44 and updates existing specs to match the new schema shape.
  • Updates RuboCop auto-gen config to account for the new spec and updated file metrics.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
lib/grape-swagger/entity/parser.rb Wraps $ref in allOf when adding description/readOnly to keep OpenAPI-compatible output.
spec/issues/44_desc_in_entity_type_spec.rb New regression spec covering non-array $ref + desc and $ref + readOnly, plus array control case.
spec/grape-swagger/entity/parser_spec.rb Updates expectations to assert allOf wrapping for referenced entities with descriptions.
spec/grape-swagger/entities/response_model_spec.rb Updates expected generated swagger definitions to reflect allOf wrapping for $ref siblings.
.rubocop_todo.yml Adds exclusion for new spec and updates thresholds per regenerated RuboCop todo.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@numbata numbata merged commit f5a0771 into master Jan 28, 2026
21 checks passed
@numbata numbata self-assigned this Jan 28, 2026
@numbata numbata deleted the 44-does-not-support-desc-in-entity-type branch January 28, 2026 19:08
numbata added a commit to ruby-grape/grape-swagger that referenced this pull request Jan 28, 2026
grape-swagger-entity 0.7.1 now wraps $ref in allOf when description
is present, which is the correct OpenAPI format.

See: ruby-grape/grape-swagger-entity#90
dblock pushed a commit to ruby-grape/grape-swagger that referenced this pull request Jan 29, 2026
* Fix Grape 3.1.0 compatibility: replace route.attributes with direct access

Grape 3.1.0 removed the `attributes` alias from BaseRoute.
Use direct method calls (route.success, route.produces) which work
in all versions via delegate_missing_to.

Fixes #971

* Update RouteHelper for Grape 3.1.0 Route/Pattern constructor changes

Grape 3.1.0 changed the Route constructor signature from
(method, origin, path, options) to (endpoint, method, pattern, options)
and Pattern now uses keyword arguments.

* Update test expectation for hidden attributes in required list

Align with grape-swagger-entity#87 which correctly excludes hidden
attributes from the required fields list in Swagger documentation.

* Add scheduled workflow for Grape HEAD compatibility testing

Runs weekly (Sundays at midnight UTC) to detect compatibility
issues with upcoming Grape releases early.

* Update test for grape-swagger-entity 0.7.1 allOf wrapper

grape-swagger-entity 0.7.1 now wraps $ref in allOf when description
is present, which is the correct OpenAPI format.

See: ruby-grape/grape-swagger-entity#90

* Update CHANGELOG for PR #972

* Use fetch with defaults in RouteHelper to handle falsey values

* Clean up: remove redundant comments, fix CHANGELOG placeholder
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.

Does not support desc in entity type?

2 participants