Comments (11)
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.
Hi. I was able to reproduce this and will probably release a fix this weekend.
from openapi_first.
@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.
This should be fixed and now just work in 1.3.6, which has just been released. Thanks for the report.
from openapi_first.
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.
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.
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.
@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.
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.
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.
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)
- Response header validation
- The purpose of hanami in this gem? HOT 10
- Manual request/response validation HOT 6
- v1.0.0.beta5 release not available via rubygems.org HOT 7
- Manual response validation breaking change in 1.0.0->1.1.0 upgrade HOT 2
- Spec has a binary field - openapi-first failing with exception trying to get the :tempfile HOT 13
- Don't read uploaded files to validate "binary" fields
- validation of string format uri wrongly fails with relative pathes HOT 5
- Parse error for kebab-case URL parameters HOT 4
- Can't seem to get rid of a response validation error with format: byte, nullable true HOT 4
- Builtin middlewares trigger deprecation warnings. HOT 4
- Getting the full response with the ResponseInvalidError HOT 4
- Validate OpenAPI file
- Assertion methods HOT 1
- NoMethodError: undefined method `find_plugin' for module OpenapiFirst HOT 5
- Error: "can't modify frozen Hash" HOT 5
- Expose webhooks HOT 5
- Binary response gets converted to an array and throws a response validation error HOT 2
- Cannot validate responses that use `oneOf` unions with `discriminator`. HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from openapi_first.