Json Schema transformer is done
Form builder stuck on infinite recurrsion
This commit is contained in:
+2
-1
@@ -14,7 +14,8 @@
|
|||||||
"phpoption/phpoption": "^1.9",
|
"phpoption/phpoption": "^1.9",
|
||||||
"spatie/image-optimizer": "^1.6",
|
"spatie/image-optimizer": "^1.6",
|
||||||
"staudenmeir/laravel-cte": "^1.0",
|
"staudenmeir/laravel-cte": "^1.0",
|
||||||
"ext-pdo": "*"
|
"ext-pdo": "*",
|
||||||
|
"opis/json-schema": "^2.3"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpstan/phpstan": "^1.8"
|
"phpstan/phpstan": "^1.8"
|
||||||
|
|||||||
Generated
+195
-1
@@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "351290446963296c5fabf750b3077a95",
|
"content-hash": "63bda0f783c53f088a85b8b35874ff00",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "brick/math",
|
"name": "brick/math",
|
||||||
@@ -1053,6 +1053,196 @@
|
|||||||
],
|
],
|
||||||
"time": "2023-09-25T11:31:05+00:00"
|
"time": "2023-09-25T11:31:05+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "opis/json-schema",
|
||||||
|
"version": "2.3.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/opis/json-schema.git",
|
||||||
|
"reference": "c48df6d7089a45f01e1c82432348f2d5976f9bfb"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/opis/json-schema/zipball/c48df6d7089a45f01e1c82432348f2d5976f9bfb",
|
||||||
|
"reference": "c48df6d7089a45f01e1c82432348f2d5976f9bfb",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"ext-json": "*",
|
||||||
|
"opis/string": "^2.0",
|
||||||
|
"opis/uri": "^1.0",
|
||||||
|
"php": "^7.4 || ^8.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"ext-bcmath": "*",
|
||||||
|
"ext-intl": "*",
|
||||||
|
"phpunit/phpunit": "^9.0"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "2.x-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Opis\\JsonSchema\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"Apache-2.0"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Sorin Sarca",
|
||||||
|
"email": "sarca_sorin@hotmail.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Marius Sarca",
|
||||||
|
"email": "marius.sarca@gmail.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Json Schema Validator for PHP",
|
||||||
|
"homepage": "https://opis.io/json-schema",
|
||||||
|
"keywords": [
|
||||||
|
"json",
|
||||||
|
"json-schema",
|
||||||
|
"schema",
|
||||||
|
"validation",
|
||||||
|
"validator"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/opis/json-schema/issues",
|
||||||
|
"source": "https://github.com/opis/json-schema/tree/2.3.0"
|
||||||
|
},
|
||||||
|
"time": "2022-01-08T20:38:03+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "opis/string",
|
||||||
|
"version": "2.0.1",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/opis/string.git",
|
||||||
|
"reference": "9ebf1a1f873f502f6859d11210b25a4bf5d141e7"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/opis/string/zipball/9ebf1a1f873f502f6859d11210b25a4bf5d141e7",
|
||||||
|
"reference": "9ebf1a1f873f502f6859d11210b25a4bf5d141e7",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"ext-iconv": "*",
|
||||||
|
"ext-json": "*",
|
||||||
|
"php": "^7.4 || ^8.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "^9.0"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "2.x-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Opis\\String\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"Apache-2.0"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Marius Sarca",
|
||||||
|
"email": "marius.sarca@gmail.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Sorin Sarca",
|
||||||
|
"email": "sarca_sorin@hotmail.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Multibyte strings as objects",
|
||||||
|
"homepage": "https://opis.io/string",
|
||||||
|
"keywords": [
|
||||||
|
"multi-byte",
|
||||||
|
"opis",
|
||||||
|
"string",
|
||||||
|
"string manipulation",
|
||||||
|
"utf-8"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/opis/string/issues",
|
||||||
|
"source": "https://github.com/opis/string/tree/2.0.1"
|
||||||
|
},
|
||||||
|
"time": "2022-01-14T15:42:23+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "opis/uri",
|
||||||
|
"version": "1.1.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/opis/uri.git",
|
||||||
|
"reference": "0f3ca49ab1a5e4a6681c286e0b2cc081b93a7d5a"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/opis/uri/zipball/0f3ca49ab1a5e4a6681c286e0b2cc081b93a7d5a",
|
||||||
|
"reference": "0f3ca49ab1a5e4a6681c286e0b2cc081b93a7d5a",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"opis/string": "^2.0",
|
||||||
|
"php": "^7.4 || ^8.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "^9"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "1.x-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Opis\\Uri\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"Apache-2.0"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Marius Sarca",
|
||||||
|
"email": "marius.sarca@gmail.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Sorin Sarca",
|
||||||
|
"email": "sarca_sorin@hotmail.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Build, parse and validate URIs and URI-templates",
|
||||||
|
"homepage": "https://opis.io",
|
||||||
|
"keywords": [
|
||||||
|
"URI Template",
|
||||||
|
"parse url",
|
||||||
|
"punycode",
|
||||||
|
"uri",
|
||||||
|
"uri components",
|
||||||
|
"url",
|
||||||
|
"validate uri"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/opis/uri/issues",
|
||||||
|
"source": "https://github.com/opis/uri/tree/1.1.0"
|
||||||
|
},
|
||||||
|
"time": "2021-05-22T15:57:08+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "phpoption/phpoption",
|
"name": "phpoption/phpoption",
|
||||||
"version": "1.9.1",
|
"version": "1.9.1",
|
||||||
@@ -2261,6 +2451,10 @@
|
|||||||
"prefer-stable": true,
|
"prefer-stable": true,
|
||||||
"prefer-lowest": false,
|
"prefer-lowest": false,
|
||||||
"platform": {
|
"platform": {
|
||||||
|
"ext-xml": "*",
|
||||||
|
"ext-zip": "*",
|
||||||
|
"ext-sqlite3": "*",
|
||||||
|
"ext-imagick": "*",
|
||||||
"php": "^8.2",
|
"php": "^8.2",
|
||||||
"ext-pdo": "*"
|
"ext-pdo": "*"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
return [
|
return [
|
||||||
"env" => env("LUCENT_ENV", "production"),
|
"env" => env("LUCENT_ENV", "production"),
|
||||||
"schemas_path" => env("LUCENT_SCHEMAS_PATH", "app/Lucent"),
|
"schemas_path" => env("LUCENT_SCHEMAS_PATH", "app/Lucent"),
|
||||||
|
"json_schemas_path" => env("LUCENT_JSON_SCHEMA_PATH", "json_schemas"),
|
||||||
"database" => env('LUCENT_DB_CONNECTION', env('DB_CONNECTION',"sqlite")),
|
"database" => env('LUCENT_DB_CONNECTION', env('DB_CONNECTION',"sqlite")),
|
||||||
"name" => env("LUCENT_NAME", "Lucent"),
|
"name" => env("LUCENT_NAME", "Lucent"),
|
||||||
"url" => env("LUCENT_URL", env('APP_URL')),
|
"url" => env("LUCENT_URL", env('APP_URL')),
|
||||||
|
|||||||
@@ -0,0 +1,75 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Lucent\JsonSchema\Command;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Lucent\Channel\ChannelService;
|
||||||
|
use Lucent\JsonSchema\Definition;
|
||||||
|
use Lucent\JsonSchema\JsonSchemaService;
|
||||||
|
use Lucent\JsonSchema\SchemaData;
|
||||||
|
use Lucent\Primitive\Collection;
|
||||||
|
use Lucent\Schema\FieldInterface;
|
||||||
|
use Lucent\Schema\Schema;
|
||||||
|
use Lucent\Schema\Type;
|
||||||
|
|
||||||
|
class GenerateJsonSchema extends Command
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $signature = 'lucent:json_schema';
|
||||||
|
|
||||||
|
protected $description = 'Generates json schema for lucent schemas';
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
public ChannelService $channelService,
|
||||||
|
public JsonSchemaService $jsonSchemaService,
|
||||||
|
)
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
|
||||||
|
$definitions = $this->channelService->channel->schemas->whereIn("type", [Type::COLLECTION, Type::FILES])->values()->map(fn(Schema $schema) => $this->fromSchema($schema));
|
||||||
|
$definitions->map(function (Definition $definition) use ($definitions) {
|
||||||
|
$this->writeToFile($definition,$definitions);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private function fromSchema(Schema $schema): Definition
|
||||||
|
{
|
||||||
|
$properties = $schema->fields->map(fn(FieldInterface $field) => $field->toJsonSchema());
|
||||||
|
|
||||||
|
return $this->jsonSchemaService->create(new SchemaData(
|
||||||
|
id: $schema->name,
|
||||||
|
title: $schema->label,
|
||||||
|
properties: $properties,
|
||||||
|
required: $schema->fields->filter(fn(FieldInterface $field) => $field->isRequired())->values()->pluck("name"),
|
||||||
|
));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private function writeToFile(Definition $definition, Collection $definitions): void
|
||||||
|
{
|
||||||
|
$json_schema_dir = public_path(config('lucent.json_schemas_path'));
|
||||||
|
if (!file_exists($json_schema_dir)) {
|
||||||
|
mkdir($json_schema_dir);
|
||||||
|
}
|
||||||
|
$nameAr = explode("/", $definition->_id);
|
||||||
|
$name = end($nameAr);
|
||||||
|
|
||||||
|
$defArray = $definition->toArray();
|
||||||
|
$defArray['$defs'] = $definitions->map(fn($def) => $def->toArray())->keyBy(function ($def){
|
||||||
|
$nameAr = explode("/", $def['$id']);
|
||||||
|
return str_replace(".json","",end($nameAr));
|
||||||
|
});
|
||||||
|
|
||||||
|
unset($defArray['$defs'][str_replace(".json","",$name)]);
|
||||||
|
|
||||||
|
file_put_contents($json_schema_dir . "/" . $name,json_encode($defArray,JSON_UNESCAPED_SLASHES));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Lucent\JsonSchema;
|
||||||
|
|
||||||
|
use Lucent\JsonSchema\Property\Property;
|
||||||
|
use Lucent\JsonSchema\Property\PropertyType;
|
||||||
|
use Lucent\JsonSchema\Property\RefProperty;
|
||||||
|
use Lucent\JsonSchema\Property\TypeProperty;
|
||||||
|
use Lucent\Primitive\Collection;
|
||||||
|
use Lucent\Schema\FieldInterface;
|
||||||
|
use PhpOption\Option;
|
||||||
|
|
||||||
|
class Definition
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param string $_schema
|
||||||
|
* @param string $_id
|
||||||
|
* @param string $title
|
||||||
|
* @param string $type
|
||||||
|
* @param Collection<Property> $properties
|
||||||
|
* @param Collection<string> $required
|
||||||
|
*/
|
||||||
|
private function __construct(
|
||||||
|
public string $_schema,
|
||||||
|
public string $_id,
|
||||||
|
public string $title,
|
||||||
|
public string $type,
|
||||||
|
public Collection $properties,
|
||||||
|
public Collection $required,
|
||||||
|
)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function new(SchemaData $schemaData)
|
||||||
|
{
|
||||||
|
return new self(
|
||||||
|
_schema: "https://json-schema.org/draft/2020-12/schema",
|
||||||
|
_id: self::getBasePath($schemaData->id),
|
||||||
|
title: $schemaData->title,
|
||||||
|
type: "object",
|
||||||
|
properties: $schemaData->properties,
|
||||||
|
required: $schemaData->required,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static function getBasePath(string $schemaName): string
|
||||||
|
{
|
||||||
|
return config("lucent.url") . "/" . config("lucent.json_schemas_path") . "/" . $schemaName . ".json";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function getRefPath(string $schemaName): string
|
||||||
|
{
|
||||||
|
return '#/$defs/' . $schemaName ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function toArray(): array
|
||||||
|
{
|
||||||
|
$newProperties = [
|
||||||
|
"random" => [
|
||||||
|
"type" => "string",
|
||||||
|
"title" => "Random"
|
||||||
|
]
|
||||||
|
];
|
||||||
|
foreach ($this->properties->toArray() as $property) {
|
||||||
|
$newProperty = [];
|
||||||
|
foreach ($property as $key => $value) {
|
||||||
|
if (($value instanceof Option && $value->isEmpty()) || in_array($key, ["id", "_ref"])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ($value instanceof Option) {
|
||||||
|
$newProperty[$key] = $value->get();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$newProperty[$key] = $value;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($property instanceof RefProperty) {
|
||||||
|
$newProperty[$property->type->value] = $property->_ref->map(function (string $ref) {
|
||||||
|
return [
|
||||||
|
'$ref' => self::getRefPath($ref)
|
||||||
|
];
|
||||||
|
});
|
||||||
|
|
||||||
|
unset($newProperty["type"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$newProperties[$property->id] = $newProperty;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$output = ['$schema' => $this->_schema, '$id' => $this->_id, ...toArray($this)];
|
||||||
|
|
||||||
|
$output["properties"] = $newProperties;
|
||||||
|
unset($output["_schema"]);
|
||||||
|
unset($output["_id"]);
|
||||||
|
unset($output["_defs"]);
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Lucent\JsonSchema;
|
||||||
|
|
||||||
|
class JsonSchemaService
|
||||||
|
{
|
||||||
|
public function create(SchemaData $schemaData): Definition
|
||||||
|
{
|
||||||
|
return Definition::new($schemaData);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Lucent\JsonSchema\Property;
|
||||||
|
|
||||||
|
interface Property
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Lucent\JsonSchema\Property;
|
||||||
|
|
||||||
|
enum PropertyType: string
|
||||||
|
{
|
||||||
|
case STRING = "string";
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Lucent\JsonSchema\Property;
|
||||||
|
|
||||||
|
use Lucent\Primitive\Collection;
|
||||||
|
use PhpOption\Option;
|
||||||
|
|
||||||
|
class RefProperty implements Property
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param RefType $type
|
||||||
|
* @param string $id
|
||||||
|
* @param Option<string> $title
|
||||||
|
* @param Option<string> $description
|
||||||
|
* @param Collection<string> $_ref
|
||||||
|
* @param Option<int> $minItems
|
||||||
|
* @param Option<int> $maxItems
|
||||||
|
* @param Option<string> $comment
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
public RefType $type,
|
||||||
|
public string $id,
|
||||||
|
public Option $title,
|
||||||
|
public Option $description,
|
||||||
|
public Collection $_ref,
|
||||||
|
public Option $minItems,
|
||||||
|
public Option $maxItems,
|
||||||
|
public Option $comment,
|
||||||
|
)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Lucent\JsonSchema\Property;
|
||||||
|
|
||||||
|
enum RefType: string
|
||||||
|
{
|
||||||
|
case ONE_OF = "oneOf";
|
||||||
|
case ANY_OF = "anyOf";
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Lucent\JsonSchema\Property;
|
||||||
|
|
||||||
|
use PhpOption\Option;
|
||||||
|
|
||||||
|
class TypeProperty implements Property
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param PropertyType $type
|
||||||
|
* @param string $id
|
||||||
|
* @param Option<string> $title
|
||||||
|
* @param Option<string> $description
|
||||||
|
* @param Option<mixed> $default
|
||||||
|
* @param Option<int> $minLength
|
||||||
|
* @param Option<int> $maxLength
|
||||||
|
* @param Option<bool> $readOnly
|
||||||
|
* @param Option<array> $enum
|
||||||
|
* @param Option<string> $comment
|
||||||
|
* @param Option<string> $format
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
public PropertyType $type,
|
||||||
|
public string $id,
|
||||||
|
public Option $title,
|
||||||
|
public Option $description,
|
||||||
|
public Option $default,
|
||||||
|
public Option $minLength,
|
||||||
|
public Option $maxLength,
|
||||||
|
public Option $readOnly,
|
||||||
|
public Option $enum,
|
||||||
|
public Option $comment,
|
||||||
|
public Option $format,
|
||||||
|
)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Lucent\JsonSchema;
|
||||||
|
|
||||||
|
use Lucent\JsonSchema\Property\Property;
|
||||||
|
use Lucent\Primitive\Collection;
|
||||||
|
|
||||||
|
class SchemaData
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param string $id
|
||||||
|
* @param string $title
|
||||||
|
* @param Collection<Property> $properties
|
||||||
|
* @param Collection<string> $required
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
public string $id,
|
||||||
|
public string $title,
|
||||||
|
public Collection $properties,
|
||||||
|
public Collection $required,
|
||||||
|
)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,6 +13,7 @@ use Lucent\Commands\RebuildThumbnails;
|
|||||||
use Lucent\Commands\RemoveOrphanEdges;
|
use Lucent\Commands\RemoveOrphanEdges;
|
||||||
use Lucent\File\FileService;
|
use Lucent\File\FileService;
|
||||||
use Lucent\File\ImageService;
|
use Lucent\File\ImageService;
|
||||||
|
use Lucent\JsonSchema\Command\GenerateJsonSchema;
|
||||||
use Lucent\Query\DatabaseGraph\DatabaseGraph;
|
use Lucent\Query\DatabaseGraph\DatabaseGraph;
|
||||||
use Lucent\Query\DatabaseGraph\PgsqlDatabaseGraph;
|
use Lucent\Query\DatabaseGraph\PgsqlDatabaseGraph;
|
||||||
use Lucent\Query\DatabaseGraph\SqliteDatabaseGraph;
|
use Lucent\Query\DatabaseGraph\SqliteDatabaseGraph;
|
||||||
@@ -70,6 +71,7 @@ class LucentServiceProvider extends ServiceProvider
|
|||||||
RebuildThumbnails::class,
|
RebuildThumbnails::class,
|
||||||
LiveLink::class,
|
LiveLink::class,
|
||||||
RemoveOrphanEdges::class,
|
RemoveOrphanEdges::class,
|
||||||
|
GenerateJsonSchema::class,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,5 +50,22 @@ class File implements FieldInterface, MinMaxInterface
|
|||||||
return count($value) < $this->min;
|
return count($value) < $this->min;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function toJsonSchema(): Property
|
||||||
|
{
|
||||||
|
return new TypeProperty(
|
||||||
|
type: PropertyType::STRING,
|
||||||
|
id: $this->name,
|
||||||
|
title: Option::fromValue($this->label),
|
||||||
|
description: Option::fromValue($this->help, ""),
|
||||||
|
default: Option::fromValue($this->default, ""),
|
||||||
|
minLength: Option::fromValue($this->min),
|
||||||
|
maxLength: Option::fromValue($this->max),
|
||||||
|
readOnly: Option::fromValue($this->readonly, false),
|
||||||
|
enum: Option::fromValue($this->selectOptions),
|
||||||
|
comment: Option::fromValue($this->group, ""),
|
||||||
|
format: none(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,5 +7,7 @@ interface FieldInterface
|
|||||||
{
|
{
|
||||||
public function format(array $input, array $output): array;
|
public function format(array $input, array $output): array;
|
||||||
|
|
||||||
|
public function isRequired(): bool;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,15 @@
|
|||||||
|
|
||||||
namespace Lucent\Schema\Ui;
|
namespace Lucent\Schema\Ui;
|
||||||
|
|
||||||
|
use Lucent\JsonSchema\Property\Property;
|
||||||
|
use Lucent\JsonSchema\Property\PropertyType;
|
||||||
|
use Lucent\JsonSchema\Property\TypeProperty;
|
||||||
use Lucent\Schema\FieldInfo;
|
use Lucent\Schema\FieldInfo;
|
||||||
use Lucent\Schema\FieldInterface;
|
use Lucent\Schema\FieldInterface;
|
||||||
use Lucent\Schema\FieldType;
|
use Lucent\Schema\FieldType;
|
||||||
use Lucent\Schema\Nullable;
|
use Lucent\Schema\Nullable;
|
||||||
use Lucent\Schema\Validator\RequiredInterface;
|
use Lucent\Schema\Validator\RequiredInterface;
|
||||||
|
use PhpOption\Option;
|
||||||
|
|
||||||
class Block implements FieldInterface, RequiredInterface
|
class Block implements FieldInterface, RequiredInterface
|
||||||
{
|
{
|
||||||
@@ -43,4 +47,26 @@ class Block implements FieldInterface, RequiredInterface
|
|||||||
{
|
{
|
||||||
return empty($value);
|
return empty($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isRequired(): bool
|
||||||
|
{
|
||||||
|
return $this->required;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toJsonSchema(): Property
|
||||||
|
{
|
||||||
|
return new TypeProperty(
|
||||||
|
type: PropertyType::STRING,
|
||||||
|
id: $this->name,
|
||||||
|
title: Option::fromValue($this->label),
|
||||||
|
description: Option::fromValue($this->help, ""),
|
||||||
|
default: Option::fromValue($this->default, ""),
|
||||||
|
minLength: none(),
|
||||||
|
maxLength: none(),
|
||||||
|
readOnly: Option::fromValue($this->readonly, false),
|
||||||
|
enum: none(),
|
||||||
|
comment: Option::fromValue($this->group, ""),
|
||||||
|
format: none(),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,15 @@
|
|||||||
|
|
||||||
namespace Lucent\Schema\Ui;
|
namespace Lucent\Schema\Ui;
|
||||||
|
|
||||||
|
use Lucent\JsonSchema\Property\Property;
|
||||||
|
use Lucent\JsonSchema\Property\PropertyType;
|
||||||
|
use Lucent\JsonSchema\Property\TypeProperty;
|
||||||
use Lucent\Schema\FieldInfo;
|
use Lucent\Schema\FieldInfo;
|
||||||
use Lucent\Schema\FieldInterface;
|
use Lucent\Schema\FieldInterface;
|
||||||
use Lucent\Schema\FieldType;
|
use Lucent\Schema\FieldType;
|
||||||
use Lucent\Schema\Nullable;
|
use Lucent\Schema\Nullable;
|
||||||
use Lucent\Schema\Validator\RequiredInterface;
|
use Lucent\Schema\Validator\RequiredInterface;
|
||||||
|
use PhpOption\Option;
|
||||||
use function is_bool;
|
use function is_bool;
|
||||||
|
|
||||||
class Checkbox implements FieldInterface, RequiredInterface
|
class Checkbox implements FieldInterface, RequiredInterface
|
||||||
@@ -45,5 +49,27 @@ class Checkbox implements FieldInterface, RequiredInterface
|
|||||||
{
|
{
|
||||||
return (bool)$value !== true;
|
return (bool)$value !== true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isRequired(): bool
|
||||||
|
{
|
||||||
|
return $this->required;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toJsonSchema(): Property
|
||||||
|
{
|
||||||
|
return new TypeProperty(
|
||||||
|
type: PropertyType::STRING,
|
||||||
|
id: $this->name,
|
||||||
|
title: Option::fromValue($this->label),
|
||||||
|
description: Option::fromValue($this->help, ""),
|
||||||
|
default: Option::fromValue($this->default, ""),
|
||||||
|
minLength: none(),
|
||||||
|
maxLength: none(),
|
||||||
|
readOnly: Option::fromValue($this->readonly, false),
|
||||||
|
enum: none(),
|
||||||
|
comment: Option::fromValue($this->group, ""),
|
||||||
|
format: none(),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,15 @@
|
|||||||
|
|
||||||
namespace Lucent\Schema\Ui;
|
namespace Lucent\Schema\Ui;
|
||||||
|
|
||||||
|
use Lucent\JsonSchema\Property\Property;
|
||||||
|
use Lucent\JsonSchema\Property\PropertyType;
|
||||||
|
use Lucent\JsonSchema\Property\TypeProperty;
|
||||||
use Lucent\Schema\FieldInfo;
|
use Lucent\Schema\FieldInfo;
|
||||||
use Lucent\Schema\FieldInterface;
|
use Lucent\Schema\FieldInterface;
|
||||||
use Lucent\Schema\FieldType;
|
use Lucent\Schema\FieldType;
|
||||||
use Lucent\Schema\Nullable;
|
use Lucent\Schema\Nullable;
|
||||||
use Lucent\Schema\Validator\RequiredInterface;
|
use Lucent\Schema\Validator\RequiredInterface;
|
||||||
|
use PhpOption\Option;
|
||||||
|
|
||||||
class Color implements FieldInterface, RequiredInterface
|
class Color implements FieldInterface, RequiredInterface
|
||||||
{
|
{
|
||||||
@@ -41,5 +45,27 @@ class Color implements FieldInterface, RequiredInterface
|
|||||||
{
|
{
|
||||||
return empty(trim($value));
|
return empty(trim($value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isRequired(): bool
|
||||||
|
{
|
||||||
|
return $this->required;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toJsonSchema(): Property
|
||||||
|
{
|
||||||
|
return new TypeProperty(
|
||||||
|
type: PropertyType::STRING,
|
||||||
|
id: $this->name,
|
||||||
|
title: Option::fromValue($this->label),
|
||||||
|
description: Option::fromValue($this->help, ""),
|
||||||
|
default: Option::fromValue($this->default, ""),
|
||||||
|
minLength: none(),
|
||||||
|
maxLength: none(),
|
||||||
|
readOnly: Option::fromValue($this->readonly, false),
|
||||||
|
enum: none(),
|
||||||
|
comment: Option::fromValue($this->group, ""),
|
||||||
|
format: none(),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,16 @@
|
|||||||
namespace Lucent\Schema\Ui;
|
namespace Lucent\Schema\Ui;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use Lucent\JsonSchema\Property\Property;
|
||||||
|
use Lucent\JsonSchema\Property\PropertyType;
|
||||||
|
use Lucent\JsonSchema\Property\TypeProperty;
|
||||||
use Lucent\Schema\FieldInfo;
|
use Lucent\Schema\FieldInfo;
|
||||||
use Lucent\Schema\FieldInterface;
|
use Lucent\Schema\FieldInterface;
|
||||||
use Lucent\Schema\FieldType;
|
use Lucent\Schema\FieldType;
|
||||||
use Lucent\Schema\Nullable;
|
use Lucent\Schema\Nullable;
|
||||||
use Lucent\Schema\Validator\MinMaxInterface;
|
use Lucent\Schema\Validator\MinMaxInterface;
|
||||||
use Lucent\Schema\Validator\RequiredInterface;
|
use Lucent\Schema\Validator\RequiredInterface;
|
||||||
|
use PhpOption\Option;
|
||||||
|
|
||||||
class Date implements FieldInterface, RequiredInterface, MinMaxInterface
|
class Date implements FieldInterface, RequiredInterface, MinMaxInterface
|
||||||
{
|
{
|
||||||
@@ -70,5 +74,27 @@ class Date implements FieldInterface, RequiredInterface, MinMaxInterface
|
|||||||
|
|
||||||
return $value->greaterThan($this->max);
|
return $value->greaterThan($this->max);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isRequired(): bool
|
||||||
|
{
|
||||||
|
return $this->required;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toJsonSchema(): Property
|
||||||
|
{
|
||||||
|
return new TypeProperty(
|
||||||
|
type: PropertyType::STRING,
|
||||||
|
id: $this->name,
|
||||||
|
title: Option::fromValue($this->label),
|
||||||
|
description: Option::fromValue($this->help, ""),
|
||||||
|
default: Option::fromValue($this->default, ""),
|
||||||
|
minLength: Option::fromValue($this->min),
|
||||||
|
maxLength: Option::fromValue($this->max),
|
||||||
|
readOnly: Option::fromValue($this->readonly, false),
|
||||||
|
enum: none(),
|
||||||
|
comment: Option::fromValue($this->group, ""),
|
||||||
|
format: some("date"),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,16 @@
|
|||||||
namespace Lucent\Schema\Ui;
|
namespace Lucent\Schema\Ui;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use Lucent\JsonSchema\Property\Property;
|
||||||
|
use Lucent\JsonSchema\Property\PropertyType;
|
||||||
|
use Lucent\JsonSchema\Property\TypeProperty;
|
||||||
use Lucent\Schema\FieldInfo;
|
use Lucent\Schema\FieldInfo;
|
||||||
use Lucent\Schema\FieldInterface;
|
use Lucent\Schema\FieldInterface;
|
||||||
use Lucent\Schema\FieldType;
|
use Lucent\Schema\FieldType;
|
||||||
use Lucent\Schema\Nullable;
|
use Lucent\Schema\Nullable;
|
||||||
use Lucent\Schema\Validator\MinMaxInterface;
|
use Lucent\Schema\Validator\MinMaxInterface;
|
||||||
use Lucent\Schema\Validator\RequiredInterface;
|
use Lucent\Schema\Validator\RequiredInterface;
|
||||||
|
use PhpOption\Option;
|
||||||
|
|
||||||
class Datetime implements FieldInterface, RequiredInterface, MinMaxInterface
|
class Datetime implements FieldInterface, RequiredInterface, MinMaxInterface
|
||||||
{
|
{
|
||||||
@@ -70,5 +74,28 @@ class Datetime implements FieldInterface, RequiredInterface, MinMaxInterface
|
|||||||
|
|
||||||
return $value->greaterThan($this->max);
|
return $value->greaterThan($this->max);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isRequired(): bool
|
||||||
|
{
|
||||||
|
return $this->required;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toJsonSchema(): Property
|
||||||
|
{
|
||||||
|
return new TypeProperty(
|
||||||
|
type: PropertyType::STRING,
|
||||||
|
id: $this->name,
|
||||||
|
title: Option::fromValue($this->label),
|
||||||
|
description: Option::fromValue($this->help, ""),
|
||||||
|
default: Option::fromValue($this->default, ""),
|
||||||
|
minLength: Option::fromValue($this->min),
|
||||||
|
maxLength: Option::fromValue($this->max),
|
||||||
|
readOnly: Option::fromValue($this->readonly, false),
|
||||||
|
enum: none(),
|
||||||
|
comment: Option::fromValue($this->group, ""),
|
||||||
|
format: some("date-time"),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,10 +2,15 @@
|
|||||||
|
|
||||||
namespace Lucent\Schema\Ui;
|
namespace Lucent\Schema\Ui;
|
||||||
|
|
||||||
|
use Lucent\JsonSchema\Property\Property;
|
||||||
|
use Lucent\JsonSchema\Property\RefProperty;
|
||||||
|
use Lucent\JsonSchema\Property\RefType;
|
||||||
|
use Lucent\Primitive\Collection;
|
||||||
use Lucent\Schema\FieldInfo;
|
use Lucent\Schema\FieldInfo;
|
||||||
use Lucent\Schema\FieldInterface;
|
use Lucent\Schema\FieldInterface;
|
||||||
use Lucent\Schema\FieldType;
|
use Lucent\Schema\FieldType;
|
||||||
use Lucent\Schema\Validator\MinMaxInterface;
|
use Lucent\Schema\Validator\MinMaxInterface;
|
||||||
|
use PhpOption\Option;
|
||||||
|
|
||||||
class File implements FieldInterface, MinMaxInterface
|
class File implements FieldInterface, MinMaxInterface
|
||||||
{
|
{
|
||||||
@@ -52,5 +57,24 @@ class File implements FieldInterface, MinMaxInterface
|
|||||||
return count($value) < $this->min;
|
return count($value) < $this->min;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function toJsonSchema(): Property
|
||||||
|
{
|
||||||
|
return new RefProperty(
|
||||||
|
type: RefType::ANY_OF,
|
||||||
|
id: $this->name,
|
||||||
|
title: Option::fromValue($this->label),
|
||||||
|
description: Option::fromValue($this->help, ""),
|
||||||
|
_ref: new Collection($this->collections),
|
||||||
|
minItems: Option::fromValue($this->min),
|
||||||
|
maxItems: Option::fromValue($this->max),
|
||||||
|
comment: Option::fromValue($this->group, ""),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isRequired(): bool
|
||||||
|
{
|
||||||
|
return $this->min > 0;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,15 @@
|
|||||||
|
|
||||||
namespace Lucent\Schema\Ui;
|
namespace Lucent\Schema\Ui;
|
||||||
|
|
||||||
|
use Lucent\JsonSchema\Property\Property;
|
||||||
|
use Lucent\JsonSchema\Property\PropertyType;
|
||||||
|
use Lucent\JsonSchema\Property\TypeProperty;
|
||||||
use Lucent\Schema\FieldInfo;
|
use Lucent\Schema\FieldInfo;
|
||||||
use Lucent\Schema\FieldInterface;
|
use Lucent\Schema\FieldInterface;
|
||||||
use Lucent\Schema\FieldType;
|
use Lucent\Schema\FieldType;
|
||||||
use Lucent\Schema\Nullable;
|
use Lucent\Schema\Nullable;
|
||||||
use Lucent\Schema\Validator\RequiredInterface;
|
use Lucent\Schema\Validator\RequiredInterface;
|
||||||
|
use PhpOption\Option;
|
||||||
|
|
||||||
class Json implements FieldInterface, RequiredInterface
|
class Json implements FieldInterface, RequiredInterface
|
||||||
{
|
{
|
||||||
@@ -43,4 +47,26 @@ class Json implements FieldInterface, RequiredInterface
|
|||||||
{
|
{
|
||||||
return empty($value);
|
return empty($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isRequired(): bool
|
||||||
|
{
|
||||||
|
return $this->required;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toJsonSchema(): Property
|
||||||
|
{
|
||||||
|
return new TypeProperty(
|
||||||
|
type: PropertyType::STRING,
|
||||||
|
id: $this->name,
|
||||||
|
title: Option::fromValue($this->label),
|
||||||
|
description: Option::fromValue($this->help, ""),
|
||||||
|
default: Option::fromValue($this->default, ""),
|
||||||
|
minLength: none(),
|
||||||
|
maxLength: none(),
|
||||||
|
readOnly: Option::fromValue($this->readonly, false),
|
||||||
|
enum: none(),
|
||||||
|
comment: Option::fromValue($this->group, ""),
|
||||||
|
format: none(),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,15 @@
|
|||||||
|
|
||||||
namespace Lucent\Schema\Ui;
|
namespace Lucent\Schema\Ui;
|
||||||
|
|
||||||
|
use Lucent\JsonSchema\Property\Property;
|
||||||
|
use Lucent\JsonSchema\Property\PropertyType;
|
||||||
|
use Lucent\JsonSchema\Property\TypeProperty;
|
||||||
use Lucent\Schema\FieldInfo;
|
use Lucent\Schema\FieldInfo;
|
||||||
use Lucent\Schema\FieldInterface;
|
use Lucent\Schema\FieldInterface;
|
||||||
use Lucent\Schema\FieldType;
|
use Lucent\Schema\FieldType;
|
||||||
use Lucent\Schema\Nullable;
|
use Lucent\Schema\Nullable;
|
||||||
use Lucent\Schema\Validator\RequiredInterface;
|
use Lucent\Schema\Validator\RequiredInterface;
|
||||||
|
use PhpOption\Option;
|
||||||
|
|
||||||
class Markdown implements FieldInterface, RequiredInterface
|
class Markdown implements FieldInterface, RequiredInterface
|
||||||
{
|
{
|
||||||
@@ -39,4 +43,26 @@ class Markdown implements FieldInterface, RequiredInterface
|
|||||||
{
|
{
|
||||||
return empty(trim($value));
|
return empty(trim($value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isRequired(): bool
|
||||||
|
{
|
||||||
|
return $this->required;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toJsonSchema(): Property
|
||||||
|
{
|
||||||
|
return new TypeProperty(
|
||||||
|
type: PropertyType::STRING,
|
||||||
|
id: $this->name,
|
||||||
|
title: Option::fromValue($this->label),
|
||||||
|
description: Option::fromValue($this->help, ""),
|
||||||
|
default: Option::fromValue($this->default, ""),
|
||||||
|
minLength: Option::fromValue($this->min),
|
||||||
|
maxLength: Option::fromValue($this->max),
|
||||||
|
readOnly: Option::fromValue($this->readonly, false),
|
||||||
|
enum: none(),
|
||||||
|
comment: Option::fromValue($this->group, ""),
|
||||||
|
format: none(),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,16 @@
|
|||||||
|
|
||||||
namespace Lucent\Schema\Ui;
|
namespace Lucent\Schema\Ui;
|
||||||
|
|
||||||
|
use Lucent\JsonSchema\Property\Property;
|
||||||
|
use Lucent\JsonSchema\Property\PropertyType;
|
||||||
|
use Lucent\JsonSchema\Property\TypeProperty;
|
||||||
use Lucent\Schema\FieldInfo;
|
use Lucent\Schema\FieldInfo;
|
||||||
use Lucent\Schema\FieldInterface;
|
use Lucent\Schema\FieldInterface;
|
||||||
use Lucent\Schema\FieldType;
|
use Lucent\Schema\FieldType;
|
||||||
use Lucent\Schema\Nullable;
|
use Lucent\Schema\Nullable;
|
||||||
use Lucent\Schema\Validator\MinMaxInterface;
|
use Lucent\Schema\Validator\MinMaxInterface;
|
||||||
use Lucent\Schema\Validator\RequiredInterface;
|
use Lucent\Schema\Validator\RequiredInterface;
|
||||||
|
use PhpOption\Option;
|
||||||
|
|
||||||
class Number implements FieldInterface, RequiredInterface, MinMaxInterface
|
class Number implements FieldInterface, RequiredInterface, MinMaxInterface
|
||||||
{
|
{
|
||||||
@@ -74,5 +78,29 @@ class Number implements FieldInterface, RequiredInterface, MinMaxInterface
|
|||||||
|
|
||||||
return $value > $this->min;
|
return $value > $this->min;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isRequired(): bool
|
||||||
|
{
|
||||||
|
return $this->required;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toJsonSchema(): Property
|
||||||
|
{
|
||||||
|
return new TypeProperty(
|
||||||
|
type: PropertyType::STRING,
|
||||||
|
id: $this->name,
|
||||||
|
title: Option::fromValue($this->label),
|
||||||
|
description: Option::fromValue($this->help, ""),
|
||||||
|
default: Option::fromValue($this->default, ""),
|
||||||
|
minLength: Option::fromValue($this->min),
|
||||||
|
maxLength: Option::fromValue($this->max),
|
||||||
|
readOnly: Option::fromValue($this->readonly, false),
|
||||||
|
enum: none(),
|
||||||
|
comment: Option::fromValue($this->group, ""),
|
||||||
|
format: none(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,10 +2,15 @@
|
|||||||
|
|
||||||
namespace Lucent\Schema\Ui;
|
namespace Lucent\Schema\Ui;
|
||||||
|
|
||||||
|
use Lucent\JsonSchema\Property\Property;
|
||||||
|
use Lucent\JsonSchema\Property\RefProperty;
|
||||||
|
use Lucent\JsonSchema\Property\RefType;
|
||||||
|
use Lucent\Primitive\Collection;
|
||||||
use Lucent\Schema\FieldInfo;
|
use Lucent\Schema\FieldInfo;
|
||||||
use Lucent\Schema\FieldInterface;
|
use Lucent\Schema\FieldInterface;
|
||||||
use Lucent\Schema\FieldType;
|
use Lucent\Schema\FieldType;
|
||||||
use Lucent\Schema\Validator\MinMaxInterface;
|
use Lucent\Schema\Validator\MinMaxInterface;
|
||||||
|
use PhpOption\Option;
|
||||||
|
|
||||||
class Reference implements FieldInterface, MinMaxInterface
|
class Reference implements FieldInterface, MinMaxInterface
|
||||||
{
|
{
|
||||||
@@ -22,7 +27,7 @@ class Reference implements FieldInterface, MinMaxInterface
|
|||||||
public ?int $min = null,
|
public ?int $min = null,
|
||||||
public ?int $max = null,
|
public ?int $max = null,
|
||||||
public array $collections = [],
|
public array $collections = [],
|
||||||
public string $searchField = "",
|
public string $searchField = "",
|
||||||
public string $layout = "",
|
public string $layout = "",
|
||||||
public string $group = "",
|
public string $group = "",
|
||||||
)
|
)
|
||||||
@@ -53,5 +58,24 @@ class Reference implements FieldInterface, MinMaxInterface
|
|||||||
return count($value) < $this->min;
|
return count($value) < $this->min;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isRequired(): bool
|
||||||
|
{
|
||||||
|
return $this->min > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toJsonSchema(): Property
|
||||||
|
{
|
||||||
|
return new RefProperty(
|
||||||
|
type: RefType::ANY_OF,
|
||||||
|
id: $this->name,
|
||||||
|
title: Option::fromValue($this->label),
|
||||||
|
description: Option::fromValue($this->help, ""),
|
||||||
|
_ref: new Collection($this->collections),
|
||||||
|
minItems: Option::fromValue($this->min),
|
||||||
|
maxItems: Option::fromValue($this->max),
|
||||||
|
comment: Option::fromValue($this->group, ""),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,15 @@
|
|||||||
|
|
||||||
namespace Lucent\Schema\Ui;
|
namespace Lucent\Schema\Ui;
|
||||||
|
|
||||||
|
use Lucent\JsonSchema\Property\Property;
|
||||||
|
use Lucent\JsonSchema\Property\PropertyType;
|
||||||
|
use Lucent\JsonSchema\Property\TypeProperty;
|
||||||
use Lucent\Schema\FieldInfo;
|
use Lucent\Schema\FieldInfo;
|
||||||
use Lucent\Schema\FieldInterface;
|
use Lucent\Schema\FieldInterface;
|
||||||
use Lucent\Schema\FieldType;
|
use Lucent\Schema\FieldType;
|
||||||
use Lucent\Schema\Nullable;
|
use Lucent\Schema\Nullable;
|
||||||
use Lucent\Schema\Validator\RequiredInterface;
|
use Lucent\Schema\Validator\RequiredInterface;
|
||||||
|
use PhpOption\Option;
|
||||||
|
|
||||||
class Rich implements FieldInterface, RequiredInterface
|
class Rich implements FieldInterface, RequiredInterface
|
||||||
{
|
{
|
||||||
@@ -39,4 +43,28 @@ class Rich implements FieldInterface, RequiredInterface
|
|||||||
{
|
{
|
||||||
return empty(trim($value));
|
return empty(trim($value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isRequired(): bool
|
||||||
|
{
|
||||||
|
return $this->required;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toJsonSchema(): Property
|
||||||
|
{
|
||||||
|
return new TypeProperty(
|
||||||
|
type: PropertyType::STRING,
|
||||||
|
id: $this->name,
|
||||||
|
title: Option::fromValue($this->label),
|
||||||
|
description: Option::fromValue($this->help, ""),
|
||||||
|
default: Option::fromValue($this->default, ""),
|
||||||
|
minLength: Option::fromValue($this->min),
|
||||||
|
maxLength: Option::fromValue($this->max),
|
||||||
|
readOnly: Option::fromValue($this->readonly, false),
|
||||||
|
enum:none(),
|
||||||
|
comment: Option::fromValue($this->group, ""),
|
||||||
|
format: none(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,15 @@
|
|||||||
namespace Lucent\Schema\Ui;
|
namespace Lucent\Schema\Ui;
|
||||||
|
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
use Lucent\JsonSchema\Property\Property;
|
||||||
|
use Lucent\JsonSchema\Property\PropertyType;
|
||||||
|
use Lucent\JsonSchema\Property\TypeProperty;
|
||||||
use Lucent\Schema\FieldInfo;
|
use Lucent\Schema\FieldInfo;
|
||||||
use Lucent\Schema\FieldInterface;
|
use Lucent\Schema\FieldInterface;
|
||||||
use Lucent\Schema\FieldType;
|
use Lucent\Schema\FieldType;
|
||||||
use Lucent\Schema\Nullable;
|
use Lucent\Schema\Nullable;
|
||||||
use Lucent\Schema\Validator\RequiredInterface;
|
use Lucent\Schema\Validator\RequiredInterface;
|
||||||
|
use PhpOption\Option;
|
||||||
|
|
||||||
class Slug implements FieldInterface, RequiredInterface
|
class Slug implements FieldInterface, RequiredInterface
|
||||||
{
|
{
|
||||||
@@ -46,5 +50,27 @@ class Slug implements FieldInterface, RequiredInterface
|
|||||||
{
|
{
|
||||||
return empty(trim($value));
|
return empty(trim($value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isRequired(): bool
|
||||||
|
{
|
||||||
|
return $this->required;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toJsonSchema(): Property
|
||||||
|
{
|
||||||
|
return new TypeProperty(
|
||||||
|
type: PropertyType::STRING,
|
||||||
|
id: $this->name,
|
||||||
|
title: Option::fromValue($this->label),
|
||||||
|
description: Option::fromValue($this->help, ""),
|
||||||
|
default: Option::fromValue($this->default, ""),
|
||||||
|
minLength: Option::fromValue($this->min),
|
||||||
|
maxLength: Option::fromValue($this->max),
|
||||||
|
readOnly: Option::fromValue($this->readonly, false),
|
||||||
|
enum: none(),
|
||||||
|
comment: Option::fromValue($this->group, ""),
|
||||||
|
format: none(),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,15 @@
|
|||||||
|
|
||||||
namespace Lucent\Schema\Ui;
|
namespace Lucent\Schema\Ui;
|
||||||
|
|
||||||
|
use Lucent\JsonSchema\Property\Property;
|
||||||
|
use Lucent\JsonSchema\Property\PropertyType;
|
||||||
|
use Lucent\JsonSchema\Property\TypeProperty;
|
||||||
use Lucent\Schema\FieldInfo;
|
use Lucent\Schema\FieldInfo;
|
||||||
use Lucent\Schema\FieldInterface;
|
use Lucent\Schema\FieldInterface;
|
||||||
use Lucent\Schema\FieldType;
|
use Lucent\Schema\FieldType;
|
||||||
use Lucent\Schema\Nullable;
|
use Lucent\Schema\Nullable;
|
||||||
use Lucent\Schema\Validator\RequiredInterface;
|
use Lucent\Schema\Validator\RequiredInterface;
|
||||||
|
use PhpOption\Option;
|
||||||
|
|
||||||
class Text implements FieldInterface, RequiredInterface
|
class Text implements FieldInterface, RequiredInterface
|
||||||
{
|
{
|
||||||
@@ -44,5 +48,27 @@ class Text implements FieldInterface, RequiredInterface
|
|||||||
{
|
{
|
||||||
return empty(trim($value));
|
return empty(trim($value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function toJsonSchema(): Property
|
||||||
|
{
|
||||||
|
return new TypeProperty(
|
||||||
|
type: PropertyType::STRING,
|
||||||
|
id: $this->name,
|
||||||
|
title: Option::fromValue($this->label),
|
||||||
|
description: Option::fromValue($this->help, ""),
|
||||||
|
default: Option::fromValue($this->default, ""),
|
||||||
|
minLength: Option::fromValue($this->min),
|
||||||
|
maxLength: Option::fromValue($this->max),
|
||||||
|
readOnly: Option::fromValue($this->readonly, false),
|
||||||
|
enum: Option::fromValue(array_keys($this->selectOptions ?? []),[]),
|
||||||
|
comment: Option::fromValue($this->group, ""),
|
||||||
|
format: none(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isRequired(): bool
|
||||||
|
{
|
||||||
|
return $this->required;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,15 @@
|
|||||||
|
|
||||||
namespace Lucent\Schema\Ui;
|
namespace Lucent\Schema\Ui;
|
||||||
|
|
||||||
|
use Lucent\JsonSchema\Property\Property;
|
||||||
|
use Lucent\JsonSchema\Property\PropertyType;
|
||||||
|
use Lucent\JsonSchema\Property\TypeProperty;
|
||||||
use Lucent\Schema\FieldInfo;
|
use Lucent\Schema\FieldInfo;
|
||||||
use Lucent\Schema\FieldInterface;
|
use Lucent\Schema\FieldInterface;
|
||||||
use Lucent\Schema\FieldType;
|
use Lucent\Schema\FieldType;
|
||||||
use Lucent\Schema\Nullable;
|
use Lucent\Schema\Nullable;
|
||||||
use Lucent\Schema\Validator\RequiredInterface;
|
use Lucent\Schema\Validator\RequiredInterface;
|
||||||
|
use PhpOption\Option;
|
||||||
|
|
||||||
class Textarea implements FieldInterface, RequiredInterface
|
class Textarea implements FieldInterface, RequiredInterface
|
||||||
{
|
{
|
||||||
@@ -41,5 +45,27 @@ class Textarea implements FieldInterface, RequiredInterface
|
|||||||
return empty(trim($value));
|
return empty(trim($value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isRequired(): bool
|
||||||
|
{
|
||||||
|
return $this->required;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toJsonSchema(): Property
|
||||||
|
{
|
||||||
|
return new TypeProperty(
|
||||||
|
type: PropertyType::STRING,
|
||||||
|
id: $this->name,
|
||||||
|
title: Option::fromValue($this->label),
|
||||||
|
description: Option::fromValue($this->help, ""),
|
||||||
|
default: Option::fromValue($this->default, ""),
|
||||||
|
minLength: Option::fromValue($this->min),
|
||||||
|
maxLength: Option::fromValue($this->max),
|
||||||
|
readOnly: Option::fromValue($this->readonly, false),
|
||||||
|
enum: none(),
|
||||||
|
comment: Option::fromValue($this->group, ""),
|
||||||
|
format: none(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,15 @@
|
|||||||
|
|
||||||
namespace Lucent\Schema\Ui;
|
namespace Lucent\Schema\Ui;
|
||||||
|
|
||||||
|
use Lucent\JsonSchema\Property\Property;
|
||||||
|
use Lucent\JsonSchema\Property\PropertyType;
|
||||||
|
use Lucent\JsonSchema\Property\TypeProperty;
|
||||||
use Lucent\Schema\FieldInfo;
|
use Lucent\Schema\FieldInfo;
|
||||||
use Lucent\Schema\FieldInterface;
|
use Lucent\Schema\FieldInterface;
|
||||||
use Lucent\Schema\FieldType;
|
use Lucent\Schema\FieldType;
|
||||||
use Lucent\Schema\Nullable;
|
use Lucent\Schema\Nullable;
|
||||||
use Lucent\Schema\Validator\RequiredInterface;
|
use Lucent\Schema\Validator\RequiredInterface;
|
||||||
|
use PhpOption\Option;
|
||||||
|
|
||||||
class Uuid implements FieldInterface, RequiredInterface
|
class Uuid implements FieldInterface, RequiredInterface
|
||||||
{
|
{
|
||||||
@@ -37,5 +41,27 @@ class Uuid implements FieldInterface, RequiredInterface
|
|||||||
{
|
{
|
||||||
return empty(trim($value));
|
return empty(trim($value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isRequired(): bool
|
||||||
|
{
|
||||||
|
return $this->required;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toJsonSchema(): Property
|
||||||
|
{
|
||||||
|
return new TypeProperty(
|
||||||
|
type: PropertyType::STRING,
|
||||||
|
id: $this->name,
|
||||||
|
title: Option::fromValue($this->label),
|
||||||
|
description: Option::fromValue($this->help, ""),
|
||||||
|
default: none(),
|
||||||
|
minLength: none(),
|
||||||
|
maxLength: none(),
|
||||||
|
readOnly: Option::fromValue($this->readonly, false),
|
||||||
|
enum: none(),
|
||||||
|
comment: Option::fromValue($this->group, ""),
|
||||||
|
format: some("uuid"),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user