-
Notifications
You must be signed in to change notification settings - Fork 52
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
Invalid request examples #618
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Avoids StackOverflowError that is otherwise thrown - Cycles in required non-nullable patterns are not valid and therefore produce a ContractException - Cycles in nullable patterns are valid so are supported. AnyPattern eventually randomly chooses a NullPattern to terminate the cycle. - Allows cycle to be terminated by omitting an optional property that would have introduced the cycle. - For stub generation, `Resolver.withCyclePrevention()` is introduced as a wrapper for any call that resolves deferred patterns to actual patterns. This is an approach also generally applicable for upcoming cycle prevention needs for similar traversal methods on Pattern (e.g. `newBasedOn()`). - Ensures Resolver remains immutable via `Resolver.withCyclePrevention()` which produces a new Resolver with a cyclePreventionStack with an addition entry for the current pattern. - `Resolver.withCyclePrevention()` has a simple overload which will throw ContractException(cycle=true) if a cycle is found, but there is also a second overload that allows returning null to give the caller an opportunity to gracefully handle the detected cycle. This is done for nullable components (see AnyPattern) and optional properties (see JSONObjectPattern). - Uses correct pattern for the referred-to component that would introduce a cycle (previously would use the referring component's pattern). See OpenApiSpecification.toSpecmaticPattern()
- Return previously calculated component patterns rather than calculating them again. - Standardize how the component pattern cache is populated by factoring into a dedicated method. - Simplify toSchemaProperties() logic to remove logic that is redundant to existing toSpecmaticPattern() logic. - Ensure typeStack is populated with proper component pattern names in all the correct recursive calls.
2 tests are failing
After merging with main, exceptionCause will be Throwable. Check if it is a ContractException and if so look for isCycle, else set isCycle to false by default.
The code was completely short-circuiting generated tests in which there was a breakable cycle. But in order to verify validity of the API implementation, we need to test at least one level in the cycle before breaking it.
harikrishnan83
approved these changes
Mar 8, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What:
Added the capability to add invalid examples of headers and query params as 400 examples.
Why:
Done as a followup to my previous PR #617 that did this for payloads.
How:
I made the parsing and matching polymorphic, and switched out the matching behaviour for 400 examples.
Checklist: