Skip to content
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

Fix error for hash object warnings with delegated method descriptions #938

Commits on Jul 9, 2024

  1. Use method_name instead of method when generating hash warnings

    In Apipie#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.
    h-lame committed Jul 9, 2024
    Configuration menu
    Copy the full SHA
    e1fd88a View commit details
    Browse the repository at this point in the history

Commits on Jul 12, 2024

  1. 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.
    h-lame committed Jul 12, 2024
    Configuration menu
    Copy the full SHA
    accd783 View commit details
    Browse the repository at this point in the history
  2. 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.
    h-lame committed Jul 12, 2024
    Configuration menu
    Copy the full SHA
    ba599dc View commit details
    Browse the repository at this point in the history
  3. 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.
    h-lame committed Jul 12, 2024
    Configuration menu
    Copy the full SHA
    6d84540 View commit details
    Browse the repository at this point in the history