Conversation
- checks if the url parameter has nested {}[]
- Adds regex for checking the same pattern
- Adds -g flag when nested {}[] is present
- Accounts the following cases
- {{}}
- [[]]
- {[]}
- [{}]
| if (error) { | ||
| expect.fail(null, null, error); | ||
| } | ||
| expect(snippet).to.include("-g"); // eslint-disable-line quotes |
There was a problem hiding this comment.
Why can't we use single quotes here?
There was a problem hiding this comment.
We can, picked up test snippet from existing one and forgot to check.
| } | ||
| }); | ||
| options = { | ||
| longFormat: false |
There was a problem hiding this comment.
Why do we need longFormat as false?
| 'raw': '' | ||
| }, | ||
| 'url': { | ||
| 'raw': 'https://google.com?a={{x:[[{[', |
There was a problem hiding this comment.
Can you split these into different cases for each pattern you are checking?
codegens/curl/lib/index.js
Outdated
| snippet += ` ${form('-m', format)} ${timeout}`; | ||
| } | ||
| // eslint-disable-next-line no-useless-escape | ||
| if ((url.match(/[\{\[]/g) || []).length > 1) { |
There was a problem hiding this comment.
Remove unnecessary escape characters. (/[{[]/g) <- this should work the same way.
There was a problem hiding this comment.
No actually they are not part of a string. Those escape characters are for the regex
There was a problem hiding this comment.
Those are redundant escape characters, not required for the regex. Removing them the regex will work the same way.
There was a problem hiding this comment.
// eslint-disable-next-line no-useless-escape
Avoid disabling any lint rules as far as possible.
There was a problem hiding this comment.
Those are redundant escape characters, not required for the regex. Removing them the regex will work the same way.
yeah they work without escape character too. Thanks
- Removes redundant backslash - Removes additional option in unit test - Adds unit test for all four different conditions
|
will be sent as: And all requests with unmatched |
|
@webholik The changes look okay. |
The requests are coming from Postman and the only use of braces there is to fill in variables. The variables will be substituted before the request going to codegen. And since we are using the |
fixes #253
Since the curl snippets fail if the url parameter has nested braces {}[], we need an additional flag to process the curl command.
Solutions: Add -g flag in curl when request url has nested braces in it.
This PR adds the following changes: