Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/sync-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Sync Docs

on:
push:
branches: [main]
paths:
- 'docs/**'

jobs:
notify-docs-repo:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.DOCS_TOKEN }}
repository: cortexphp/docs
event-type: docs-updated
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
## Features

- 🏗️ **Fluent Builder API** - Build JSON Schemas using an intuitive fluent interface
- 📝 **Multi-Version Support** - Support for JSON Schema Draft-07, Draft 2019-09, and Draft 2020-12
- 📝 **Multi-Version Support** - Support for JSON Schema Draft-06, Draft-07, Draft 2019-09, and Draft 2020-12
- ✅ **Validation** - Validate data against schemas with detailed error messages
- 🤝 **Conditional Schemas** - Support for if/then/else, allOf, anyOf, and not conditions
- 🔄 **Reflection** - Generate schemas from PHP Classes, Enums and Closures
Expand All @@ -24,7 +24,8 @@ This package supports multiple JSON Schema specification versions with automatic

- **Draft 2020-12** - (Default) Latest version with `prefixItems`, dynamic references, and format vocabularies
- **Draft 2019-09** - Adds advanced features like `$defs`, `unevaluatedProperties`, `deprecated`
- **Draft-07** (2018) - Legacy version for maximum compatibility
- **Draft-07** (2018) - Legacy version with broad tool compatibility
- **Draft-06** (2017) - Legacy version for maximum compatibility with older tooling

## Requirements

Expand Down
41 changes: 21 additions & 20 deletions docs/json-schema/advanced/string-formats.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -173,27 +173,28 @@ $userProfileSchema->isValid($validProfile); // true

## Format Support by Version

| Format | Draft-07 | Draft 2019-09 | Draft 2020-12 | Description |
|--------|----------|---------------|---------------|-------------|
| `Email` | ✅ | ✅ | ✅ | Standard email address |
| `Uri` | ✅ | ✅ | ✅ | URI reference |
| `UriReference` | ✅ | ✅ | ✅ | URI reference (relative or absolute) |
| `Hostname` | ✅ | ✅ | ✅ | Internet hostname |
| `Ipv4` | ✅ | ✅ | ✅ | IPv4 address |
| `Ipv6` | ✅ | ✅ | ✅ | IPv6 address |
| `Date` | ✅ | ✅ | ✅ | Full date |
| `Time` | ✅ | ✅ | ✅ | Time |
| `DateTime` | ✅ | ✅ | ✅ | Date and time |
| `JsonPointer` | ✅ | ✅ | ✅ | JSON Pointer |
| `RelativeJsonPointer` | ✅ | ✅ | ✅ | Relative JSON Pointer |
| `UriTemplate` | ✅ | ✅ | ✅ | URI Template |
| `Regex` | ✅ | ✅ | ✅ | Regular expression pattern |
| Format | Draft-06 | Draft-07 | Draft 2019-09 | Draft 2020-12 | Description |
|--------|----------|----------|---------------|---------------|-------------|
| `Email` | ✅ | ✅ | ✅ | ✅ | Standard email address |
| `Uri` | ✅ | ✅ | ✅ | ✅ | URI reference |
| `UriReference` | ✅ | ✅ | ✅ | ✅ | URI reference (relative or absolute) |
| `Hostname` | ✅ | ✅ | ✅ | ✅ | Internet hostname |
| `Ipv4` | ✅ | ✅ | ✅ | ✅ | IPv4 address |
| `Ipv6` | ✅ | ✅ | ✅ | ✅ | IPv6 address |
| `Date` | ❌ | ✅ | ✅ | ✅ | Full date |
| `Time` | ❌ | ✅ | ✅ | ✅ | Time |
| `DateTime` | ✅ | ✅ | ✅ | ✅ | Date and time |
| `JsonPointer` | ✅ | ✅ | ✅ | ✅ | JSON Pointer |
| `RelativeJsonPointer` | ❌ | ✅ | ✅ | ✅ | Relative JSON Pointer |
| `UriTemplate` | ✅ | ✅ | ✅ | ✅ | URI Template |
| `Regex` | ❌ | ✅ | ✅ | ✅ | Regular expression pattern |
| `IdnEmail` | ❌ | ✅ | ✅ | ✅ | Internationalized email |
| `IdnHostname` | ❌ | ✅ | ✅ | ✅ | Internationalized hostname |
| `Iri` | ❌ | ✅ | ✅ | ✅ | Internationalized URI |
| `IriReference` | ❌ | ✅ | ✅ | ✅ | IRI reference |
| **Draft 2019-09+** |
| `Duration` | ❌ | ✅ | ✅ | ISO 8601 duration |
| `Uuid` | ❌ | ✅ | ✅ | UUID string |
| `IdnEmail` | ❌ | ✅ | ✅ | Internationalized email |
| `Iri` | ❌ | ✅ | ✅ | Internationalized URI |
| `IriReference` | ❌ | ✅ | ✅ | IRI reference |
| `Duration` | ❌ | ❌ | ✅ | ✅ | ISO 8601 duration |
| `Uuid` | ❌ | ❌ | ✅ | ✅ | UUID string |

## Common Use Cases

Expand Down
2 changes: 1 addition & 1 deletion docs/json-schema/installation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ icon: 'terminal'
use Cortex\JsonSchema\Enums\SchemaVersion;

// Override default version (if needed)
Schema::setDefaultVersion(SchemaVersion::Draft_07); // For maximum compatibility
Schema::setDefaultVersion(SchemaVersion::Draft_06); // For maximum compatibility
// or
Schema::setDefaultVersion(SchemaVersion::Draft_2019_09); // For balanced features
```
Expand Down
26 changes: 13 additions & 13 deletions docs/json-schema/introduction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ icon: 'book-open'
href="/json-schema/versions"
icon="layers"
>
Support for JSON Schema Draft-07, Draft 2019-09, and Draft 2020-12 with automatic feature validation.
Support for JSON Schema Draft-06, Draft-07, Draft 2019-09, and Draft 2020-12 with automatic feature validation.
</Card>
<Card
title="Data Validation"
Expand Down Expand Up @@ -157,17 +157,17 @@ The package automatically validates feature compatibility with your chosen JSON
</Warning>

<Tip>
The package defaults to Draft 2020-12 for the latest features. Use Draft-07 for maximum compatibility with older tools, or Draft 2019-09 for a balance of features and compatibility.
The package defaults to Draft 2020-12 for the latest features. Use Draft-06 for maximum compatibility with older tools, or Draft 2019-09 for a balance of features and compatibility.
</Tip>

| Feature | Draft-07 | Draft 2019-09 | Draft 2020-12 |
|---------|----------|---------------|---------------|
| Basic validation | ✅ | ✅ | ✅ |
| Conditionals | ✅ | ✅ | ✅ |
| Basic formats | ✅ | ✅ | ✅ |
| `deprecated` | ❌ | ✅ | ✅ |
| `$defs` | ❌ | ✅ | ✅ |
| `minContains`/`maxContains` | ❌ | ✅ | ✅ |
| `unevaluatedProperties` | ❌ | ✅ | ✅ |
| `dependentSchemas` | ❌ | ✅ | ✅ |
| `prefixItems` | ❌ | ❌ | ✅ |
| Feature | Draft-06 | Draft-07 | Draft 2019-09 | Draft 2020-12 |
|---------|----------|----------|---------------|---------------|
| Basic validation | ✅ | ✅ | ✅ | ✅ |
| Conditionals | ❌ | ✅ | ✅ | ✅ |
| Basic formats | ✅ | ✅ | ✅ | ✅ |
| `deprecated` | ❌ | ❌ | ✅ | ✅ |
| `$defs` | ❌ | ❌ | ✅ | ✅ |
| `minContains`/`maxContains` | ❌ | ❌ | ✅ | ✅ |
| `unevaluatedProperties` | ❌ | ❌ | ✅ | ✅ |
| `dependentSchemas` | ❌ | ❌ | ✅ | ✅ |
| `prefixItems` | ❌ | ❌ | ❌ | ✅ |
4 changes: 2 additions & 2 deletions docs/json-schema/quickstart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ $modernSchema = Schema::string('field')
->comment('Use newField instead');

// Override default version if needed
Schema::setDefaultVersion(SchemaVersion::Draft_07); // For maximum compatibility
Schema::setDefaultVersion(SchemaVersion::Draft_06); // For maximum compatibility
```

## Common Validation Patterns
Expand Down Expand Up @@ -322,7 +322,7 @@ Schema::setDefaultVersion(SchemaVersion::Draft_07); // For maximum compatibility
->comment('Use new_field instead');

// Override default version if needed for compatibility
Schema::setDefaultVersion(SchemaVersion::Draft_07);
Schema::setDefaultVersion(SchemaVersion::Draft_06);
```

<Warning>
Expand Down
70 changes: 62 additions & 8 deletions docs/json-schema/schema-types/string.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -129,23 +129,73 @@ $timeSchema = Schema::string('appointment_time')
| `Hostname` | Internet hostname | `example.com` |
| `Ipv4` | IPv4 address | `192.168.1.1` |
| `Ipv6` | IPv6 address | `2001:db8::1` |
| `Date` | Full date (RFC 3339) | `2023-12-25` |
| `Time` | Time (RFC 3339) | `14:30:00` |
| `Date` | Full date (RFC 3339) | `2023-12-25` |
| `Time` | Time (RFC 3339) | `14:30:00` |
| `DateTime` | Date-time (RFC 3339) | `2023-12-25T14:30:00Z` |
| `Duration` | Duration (ISO 8601)* | `P1Y2M3DT4H5M6S` |
| `Uuid` | UUID string* | `123e4567-e89b-12d3-a456-426614174000` |
| `JsonPointer` | JSON Pointer | `/users/123/name` |
| `RelativeJsonPointer` | Relative JSON Pointer | `1/name` |
| `RelativeJsonPointer` | Relative JSON Pointer | `1/name` |
| `UriTemplate` | URI Template | `/users/{id}` |
| `IdnEmail` | Internationalized email | `用户@example.com` |
| `IdnHostname` | Internationalized hostname | `例え.テスト` |
| `Iri` | Internationalized URI | `https://例え.テスト` |
| `IriReference` | IRI reference | `//例え.テスト/path` |
| `Regex`† | Regular expression pattern | `^[a-zA-Z0-9_]+$` |
| `IdnEmail`† | Internationalized email | `用户@example.com` |
| `IdnHostname`† | Internationalized hostname | `例え.テスト` |
| `Iri`† | Internationalized URI | `https://例え.テスト` |
| `IriReference`† | IRI reference | `//例え.テスト/path` |

<Note>
Formats marked with * require JSON Schema Draft 2019-09 or later.
Formats marked with require JSON Schema Draft-07 or later. Formats marked with * require Draft 2019-09 or later.
</Note>

## Content Annotations

Describe encoded content carried by a string using `contentEncoding` and `contentMediaType`, and (optionally) validate the decoded content with `contentSchema`:

```php
use Cortex\JsonSchema\Enums\SchemaVersion;
use Cortex\JsonSchema\Enums\SchemaFormat;

$payloadSchema = Schema::string('payload', SchemaVersion::Draft_2019_09)
->contentEncoding('base64')
->contentMediaType('application/json')
->contentSchema(
Schema::object()
->properties(
Schema::string('event_id')->required(),
Schema::string('type')->required(),
Schema::string('created_at')->format(SchemaFormat::DateTime)->required(),
Schema::object('data')
->properties(
Schema::string('user_id')->required(),
Schema::string('email')->format(SchemaFormat::Email),
)
->required(),
),
);
```

<Note>
`contentSchema` requires JSON Schema Draft 2019-09 or later. `contentEncoding` and `contentMediaType` are available in all supported versions.
</Note>

Validation examples:

```php
$payloadSchema->isValid(base64_encode(
json_encode([
'event_id' => 'evt_123',
'type' => 'user.created',
'created_at' => '2024-03-14T12:00:00Z',
'data' => [
'user_id' => 'usr_1',
'email' => 'ada@example.com',
],
], JSON_THROW_ON_ERROR),
)); // true (base64 encoded string value and matches the content schema)

$payloadSchema->isValid(123); // false (not a string)
```

## Enumeration Values

Restrict strings to a specific set of allowed values:
Expand Down Expand Up @@ -195,6 +245,10 @@ $passwordSchema = Schema::string('password')
->pattern('(?=.*[a-z])(?=.*[A-Z])(?=.*\d)');
```

<Note>
Read-only and write-only annotations require JSON Schema Draft-07 or later.
</Note>

## Complex Example

Here's a comprehensive example combining multiple string validation features:
Expand Down
41 changes: 22 additions & 19 deletions docs/json-schema/versions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ icon: 'history'
This package supports multiple JSON Schema specification versions with automatic feature validation to ensure compatibility.

<CardGroup cols={1}>
<Card title="Draft-06 (2017)" icon="shield-check">
Legacy version for maximum compatibility with older tools. Includes core validation features and basic constraints.
</Card>
<Card title="Draft-07 (2018)" icon="shield-check">
Legacy version for maximum compatibility across tools and libraries. Includes core validation features and basic conditionals.
Legacy version with broad compatibility across tools and libraries. Includes core validation features and conditionals.
</Card>
<Card title="Draft 2019-09" icon="star">
Adds advanced features like `$defs`, `unevaluatedProperties`, `deprecated`, and enhanced array validation.
Expand Down Expand Up @@ -96,28 +99,28 @@ $arraySchema = Schema::array('items', SchemaVersion::Draft_07)

## Feature Support Matrix

| Feature | Draft-07 | Draft 2019-09 | Draft 2020-12 | Description |
|---------|----------|---------------|---------------|-------------|
| Feature | Draft-06 | Draft-07 | Draft 2019-09 | Draft 2020-12 | Description |
|---------|----------|----------|---------------|---------------|-------------|
| **Core Validation** |
| `minLength`, `maxLength`, `pattern` | ✅ | ✅ | ✅ | Basic string validation |
| `minimum`, `maximum`, `multipleOf` | ✅ | ✅ | ✅ | Numeric constraints |
| `minItems`, `maxItems`, `uniqueItems` | ✅ | ✅ | ✅ | Array validation |
| `properties`, `required`, `additionalProperties` | ✅ | ✅ | ✅ | Object validation |
| `minLength`, `maxLength`, `pattern` | ✅ | ✅ | ✅ | ✅ | Basic string validation |
| `minimum`, `maximum`, `multipleOf` | ✅ | ✅ | ✅ | ✅ | Numeric constraints |
| `minItems`, `maxItems`, `uniqueItems` | ✅ | ✅ | ✅ | ✅ | Array validation |
| `properties`, `required`, `additionalProperties` | ✅ | ✅ | ✅ | ✅ | Object validation |
| **Conditionals** |
| `if`/`then`/`else` | ✅ | ✅ | ✅ | Conditional schemas |
| `allOf`, `anyOf`, `oneOf`, `not` | ✅ | ✅ | ✅ | Logical combinations |
| `if`/`then`/`else` | ❌ | ✅ | ✅ | ✅ | Conditional schemas |
| `allOf`, `anyOf`, `oneOf`, `not` | ✅ | ✅ | ✅ | ✅ | Logical combinations |
| **Advanced Features** |
| `deprecated` | ❌ | ✅ | ✅ | Property deprecation |
| `$defs` (replaces `definitions`) | ❌ | ✅ | ✅ | Schema definitions |
| `minContains`, `maxContains` | ❌ | ✅ | ✅ | Array contains validation |
| `unevaluatedProperties`, `unevaluatedItems` | ❌ | ✅ | ✅ | Strict validation |
| `dependentSchemas` | ❌ | ✅ | ✅ | Property dependencies |
| `deprecated` | ❌ | ❌ | ✅ | ✅ | Property deprecation |
| `$defs` (replaces `definitions`) | ❌ | ❌ | ✅ | ✅ | Schema definitions |
| `minContains`, `maxContains` | ❌ | ❌ | ✅ | ✅ | Array contains validation |
| `unevaluatedProperties`, `unevaluatedItems` | ❌ | ❌ | ✅ | ✅ | Strict validation |
| `dependentSchemas` | ❌ | ❌ | ✅ | ✅ | Property dependencies |
| **Draft 2020-12 Only** |
| `prefixItems` | ❌ | ❌ | ✅ | Tuple validation |
| Dynamic references (`$dynamicRef`) | ❌ | ❌ | ✅ | Dynamic schema refs |
| `prefixItems` | ❌ | ❌ | ❌ | ✅ | Tuple validation |
| Dynamic references (`$dynamicRef`) | ❌ | ❌ | ❌ | ✅ | Dynamic schema refs |
| **Formats** |
| `email`, `uri`, `date-time` | ✅ | ✅ | ✅ | Basic formats |
| `duration`, `uuid` | ❌ | ✅ | ✅ | Extended formats |
| `email`, `uri`, `date-time` | ✅ | ✅ | ✅ | ✅ | Basic formats |
| `duration`, `uuid` | ❌ | ❌ | ✅ | ✅ | Extended formats |

## Version-Appropriate Output

Expand Down Expand Up @@ -181,5 +184,5 @@ echo $feature->getMinimumVersion()->name; // "Draft201909"
```

<Tip>
The package defaults to Draft 2020-12 for the latest features. Use Draft-07 for maximum compatibility with older tools if needed.
The package defaults to Draft 2020-12 for the latest features. Use Draft-06 for maximum compatibility with older tools if needed.
</Tip>
Loading