rswag/rswag

[BUG] multiple responses with the same http code

zhisme opened this issue · 0 comments

Describe the bug

Examine the following code, I have 2 examples for 200 http response, I want both them to be included in result swagger.yaml and then to be seen in web interface provided by the gem

response 200, 'when success' do
  let(:company_id) { company.id }

  schema type: :object, properties: {
    body: {
      type: :object,
      properties: {
        items: {
          type: :array,
          items: { '$ref': '#/components/schemas/company' },
        },
      },
    },
  }

  run_test! do
    expect(json_response).to include 'body'
    expect(json_response['body']['items'].length).to eq 3
  end
end

response 200, 'when filtered by name' do
  let(:company_id) { company.id }
  let(:filter) { { name: 'test' } }

  schema type: :object, properties: {
    body: {
      type: :object,
      properties: {
        filter: { type: :object, properties: {
          name: { type: :string, nullable: false }
        } },
        items: {
          type: :array,
          items: { '$ref': '#/components/schemas/company' },
        },
      },
    },
  }

  run_test! do
    expect(json_response).to include 'body'
    expect(json_response['body']['items'].length).to eq 1
  end
end

However the second response gets evaluated only and overwrites the first one as they both return same http code.

Steps to Test or Reproduce

  • Create 2 responses with the same response http code

Expected behavior

2 responses are evaluated and seen in the result swagger.yaml file

Additional context

Is 1 example per response is by design or it is unexpected behavior? What is the right approach for such cases? Make 1 big example with all possible params? The example above from real controller index action where you can both filter collection and receive full collection with no filters.

Dependency versions

The version of are you using for:

  • Rswag: 2.8.0
  • RSpec: 3.12
  • Rails: 6.1.7.6
  • Ruby: 3.1.4

Relates to which version of OAS (OpenAPI Specification)

  • OAS2
  • OAS3
  • OAS3.1