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
10 changes: 2 additions & 8 deletions src/Ephemeral/EphemeralSection.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,15 @@ public function toJsonSchema(): array

foreach ($this->fieldDefinitions() as $field) {
$properties[$field->name] = $field->toJsonSchemaProperty();

if ($field->required) {
$required[] = $field->name;
}
$required[] = $field->name;
}

$schema = [
'type' => 'object',
'properties' => $properties,
'required' => $required,
];
Comment on lines 60 to 69
Copy link

Copilot AI Mar 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change makes every field required in the generated JSON Schema ($required[] = $field->name;), which contradicts the documented behavior that required: false makes a field optional (typically paired with nullable: true). It also makes FieldDefinition::$required (and the addField(..., bool $required)) ineffective for schema generation. Consider restoring the conditional so only $field->required fields are listed in required (while still always emitting the required key, possibly empty), so the schema matches both docs and the FieldDefinition API.

Copilot uses AI. Check for mistakes.

if ($required !== []) {
$schema['required'] = $required;
}

if ($this->description) {
$schema['description'] = $this->description;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Ephemeral/EphemeralTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Yannelli\Schematic\Ephemeral;

use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Yannelli\Schematic\Compiler;
use Yannelli\Schematic\Contracts\Renderable;
use Yannelli\Schematic\Contracts\SchemaGeneratable;
Expand Down Expand Up @@ -158,7 +159,7 @@ public function toJsonSchemaDocument(): array
{
return [
'$schema' => config('schematic.schema.draft'),
'title' => $this->name,
'title' => Str::snake($this->name),
...$this->toJsonSchema(),
];
}
Expand Down
10 changes: 2 additions & 8 deletions src/Models/Section.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,15 @@ public function toJsonSchema(): array

foreach ($this->field_definitions as $field) {
$properties[$field->name] = $field->toJsonSchemaProperty();

if ($field->required) {
$required[] = $field->name;
}
$required[] = $field->name;
}

$schema = [
'type' => 'object',
'properties' => $properties,
'required' => $required,
];
Comment on lines 65 to 74
Copy link

Copilot AI Mar 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change makes every field required in the generated JSON Schema ($required[] = $field->name;), which contradicts the documented behavior that required: false makes a field optional (typically paired with nullable: true). It also makes FieldDefinition::$required (and the addField(..., bool $required)) ineffective for schema generation. Consider restoring the conditional so only $field->required fields go into required (while still always emitting the required key, possibly as an empty array), so the schema matches both docs and the FieldDefinition API.

Copilot uses AI. Check for mistakes.

if ($required !== []) {
$schema['required'] = $required;
}

if ($this->description) {
$schema['description'] = $this->description;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Models/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Str;
use Yannelli\Schematic\Compiler;
use Yannelli\Schematic\Contracts\Renderable;
use Yannelli\Schematic\Contracts\SchemaGeneratable;
Expand Down Expand Up @@ -150,7 +151,7 @@ public function toJsonSchemaDocument(): array
{
return [
'$schema' => config('schematic.schema.draft'),
'title' => $this->name,
'title' => Str::snake($this->name),
...$this->toJsonSchema(),
];
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/EphemeralSectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
->and($schema['properties'])->toHaveKey('count')
->and($schema['properties']['title']['type'])->toBe('string')
->and($schema['properties']['count']['type'])->toBe('integer')
->and($schema['required'])->toBe(['title'])
->and($schema['required'])->toBe(['title', 'count'])
->and($schema['description'])->toBe('Test section');
});

Expand Down Expand Up @@ -86,7 +86,7 @@
$schema = $section->toJsonSchema();

expect($schema['properties']['notes']['type'])->toBe(['string', 'null'])
->and($schema)->not->toHaveKey('required');
->and($schema['required'])->toBe(['notes']);
});

// ---------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/EphemeralTemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
$doc = $template->toJsonSchemaDocument();

expect($doc)->toHaveKey('$schema')
->and($doc['title'])->toBe('Document')
->and($doc['title'])->toBe('document')
->and($doc['type'])->toBe('object');
});

Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/SchematicServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
$doc = $this->schematic->schemaDocument('doc-svc');

expect($doc)->toHaveKey('$schema')
->and($doc['title'])->toBe('Document');
->and($doc['title'])->toBe('document');
});

// ---------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/SectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
expect($schema['type'])->toBe('object')
->and($schema['properties'])->toHaveKey('title')
->and($schema['properties'])->toHaveKey('optional')
->and($schema['required'])->toBe(['title'])
->and($schema['required'])->toBe(['title', 'optional'])
->and($schema['additionalProperties'])->toBeFalse();
});

Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/TemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
$doc = $template->toJsonSchemaDocument();

expect($doc['$schema'])->toBe('https://json-schema.org/draft/2020-12/schema')
->and($doc['title'])->toBe('Document')
->and($doc['title'])->toBe('document')
->and($doc['type'])->toBe('object');
});

Expand Down
Loading