Json Schema transformer is done

Form builder stuck on infinite recurrsion
This commit is contained in:
2024-03-14 22:12:26 +02:00
parent 584fe7eb95
commit 842bd71a18
30 changed files with 919 additions and 3 deletions
+17
View File
@@ -50,5 +50,22 @@ class File implements FieldInterface, MinMaxInterface
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(),
);
}
}
+2
View File
@@ -7,5 +7,7 @@ interface FieldInterface
{
public function format(array $input, array $output): array;
public function isRequired(): bool;
}
+26
View File
@@ -2,11 +2,15 @@
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\FieldInterface;
use Lucent\Schema\FieldType;
use Lucent\Schema\Nullable;
use Lucent\Schema\Validator\RequiredInterface;
use PhpOption\Option;
class Block implements FieldInterface, RequiredInterface
{
@@ -43,4 +47,26 @@ class Block implements FieldInterface, RequiredInterface
{
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(),
);
}
}
+26
View File
@@ -2,11 +2,15 @@
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\FieldInterface;
use Lucent\Schema\FieldType;
use Lucent\Schema\Nullable;
use Lucent\Schema\Validator\RequiredInterface;
use PhpOption\Option;
use function is_bool;
class Checkbox implements FieldInterface, RequiredInterface
@@ -45,5 +49,27 @@ class Checkbox implements FieldInterface, RequiredInterface
{
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(),
);
}
}
+26
View File
@@ -2,11 +2,15 @@
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\FieldInterface;
use Lucent\Schema\FieldType;
use Lucent\Schema\Nullable;
use Lucent\Schema\Validator\RequiredInterface;
use PhpOption\Option;
class Color implements FieldInterface, RequiredInterface
{
@@ -41,5 +45,27 @@ class Color implements FieldInterface, RequiredInterface
{
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(),
);
}
}
+26
View File
@@ -3,12 +3,16 @@
namespace Lucent\Schema\Ui;
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\FieldInterface;
use Lucent\Schema\FieldType;
use Lucent\Schema\Nullable;
use Lucent\Schema\Validator\MinMaxInterface;
use Lucent\Schema\Validator\RequiredInterface;
use PhpOption\Option;
class Date implements FieldInterface, RequiredInterface, MinMaxInterface
{
@@ -70,5 +74,27 @@ class Date implements FieldInterface, RequiredInterface, MinMaxInterface
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"),
);
}
}
+27
View File
@@ -3,12 +3,16 @@
namespace Lucent\Schema\Ui;
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\FieldInterface;
use Lucent\Schema\FieldType;
use Lucent\Schema\Nullable;
use Lucent\Schema\Validator\MinMaxInterface;
use Lucent\Schema\Validator\RequiredInterface;
use PhpOption\Option;
class Datetime implements FieldInterface, RequiredInterface, MinMaxInterface
{
@@ -70,5 +74,28 @@ class Datetime implements FieldInterface, RequiredInterface, MinMaxInterface
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"),
);
}
}
+24
View File
@@ -2,10 +2,15 @@
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\FieldInterface;
use Lucent\Schema\FieldType;
use Lucent\Schema\Validator\MinMaxInterface;
use PhpOption\Option;
class File implements FieldInterface, MinMaxInterface
{
@@ -52,5 +57,24 @@ class File implements FieldInterface, MinMaxInterface
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;
}
}
+26
View File
@@ -2,11 +2,15 @@
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\FieldInterface;
use Lucent\Schema\FieldType;
use Lucent\Schema\Nullable;
use Lucent\Schema\Validator\RequiredInterface;
use PhpOption\Option;
class Json implements FieldInterface, RequiredInterface
{
@@ -43,4 +47,26 @@ class Json implements FieldInterface, RequiredInterface
{
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(),
);
}
}
+26
View File
@@ -2,11 +2,15 @@
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\FieldInterface;
use Lucent\Schema\FieldType;
use Lucent\Schema\Nullable;
use Lucent\Schema\Validator\RequiredInterface;
use PhpOption\Option;
class Markdown implements FieldInterface, RequiredInterface
{
@@ -39,4 +43,26 @@ class Markdown implements FieldInterface, RequiredInterface
{
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(),
);
}
}
+28
View File
@@ -2,12 +2,16 @@
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\FieldInterface;
use Lucent\Schema\FieldType;
use Lucent\Schema\Nullable;
use Lucent\Schema\Validator\MinMaxInterface;
use Lucent\Schema\Validator\RequiredInterface;
use PhpOption\Option;
class Number implements FieldInterface, RequiredInterface, MinMaxInterface
{
@@ -74,5 +78,29 @@ class Number implements FieldInterface, RequiredInterface, MinMaxInterface
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(),
);
}
}
+25 -1
View File
@@ -2,10 +2,15 @@
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\FieldInterface;
use Lucent\Schema\FieldType;
use Lucent\Schema\Validator\MinMaxInterface;
use PhpOption\Option;
class Reference implements FieldInterface, MinMaxInterface
{
@@ -22,7 +27,7 @@ class Reference implements FieldInterface, MinMaxInterface
public ?int $min = null,
public ?int $max = null,
public array $collections = [],
public string $searchField = "",
public string $searchField = "",
public string $layout = "",
public string $group = "",
)
@@ -53,5 +58,24 @@ class Reference implements FieldInterface, MinMaxInterface
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, ""),
);
}
}
+28
View File
@@ -2,11 +2,15 @@
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\FieldInterface;
use Lucent\Schema\FieldType;
use Lucent\Schema\Nullable;
use Lucent\Schema\Validator\RequiredInterface;
use PhpOption\Option;
class Rich implements FieldInterface, RequiredInterface
{
@@ -39,4 +43,28 @@ class Rich implements FieldInterface, RequiredInterface
{
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(),
);
}
}
+26
View File
@@ -3,11 +3,15 @@
namespace Lucent\Schema\Ui;
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\FieldInterface;
use Lucent\Schema\FieldType;
use Lucent\Schema\Nullable;
use Lucent\Schema\Validator\RequiredInterface;
use PhpOption\Option;
class Slug implements FieldInterface, RequiredInterface
{
@@ -46,5 +50,27 @@ class Slug implements FieldInterface, RequiredInterface
{
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(),
);
}
}
+26
View File
@@ -2,11 +2,15 @@
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\FieldInterface;
use Lucent\Schema\FieldType;
use Lucent\Schema\Nullable;
use Lucent\Schema\Validator\RequiredInterface;
use PhpOption\Option;
class Text implements FieldInterface, RequiredInterface
{
@@ -44,5 +48,27 @@ class Text implements FieldInterface, RequiredInterface
{
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;
}
}
+26
View File
@@ -2,11 +2,15 @@
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\FieldInterface;
use Lucent\Schema\FieldType;
use Lucent\Schema\Nullable;
use Lucent\Schema\Validator\RequiredInterface;
use PhpOption\Option;
class Textarea implements FieldInterface, RequiredInterface
{
@@ -41,5 +45,27 @@ class Textarea implements FieldInterface, RequiredInterface
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(),
);
}
}
+26
View File
@@ -2,11 +2,15 @@
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\FieldInterface;
use Lucent\Schema\FieldType;
use Lucent\Schema\Nullable;
use Lucent\Schema\Validator\RequiredInterface;
use PhpOption\Option;
class Uuid implements FieldInterface, RequiredInterface
{
@@ -37,5 +41,27 @@ class Uuid implements FieldInterface, RequiredInterface
{
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"),
);
}
}