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

[BUG] multiple responses with the same http code #728

Open
1 of 4 tasks
zhisme opened this issue Jan 30, 2024 · 0 comments
Open
1 of 4 tasks

[BUG] multiple responses with the same http code #728

zhisme opened this issue Jan 30, 2024 · 0 comments

Comments

@zhisme
Copy link

zhisme commented Jan 30, 2024

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
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

1 participant