{
  "openapi": "3.0.3",
  "info": { "title": "Spindle API", "version": "1.0.0", "description": "Public API of Spindle, a fictional record exchange." },
  "servers": [{ "url": "/" }],
  "paths": {
    "/api/v1/login": {
      "post": {
        "operationId": "login",
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/LoginRequest" } } } },
        "responses": {
          "200": { "description": "Signed in", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/LoginResponse" } } } },
          "401": { "description": "Wrong username or password", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      }
    },
    "/api/v1/releases": {
      "get": {
        "operationId": "searchReleases",
        "parameters": [{ "name": "q", "in": "query", "required": false, "schema": { "type": "string", "maxLength": 100 } }],
        "responses": {
          "200": { "description": "Matching releases", "content": { "application/json": { "schema": { "type": "array", "items": { "$ref": "#/components/schemas/Release" } } } } }
        }
      }
    },
    "/api/v1/orders": {
      "get": {
        "operationId": "listOrders",
        "responses": {
          "200": { "description": "Your orders", "content": { "application/json": { "schema": { "type": "array", "items": { "$ref": "#/components/schemas/Order" } } } } },
          "401": { "description": "Not signed in", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      }
    },
    "/api/v1/orders/{orderId}": {
      "get": {
        "operationId": "getOrder",
        "parameters": [{ "name": "orderId", "in": "path", "required": true, "schema": { "type": "integer", "minimum": 1000, "maximum": 99999 } }],
        "responses": {
          "200": { "description": "The order", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Order" } } } },
          "401": { "description": "Not signed in", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "403": { "description": "Not your order", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "404": { "description": "No such order", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      }
    },
    "/api/v1/profile": {
      "put": {
        "operationId": "updateProfile",
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Profile" } } } },
        "responses": {
          "200": { "description": "Updated profile", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ProfileView" } } } },
          "401": { "description": "Not signed in", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      }
    },
    "/api/v1/listings": {
      "post": {
        "operationId": "createListing",
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ListingRequest" } } } },
        "responses": {
          "201": { "description": "Listing created", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Listing" } } } },
          "401": { "description": "Not signed in", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Error": { "type": "object", "additionalProperties": false, "required": ["error"], "properties": { "error": { "type": "string", "maxLength": 200 } } },
      "LoginRequest": {
        "type": "object", "additionalProperties": false, "required": ["username", "password"],
        "properties": { "username": { "type": "string", "minLength": 1, "maxLength": 64 }, "password": { "type": "string", "minLength": 1, "maxLength": 128 } }
      },
      "LoginResponse": {
        "type": "object", "additionalProperties": false, "required": ["token", "displayName"],
        "properties": { "token": { "type": "string", "maxLength": 64 }, "displayName": { "type": "string", "maxLength": 80 } }
      },
      "Release": {
        "type": "object", "additionalProperties": true,
        "properties": { "id": { "type": "integer" }, "artist": { "type": "string" }, "title": { "type": "string" }, "label": { "type": "string" }, "cat": { "type": "string" }, "year": { "type": "integer" }, "format": { "type": "string" }, "genre": { "type": "string" } }
      },
      "Order": {
        "type": "object", "additionalProperties": false, "required": ["id", "item", "total", "status"],
        "properties": {
          "id": { "type": "integer" }, "releaseId": { "type": "integer" }, "item": { "type": "string", "maxLength": 200 },
          "total": { "type": "number" }, "status": { "type": "string", "enum": ["Paid", "Shipped", "Delivered"] },
          "shipTo": { "type": "string", "maxLength": 200 }
        }
      },
      "Profile": {
        "type": "object", "additionalProperties": false,
        "properties": { "displayName": { "type": "string", "minLength": 1, "maxLength": 80 }, "email": { "type": "string", "format": "email", "maxLength": 120 } }
      },
      "ProfileView": {
        "type": "object", "additionalProperties": true,
        "properties": { "username": { "type": "string" }, "displayName": { "type": "string" }, "email": { "type": "string" } }
      },
      "ListingRequest": {
        "type": "object", "additionalProperties": false, "required": ["releaseId", "price", "condition"],
        "properties": {
          "releaseId": { "type": "integer", "minimum": 1, "maximum": 99999 },
          "price": { "type": "number", "minimum": 0.5, "maximum": 10000 },
          "condition": { "type": "string", "enum": ["Mint (M)", "Near Mint (NM)", "Very Good Plus (VG+)", "Very Good (VG)", "Good (G)"] },
          "comments": { "type": "string", "maxLength": 500, "description": "Free text from the seller, shown on the listing." }
        }
      },
      "Listing": {
        "type": "object", "additionalProperties": true,
        "properties": { "id": { "type": "string" }, "releaseId": { "type": "integer" }, "price": { "type": "number" }, "condition": { "type": "string" }, "comments": { "type": "string" } }
      }
    }
  }
}
