{
  "openapi": "3.1.0",
  "info": {
    "title": "Crewzy Work giver API",
    "version": "1",
    "description": "A contractor on Crewzy makes the key under Connections and gives it to you, with the API address. Each key belongs to one contractor and one of your organisations or sites, and sees only the jobs it sent."
  },
  "servers": [
    {
      "url": "{address}/api/v1/work-giver",
      "variables": {
        "address": {
          "default": "https://app.getcrewzy.com",
          "description": "The API address Crewzy gives you."
        }
      }
    }
  ],
  "components": {
    "securitySchemes": {
      "key": {
        "type": "http",
        "scheme": "bearer",
        "description": "The key, starting crewzy_wg_, as a bearer token."
      }
    }
  },
  "security": [
    {
      "key": []
    }
  ],
  "paths": {
    "/connection": {
      "get": {
        "summary": "Checks the key: the contractor's business, the connection's name and the callback address, if set.",
        "responses": {
          "200": {
            "description": "The connection."
          },
          "401": {
            "description": "The key is not recognised, or was disconnected."
          }
        }
      },
      "put": {
        "summary": "Sets the https address results go to. The answer carries a new signing secret, shown only there.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "callbackUrl": {
                    "type": "string",
                    "maxLength": 500
                  }
                },
                "required": [
                  "callbackUrl"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The address and its signing secret."
          },
          "400": {
            "description": "The address cannot be used."
          }
        }
      }
    },
    "/work-orders/{ref}": {
      "put": {
        "summary": "Sends a new job, or changes one, under your own reference for it.",
        "parameters": [
          {
            "name": "ref",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "title": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 200
                  },
                  "description": {
                    "type": "string",
                    "maxLength": 5000
                  },
                  "priority": {
                    "type": "string",
                    "enum": [
                      "low",
                      "normal",
                      "high",
                      "urgent"
                    ]
                  },
                  "reference": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100
                  },
                  "requestedBy": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 120
                  },
                  "dueAt": {
                    "type": "string",
                    "format": "date-time",
                    "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
                  },
                  "site": {
                    "type": "object",
                    "properties": {
                      "address": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 200
                      },
                      "suburb": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 100
                      },
                      "postcode": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 10
                      },
                      "name": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 120
                      }
                    },
                    "required": [
                      "address"
                    ]
                  },
                  "updatedAt": {
                    "type": "string",
                    "format": "date-time",
                    "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
                  },
                  "cancelled": {
                    "type": "boolean"
                  },
                  "status": {
                    "type": "string",
                    "enum": [
                      "approved",
                      "rejected",
                      "closed"
                    ]
                  }
                },
                "required": [
                  "title"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The job was there and is updated."
          },
          "201": {
            "description": "The job is new."
          },
          "400": {
            "description": "The reference or the job cannot be used."
          }
        }
      },
      "get": {
        "summary": "Where the job stands at the contractor's end.",
        "parameters": [
          {
            "name": "ref",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The job."
          },
          "404": {
            "description": "Nothing with that id this key may see. Another business or enterprise answers the same."
          }
        }
      }
    }
  }
}