{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Dinner Framework OpenAPI Schema",
  "description": "JSON Schema for OpenAPI 3.0.3 specification with Dinner framework extensions",
  "type": "object",
  "required": [],
  "properties": {
    "openapi": {
      "type": "string",
      "pattern": "^3\\.0\\.[0-9]+(\\.[0-9]+)*$",
      "description": "The OpenAPI specification version"
    },
    "info": {
      "type": "object",
      "required": ["title", "version"],
      "properties": {
        "title": {
          "type": "string",
          "description": "The title of the API"
        },
        "version": {
          "type": "string",
          "description": "The version of the API"
        },
        "description": {
          "type": "string",
          "description": "A description of the API"
        },
        "contact": {
          "type": "object",
          "properties": {
            "name": { "type": "string" },
            "url": { "type": "string" },
            "email": { "type": "string" }
          }
        },
        "license": {
          "type": "object",
          "required": ["name"],
          "properties": {
            "name": { "type": "string" },
            "url": { "type": "string" }
          }
        }
      }
    },
    "servers": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["url"],
        "properties": {
          "url": {
            "type": "string",
            "description": "A URL to the target host"
          },
          "description": {
            "type": "string",
            "description": "An optional string describing the host"
          }
        }
      }
    },
    "paths": {
      "type": "object",
      "patternProperties": {
        "^/": {
          "type": "object",
          "properties": {
            "get": { "$ref": "#/definitions/operation" },
            "post": { "$ref": "#/definitions/operation" },
            "put": { "$ref": "#/definitions/operation" },
            "delete": { "$ref": "#/definitions/operation" },
            "patch": { "$ref": "#/definitions/operation" },
            "head": { "$ref": "#/definitions/operation" },
            "options": { "$ref": "#/definitions/operation" },
            "trace": { "$ref": "#/definitions/operation" },
            "parameters": {
              "type": "array",
              "items": { "$ref": "#/definitions/parameter" }
            }
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    },
    "module": {
      "type": "object",
      "description": "Dinner framework: Module definitions with base paths and sub-paths",
      "patternProperties": {
        "^[a-zA-Z0-9_-]+$": {
          "type": "object",
          "required": ["basePath", "paths"],
          "properties": {
            "basePath": {
              "type": "string",
              "pattern": "^/",
              "description": "Base path for all routes in this module"
            },
            "paths": {
              "type": "object",
              "patternProperties": {
                "^/": {
                  "type": "object",
                  "properties": {
                    "get": { "$ref": "#/definitions/operation" },
                    "post": { "$ref": "#/definitions/operation" },
                    "put": { "$ref": "#/definitions/operation" },
                    "delete": { "$ref": "#/definitions/operation" },
                    "patch": { "$ref": "#/definitions/operation" },
                    "head": { "$ref": "#/definitions/operation" },
                    "options": { "$ref": "#/definitions/operation" },
                    "trace": { "$ref": "#/definitions/operation" },
                    "parameters": {
                      "type": "array",
                      "items": { "$ref": "#/definitions/parameter" }
                    }
                  },
                  "additionalProperties": false
                }
              },
              "additionalProperties": false
            }
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    },
    "components": {
      "type": "object",
      "properties": {
        "schemas": {
          "type": "object",
          "patternProperties": {
            "^[a-zA-Z0-9\\.\\-_]+$": {
              "$ref": "#/definitions/schema"
            }
          }
        },
        "responses": {
          "type": "object",
          "patternProperties": {
            "^[a-zA-Z0-9\\.\\-_]+$": {
              "$ref": "#/definitions/response"
            }
          }
        },
        "parameters": {
          "type": "object",
          "patternProperties": {
            "^[a-zA-Z0-9\\.\\-_]+$": {
              "$ref": "#/definitions/parameter"
            }
          }
        },
        "securitySchemes": {
          "type": "object",
          "patternProperties": {
            "^[a-zA-Z0-9\\.\\-_]+$": {
              "$ref": "#/definitions/securityScheme"
            }
          }
        }
      }
    },
    "security": {
      "type": "array",
      "items": {
        "type": "object"
      }
    },
    "tags": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["name"],
        "properties": {
          "name": { "type": "string" },
          "description": { "type": "string" }
        }
      }
    }
  },
  "definitions": {
    "operation": {
      "type": "object",
      "required": ["x-controller", "x-action"],
      "properties": {
        "summary": {
          "type": "string",
          "description": "A brief summary of what the operation does"
        },
        "description": {
          "type": "string",
          "description": "A verbose explanation of the operation behavior"
        },
        "operationId": {
          "type": "string",
          "description": "Unique string used to identify the operation"
        },
        "parameters": {
          "type": "array",
          "items": { "$ref": "#/definitions/parameter" }
        },
        "requestBody": {
          "$ref": "#/definitions/requestBody"
        },
        "responses": {
          "type": "object",
          "patternProperties": {
            "^[1-5][0-9][0-9]$|^default$": {
              "$ref": "#/definitions/response"
            }
          }
        },
        "tags": {
          "type": "array",
          "items": { "type": "string" }
        },
        "security": {
          "type": "array",
          "items": { "type": "object" }
        },
        "x-controller": {
          "type": "string",
          "description": "Dinner framework: Controller class path (e.g., 'controllers/user.controller')"
        },
        "x-action": {
          "type": "string",
          "description": "Dinner framework: Controller method name (e.g., 'create', 'getAll')"
        },
        "x-middleware": {
          "type": "array",
          "items": { "type": "string" },
          "description": "Dinner framework: Middleware chain to apply before controller action"
        }
      },
      "additionalProperties": false
    },
    "response": {
      "type": "object",
      "required": ["description"],
      "properties": {
        "description": {
          "type": "string",
          "description": "A description of the response"
        },
        "content": {
          "type": "object",
          "patternProperties": {
            "^[a-zA-Z0-9][a-zA-Z0-9!#$&\\-\\^_]*\\/[a-zA-Z0-9][a-zA-Z0-9!#$&\\-\\^_]*$": {
              "type": "object",
              "properties": {
                "schema": { "$ref": "#/definitions/schema" }
              }
            }
          }
        },
        "headers": {
          "type": "object",
          "patternProperties": {
            "^[a-zA-Z0-9\\.\\-_]+$": {
              "type": "object",
              "properties": {
                "description": { "type": "string" },
                "schema": { "$ref": "#/definitions/schema" }
              }
            }
          }
        }
      }
    },
    "parameter": {
      "type": "object",
      "required": ["name", "in"],
      "properties": {
        "name": { "type": "string" },
        "in": {
          "type": "string",
          "enum": ["query", "header", "path", "cookie"]
        },
        "description": { "type": "string" },
        "required": { "type": "boolean" },
        "schema": { "$ref": "#/definitions/schema" }
      }
    },
    "requestBody": {
      "type": "object",
      "properties": {
        "description": { "type": "string" },
        "content": {
          "type": "object",
          "patternProperties": {
            "^[a-zA-Z0-9][a-zA-Z0-9!#$&\\-\\^_]*\\/[a-zA-Z0-9][a-zA-Z0-9!#$&\\-\\^_]*$": {
              "type": "object",
              "properties": {
                "schema": { "$ref": "#/definitions/schema" }
              }
            }
          }
        },
        "required": { "type": "boolean" }
      }
    },
    "schema": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": ["null", "boolean", "object", "array", "number", "string", "integer"]
        },
        "properties": {
          "type": "object",
          "patternProperties": {
            "^.*$": { "$ref": "#/definitions/schema" }
          }
        },
        "items": { "$ref": "#/definitions/schema" },
        "required": {
          "type": "array",
          "items": { "type": "string" }
        },
        "format": { "type": "string" },
        "enum": {
          "type": "array"
        },
        "minimum": { "type": "number" },
        "maximum": { "type": "number" },
        "minLength": { "type": "integer", "minimum": 0 },
        "maxLength": { "type": "integer", "minimum": 0 },
        "pattern": { "type": "string" },
        "description": { "type": "string" },
        "example": {},
        "default": {},
        "$ref": { "type": "string" }
      }
    },
    "securityScheme": {
      "type": "object",
      "required": ["type"],
      "properties": {
        "type": {
          "type": "string",
          "enum": ["apiKey", "http", "oauth2", "openIdConnect"]
        },
        "description": { "type": "string" },
        "name": { "type": "string" },
        "in": {
          "type": "string",
          "enum": ["query", "header", "cookie"]
        },
        "scheme": { "type": "string" },
        "bearerFormat": { "type": "string" }
      }
    }
  }
}

