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 Schema Extraction for Arrays #485

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

smridge
Copy link

@smridge smridge commented Nov 12, 2020

In attempting to use response_field to generate schema properties, errors occurred when using arrays.

Error Message:

../rspec_api_documentation-6.1.0/lib/rspec_api_documentation/writers/open_api_writer.rb:147:in `block in extract_schema': undefined method `[]' for nil:NilClass (NoMethodError)

After binding.pry my way through, this solved and the 201 schema properties generated as expected. Not sure if this is something I misconfigured? However, I would think it should pass in the array (field[:value]) and not the first array element. Additional reference for method being called: https://github.com/smridge/rspec_api_documentation/blob/d3892cc7388460a98476734963face5a7a2ac158/lib/rspec_api_documentation/open_api/helper.rb#L18-L19 .

Definitely open to thoughts.

Example Setup:

# frozen_string_literal: true

require 'rails_helper'
require 'rspec_api_documentation/dsl'

describe '/v2/bazz/foos', type: :request do
  resource 'Foos' do
    header 'Content-Type', 'application/json'
    explanation 'Requests for Foos'

    # create
    post '/v2/:slug/foos' do
      with_options scope: :foo, with_example: true do
        parameter :title, required: true
        parameter :description
        parameter :bars
      end

      with_options scope: :resource do
        response_field :token, 'foo token', type: :string
        response_field :title, 'foo title', type: :string
        response_field :description, 'foo description', type: :string
        response_field :bars, 'list of foo bars', type: :array
      end

      let(:slug) { 'foobar' }

      let(:title) { 'Foo Title' }
      let(:description) { 'Some Description' }
      let(:bars) { %w[anything something] }

      context 'when valid' do
        example_request 'creates foo' do
          expect(response_status).to eq(201)
        end
      end
    end
  end
end

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

Successfully merging this pull request may close these issues.

None yet

1 participant