Skip to content

feat: Converters support pm methods: success, jsonBody, jsonSchema - #4856

Closed
thim81 wants to merge 7 commits into
usebruno:mainfrom
thim81:postman-trans-extensions
Closed

thim81 wants to merge 7 commits into
usebruno:mainfrom
thim81:postman-trans-extensions

Conversation

@thim81

@thim81 thim81 commented Jun 7, 2025 •

Copy link
Copy Markdown
Contributor

Description

The Bruno Converters package, already converts a number of Postman methods into Bruno methods.

This PR adds support for the very common methods:

  • pm.response.to.be.success;
  • pm.response.to.have.jsonBody();
  • pm.response.to.have.jsonSchema(schema,{unknownFormats: ["int32", "int64", "float", "double"]});

Jira

BEFORE
image

AFTER
image

Contribution Checklist:

  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.

Publishing to New Package Managers

Please see here for more information.

@pull-request-size pull-request-size Bot added size/L and removed size/XS labels Jun 7, 2025
@thim81

thim81 commented Jun 7, 2025 •

Copy link
Copy Markdown
Contributor Author

Linked to #4857

@helloanoop

Copy link
Copy Markdown
Contributor

@thim81 Can you also add the unit test cases here ?

@helloanoop
helloanoop requested a review from sanish-bruno June 8, 2025 15:24
@thim81

thim81 commented Jun 8, 2025

Copy link
Copy Markdown
Contributor Author

Hi @helloanoop

Offcourse, I ll have a look and try to add additional tests that cover the 3 new pm translations.

@thim81

thim81 commented Jun 8, 2025

Copy link
Copy Markdown
Contributor Author

hi @helloanoop

I added the requested unit tests, let me know if you have remarks or changes needed.

}
},

// pm.response.to.have.jsonBody → expect(res.getBody()).to.satisfy(u => Array.isArray(u) || (u !== null && typeof u === "object")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

From the intelliSense i got to understand, pm.response.to.have.jsonBody can accept arguments too, i believe 90% of the people will be happy with just JsonBody(). also i couldn't find any extensive documentation on how postman handles those arguments. Let me know you thoughts on this!

pm.response.to.have.jsonBody()
pm.response.to.have.jsonBody(optionalExpectEqual:Object)
pm.response.to.have.jsonBody(optionalExpectPath:String)
pm.response.to.have.jsonBody(optionalExpectPath:String, optionalValue:*)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was not aware of the jsonBody() function supporting arguments.

The PR handles only pm.response.to.have.jsonBody(), which was the case that Portman generates, which is why I'm doing this PR.

Do you want to me to extend the support for all the possible arguments? Or built in a detection in that case that fallbacks to the commenting out of the // pm.response.to.have.jsonBody(optionalExpectEqual:Object)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

hi @sanish-bruno

I did some browsing in the Postman documentation and github.
In their docs I did not found a clear explanations, but on Github there was an issue referenced.

Based on that, I added the support for the arguments (to my best knowledge of Chai) and added additional tests to validate the behaviour.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hi, @thim81 Thanks for this. let me know when you push the latest changes

hi @sanish-bruno

I did some browsing in the Postman documentation and github. In their docs I did not found a clear explanations, but on Github there was an issue referenced.

Based on that, I added the support for the arguments (to my best knowledge of Chai) and added additional tests to validate the behaviour.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The changes have been pushed for pm.response.to.have.jsonBody()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@thim81 i couldn't find any related changes on last commit , Am i missing something here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

hi @sanish-bruno

I committed, but forgot to push the changes 🤦 . The PR should now be updated for pm.response.to.have.jsonBody()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @thim81 we are having an internal discussion on what should be the translations, like supporting jsonBody, jsonSchema, to make the translations more straight forward, will get back to you soon.

}
},

// pm.response.to.have.jsonSchema → const tv4 = require("tv4"); expect(tv4.validate(res.getBody(), schema), tv4.error && tv4.error.message).to.be.true;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@thim81 when i searched online, i came to know that pm.response.to.have.jsonSchema accepts 2 arguments, second one is optional, from the quick glance it seems like, postman is using "ajv" under the hood to validate the jsonSchema, can we also use the same. i think ajv is available across our script runtimes just like tv4, probably will be easier for us to pass ajvOptions if any user explicitly using the second argument.

pm.response.to.have.jsonSchema(schema:Object)
pm.response.to.have.jsonSchema(schema:Object, ajvOptions:Object)

@helloanoop @maintainer-bruno @lohit-bruno @naman-bruno currently "ajv" is only available on developer mode, so the script will fail in safe mode if we adopt ajv, to be in parity with postman, we probably need to have "ajv", what should we do here?

@thim81 thim81 Jun 9, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Let me know, what the final suggestion will be: using Ajv or tv4?

I took tv4, because of it being mentioned in guides and not needing the developer mode.
Postman is indeed using Ajv behind the scenes: https://learning.postman.com/docs/tests-and-scripts/write-scripts/postman-sandbox-api-reference/#validate-response-data-with-a-json-schema
Changing the PR to switch to Ajv, should be straightforward to do.

@thim81
thim81 requested a review from sanish-bruno June 9, 2025 11:02
@thim81

thim81 commented Jun 12, 2025

Copy link
Copy Markdown
Contributor Author

hi @sanish-bruno

Is there any news on the tv4 <> AJV preference?
So I can update the PR accordingly.

@sanishchirayath1

sanishchirayath1 commented Jun 13, 2025 •

Copy link
Copy Markdown

hi @sanish-bruno

Is there any news on the tv4 <> AJV preference?
So I can update the PR accordingly.

@thim81 we will most likely be going with ajv, we plan to support jsonSchema, Json within chai using extensions, so that the translations can be easier and straight forward. We haven't yet started working on it. we will work on it soon. Once that PR is merged, I will ping here so that you can make necessary changes to the translation PR.

@sanish-bruno

Copy link
Copy Markdown
Collaborator

#2519 related

@sanish-bruno

Copy link
Copy Markdown
Collaborator

@thim81 sorry for the delay, we were facing some problems with making ajv work with quick-js cause for some regex compatability issues, we have raised a PR on quickjs-emscripten and waiting for it to get merged. or use a forked version. will update you once we make any progress.

@thim81

thim81 commented Jul 10, 2025

Copy link
Copy Markdown
Contributor Author

@sanish-bruno Any news on the item? I see that there conflicts on the PR, should I update them already or wait untill there is movement on the quickjs-emscripten PR?

@sanish-bruno

Copy link
Copy Markdown
Collaborator

@sanish-bruno Any news on the item? I see that there conflicts on the PR, should I update them already or wait untill there is movement on the quickjs-emscripten PR?

@thim81 i think it is better to wait until the quickjs-emscripten. We have been caught up with other issues. So we still haven't got the time to discuss this. I think, It is better to wait!

@thim81

thim81 commented Sep 13, 2025

Copy link
Copy Markdown
Contributor Author

hi @sanish-bruno

Is there any news or plans on this PR?

@thim81

thim81 commented Nov 23, 2025 •

Copy link
Copy Markdown
Contributor Author

hi @sanish-bruno

It does not seems there is any news quickjs-emscripten PR
We just have to wait? Or is there another route to get some progress on this PR for extending Bruno withe the Converter package?

@sanish-bruno

Copy link
Copy Markdown
Collaborator

hi @sanish-bruno

It does not seems there is any news quickjs-emscripten PR We just have to wait? Or is there another route to get some progress on this PR for extending Bruno withe the Converter package?

Sorry for delayed response @thim81 . We haven't had time to look into the issue deep. We are caught up with bruno v3 release. Due to time constraints, we wouldn't be able to look into this issue soon. we will plan for this some time in future, cause it may take some time as we are dependent on the other library. Forking it and maintaining it will also be a hassle to manage as our understanding is limited and there will be a learning curve. We cannot assure a timeline as of now

Let us know if you have any simpler solution in mind! Thanks for understanding! Again really sorry for delay!

@sanish-bruno

Copy link
Copy Markdown
Collaborator

@thim81 Really sorry that we couldn't get your PR in time! We really appreciate the time that you put into the PR as well as the discussion, I have raised couple of PRs, that handle JsonBody, JsonSchema by natively supporting through chai assersions. Would love to hear your thoughts on those! Let me know if you have any other suggestions. or any other APIs you want to see in Bruno! We are prioritising on adding parity with postman for next few months. so your suggestions will considered with higher priority!

@lohit-bruno
lohit-bruno requested a review from bijin-bruno as a code owner April 2, 2026 15:34
@sanish-bruno

Copy link
Copy Markdown
Collaborator

Closing this PR, as the changes have already been addressed in #7301, #7299, and #7052. Thanks for your efforts and contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants