sam-goodwin / eventual

Build scalable and durable micro-services with APIs, Messaging and Workflows
https://docs.eventual.ai
MIT License
174 stars 4 forks source link

chore: improve command output #356

Closed thantos closed 1 year ago

thantos commented 1 year ago

Improving the command output to API Specification.

  1. outputs now default to a description of "OK". This description is required by openAPI, unfortunately.
  2. allow overriding of the description from the service. Useful for things like openai plugins that may care about the description.
  3. allow overriding of the status code for REST path commands. Reflected in the API Spec and the status code returned at runtime.
    1. Would allow a command with a rest path to represent a 304 redirect or be labelled as 204 when no content is returned.
  4. allow api.[method] commands (pass through) to specify an array of output schemas, descriptions, and status codes.
  5. default schema for RPC and REST commands (not pass through) is now z.any instead of undefined.
    1. in openapi, this is { nullable: true }
  6. allow api.[method] to provide a description for the command, pass through to the ApiSpecification.
{
  "openapi": "3.0.1",
  "info": {
    "title": "eventual-tests",
    "version": "1"
  },
  "servers": [
    {
      "url": "https://ip98djye54.execute-api.us-east-1.amazonaws.com"
    }
  ],
  "paths": {
    "/hello3": {
      "post": {
        "operationId": "/hello3-POST",
        "parameters": [],
        "requestBody": {
          "content": {}
        },
        "responses": {}
      }
    },
    "/hello": {
      "get": {
        "operationId": "helloApi-get",
        "parameters": [],
        "requestBody": {
          "content": {}
        },
        "responses": {
          "201": {
            "content": {
              "application/json": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "description": "default output of hello command"
          }
        }
      }
    },
    "/user/typed1/{userId}": {
      "get": {
        "operationId": "typed1-get",
        "parameters": [
          {
            "in": "path",
            "name": "userId",
            "schema": {
              "type": "string",
              "description": "The user ID to retrieve"
            }
          }
        ],
        "requestBody": {
          "content": {}
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "nullable": true
                }
              }
            },
            "description": "OK"
          }
        }
      }
    },
    "/user/typed2/{userId}": {
      "get": {
        "operationId": "typed2-GET",
        "parameters": [
          {
            "in": "query",
            "name": "detailed",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "in": "path",
            "name": "userId",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {}
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "userId": {
                      "type": "string"
                    },
                    "createdTime": {
                      "type": "string",
                      "format": "date-time",
                      "description": "Time the user was created"
                    }
                  },
                  "required": [
                    "userId",
                    "createdTime"
                  ]
                }
              }
            },
            "description": "OK"
          }
        }
      }
    },
    "/user/typedPut/{userId}": {
      "put": {
        "operationId": "typedPut-PUT",
        "description": "Update a user's info. Will write over whatever was set before.",
        "summary": "Update a user's info",
        "parameters": [
          {
            "in": "query",
            "name": "ExpectedVersion",
            "schema": {
              "type": "number"
            }
          },
          {
            "in": "path",
            "name": "userId",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "age": {
                    "type": "number"
                  }
                },
                "required": [
                  "age"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "nullable": true
                }
              }
            },
            "description": "OK"
          }
        }
      }
    },
    "/early-middleware-response": {
      "get": {
        "operationId": "/early-middleware-response-GET",
        "parameters": [],
        "requestBody": {
          "content": {}
        },
        "responses": {}
      }
    },
    "/modify-response-http": {
      "get": {
        "operationId": "/modify-response-http-GET",
        "description": "modify response middleware",
        "parameters": [],
        "requestBody": {
          "content": {}
        },
        "responses": {}
      }
    }
  }
}