Skip to content
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 14 commits into from
Mar 8, 2023
Merged

Invalid request examples #618

merged 14 commits into from
Mar 8, 2023

Conversation

joelrosario
Copy link
Member

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:

westse and others added 7 commits February 27, 2023 18:09
- 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.
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 harikrishnan83 self-assigned this Mar 8, 2023
@joelrosario joelrosario merged commit 4dcf51a into main Mar 8, 2023
@joelrosario joelrosario deleted the invalid_request_examples branch September 6, 2024 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants