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

Request with optional complex objects #2153

Open
ltuch opened this issue Feb 1, 2025 · 0 comments
Open

Request with optional complex objects #2153

ltuch opened this issue Feb 1, 2025 · 0 comments

Comments

@ltuch
Copy link

ltuch commented Feb 1, 2025

This issue is similar to #354 and apologies for my duplicated comment.

The API I am looking at testing with Spring Cloud Contract has multiple non-primitive optional request fields, and when certain optional request fields are provided then certain optional fields are conditionally returned by the API.

This seems difficult to model in Spring Cloud Contract. I can see a few options and each of which has some downsides.

  1. Do not include the optional attributes in the contract. The downside of this is that the contract covers less. If there are a large number of optional fields, then the contracts aren't that expressive as they cover a small number of fields.

  2. Create additional contract scenarios which cover the optional fields. The problem with this approach is that you can end up with a large number of contracts scenarios (just for the success cases) and this has a few downsides:

    • multiple contract scenarios can match a request - then you need to use something like priorities to preference one contract over another one.
    • if there are multiple scenarios there can be duplicated parts of the request between the scenarios which isn't ideal. An issue could get fixed in one contract scenario, but remain in other scenarios.
    • slower to run the stub runners when there are a large number of scenarios.

If optional complex object is not a feature on the radar for the project, then how would people typically handle testing for this type of API? Any recommendations or advice is appreciated.

@ltuch ltuch changed the title Request with opional complex objects Request with optional complex objects Feb 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants