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
Allow passing additional options to curl command for "Try it out" #6288
Conversation
Allows `requestInterceptor` to add options to the curl command. For example: ```js requestInterceptor: function (request) { if (request.method === 'GET') { request.curlOptions = ['-g'] request.url = request.url .replace('%5B', '[') .replace('%5D', ']') .replace('%2C', ','); } return request; } ```
@adamrdavid Thanks for the PR! Functionally looks good. However, can you migrate the newly added tests to |
Thanks @tim-lai I've updated the tests. I was also wondering if you'd consider a pr that optionally disables the |
@adamrdavid PR merged! Thanks for the contribution! Fyi, the generation of the curl sample occurs and is dependent on |
Thank you @tim-lai. I was thinking of (based on a setting somewhere) making the |
@adamrdavid I suggest creating a new feature request to generate curl sample only (if it doesn't already exist). I would create a new button, and would not attach the feature to |
The documentation for this feature seems a little weird:
swagger-ui/docs/usage/configuration.md Line 15 in 5ada9ef
swagger-ui/docs/usage/configuration.md Line 84 in 5ada9ef
So those seems to suggest you'd use this as follows: Swagger({
'request.curlOptions': [ '--insecure' ],
...
}); When in reality it seems you have to do this: Swagger({
requestInterceptor: (request) => {
request.curlOptions = [ '--insecure' ];
return request;
},
...
}); I'm not sure if the actual |
Description
Updates
curlify.js
to check forcurlOptions
on therequest
object and passes them in as options in betweencurl
and-X
Allows
requestInterceptor
to add options to the curl command.For example:
Motivation and Context
Fixes #5537
The issue mentions other use cases (like adding cookies), but for my use case I just want to be able to pass the
-g
option so the curl command looks better for nested url parameters (like thefields
parameter in jsonapi spec).This allows you to use the existing
requestInterceptor
to add any additional options to an array attribute on therequest
object.I don't think this actually changes the behavior of the request, but updating what is displayed in the curl command is enough for my use case. (actually I'd prefer an option to remove the
execute
part of the "try it out" function and just display the curl command)How Has This Been Tested?
I have added 2 tests to
curlify.js
: 1 for passing a single option, 1 for passing multiple options with an argument.The existing tests here ensure that this is backwards compatible when not passing any extra options.
For testing locally I just used the main api repo I work in and changed the src to my local copy.
Screenshots (if appropriate):
Checklist
My PR contains...
src/
is unmodified: changes to documentation, CI, metadata, etc.)package.json
)My changes...
Documentation
Seeking guidance on where would be good to add this. I was thinking in the configuration documentation under
requestInterceptor
, but that might get crowded.Automated tests
I think so, but I'm not very familiar with the codebase.