rswag: OAS 3 Document has examples in the wrong path
According to the README:
Enable auto generation examples from responses To enable examples generation from responses add callback above run_test! like:
after do |example|
example.metadata[:response][:examples] = { 'application/json' => JSON.parse(response.body, symbolize_names: true) }
end
However this results in the examples being directly on the response object, whereas it should be on the media type object of the response’s content property.
Structural error at paths./api/v1/accounts.get.responses.200
should NOT have additional properties
additionalProperty: examples
Jump to line 158
Any suggestions for a way to work around this?
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 12
- Comments: 17 (4 by maintainers)
Commits related to this issue
- Workaround rswag/rswag#325 — committed to daniel-shuy/pender by daniel-shuy 4 years ago
- Workaround rswag/rswag#325 — committed to daniel-shuy/pender by daniel-shuy 4 years ago
- Workaround rswag/rswag#325 — committed to meedan/pender by daniel-shuy 4 years ago
- OpenAPI 3.x support (#233) * Add Rswag * Remove swagger-docs * Enable SimpleCov for Rswag * Enable Rswag auto generation examples from responses * Workaround * rswag/rswag#359 * rswag/rswag... — committed to meedan/pender by daniel-shuy 4 years ago
Rswag: 2.3.1 Rails: 6.0.3.x
Here my code how to fix in the meantime the examples problem:
And the examples collecting should look like:
As a quick workaround, I had to monkey patch the formatter:
And the examples collecting should look like
@oblakeerickson you’re right, was on 2.3.2. Thanks for letting me know! 🙏
@phlegx Thank you so much. Will give it a try
Update: It works! Thank you again.
I wanted automatic generation of both multiple response AND payload examples. At the point, it got a little thick, so threw auto-generation of path parameters too.
Can see solution at https://gist.github.com/rdnewman/ba5143f1598eff72b2cba48ce78ca43d. Most files should be plug and play (but watch the top level module names). Only tested with my own project that I did this for (using Redoc), so YMMV.
I haven’t been able to get this workaround to work for my examples. Has there been any progress on the PR that would fix this?
Hi @olegykz,
I can confirm that your workaround works as advertised 😃
Gerard.