Package: curl-arguments-url
AWS Cloudwatch InsightsFree software: Apache Software License 2.0Though OpenAPI documented services offer a nice UI to test the endpoints, I couldn't find a good command line tool for
this.  Here I created something that works nicely with zsh completions.  If you have the OpenAPI spec available, you
put it in your~/.carl/open_api.  Then parameters can be passed as+{param-name}, with tab-completions, and then
these are passed tocurl.There is no way that this covers all the cases for the OpenAPI spec, but it hopefully covers the vast majority people
of cases people actually encounter.Installation# globally%pipxinstall'curl_arguments_url'# or in a particular virtual env%pipinstall'curl_arguments_url'# to get the completions to work, add the following to your .zshrceval"$(carlutilszsh-print-script)"# And copy the OpenAPI spec into ~/.carl/open_api to get the completions and curl-building working%cpopen_api-spec.yml~/.carl/open_api# if parsing of the open_api files is too slow for you, you can try installing the ryaml (Rust Yaml) extension. I# didn't include this by default because I'm afraid it might not install correctly on certain systems, but it's much# faster%pipxinstall'curl_arguments_url[ryaml]'ExamplesThese examples usetests/resources/open_api/openapi-demo.ymlBasic GET%carlhttp://demo.io/v0/entities/\{path-item\}GET+path-itemID+query-itemquery-this--no-run--print-cmd
curl-XGET'http://demo.io/v0/entities/ID?query-item=query-this'More complicated POST command%carlhttp://demo.io/v0/entities/\{path-item\}POST\+path-itemID+field-onevalue+field-twoanarrayofvalues\+field-three'{"complex":["sub","value"]}'\+field-header'Header Param Value'\--no-run--print-cmd\----silent# you can get other arguments passed to curl at the end, like this# the output wouldn't be this nicely formatted, but so you can see what curl command would be runcurl-XPOSThttp://demo.io/v0/entities/ID\-H'field-header: Header Param Value'-H'Content-Type: application/json'\--data-binary\'{"field-one": "value", "field-two": ["an", "array", "of", "values"], "field-three": {"complex": ["sub", "value"]}}'\--silentValues are cached for completion by param name.These cached values can be managed with thecarl utils cached-valuesutility:%carlutilscached-values--help
usage:carlutilscached-values[-h]{params,ls,rm,add}...

positionalarguments:{params,ls,rm,add}paramsListalltheparamnamesthathavevaluescachedlsListallthevaluescachedforaparticularparamrmRemoveavalueforanparamfromthecacheforcompletionsaddAddoneormorevaluesforaparamtothecache

options:-h,--helpshowthishelpmessageandexitHelp is generated from the OpenAPI spec for your reference% carl --help
usage: carl [-h] {utils,http://demo.io/v0/entities/{path-item},http://demo.io/v0/restricted,http://demo.io/v0/other,http://demo.io/v0/endpoints} ...

A Utility to cleanly take command-line arguments, for an endpoint you have the
OpenAPI specification for, and convert them into an appropriate curl command.
Spec files should be in /root/.carl/open_api directory or directory defined by
env variables (See below)

positional arguments:
  {utils,http://demo.io/v0/entities/{path-item},http://demo.io/v0/restricted,http://demo.io/v0/other,http://demo.io/v0/endpoints}
    utils               Utilities
    http://demo.io/v0/entities/{path-item}
                        Demo Entity Endpoint
    http://demo.io/v0/restricted
                        A Restricted Endpoint
    http://demo.io/v0/other
                        Another Endpoint
    http://demo.io/v0/endpoints
                        Yet Another Endpoint

options:
  -h, --help            show this help message and exit

Environment Variables:
    CARL_DIR: Directory which contains files for carl. Default: ~/.carl
    CARL_OPEN_API_DIR: Directory containing the OpenApi specifications and
                        Yaml files. Default: $CARL_DIR/open_api
    CARL_CACHE_DIR: Directory containing the cache. Default $CARL_DIR/cacheFor a specific endpoint:% carl http://demo.io/v0/entities/\{path-item\} POST --help
usage: carl http://demo.io/v0/entities/{path-item} POST [-h] [-p] [-n] [-R] [-b BODY_JSON] [+field-header FIELD_HEADER] [+field-one FIELD_ONE]
                                                        [+field-two FIELD_TWO [FIELD_TWO ...]] [+field-three FIELD_THREE] +path-item PATH_ITEM
                                                        [passed_to_curl ...]

Demo Post Command

positional arguments:
  passed_to_curl        Extra argument passed to curl, often after "--"

options:
  -h, --help            show this help message and exit
  -p, --print-cmd       Print the resulting curl command to standard out
  -n, --no-run          Don't run the curl command. Useful with -p
  -R, --no-requires     Don't check to see if required parameter values are missing or if values are one of the enumerated values
  -b BODY_JSON, --body-json BODY_JSON, --body BODY_JSON
                        Base json object to send in the body. Required body params are still required unless -R option passed. Useful for dealing with incomplete specs.
  +field-header FIELD_HEADER
                        Header Param
  +field-one FIELD_ONE  Demo Body String Field
  +field-two FIELD_TWO [FIELD_TWO ...]
                        Demo Body Array Field
  +field-three FIELD_THREE
                        Demo Body Complex Field
  +path-item PATH_ITEMGeneric Optional Args:-p, --print-cmd       Print the resulting curl command to standard out
  -n, --no-run          Don't run the curl command. Useful with -p
  -R, --no-requires     Don't check to see if required parameter values are missing or if values are one of the enumerated values
  -b BODY_JSON, --body-json BODY_JSON, --body BODY_JSON
                        Base json object to send in the body. Required body params are still required unless -R option passed. Useful for dealing with incomplete specs.Relevant Environment VariablesCARL_DIR: Directory which contains files for carl. Default: ~/.carl
    CARL_OPEN_API_DIR: Directory containing the OpenApi specifications and
                        Yaml files. Default: $CARL_DIR/open_api
    CARL_CACHE_DIR: Directory containing the cache. Default $CARL_DIR/cacheHints for finding OpenAPI specsThe spec you're interested in might be onhttps://app.swaggerhub.com/.  Also, sometimes the doc/sandbox page, for an
api, which gives you a gui for interacting with the api, loads the swagger spec in the background.  You can see this
if you open the developer tools in Chrome under NetworkDevelopmentRequires make:# setting up dev environment$makedevelop# run tests$maketest# ... or$pytest# run tests for all environments$maketest-allNo CI/CD or coverage yetTo Do/Future FeaturesA--queryoption for adding query parameters directlySome sort of hook infrastructure, so you could do things like have custom-completions for certain parameters or
automatically add a particular env variable as an auth headerSupport file uploading and downloadingUtilize the authorization part of the OpenAPI specBetter support for nested json objects in the body, so that+param.sub-param valuewould set{"param"{"sub-param":"value"}}Maybe support older versions of Swagger/OpenApiSpeaking of which, in the code I sometimes use the term "swagger" and sometimes "open_api".  I should make this
consistent.Support bash and fish.  With how I implemented this, I thought it would be easy to implement bash.  But the way bash
parses and escapes arguments passed to the completion function made it surprisingly challenging.  Thebash-completionbranch has my so-far attempts to deal with these issues.  It might be close to done, or there
might be a slew of other issues I haven't realized yet.CreditsThis package was created withcookiecutterand theaudreyr/cookiecutter-pypackageproject template.