restish icon indicating copy to clipboard operation
restish copied to clipboard

separating commands by tags

Open jmls opened this issue 2 years ago • 1 comments

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)

jmls avatar Oct 20 '23 11:10 jmls

@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

danielgtaylor avatar Oct 23 '23 17:10 danielgtaylor