Giter Site home page Giter Site logo

Comments (11)

samanthawritescode avatar samanthawritescode commented on August 10, 2024 2

Alright, fresh eyes after the weekend did me good, I think I figured out the issue.

The problem is actually on this line in Middlewares::ResponseValidation.call:

body = body.to_ary if body.respond_to?(:to_ary)

The problem is that body.respond_to?(:to_ary) returns true, but it shouldn't, because the response is not an array (it's a JSON object). So when we call body.to_ary, body ends up nil.

So why are we incorrectly calling to_ary and why does it end up nil?

I'm using Rails 6.1.7.7, and the respond_to? and to_ary methods are defined as such in ActionDispatch:

      def respond_to?(method, include_private = false)
        if method.to_sym == :to_path
          @response.stream.respond_to?(method)
        else
          super
        end
      end

      def to_ary
        nil
      end

This has since changed in rails 7, and I assume that's what the intended behavior was.

As for what the actual fix is, I'm not sure, this is a quite a bit more in the weeds of Rails/Rack than I typically get. I hope that's helpful, though.

from openapi_first.

ahx avatar ahx commented on August 10, 2024 2

Hi. I was able to reproduce this and will probably release a fix this weekend.

from openapi_first.

samanthawritescode avatar samanthawritescode commented on August 10, 2024 1

@MrBananaLord I ran the same request without the response validation middleware after installing the gem, upgrading any dependencies, etc... just commenting out the config.middleware.use OpenapiFirst::Middlewares::ResponseValidation line. It succeeds successfully.

I'll see if I can get a reproducible example.

from openapi_first.

ahx avatar ahx commented on August 10, 2024 1

This should be fixed and now just work in 1.3.6, which has just been released. Thanks for the report.

from openapi_first.

samanthawritescode avatar samanthawritescode commented on August 10, 2024

Actually, body is still nil in this case, I think that's why now it says it can't parse. I'm honestly kind of at a loss here, any help would be appreciated. My OAS is here, but I changed the URL parameters to continue testing according to this issue.

from openapi_first.

ahx avatar ahx commented on August 10, 2024

Thanks for the report @samanthawritescode. I am not fully understanding what's going on here. Can you reproduce this in a test, Maybe a rack-test test or Rails' request test and can share a part of that maybe?

from openapi_first.

MrBananaLord avatar MrBananaLord commented on August 10, 2024

I am wondering... what happens when you run the same request without the validation middleware? could it be that you are getting a 302? 🤔

from openapi_first.

ahx avatar ahx commented on August 10, 2024

@samanthawritescode Thanks for the update. This is helpful. I still have a hard time understanding the Rack spec about these parts. That's probably why this slipped through.
If I understand you correctly this happens only in tests, right? This looks similar to something I tested/implemented here. Maybe we can come up with a (failing) test that looks similar.

from openapi_first.

ahx avatar ahx commented on August 10, 2024

What I don't get about the spec is what middlewares should check first: call, to_ary or each. I will have to find some time to look into that. I hope that this issue does not block you. If it does, let's look for a quick solution instead.

from openapi_first.

ahx avatar ahx commented on August 10, 2024

I did not find the time to reproduce this. Can you maybe share a tiny example app via a gist or the like?

from openapi_first.

samanthawritescode avatar samanthawritescode commented on August 10, 2024

Great, thanks! Sorry, I had to pivot to work on something else, so I haven't had further time to poke at this.

from openapi_first.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.