Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix error for hash object warnings with delegated method descriptions (…
…#938) * Use `method_name` instead of `method` when generating hash warnings In #865 we introduced a `method_name` method on `MethodDescription` to avoid this bug, but the commit didn't actually use that method. Sometimes the `@controller_method` object used is a `Apipie::Generator::Swagger::MethodDescription::Decorator` which is a `SimpleDelegate` onto a `Apipie::MethodDescription` and we'd expect to be able to call `method` on it, but unfortunately `method` is one of the things _not_ delegated by `SimpleDelegate` because it's a standard ruby method and so you get ArgumentError: wrong number of arguments (given 0, expected 1) when you try to call it. Using `method_name` instead avoids that so that's what we do - and now we can happily generate the swagger warnings when we have hash type objects without defined params. * Use `method_name` instead of `method` when generating required warnings Unlike the previous commit, this isn't strictly required as we're not calling the un-delegated `method`, but instead the warning will contain a standard `to_s` of the `@controller_method` that isn't very easy to read, like this: WARNING (105): [#<Apipie::MethodDescription:0x0000000126316f60>] -- The parameter :param is optional but default value is not specified (use :default_value => ...) By using `method_name` instead we get symmetry with the hash warning from the previous commit. * Fix rubocop-rspec by removing a redundant `let` Only allowed 15 `let` or `subject`s for a given spec, and we now have 16. Removing the `with_null` memoization lets us proceed. In theory it would have allowed us to run the specs with_null set to both true and false, but in practice, we weren't, and the other memoized values _were_ useful for customising the specs. * Handle warnings for param descriptions without a controller method If we're generating swagger via `SwaggerGenerator.json_schema_for_self_describing_class` we explicitly don't have a `controller_method` being passed around so we can't use it for the warnings. Introduce a test for type and builder to cover this scenario (first spotted by a failing spec for `SwaggerGenerator`) and then change the implementation to cope with it. Luckily, `Apipie::Generator::Swagger::MethodDescription::Decorator` already had a `ruby_name` implementation that handles being given `nil`, so we use that.
- Loading branch information