{
  "openapi": "3.1.0",
  "info": {
    "title": "Starfleet API",
    "version": "1.0",
    "description": "Command a small fleet: crew rosters, warp-speed changes with physics-based validation, a breached warp core that refuses orders, and a tribble endpoint that doubles on every GET — a read that mutates, which your test suite should absolutely complain about."
  },
  "servers": [
    {
      "url": "https://funapi.dev/api/starfleet/v1"
    }
  ],
  "tags": [
    {
      "name": "ships",
      "description": "the fleet, mostly functional"
    },
    {
      "name": "crew",
      "description": "rosters and redshirts"
    },
    {
      "name": "tribbles",
      "description": "do NOT keep GETting"
    }
  ],
  "paths": {
    "/ships": {
      "get": {
        "tags": [
          "ships"
        ],
        "summary": "List ships, filter by class or status",
        "operationId": "sf-ships",
        "responses": {
          "200": {
            "description": "Fleet list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "class",
            "in": "query",
            "required": false,
            "description": "Constitution, Miranda, Excelsior or Defiant.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "status",
            "in": "query",
            "required": false,
            "description": "active or in-refit.",
            "schema": {
              "type": "string"
            }
          }
        ]
      },
      "post": {
        "tags": [
          "ships"
        ],
        "summary": "Commission a new ship",
        "operationId": "sf-commission",
        "responses": {
          "201": {
            "description": "Ship commissioned",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            },
            "headers": {
              "Location": {
                "schema": {
                  "type": "string",
                  "format": "uri-reference"
                }
              }
            }
          },
          "400": {
            "description": "Missing name or unknown class",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "A ship with that name already exists",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "class": {
                    "type": "string"
                  }
                },
                "required": [
                  "name",
                  "class"
                ],
                "additionalProperties": false
              },
              "example": {
                "name": "USS Unsinkable II",
                "class": "Miranda"
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ]
      }
    },
    "/ships/{id}": {
      "get": {
        "tags": [
          "ships"
        ],
        "summary": "Get one ship",
        "operationId": "sf-ship",
        "responses": {
          "200": {
            "description": "The ship",
            "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": "Ship id 1–4. Ship 4 has a breached warp core.",
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 1
          }
        ]
      }
    },
    "/ships/{id}/warp": {
      "put": {
        "tags": [
          "ships"
        ],
        "summary": "Set warp factor (physics says no above 9.9)",
        "operationId": "sf-warp",
        "responses": {
          "200": {
            "description": "Warp factor set",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Factor not between 0 and 9.9",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Unknown ship",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Warp core breached or ship in refit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Ship id. Ship 4’s core is breached → 409.",
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 1
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "factor": {
                    "type": "integer"
                  }
                },
                "required": [
                  "factor"
                ],
                "additionalProperties": false
              },
              "example": {
                "factor": 5
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ]
      }
    },
    "/crew": {
      "get": {
        "tags": [
          "crew"
        ],
        "summary": "List crew, filter by species or ship",
        "operationId": "sf-crew",
        "responses": {
          "200": {
            "description": "Crew roster",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "species",
            "in": "query",
            "required": false,
            "description": "human, vulcan, klingon, bolian…",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "shipId",
            "in": "query",
            "required": false,
            "description": "Filter by assigned ship.",
            "schema": {
              "type": "integer",
              "format": "int32"
            }
          }
        ]
      },
      "post": {
        "tags": [
          "crew"
        ],
        "summary": "Enlist a crew member",
        "operationId": "sf-enlist",
        "responses": {
          "201": {
            "description": "Welcome aboard",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            },
            "headers": {
              "Location": {
                "schema": {
                  "type": "string",
                  "format": "uri-reference"
                }
              }
            }
          },
          "400": {
            "description": "Missing name/rank",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Unknown shipId",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "rank": {
                    "type": "string"
                  },
                  "species": {
                    "type": "string"
                  },
                  "shipId": {
                    "type": "integer"
                  }
                },
                "required": [
                  "name",
                  "rank",
                  "species",
                  "shipId"
                ],
                "additionalProperties": false
              },
              "example": {
                "name": "Ens. Nova Reyes",
                "rank": "ensign",
                "species": "human",
                "shipId": 1
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ]
      }
    },
    "/crew/{id}": {
      "get": {
        "tags": [
          "crew"
        ],
        "summary": "Get one crew member",
        "operationId": "sf-crewman",
        "responses": {
          "200": {
            "description": "The crew member",
            "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": "Crew id 1–6.",
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 1
          }
        ]
      },
      "delete": {
        "tags": [
          "crew"
        ],
        "summary": "Discharge a crew member (admin only)",
        "operationId": "sf-discharge",
        "responses": {
          "204": {
            "description": "Beamed home safely"
          },
          "401": {
            "description": "Missing or invalid token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Viewer token not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Unknown id",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Crew id. Statistically risky for ensigns in red.",
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 6
          }
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ]
      }
    },
    "/tribbles": {
      "get": {
        "tags": [
          "tribbles"
        ],
        "summary": "Count tribbles — doubles on EVERY read",
        "operationId": "sf-tribbles",
        "responses": {
          "200": {
            "description": "The count, which just doubled. A GET with side effects — find it with your contract tests.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/tribbles/purge": {
      "post": {
        "tags": [
          "tribbles"
        ],
        "summary": "Beam the tribbles away (admin only)",
        "operationId": "sf-purge",
        "responses": {
          "200": {
            "description": "Population reset to 1",
            "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 not allowed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ]
      }
    }
  },
  "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
      }
    }
  }
}
