# VSCode Schema Validation Setup

This project now has VSCode schema validation configured for OpenAPI YAML files using the Dinner framework schema.

## What's Configured

- **Schema**: `./schemas/schema.json` - Extended OpenAPI 3.0 schema with Dinner framework extensions
- **Target Files**: All `*.yaml` files in the project
- **VSCode Settings**: `.vscode/settings.json` automatically configured

## Supported Extensions

### Dinner Framework Extensions

#### Required for all operations:
- `x-controller`: Controller class path (e.g., `controllers/user.controller`) - **REQUIRED**
- `x-action`: Controller method name (e.g., `create`, `getAll`) - **REQUIRED**

#### Optional:
- `x-middleware`: Middleware chain array (e.g., `["auth.middleware", "validation.middleware"]`)

### Module System
- `module`: Object containing module definitions with `basePath` and `paths`
- Each module must have:
  - `basePath`: Base URL path for the module (e.g., `"/users"`)
  - `paths`: Object with route definitions (same structure as main `paths`)

## Example Valid YAML

```yaml
openapi: 3.0.0
info:
  title: My API
  version: 1.0.0
paths:
  /users:
    get:
      x-controller: controllers/user.controller
      x-action: getAll
      summary: Get all users
      responses:
        '200':
          description: Success
    post:
      x-controller: controllers/user.controller
      x-action: create
      x-middleware: 
        - auth.middleware
      summary: Create user
      responses:
        '201':
          description: Created

# Module system example
module:
  posts:
    basePath: "/posts"
    paths:
      "/":
        get:
          x-controller: controllers/post.controller
          x-action: getAll
          summary: Get all posts
          responses:
            '200':
              description: Success
      "/{id}":
        get:
          x-controller: controllers/post.controller
          x-action: getById
          x-middleware:
            - auth.middleware
          summary: Get post by ID
          parameters:
            - name: id
              in: path
              required: true
              schema:
                type: integer
          responses:
            '200':
              description: Success
            '404':
              description: Post not found
```

## Features

- **Real-time validation** as you type in VSCode
- **Required field validation** - ensures `x-controller` and `x-action` are present
- **Autocomplete** for OpenAPI properties and Dinner extensions
- **Error highlighting** for invalid properties or structure
- **Module validation** - validates module structure and paths
- **Schema-based IntelliSense** with descriptions for all Dinner extensions

## Manual Installation

If you need to install the schema for a different project:

```bash
# Using Stitch CLI (if available)
stitch install ./schemas/schema.json --target "**/*.yaml"

# Or manually add to .vscode/settings.json:
{
  "yaml.schemas": {
    "./schemas/schema.json": ["**/*.yaml"]
  }
}
```

## Validation Examples

✅ **Valid Dinner operation**:
```yaml
get:
  x-controller: controllers/user.controller
  x-action: getAll
  x-middleware: ["auth.middleware"]
  summary: Get all users
  responses:
    '200':
      description: Success
```

❌ **Invalid - missing required fields**:
```yaml
get:
  # Error: missing required x-controller and x-action
  summary: Get all users
  responses:
    '200':
      description: Success
```

## Requirements

- VSCode with "YAML" extension by Red Hat
- Local `schemas/schema.json` file in project
