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

no implicit conversion of String into Integer #462

Open
lewispb opened this issue Feb 6, 2020 · 3 comments
Open

no implicit conversion of String into Integer #462

lewispb opened this issue Feb 6, 2020 · 3 comments

Comments

@lewispb
Copy link

lewispb commented Feb 6, 2020

Just updated from 5.1.0 to 6.1.0.

This is the spec:

patch "/api/v1/keyword-alerts" do
    parameter :data, required: true
    parameter :attributes, scope: [:data], required: true

    example "Update email attribute" do
      do_request data: [{
        id: 1,
        attributes: {
          email: false,
          keywords: []
        }
      }]

      expect(status).to eq(200)
      expect(JSON.parse(response_body)["data"][0]["attributes"]["email"]).to eq(false)
    end
end

It now fails with

Failure/Error:
       do_request data: [{
         id: 1,
         attributes: {
           email: false,
           keywords: []
         }
       }]

     TypeError:
       no implicit conversion of String into Integer

It passes when we remove these lines:

    parameter :data, required: true
    parameter :attributes, scope: [:data], required: true

The problematic code is in:

RspecApiDocumentation::DSL::Endpoint::Params#extended
@jsmartt
Copy link

jsmartt commented Apr 1, 2020

I'm seeing the same issue on 6.1.0, trying to document an array of objects.

parameter :data, '(array of objects) Description'
with_options scope: :data do
  parameter :key, '(string) Description'
end

example 'Example 1' do
  do_request(data: [{ key: 'val' }])
end

Error produced:

TypeError: no implicit conversion of String into Integer
# From: /usr/local/rvm/gems/ruby-2.4.5/gems/rspec_api_documentation-6.1.0/lib/rspec_api_documentation/dsl/endpoint/params.rb:33

Related to #398

@ngoral
Copy link

ngoral commented Feb 16, 2022

Same problem here.
All I found during debugging was the following:

  1. It fails because somewhere on the way scope becomes an array of two elements, with the second element equals ''. (E.g. if we defined parameter :key, scope: %i[level_one], we will end up with the scope equal [:level_one, '']. That's what failing everything. I spent some time, but couldn't find where it happens.
  2. If we do not use example and do_request, but use request_example instead, it works just fine.

@ngoral
Copy link

ngoral commented Feb 16, 2022

Ah, I found the impostor =)
You can see my comment in #413 and maybe say something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants