danielgtaylor / openapi-cli-generator

Generate a CLI from an OpenAPI 3 specification
MIT License
179 stars 49 forks source link

Waiter Support #18

Closed danielgtaylor closed 5 years ago

danielgtaylor commented 5 years ago

Add an OpenAPI extension to provide waiter support that blocks until a specific state has been met. Typically you would do a request on a cadence to return some state information and use a query to match a state in the response to exit the loop.

For example, the configuration for such a feature might look something like:

x-cli-waiters:
  order-ready:
    delay: 10
    attempts: 30
    operation: GetOrder
    matchers:
      - select: response.body#order.status
        expected: Ready

Assuming the GetOrder operation has a required order-id parameter, this results in a command something like:

$ my-cli wait order-ready $ORDER_ID

This could also be automatically combined with creation or update operations by mapping response information to parameters on the waiter operation:

x-cli-waiters:
  order-ready:
    # ...
    operation: GetOrder
    after:
      PostOrder:
        order-id: response.body#order.id

Then you could do something like:

# With automatic waiter:
$ my-cli post-order <details.json --wait-order-ready

# Without:
$ ID=my-cli post-order <details.json -q order.id
$ my-cli wait order-ready $ID

This gets even more difficult with multiple params where you have to save the response and somehow get each param to pass into the wait command.