Comments (9)
I can explain why the Host and Cookie headers are included, but I am now sure how this issue should be resolved.
cURL examples are generated based on the the request that was actually sent to the API when the test ran. I believe that the (default) RackTestClient will add those two headers to every request.
One possible solution would be to use Rack::MockRequest instead of Rack::Test::Session. I believe that Rack::MockRequest will not alter the outgoing request in any way, but I haven't checked. We could also try to configure Rack::Test::Session to prevent this behavior. (Do Rack apps needs these headers?)
We could also exclude those 2 headers explicitly from the cURL example output, but it would be Wrong to exclude the headers if their value were set intentionally in the spec file. I don't support this idea.
from rspec_api_documentation.
Thank you for the feedback.
If one defines an example like this:
get '/orders.json' do
header 'Accept', 'application/json'
header 'Content-Type', 'application/json'
(..)
end
I believe it would be more intuitive if the default headers were not used, given that the developer is already specifing the headers that are to be used.
Conversely, adding a no_headers option could also drop all existing records, but that wouldn't be as intuitive.
I really don't see the value of the default headers. Most end-users will simply do a 'curl url' and be done with it, I think..
from rspec_api_documentation.
I agree that it is confusing to include the headers when they weren't requested. It's similarly confusing when they same headers appear in every other output format, as they currently do.
Eric and I agree that "hiding" the headers from the generated output is a bad idea (then your test is different from your documentation!). We need to find a way to prevent these headers from being sent in the first place.
from rspec_api_documentation.
+1
from rspec_api_documentation.
Chiming in pretty late but, I'm not entirely sure how to handle this. We could potentially change this line to be:
def request_headers
@request_headers
end
protected
def do_request(method, path, params, request_headers)
@request_headers = headers(method, path, params, request_headers)
# ...
end
This way we ignore whatever else gets added via Rack::Test. If someone wants to specify the Host
header then they still could.
from rspec_api_documentation.
Since the output for the curl is just for a curl example, I don't see the harm in filtering out blank headers. Are there any cases where you need to include an empty header for the request to work? For me that sounds just... wrong.
from rspec_api_documentation.
Right now, to hide these blank headers when visualizing the docs (reading from the json) is pretty easy. But to change the generated curl it requires way more effort.
from rspec_api_documentation.
I added the ability to filter out cURL headers per this issue. I'm not entirely sold on filtering the example request in the documentation itself. I am fine with the cURL example because it's meant to be something the user can copy and paste, not necessarily documentation.
I sort of think that the documentation viewer should be the one filtering out headers since it's just a Hash. The HTML generated with this plugin isn't really meant to be your final documentation since it's very plain.
from rspec_api_documentation.
Great! That's exactly what I needed.
As you said, the viewer can choose from the json array which headers to display. My problem was with the curl output that is plain text. This patch allows me to remove it from the curl generation, so now I can filter out headers for my API consistently :)
Thank you!
from rspec_api_documentation.
Related Issues (20)
- Document multiple examples for the same endpoint
- Request headers missing when using :open_api
- Docs generation fails if upload multiple files in a test case HOT 2
- Get `NoMethodError` when there is an example that expect an api to raise 500 error HOT 5
- Can't name parameter "pending" HOT 1
- Rails 5.2 update fixture changes
- Maintenance status HOT 23
- Can we please opt-in to Hacktoberfest? 🙏🏻 HOT 4
- No ability to generate a nullable option on response fields
- Add support for context blocks in HTML index HOT 3
- Open api: Ability to add description for scope
- Sample linked in README is not working HOT 1
- Bug in OpenApi formatter with multiple examples for same HTTP action? HOT 2
- Example site is offline HOT 1
- How To: Run tests in parallel and generate documentation HOT 2
- Allow to use short example definition
- Support for the latest version of Ruby
- EOFError on trying to test upload apis without file
- Support for OAS 3.1?
- Support ruby 3.2, DEPRECATED File.exists? HOT 1
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 rspec_api_documentation.