-
Notifications
You must be signed in to change notification settings - Fork 414
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
Strict schema validation #604
Conversation
ff3ea5b
to
f2aee85
Compare
@jtannas |
f2aee85
to
2a1ae07
Compare
@romanblanco I've fixed conflicts and updated the branch |
Looks good 👍 Plus 1 for merging 🥇 |
GitHub had issues earlier today. Re-opening the PR to try and run CI tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@IlkhamGaysin, thank you for the PR!
I like the suggestion, but I've tried to run the tests locally and they're failing as well as in the CI.
Please, take a look at https://github.com/rswag/rswag/blob/master/CONTRIBUTING.md#test and update the PR.
I'm also thinking that it would be really nice if you could update the |
@romanblanco I will fix the specs and add a test case, thank you. I had a problem with docker locally so I relied on CI... |
@romanblanco I've fixed the specs and added the test case. The GitHub Actions has issues but locally the test suites aregreen |
@@ -132,7 +138,7 @@ def run_test!(&block) | |||
end | |||
|
|||
it "returns a #{metadata[:response][:code]} response", rswag: true do |example| | |||
assert_response_matches_metadata(example.metadata, &block) | |||
assert_response_matches_metadata(example.metadata.merge(options), &block) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of merging **options
with metadata
, could we pass **options
to it
?
def run_test!(**options, &block)
options[:rswag] = true unless options.key?(:rswag)
if RSPEC_VERSION < 3
ActiveSupport::Deprecation.warn('Rswag::Specs: WARNING: Support for RSpec 2.X will be dropped in v3.0')
before do
submit_request(example.metadata)
end
it "returns a #{metadata[:response][:code]} response", **options do
assert_response_matches_metadata(metadata)
block.call(response) if block_given?
end
else
before do |example|
submit_request(example.metadata)
end
it "returns a #{metadata[:response][:code]} response", **options do |example|
assert_response_matches_metadata(example.metadata, &block)
example.instance_exec(response, &block) if block_given?
end
end
end
This should work, according to the README:
Lines 276 to 278 in 4043166
it 'returns a valid 201 response', swagger_strict_schema_validation: true do |example| | |
assert_response_matches_metadata(example.metadata) | |
end |
This would allow us to pass in other options to it
, which is a feature I'd like to have. For example, this would allow us to do the following:
run_test! focus: true
I could put this up in a separate PR after this one is merged if folks would prefer that, but I thought I'd mention it here since we're already adding the **options
parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like the idea 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I put up a sub-PR here if that is helpful:
IlkhamGaysin#1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@romanblanco I'm gonna merge changes of @a-lavis to my PR to push it all together
are you ok with that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@IlkhamGaysin, sounds good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@IlkhamGaysin, I'll need you to rebase your branch once more because of the recent merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@romanblanco done!
307d138
to
c645fb6
Compare
c645fb6
to
76711b1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
@IlkhamGaysin, @a-lavis, thank you guys!
Hey @IlkhamGaysin, I'm trying to use this feature in a new API spec I'm working on, and I'm running into a problem with fields that are not required. In Line 117 in 0edbe25
Using the same approach to describe pagination schema:
If I have an example request that only has one page, I'm getting back error message:
I suspect, that parametrizing I'm wondering if I'm using it wrong or if it is a bug. Any ideas? |
The
Because of number 1, it will ignore what you set in the In the future, we should take advantage of this new feature in That will allow us to either make All Properties Required or make Additional Properties Not Permitted. |
We ran into that as well when we manually made json-schema strict. The findings were the same as @a-lavis. Strict schema validation makes all declared keys required regardless of what is defined as 'required' in rswag. |
@mattpolito @romanblanco Hi guys, sorry for the delay, I've been on vacation. The initial idea of the strict option is to strictly ask for the presence of all options listed. I can apply the new flexible changes from json-schema if you would like to have them.
Are you ok with me doing that? |
Here is the first PR guys |
@mattpolito @romanblanco hey guys, here is the fix that will make the restrictions more flexible. |
Problem
I see some problems in ruby projects - it's data bloating. As projects grow they get complicated so it's hard to keep responses clean. It happed to projects I am working on and others(see the issue). So I decided to bring the changes back from initial issue.
Solution
I want to add a new configuration option on top of the main called
additionalProperties
from json-schema to allow users to validate their schemas strictly.This concerns this parts of the OpenAPI Specification:
The changes I made are compatible with:
Related Issues
Closes #163
Checklist
Steps to Test or Reproduce
Outline the steps to test or reproduce the PR here.