{
  "openapi": "3.1.0",
  "info": {
    "title": "Dino Park API",
    "version": "1.0",
    "description": "A fictional dinosaur park: creatures, enclosure capacity, and a breach simulator. Practice CRUD, Bearer auth, nested resources, capacity conflicts (409), pagination and optimistic concurrency."
  },
  "servers": [
    {
      "url": "https://funapi.dev/api/dinopark/v1"
    }
  ],
  "tags": [
    {
      "name": "dinosaurs",
      "description": "seven residents, one very hungry rex"
    },
    {
      "name": "enclosures",
      "description": "capacity matters"
    },
    {
      "name": "incidents",
      "description": "breach reports, growing list"
    }
  ],
  "paths": {
    "/dinosaurs": {
      "get": {
        "tags": [
          "dinosaurs"
        ],
        "summary": "List dinosaurs (paginated, filter by diet)",
        "operationId": "dp-list",
        "responses": {
          "200": {
            "description": "Paginated dinosaur list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Invalid page or diet",
            "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": "diet",
            "in": "query",
            "required": false,
            "description": "\"carnivore\" or \"herbivore\".",
            "schema": {
              "type": "string"
            }
          }
        ]
      },
      "post": {
        "tags": [
          "dinosaurs"
        ],
        "summary": "Add a dinosaur (409 if enclosure is at capacity)",
        "operationId": "dp-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/species or unknown enclosureId",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Enclosure is at capacity",
            "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"
                  },
                  "species": {
                    "type": "string"
                  },
                  "diet": {
                    "type": "string"
                  },
                  "enclosureId": {
                    "type": "number"
                  },
                  "dangerLevel": {
                    "type": "string"
                  }
                }
              },
              "example": {
                "name": "Indominus",
                "species": "Indominus rex",
                "diet": "carnivore",
                "enclosureId": 1,
                "dangerLevel": "extreme"
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ]
      }
    },
    "/dinosaurs/{id}": {
      "get": {
        "tags": [
          "dinosaurs"
        ],
        "summary": "Get one dinosaur",
        "operationId": "dp-get",
        "responses": {
          "200": {
            "description": "The dinosaur",
            "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": "Dinosaur id. Try 999 for a 404.",
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 1
          }
        ]
      },
      "put": {
        "tags": [
          "dinosaurs"
        ],
        "summary": "Update a dinosaur",
        "operationId": "dp-put",
        "responses": {
          "200": {
            "description": "Updated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Empty body / invalid JSON",
            "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 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": "Dinosaur id to update.",
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 5
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": false,
            "description": "Optimistic concurrency: pass a prior etag (e.g. v1). Mismatch → 412.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "dangerLevel": {
                    "type": "string"
                  }
                }
              },
              "example": {
                "dangerLevel": "high"
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ]
      },
      "delete": {
        "tags": [
          "dinosaurs"
        ],
        "summary": "Relocate a dinosaur off-site",
        "operationId": "dp-del",
        "responses": {
          "204": {
            "description": "Relocated"
          },
          "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": "Dinosaur id. Viewer token → 403.",
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 6
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": false,
            "description": "Optimistic concurrency check. Mismatch → 412.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ]
      }
    },
    "/dinosaurs/{id}/enclosure": {
      "get": {
        "tags": [
          "dinosaurs"
        ],
        "summary": "Get a dinosaur's enclosure (nested resource)",
        "operationId": "dp-enclosure",
        "responses": {
          "200": {
            "description": "The enclosure",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "404": {
            "description": "Unknown dinosaur",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Dinosaur id.",
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "example": 1
          }
        ]
      }
    },
    "/enclosures": {
      "get": {
        "tags": [
          "enclosures"
        ],
        "summary": "List all enclosures with current occupancy",
        "operationId": "dp-enclosures",
        "responses": {
          "200": {
            "description": "Enclosure list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/incidents/breach": {
      "post": {
        "tags": [
          "incidents"
        ],
        "summary": "Simulate a containment breach (random dinosaur & severity)",
        "operationId": "dp-breach",
        "responses": {
          "201": {
            "description": "Incident logged",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            },
            "headers": {
              "Location": {
                "schema": {
                  "type": "string",
                  "format": "uri-reference"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ]
      }
    },
    "/incidents": {
      "get": {
        "tags": [
          "incidents"
        ],
        "summary": "List incident history (empty until you POST a breach)",
        "operationId": "dp-incidents",
        "responses": {
          "200": {
            "description": "Incident list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    }
  },
  "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
      }
    }
  }
}
