Skip to content
This documentation is in construction.

Export Schemas

One of the main strengths of epsicube/schemas is that the same schema can be exported to multiple targets. The package ships with four built-in exporters and shortcut methods on Schema.

Use JSON Schema when you need a portable machine-readable contract for APIs, front-end consumers, external tooling, or documentation.

use Epsicube\Schemas\Exporters\JsonSchemaExporter;
$jsonSchema = $schema->export(new JsonSchemaExporter);
// Shortcut
$jsonSchema = $schema->toJsonSchema();

What the exporter does:

  • wraps the root schema as an object
  • includes titles and descriptions when available
  • includes defaults when available
  • marks non-optional fields as required
  • sets additionalProperties to false at the root
  • adapts nullable fields to valid JSON Schema output

For example, a nullable string becomes a type array that includes "null", and a nullable enum gets null added to its allowed values.

Use Filament export to generate forms or infolists from the same schema used for validation.

use Filament\Support\Enums\Operation;
$formComponents = $schema->toFilamentComponents(Operation::Create);
$editComponents = $schema->toFilamentComponents(Operation::Edit);
$infolistComponents = $schema->toFilamentComponents(Operation::View);

You can also customize every generated component:

use Filament\Support\Enums\Operation;
$components = $schema->toFilamentComponents(
Operation::Edit,
function ($property, ?string $name, $component): void {
$component->columnSpanFull();
}
);

What the exporter applies globally when possible:

  • default values on non-view operations
  • required state for non-optional non-nullable fields
  • labels from property titles
  • helper text or hints from property descriptions

Use prompt export to build interactive CLI configuration flows from the schema:

$result = $schema->toExecutedPrompts();

You can pass current values to prefill the interaction:

$result = $schema->toExecutedPrompts([
'endpoint' => '/rpc/v2/endpoint',
]);

This exporter is used by Epsicube’s interactive option management commands. It is especially useful when you want a typed CLI wizard without duplicating field definitions.

Property-specific behaviors include:

  • booleans map to confirm or select prompts
  • enums map to select prompts
  • objects build nested forms
  • arrays provide add, edit, delete, and finish interactions

Use Laravel validation export when you need a validator instance:

use Epsicube\Schemas\Exporters\LaravelValidatorExporter;
$validator = $schema->export(new LaravelValidatorExporter($payload));
// Shortcut
$validator = $schema->toValidator($payload);

In most cases, the higher-level API is simpler:

$validated = $schema->validated($payload);

What the validator exporter handles:

  • present for non-optional fields
  • nullable for nullable fields
  • nested child rule generation for objects and arrays
  • prohibition or validation of unknown object keys through additionalProperties()
  • support for prepended rules such as bail

To target another output format, implement Epsicube\Schemas\Contracts\SchemaExporter and pass your exporter to Schema::export(...).

use Epsicube\Schemas\Contracts\SchemaExporter;
use Epsicube\Schemas\Schema;
class MyExporter implements SchemaExporter
{
public function exportSchema(Schema $schema): mixed
{
// Convert $schema to your target format.
}
}
$result = $schema->export(new MyExporter);

This is the right extension point when you want to generate another UI layer, API contract, cache artifact, or adapter on top of the same schema model.