{
  "openapi": "3.0.3",
  "info": {
    "title": "Hermicache",
    "description": "Hermicache",
    "version": "0.0.1"
  },
  "servers": [
    {
      "url": "/"
    }
  ],
  "tags": [
    {
      "name": "auth"
    },
    {
      "name": "content"
    }
  ],
  "paths": {
    "/register": {
      "post": {
        "tags": [
          "auth"
        ],
        "summary": "Register a new user",
        "operationId": "register",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UserPair"
              }
            }
          },
          "required": true
        },
        "security": [],
        "responses": {
          "200": {
            "description": "Successful registration",
            "headers": {
              "Set-Cookie": {
                "schema": {
                  "type": "string",
                  "example": "username=username; secret=abcde12345;"
                }
              }
            }
          },
          "400": {
            "description": "Invalid username or password"
          }
        }
      }
    },
    "/login": {
      "post": {
        "tags": [
          "auth"
        ],
        "summary": "Log in into existing account",
        "operationId": "login",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UserPair"
              }
            }
          },
          "required": true
        },
        "security": [],
        "responses": {
          "200": {
            "description": "Successful registration",
            "headers": {
              "Set-Cookie": {
                "schema": {
                  "type": "string",
                  "example": "username=username; secret=abcde12345;"
                }
              }
            }
          },
          "400": {
            "description": "Invalid username or password"
          }
        }
      }
    },
    "/field": {
      "post": {
        "security": [
          {
            "cookieSecret": []
          },
          {
            "cookieName": []
          }
        ],
        "tags": [
          "content"
        ],
        "summary": "Create field",
        "operationId": "create_field",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Field"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Successful field creation",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string",
                  "example": "OK"
                }
              }
            }
          },
          "400": {
            "description": "Failed auth or invalid field"
          },
          "401": {
            "description": "Unauthorized"
          }
        }
      }
    },
    "/field/{uuid}": {
      "get": {
        "security": [
          {
            "cookieSecret": []
          },
          {
            "cookieName": []
          }
        ],
        "tags": [
          "content"
        ],
        "summary": "Get field",
        "operationId": "get_field",
        "responses": {
          "200": {
            "description": "Field",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Field"
                }
              }
            }
          },
          "400": {
            "description": "Failed auth or invalid field uuid"
          },
          "401": {
            "description": "Unauthorized"
          }
        }
      }
    },
    "/list_fields": {
      "get": {
        "security": [
          {
            "cookieSecret": []
          },
          {
            "cookieName": []
          }
        ],
        "tags": [
          "content"
        ],
        "summary": "List your own field uuids",
        "operationId": "List your own field uuids",
        "responses": {
          "200": {
            "description": "Field uuid list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "number"
                  }
                }
              }
            }
          },
          "400": {
            "description": "Failed auth or invalid field uuid"
          },
          "401": {
            "description": "Unauthorized"
          }
        }
      }
    },
    "/compute": {
      "get": {
        "security": [
          {
            "cookieSecret": []
          },
          {
            "cookieName": []
          }
        ],
        "tags": [
          "content"
        ],
        "summary": "Run compute",
        "operationId": "Run compute",
        "parameters": [
          {
            "in": "query",
            "name": "field_uuid",
            "schema": {
              "type": "integer"
            },
            "description": "Field uuid",
            "required": true
          },
          {
            "in": "query",
            "name": "arg",
            "schema": {
              "type": "string"
            },
            "description": "function argument (empty for palindrome field)",
            "required": true
          }
        ],
        "responses": {
          "200": {
            "description": "Field uuid list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "number"
                  }
                }
              }
            }
          },
          "400": {
            "description": "Failed auth or invalid field uuid"
          },
          "401": {
            "description": "Unauthorized"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "cookieSecret": {
        "type": "apiKey",
        "in": "cookie",
        "name": "secret"
      },
      "cookieName": {
        "type": "apiKey",
        "in": "cookie",
        "name": "name"
      }
    },
    "schemas": {
      "UserPair": {
        "required": [
          "username",
          "password"
        ],
        "type": "object",
        "properties": {
          "username": {
            "type": "string",
            "example": "username"
          },
          "password": {
            "type": "string",
            "example": "password"
          }
        }
      },
      "Field": {
        "oneOf": [
          {
            "type": "object",
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "palindrome"
                ]
              },
              "content": {
                "type": "string"
              }
            },
            "description": "palindrome field, just a simple string"
          },
          {
            "type": "object",
            "description": "recurrent function field",
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "recurrent"
                ]
              },
              "content": {
                "type": "object",
                "properties": {
                  "base": {
                    "type": "array",
                    "items": {
                      "type": "array",
                      "items": {
                        "type": "number"
                      },
                      "minItems": 2,
                      "maxItems": 2
                    }
                  },
                  "coefficients": {
                    "type": "array",
                    "items": {
                      "type": "number"
                    }
                  }
                },
                "additionalProperties": false
              }
            }
          }
        ]
      }
    }
  }
}