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 of response example when Content-Disposition header is inline #24

Merged
merged 2 commits into from
Apr 24, 2021

Conversation

kyoshidajp
Copy link
Contributor

The Issue

My action returns binary (Image) data using send_data with disposition: "inline" like this.

class ImagesController < ActionController::Base
  protect_from_forgery

  def show
    path = "/file/to/image.png"
    image = File.open(path, "r")
    send_data image.read, type: "image/png", disposition: "inline"
  end
end

Generation was failed.

require "rails_helper"

RSpec.describe "Images", type: :request do
  describe "show" do
    it "return 200" do
      get "/image/:id" do
        expect(response.status).to eq 200
      end
    end
  end
end
% export OEPNAPI=1
% bundle exec rspec
...
An error occurred in an `after(:suite)` hook.
Failure/Error: elsif o =~ /\n(?!\Z)/  # match \n except blank line at the end of string

ArgumentError:
  invalid byte sequence in UTF-8
# /file/to/rspec-openapi/lib/rspec/openapi/schema_file.rb:29:in `write'
# /file/to/rspec-openapi/lib/rspec/openapi/schema_file.rb:15:in `edit'
# /file/to/rspec-openapi/lib/rspec/openapi/hooks.rb:19:in `block in <main>'

Solution

If Content-Disposition response header is presented, then example will not be shown.

Other information

This PR's spec will fail before merging #23 or other fixing PRs to be modified.

@k0kubun
Copy link
Collaborator

k0kubun commented Apr 24, 2021

Is it possible to add a spec for this?

@kyoshidajp
Copy link
Contributor Author

I forgot to add spec. I added it.

Copy link
Collaborator

@k0kubun k0kubun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@k0kubun k0kubun merged commit 38c89f6 into exoego:master Apr 24, 2021
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.

2 participants