{
  "openapi": "3.1.0",
  "info": {
    "title": "Superhero API",
    "version": "1.0",
    "description": "Original heroes and villains with powers, teams and nemeses. Practice nested resources (/heroes/{id}/nemesis), filtering and role-based auth."
  },
  "servers": [
    {
      "url": "https://funapi.dev/api/superheroes/v1"
    }
  ],
  "tags": [
    {
      "name": "heroes",
      "description": "capes, powers and their sworn enemies"
    }
  ],
  "paths": {
    "/heroes": {
      "get": {
        "tags": [
          "heroes"
        ],
        "summary": "List heroes (paginated, filterable)",
        "operationId": "sh-list",
        "responses": {
          "200": {
            "description": "Paginated hero list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Invalid page",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Page out of range",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "required": false,
            "description": "Page number, default 1.",
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 1
          },
          {
            "name": "power",
            "in": "query",
            "required": false,
            "description": "Filter by power, e.g. light.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "team",
            "in": "query",
            "required": false,
            "description": "Filter by team, e.g. Alpha Squad.",
            "schema": {
              "type": "string"
            }
          }
        ]
      },
      "post": {
        "tags": [
          "heroes"
        ],
        "summary": "Register a new hero",
        "operationId": "sh-post",
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            },
            "headers": {
              "Location": {
                "schema": {
                  "type": "string",
                  "format": "uri-reference"
                }
              }
            }
          },
          "400": {
            "description": "Missing name or power",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "description": "Repeat the same key on retry to get the original response instead of a duplicate.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "power": {
                    "type": "string"
                  },
                  "team": {
                    "type": "string"
                  }
                }
              },
              "example": {
                "name": "Query Queen",
                "power": "finding anything",
                "team": "Freelance"
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ]
      }
    },
    "/heroes/{id}": {
      "get": {
        "tags": [
          "heroes"
        ],
        "summary": "Get one hero",
        "operationId": "sh-get",
        "responses": {
          "200": {
            "description": "The hero",
            "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": "Hero id 1–8.",
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 1
          }
        ]
      },
      "delete": {
        "tags": [
          "heroes"
        ],
        "summary": "Retire a hero",
        "operationId": "sh-del",
        "responses": {
          "204": {
            "description": "Retired"
          },
          "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"
                }
              }
            }
          },
          "412": {
            "description": "If-Match does not match current version",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Hero id. Viewer token → 403.",
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 4
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": false,
            "description": "Optimistic concurrency check. Mismatch → 412.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ]
      }
    },
    "/heroes/{id}/nemesis": {
      "get": {
        "tags": [
          "heroes"
        ],
        "summary": "Get a hero's nemesis (nested resource)",
        "operationId": "sh-nem",
        "responses": {
          "200": {
            "description": "The nemesis",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "404": {
            "description": "Unknown hero or no nemesis",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Try 3 — Aqua Comet has no nemesis → 404.",
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 1
          }
        ]
      }
    },
    "/heroes/versus": {
      "post": {
        "tags": [
          "heroes"
        ],
        "summary": "Simulate a fight between two heroes",
        "operationId": "sh-versus",
        "responses": {
          "201": {
            "description": "Fight resolved, random winner",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            },
            "headers": {
              "Location": {
                "schema": {
                  "type": "string",
                  "format": "uri-reference"
                }
              }
            }
          },
          "400": {
            "description": "Same hero twice or unknown id",
            "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": {
                  "heroAId": {
                    "type": "number"
                  },
                  "heroBId": {
                    "type": "number"
                  }
                }
              },
              "example": {
                "heroAId": 1,
                "heroBId": 3
              }
            }
          }
        },
        "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
      }
    }
  }
}
