Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
27pchrisl committed Sep 19, 2024
1 parent b812db2 commit 5785ee1
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Drivers/EloquentEntitySet.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public function read(PropertyValue $key): Entity
*/
protected function setModelAttributes(Model $model, PropertyValues $propertyValues): Model
{
return $propertyValues->getDeclaredPropertyValues()->reduce(function(Model $model, PropertyValue $value) {
return $propertyValues->getDeclaredPropertyValues()->reduce(function (Model $model, PropertyValue $value) {
return $model->setAttribute(
$this->getPropertySourceName($value->getProperty()),
$value->getPrimitive()->toMixed(),
Expand Down
1 change: 1 addition & 0 deletions src/Helper/ObjectArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ public function map(callable $callback)
}

/**
* Reduce the objects in the array
* @param callable(mixed $initial, mixed $value, mixed $key): mixed $callback
* @param $initial
* @return mixed|null
Expand Down
2 changes: 1 addition & 1 deletion src/PathSegment/OpenAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ public static function applyProperty(?Property $property = null, array $schema =
$schema['nullable'] = $property->isNullable();

if ($property->hasStaticDefaultValue()) {
$schema['default'] = $property->computeDefaultValue();
$schema['default'] = $property->computeDefaultValue()->toJson();
}

if ($property->hasMaxLength()) {
Expand Down
10 changes: 8 additions & 2 deletions src/Primitive.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Flat3\Lodata\Interfaces\ResponseInterface;
use Flat3\Lodata\Interfaces\SerializeInterface;
use Flat3\Lodata\Traits\HasIdentifier;
use Stringable;

/**
* Primitive
Expand Down Expand Up @@ -57,7 +58,12 @@ public function __construct($value = null)
* @return Primitive
*/
abstract public function set($value);


/**
* Test the provided value is formatted correctly for this type
* @param $value
* @return bool
*/
public function allows($value): bool
{
return true;
Expand Down Expand Up @@ -186,7 +192,7 @@ public function matches($value): bool
$value = $value->get();
}

if (is_scalar($value) || is_null($value) || $value instanceof \Stringable) {
if (is_scalar($value) || is_null($value) || $value instanceof Stringable) {
return (string) $this->get() === (string) $value;
}

Expand Down
5 changes: 5 additions & 0 deletions src/PrimitiveType.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ public function getOpenAPISchema(): array
return $this->instance()->getOpenAPISchema();
}

/**
* Test the provided value is correctly formatted for this type
* @param $value
* @return bool
*/
public function allowsValue($value): bool
{
return $this->instance()->allows($value);
Expand Down
5 changes: 5 additions & 0 deletions src/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ public function is(string $class): bool
return is_a($this->factory, $class, true);
}

/**
* Test the provided value is correctly formatted for this type
* @param $value
* @return bool
*/
public function allowsValue($value): bool
{
return true;
Expand Down
3 changes: 2 additions & 1 deletion src/Type/Guid.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Flat3\Lodata\PathSegment\OpenAPI;
use Flat3\Lodata\Primitive;
use Flat3\Lodata\Property;
use Stringable;

/**
* Guid
Expand All @@ -27,7 +28,7 @@ public function matches($value): bool
$value = $value->get();
}

if (is_scalar($value) || is_null($value) || $value instanceof \Stringable) {
if (is_scalar($value) || is_null($value) || $value instanceof Stringable) {
return (string) $this->get() === strtoupper((string) $value);
}

Expand Down
9 changes: 9 additions & 0 deletions tests/Queries/GuidTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,14 @@ public function test_filter_guid()
(new Request)
->path('/examples(00000000-0000-0000-0000-0012ea25eefb)')
);

$this->assertBadRequest(
(new Request)
->path('/examples')
->body([
'id' => 'hello',
])
->post(),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@
"a": {
"type": "string",
"nullable": false,
"default": {}
"default": "a"
},
"b": {
"type": "string",
Expand All @@ -260,7 +260,7 @@
"a": {
"type": "string",
"nullable": false,
"default": {}
"default": "a"
},
"b": {
"type": "string",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"error": {
"code": "property_value_invalid",
"message": "The value property 'id' is not valid",
"target": null,
"details": [],
"innererror": {}
}
}

0 comments on commit 5785ee1

Please sign in to comment.