# JSON Validator Service

HTTP-Microservice zur Validierung von JSON-Daten gegen JSON-Schema-Definitionen (PHP 8.5 + Apache).

## Features

- Validierung mit Inline-Schema (`schema` im Request)
- Validierung mit Datei-Schema (`schemaId` verweist auf Schema unter `/schemas`)
- Health-Endpoint `/health`
- Begrenzte Fehlerausgabe (max. 20 Fehler)

## API

### GET /health

```bash
curl http://localhost:8085/health
```

Response:

```json
{
  "ok": true,
  "service": "json-validator-service"
}
```

### POST /validate (mit Inline-Schema)

```bash
curl -X POST http://localhost:8085/validate \
  -H "Content-Type: application/json" \
  -d '{
    "data": {"name": "Alice"},
    "schema": {
      "type": "object",
      "properties": {
        "name": {"type": "string"}
      },
      "required": ["name"]
    }
  }'
```

### POST /validate (mit Datei-Schema)

```bash
curl -X POST http://localhost:8085/validate \
  -H "Content-Type: application/json" \
  -d '{
    "data": {"name": "Alice"},
    "schemaId": "user-v0.0.1.json"
  }'
```

Schema-Dateien liegen im Container unter `/var/www/html/schemas` (per Volume gemountet, z. B. `./contracts/schemas:/var/www/html/schemas:ro`).

## Response-Format

Erfolg:

```json
{
  "ok": true,
  "valid": true
}
```

Fehler:

```json
{
  "ok": false,
  "valid": false,
  "errors": [
    {
      "instanceLocation": "/name",
      "keywordLocation": "/properties/name/type",
      "error": "Value is not a string"
    }
  ]
}
```

## Build & Start

```bash
docker compose up --build validator-php
```

Service läuft dann auf `http://localhost:8085`.

## Projektstruktur

- `src/Validator.php` – Hauptlogik
- `public/index.php` – Entry Point
- `composer.json` – Abhängigkeiten (`opis/json-schema`)
- `Dockerfile` – PHP 8.5 + Apache
- `compose.yml` – Service-Definition mit Healthcheck

## Lizenz

Proprietär (mlxs/json-validator-service)





Nach dem Kopieren der Datei muss bei einer lokalen Composer-Installation einmal ausgeführt werden:
composer dump-autoload

Beim Docker-Build wird der Autoloader automatisch neu erzeugt:
docker compose up -d --build

 FEHLER nach RFC 7807 



ACHTUNG, weil contracts ausserhalb der Docker-Build-Kontexts liegt, muss  das Build aus dem Projekt-Ordner herus erfolgen:

```bash
docker build -f services/php/Dockerfile -t json-validator-php .
```

Docker Container starten
```bash
docker run --name validator-php -p 8085:80 json-validator-php
```
