Fix Grape 3.2 compatibility: keyword args for desc and custom param types#978
Open
numbata wants to merge 4 commits into
Open
Fix Grape 3.2 compatibility: keyword args for desc and custom param types#978numbata wants to merge 4 commits into
numbata wants to merge 4 commits into
Conversation
Grape 3.2.1 deprecates passing a positional options Hash to `desc` and requires unknown types in params blocks to either be a registered dry-type or implement `parse` (custom type protocol). This change addresses both. - Pass keyword arguments to `desc` in doc_methods.rb so Grape's deprecator does not fire (or raise when behavior = :raise) - Add `self.parse` to the mock `Entities::NestedModule::ApiResponse` so Grape treats it as a custom type instead of attempting a dry-types lookup - Move `type: 'Object'` into the `documentation` hash in params_example_spec so Grape no longer sees an unknown string type; grape-swagger still reads it from the merged settings and emits the expected swagger output
Moving SwaggerRouting and SwaggerDocumentationAdder inside the GrapeSwagger namespace would be a breaking change for dependent gems that reference these constants by their top-level names. Exclude the affected files in .rubocop_todo.yml to keep CI green until that rename ships separately.
Add comments explaining: - 'Object' is a swagger documentation hint, not a valid Grape coercion type; the type lives in documentation: so grape-swagger picks it up via settings merge - ApiResponse.parse is required because Grape 3.2+ validates unknown types via Types.custom? (arity-1 parse check); minimal pass-through is sufficient since tests exercise documentation generation, not request coercion
Representable::Decorator does not implement .parse, so Grape 3.2+ raises ArgumentError when ApiResponse is used as a param type. Same fix as mock_parser.
Danger ReportNo issues found. |
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
Grape 3.2 introduces two breaking changes that cause
add_swagger_documentationto raise whenGrape.deprecator.behavior = :raise(the default in Grape's own CI). First,descemits a deprecation when called with a positional options Hash; grape-swagger called it that way in two places indoc_methods.rb. Second,optional/requiresnow routes:typethrough Grape's dry-types coercion infrastructure, which rejects plain string type names (e.g.'Object') and unknown classes that don't implement.parse. This PR fixes both issues and documents the'Object'type pattern for future maintainers.Changes
lib/grape-swagger/doc_methods.rbdesccalls so Grape's deprecator does not fire (or raise whenbehavior = :raise).spec/support/model_parsers/mock_parser.rbandrepresentable_parser.rbdef self.parse(val) = valtoNestedModule::ApiResponsein both parsers. Grape 3.2+ requires unknown types used inparamsblocks to satisfyTypes.custom?(i.e. respond to.parsewith arity 1), otherwise it attempts a dry-types lookup that raisesArgumentError.Grape::Entityalready implements.parse, soentity_parser.rbneeds no change. The implementation is intentionally minimal — these specs test swagger documentation generation only, not request coercion.spec/swagger_v2/params_example_spec.rbtype: 'Object'from the Grape params declaration intodocumentation: { type: 'Object' }.'Object'is not a valid Grape coercion type; it is a swagger documentation hint. Grape 3.2+ rejects string type names in params blocks. grape-swagger picks up the type from the merged settings hash inParseParams#call, so the swagger output is unchanged. A comment in the spec explains the pattern..rubocop_todo.ymlStyle/OneClassPerFileforlib/grape-swagger.rband two spec files where multiple top-level modules are a pre-existing condition. MovingSwaggerRoutingandSwaggerDocumentationAdderinside theGrapeSwaggernamespace would be a breaking change for dependent gems referencing those constants; that rename will ship separately.Validation — all three MODEL_PARSER values
Tested against Grape 3.2.1 (the version in this worktree's
Gemfile.lock).Closes #977