Fix #44: description not rendered for non-array entity references#90
Merged
Fix #44: description not rendered for non-array entity references#90
Conversation
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".
Danger ReportNo issues found. |
There was a problem hiding this comment.
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
$refinallOfwhendesc(description) orread_onlyis 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.
mscrivo
approved these changes
Jan 28, 2026
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #44
In OpenAPI/Swagger 2.0 and 3.0.x,
$refcannot have sibling properties - they are ignored by tools like Swagger-UI. This caused:desc(description) on non-array entity references to not be displayedreadOnlyflags to be ignoredThe fix wraps
$refinallOfwhendescriptionorreadOnlyis 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
typeanditems, not$ref.