danielgtaylor / restish

Restish is a CLI for interacting with REST-ish HTTP APIs with some nice features built-in
https://rest.sh/
MIT License
717 stars 69 forks source link

separating commands by tags #224

Open jmls opened 9 months ago

jmls commented 9 months ago

if I have an openapi spec that has a number of tags (let say "foo" and "bar") then when I do a restish myapi -h I get

Usage:
  restish myapi [command]

  foo commands:
    update

  bar commands
    update

yes, my operation ids are the same (using nestjs and controllers, so generated from the method name)

I was hoping to be able to do something like

restish myapi foo update restish myapi bar update

but it seems not.

Am I forced into changing the operationIds to be fooUpdate and barUpdate ? my restish api then looks like this

Usage:
  restish myapi [command]

  foo commands:
    fooupdate

  bar commands
    barupdate

which kinda looks .. sucky ;)

So in a nutshell, I 'm looking for some way of using the tags in the spec to specify a command and sub-command (tag / operratiionid)

danielgtaylor commented 9 months ago

@jmls great question. Right now Restish is set up to have a flat list of operation commands rather than a hierarchy like you are describing. There are a few different ways you could make a hierarchy and it's not easy to do this in a generic way that would work for everyone, but I'm open to ideas!

As for using the same operation ID multiple times... see the OpenAPI spec:

Unique string used to identify the operation. The id MUST be unique among all operations described in the API. The operationId value is case-sensitive. Tools and libraries MAY use the operationId to uniquely identify an operation, therefore, it is RECOMMENDED to follow common programming naming conventions.

I'm not sure what nestjs is doing or recommends, but the spec says they must be unique, which is why Restish uses them as the unique command name.

Edit: also just FYI, you can provide an OpenAPI extension x-cli-name which overrides the operation name in Restish to anything you like. See here: https://rest.sh/#/openapi?id=name