{
  "openapi": "3.1.0",
  "info": {
    "title": "Space Agency API",
    "version": "1.0",
    "description": "Run a small space program: schedule launches, scrub them for weather, and actually light the candle — a slow, risky operation that sometimes aborts. Probe pings take seconds, ideal for exercising client timeouts."
  },
  "servers": [
    {
      "url": "https://funapi.dev/api/space/v1"
    }
  ],
  "tags": [
    {
      "name": "launches",
      "description": "countdowns and scrubs"
    },
    {
      "name": "crew",
      "description": "astronauts on the roster"
    },
    {
      "name": "probes",
      "description": "deep space, slow answers"
    }
  ],
  "paths": {
    "/launches": {
      "get": {
        "tags": [
          "launches"
        ],
        "summary": "List launches, filter by status",
        "operationId": "sp-launches",
        "responses": {
          "200": {
            "description": "Launch list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Unknown status",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "required": false,
            "description": "scheduled, launched or scrubbed.",
            "schema": {
              "type": "string"
            }
          }
        ]
      },
      "post": {
        "tags": [
          "launches"
        ],
        "summary": "Schedule a launch",
        "operationId": "sp-schedule",
        "responses": {
          "201": {
            "description": "Launch scheduled",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            },
            "headers": {
              "Location": {
                "schema": {
                  "type": "string",
                  "format": "uri-reference"
                }
              }
            }
          },
          "400": {
            "description": "Missing mission or vehicle",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "mission": {
                    "type": "string"
                  },
                  "vehicle": {
                    "type": "string"
                  },
                  "window": {
                    "type": "string"
                  }
                }
              },
              "example": {
                "mission": "Lunar Coffee Delivery",
                "vehicle": "Kestrel IX",
                "window": "2026-09-15T06:00:00Z"
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ]
      }
    },
    "/launches/{id}": {
      "get": {
        "tags": [
          "launches"
        ],
        "summary": "Get one launch",
        "operationId": "sp-launch",
        "responses": {
          "200": {
            "description": "The launch",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "404": {
            "description": "Unknown id",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Launch id 1–3.",
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 1
          }
        ]
      }
    },
    "/launches/{id}/scrub": {
      "post": {
        "tags": [
          "launches"
        ],
        "summary": "Scrub a scheduled launch",
        "operationId": "sp-scrub",
        "responses": {
          "200": {
            "description": "Scrubbed, count incremented",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Unknown id",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Already launched or already scrubbed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Launch id — must be scheduled.",
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 1
          }
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ]
      }
    },
    "/launches/{id}/launch": {
      "post": {
        "tags": [
          "launches"
        ],
        "summary": "Light the candle — slow & occasionally aborts (admin only)",
        "operationId": "sp-ignite",
        "responses": {
          "200": {
            "description": "Liftoff (after a ~3s hold-down)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Viewer token cannot push the big red button",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Unknown id",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Not scheduled, or an auto-abort at T-0 (~25% chance)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Launch id — must be scheduled (re-schedule a scrubbed one by scrubbing… no wait, just use launch 1).",
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 1
          }
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ]
      }
    },
    "/launches/{id}/countdown": {
      "get": {
        "tags": [
          "launches"
        ],
        "summary": "T-minus for a scheduled launch",
        "operationId": "sp-countdown",
        "responses": {
          "200": {
            "description": "T-minus seconds (random-ish; deterministic mode pins it)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "404": {
            "description": "Unknown id",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Launch is not scheduled",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Launch id.",
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 1
          }
        ]
      }
    },
    "/astronauts": {
      "get": {
        "tags": [
          "crew"
        ],
        "summary": "List astronauts",
        "operationId": "sp-astronauts",
        "responses": {
          "200": {
            "description": "Astronaut roster",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "role",
            "in": "query",
            "required": false,
            "description": "Filter by role, e.g. pilot.",
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/astronauts/{id}": {
      "get": {
        "tags": [
          "crew"
        ],
        "summary": "Get one astronaut",
        "operationId": "sp-astronaut",
        "responses": {
          "200": {
            "description": "The astronaut",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "404": {
            "description": "Unknown id",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Astronaut id 1–5.",
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 1
          }
        ]
      }
    },
    "/probes/{id}/ping": {
      "get": {
        "tags": [
          "probes"
        ],
        "summary": "Ping a deep-space probe — takes ~3s",
        "operationId": "sp-ping",
        "responses": {
          "200": {
            "description": "Pong, eventually. Great for testing client timeouts.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "404": {
            "description": "Unknown probe",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Probe id 1–3. Light is slow; this endpoint is slower.",
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 1
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "description": "Use qa-admin-token / qa-viewer-token, or a JWT from POST /auth/v1/login."
      },
      "apiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "Cargo demo key: cargo-key-123."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error",
          "message"
        ],
        "properties": {
          "error": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "requestId": {
            "type": "string"
          }
        },
        "additionalProperties": true
      }
    }
  }
}
