-
Notifications
You must be signed in to change notification settings - Fork 41
Fix #44: description not rendered for non-array entity references #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
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
$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.
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
* 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
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.