Skip to content

Commit

Permalink
Fixing JSONapi pointer definition (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Nov 6, 2022
1 parent feeb309 commit 3b844e0
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 20 deletions.
9 changes: 6 additions & 3 deletions src/Controllers/ChannelPropertiesV1.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use FastyBird\Module\Devices\Queries;
use FastyBird\Module\Devices\Router;
use FastyBird\Module\Devices\Schemas;
use FastyBird\Module\Devices\Utilities;
use Fig\Http\Message\StatusCodeInterface;
use InvalidArgumentException;
use IPub\DoctrineCrud\Exceptions as DoctrineCrudExceptions;
Expand Down Expand Up @@ -148,7 +149,7 @@ public function create(
$this->translator->translate('//devices-module.base.messages.missingAttribute.heading'),
$this->translator->translate('//devices-module.base.messages.missingAttribute.message'),
[
'pointer' => 'data/attributes/' . $ex->getField(),
'/pointer' => 'data/attributes/' . $ex->getField(),
],
);
} catch (DoctrineCrudExceptions\EntityCreationException $ex) {
Expand All @@ -157,7 +158,7 @@ public function create(
$this->translator->translate('//devices-module.base.messages.missingAttribute.heading'),
$this->translator->translate('//devices-module.base.messages.missingAttribute.message'),
[
'pointer' => 'data/attributes/' . $ex->getField(),
'pointer' => '/data/attributes/' . Utilities\Api::fieldToJsonApi($ex->getField()),
],
);
} catch (Doctrine\DBAL\Exception\UniqueConstraintViolationException $ex) {
Expand All @@ -180,7 +181,9 @@ public function create(
$this->translator->translate('//devices-module.base.messages.uniqueAttribute.heading'),
$this->translator->translate('//devices-module.base.messages.uniqueAttribute.message'),
[
'pointer' => '/data/attributes/' . Utils\Strings::substring($columnKey, 7),
'pointer' => '/data/attributes/' . Utilities\Api::fieldToJsonApi(
Utils\Strings::substring($columnKey, 7),
),
],
);
}
Expand Down
9 changes: 6 additions & 3 deletions src/Controllers/ChannelsV1.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use FastyBird\Module\Devices\Queries;
use FastyBird\Module\Devices\Router;
use FastyBird\Module\Devices\Schemas;
use FastyBird\Module\Devices\Utilities;
use Fig\Http\Message\StatusCodeInterface;
use InvalidArgumentException;
use IPub\DoctrineCrud\Exceptions as DoctrineCrudExceptions;
Expand Down Expand Up @@ -137,7 +138,7 @@ public function create(
$this->translator->translate('//devices-module.base.messages.missingAttribute.heading'),
$this->translator->translate('//devices-module.base.messages.missingAttribute.message'),
[
'pointer' => 'data/attributes/' . $ex->getField(),
'pointer' => '/data/attributes/' . Utilities\Api::fieldToJsonApi($ex->getField()),
],
);
} catch (DoctrineCrudExceptions\EntityCreationException $ex) {
Expand All @@ -146,7 +147,7 @@ public function create(
$this->translator->translate('//devices-module.base.messages.missingAttribute.heading'),
$this->translator->translate('//devices-module.base.messages.missingAttribute.message'),
[
'pointer' => 'data/attributes/' . $ex->getField(),
'pointer' => '/data/attributes/' . Utilities\Api::fieldToJsonApi($ex->getField()),
],
);
} catch (Doctrine\DBAL\Exception\UniqueConstraintViolationException $ex) {
Expand All @@ -169,7 +170,9 @@ public function create(
$this->translator->translate('//devices-module.base.messages.uniqueAttribute.heading'),
$this->translator->translate('//devices-module.base.messages.uniqueAttribute.message'),
[
'pointer' => '/data/attributes/' . Utils\Strings::substring($columnKey, 7),
'pointer' => '/data/attributes/' . Utilities\Api::fieldToJsonApi(
Utils\Strings::substring($columnKey, 7),
),
],
);
}
Expand Down
9 changes: 6 additions & 3 deletions src/Controllers/ConnectorPropertiesV1.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use FastyBird\Module\Devices\Queries;
use FastyBird\Module\Devices\Router;
use FastyBird\Module\Devices\Schemas;
use FastyBird\Module\Devices\Utilities;
use Fig\Http\Message\StatusCodeInterface;
use InvalidArgumentException;
use IPub\DoctrineCrud\Exceptions as DoctrineCrudExceptions;
Expand Down Expand Up @@ -141,7 +142,7 @@ public function create(
$this->translator->translate('//devices-module.base.messages.missingAttribute.heading'),
$this->translator->translate('//devices-module.base.messages.missingAttribute.message'),
[
'pointer' => 'data/attributes/' . $ex->getField(),
'pointer' => '/data/attributes/' . Utilities\Api::fieldToJsonApi($ex->getField()),
],
);
} catch (DoctrineCrudExceptions\EntityCreationException $ex) {
Expand All @@ -150,7 +151,7 @@ public function create(
$this->translator->translate('//devices-module.base.messages.missingAttribute.heading'),
$this->translator->translate('//devices-module.base.messages.missingAttribute.message'),
[
'pointer' => 'data/attributes/' . $ex->getField(),
'pointer' => '/data/attributes/' . Utilities\Api::fieldToJsonApi($ex->getField()),
],
);
} catch (Doctrine\DBAL\Exception\UniqueConstraintViolationException $ex) {
Expand All @@ -173,7 +174,9 @@ public function create(
$this->translator->translate('//devices-module.base.messages.uniqueAttribute.heading'),
$this->translator->translate('//devices-module.base.messages.uniqueAttribute.message'),
[
'pointer' => '/data/attributes/' . Utils\Strings::substring($columnKey, 7),
'pointer' => '/data/attributes/' . Utilities\Api::fieldToJsonApi(
Utils\Strings::substring($columnKey, 7),
),
],
);
}
Expand Down
9 changes: 6 additions & 3 deletions src/Controllers/DevicePropertiesV1.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use FastyBird\Module\Devices\Queries;
use FastyBird\Module\Devices\Router;
use FastyBird\Module\Devices\Schemas;
use FastyBird\Module\Devices\Utilities;
use Fig\Http\Message\StatusCodeInterface;
use InvalidArgumentException;
use IPub\DoctrineCrud\Exceptions as DoctrineCrudExceptions;
Expand Down Expand Up @@ -140,7 +141,7 @@ public function create(
$this->translator->translate('//devices-module.base.messages.missingAttribute.heading'),
$this->translator->translate('//devices-module.base.messages.missingAttribute.message'),
[
'pointer' => 'data/attributes/' . $ex->getField(),
'pointer' => '/data/attributes/' . Utilities\Api::fieldToJsonApi($ex->getField()),
],
);
} catch (DoctrineCrudExceptions\EntityCreationException $ex) {
Expand All @@ -149,7 +150,7 @@ public function create(
$this->translator->translate('//devices-module.base.messages.missingAttribute.heading'),
$this->translator->translate('//devices-module.base.messages.missingAttribute.message'),
[
'pointer' => 'data/attributes/' . $ex->getField(),
'pointer' => '/data/attributes/' . Utilities\Api::fieldToJsonApi($ex->getField()),
],
);
} catch (Doctrine\DBAL\Exception\UniqueConstraintViolationException $ex) {
Expand All @@ -172,7 +173,9 @@ public function create(
$this->translator->translate('//devices-module.base.messages.uniqueAttribute.heading'),
$this->translator->translate('//devices-module.base.messages.uniqueAttribute.message'),
[
'pointer' => '/data/attributes/' . Utils\Strings::substring($columnKey, 7),
'pointer' => '/data/attributes/' . Utilities\Api::fieldToJsonApi(
Utils\Strings::substring($columnKey, 7),
),
],
);
}
Expand Down
13 changes: 9 additions & 4 deletions src/Controllers/DevicesV1.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use FastyBird\Module\Devices\Queries;
use FastyBird\Module\Devices\Router;
use FastyBird\Module\Devices\Schemas;
use FastyBird\Module\Devices\Utilities;
use Fig\Http\Message\StatusCodeInterface;
use InvalidArgumentException;
use IPub\DoctrineCrud\Exceptions as DoctrineCrudExceptions;
Expand Down Expand Up @@ -128,7 +129,7 @@ public function create(
$this->translator->translate('//devices-module.base.messages.missingAttribute.heading'),
$this->translator->translate('//devices-module.base.messages.missingAttribute.message'),
[
'pointer' => 'data/attributes/' . $ex->getField(),
'pointer' => '/data/attributes/' . Utilities\Api::fieldToJsonApi($ex->getField()),
],
);
} catch (DoctrineCrudExceptions\EntityCreationException $ex) {
Expand All @@ -137,7 +138,7 @@ public function create(
$this->translator->translate('//devices-module.base.messages.missingAttribute.heading'),
$this->translator->translate('//devices-module.base.messages.missingAttribute.message'),
[
'pointer' => 'data/attributes/' . $ex->getField(),
'pointer' => '/data/attributes/' . Utilities\Api::fieldToJsonApi($ex->getField()),
],
);
} catch (Doctrine\DBAL\Exception\UniqueConstraintViolationException $ex) {
Expand All @@ -160,7 +161,9 @@ public function create(
$this->translator->translate('//devices-module.base.messages.uniqueAttribute.heading'),
$this->translator->translate('//devices-module.base.messages.uniqueAttribute.message'),
[
'pointer' => '/data/attributes/' . Utils\Strings::substring($columnKey, 7),
'pointer' => '/data/attributes/' . Utilities\Api::fieldToJsonApi(
Utils\Strings::substring($columnKey, 7),
),
],
);
}
Expand Down Expand Up @@ -254,7 +257,9 @@ public function update(
$this->translator->translate('//devices-module.base.messages.uniqueAttribute.heading'),
$this->translator->translate('//devices-module.base.messages.uniqueAttribute.message'),
[
'pointer' => '/data/attributes/' . Utils\Strings::substring($columnKey, 7),
'pointer' => '/data/attributes/' . Utilities\Api::fieldToJsonApi(
Utils\Strings::substring($columnKey, 7),
),
],
);
}
Expand Down
30 changes: 30 additions & 0 deletions src/Utilities/Api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php declare(strict_types = 1);

/**
* Database.php
*
* @license More in LICENSE.md
* @copyright https://www.fastybird.com
* @author Adam Kadlec <adam.kadlec@fastybird.com>
* @package FastyBird:DevicesModule!
* @subpackage Utilities
* @since 0.73.0
*
* @date 26.10.22
*/

namespace FastyBird\Module\Devices\Utilities;

use function preg_replace;
use function strtolower;
use function strval;

class Api
{

public static function fieldToJsonApi(string $field): string
{
return strtolower(strval(preg_replace('/(?<!^)[A-Z]/', '_$0', $field)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"title" : "Missing attribute",
"detail" : "Provided request is missing required attribute",
"source" : {
"pointer" : "data/attributes/identifier"
"pointer" : "/data/attributes/identifier"
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"title" : "Missing attribute",
"detail" : "Provided request is missing required attribute",
"source" : {
"pointer" : "data/attributes/identifier"
"pointer" : "/data/attributes/identifier"
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"title" : "Missing attribute",
"detail" : "Provided request is missing required attribute",
"source" : {
"pointer" : "data/attributes/identifier"
"pointer" : "/data/attributes/identifier"
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"title" : "Missing attribute",
"detail" : "Provided request is missing required attribute",
"source" : {
"pointer" : "data/attributes/identifier"
"pointer" : "/data/attributes/identifier"
}
}
],
Expand Down

0 comments on commit 3b844e0

Please sign in to comment.