Skip to content

Create a portable binary from an OpenAPI Specification

License

Notifications You must be signed in to change notification settings

eliottness/openapi2cli

Repository files navigation

openapi2cli

Create a portable binary from an OpenAPI Specification

Usage

Generate a binary cli from the yaml openAPI file with the given url as base.

$ openapi2cli openapi.yaml http:localhost/8080 --out-bin cli

Elements mandatory in the openapi spec

  • title
  • version
  • global description

Samples of pairs: spec + how to use it as cli

Simple example

paths:
  /batch:
    get:
      operationId: get-batches
      description: "Return a list of batches"
      tags:
      - Batch Resource
      responses:
        "200":
          description: OK
$ ./cli get-batches # Print the response if return code is 200

Path argument

paths:
  /batch/{batchId}:
    get:
      operationId: get-batch
      tags:
      - Batch Resource
      parameters:
      - name: batchId
        in: path
        required: true
        schema:
          $ref: '#/components/schemas/UUID'
      responses:
        "200":
          description: OK
$ ./cli get-batch --batchId XXXX-XXXX-XXXX-XXXX # Print the response

Here we need to check that the param exists for the command get-batch and then we need to check it is the good format of parameter. And finally if the parameter is set to required: true the cli must throw and error and ask the user to specify.

Request Body

paths:
  /batch/publish:
    put:
      operationId: put-batch-publish
      tags:
      - Batch Resource
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Request3'
      responses:
        "200":
          description: OK
$ ./cli put-batch-publish --body-file file.json # Get the request body from the file: file.json
$ ./cli put-batch-publish --body-stdin          # Get the request body from stdin
$ ./cli put-batch-publish --body {}             # Get the request body from the argument

Here we must check if the input body is a good json and add the proper header Content-Type header in the request and if the command put-batch-publish takes a body

About

Create a portable binary from an OpenAPI Specification

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published