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

Added simplified request and response body matching in case of multiple examples. #792

Merged
merged 4 commits into from
May 17, 2024

Conversation

VShingala
Copy link
Member

@VShingala VShingala commented May 14, 2024

Overview

This PR simplifies the logic to generate the request examples in case when multiple request and response body examples are mentioned in definition.

What's changing?

We've removed functionality where if example was used in one response code, it wasn't being used in other response code examples. This was intended before but it creates a lot of confusion to users.

We are also changing how the matching of request and response bodies happens to create examples in below order.

  • Check if request and response body have examples with matching keys. (Example Key)
  • If we find any matching, we'll create example with matching keys (request and response example) and ignore other examples with non matching keys.
  • If no matching could be found, we'll switch to matching based on Positions. i.e. First response example with first request example, second response example with second request example and so on.
    • If there are req/res examples left for which positional match could not be found, then we'll default to using the first example of counter part.

@VShingala VShingala force-pushed the feature/fix-multi-examples-matching branch from a9a4f90 to c12e738 Compare May 14, 2024 13:33
@VShingala VShingala marked this pull request as ready for review May 15, 2024 04:55
return exampleKeyComparator(example, key);
});

let requestExample = _.find(matchedRequestExamples, ['contentType', _.get(responseExample, 'contentType')]),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VShingala What's the reason for doing this? The request and response can be of different types. Why give preference to same content types?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@webholik Yes, we only give preference to same content type if available. Reasoning is, It makes better example if both request and response body are in same content type.

Although, if same content type is not present we do pair different content types as well.

@VShingala VShingala merged commit e90b218 into develop May 17, 2024
6 checks passed
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