Improved schema infos of Manufacturer endpoints

This commit is contained in:
Jan Böhmer 2023-08-06 20:50:19 +02:00
parent 676c8eeefb
commit 6b5c51bdc5
5 changed files with 20 additions and 8 deletions

View file

@ -35,7 +35,7 @@ use App\State\PartDBInfoProvider;
#[ApiResource(
uriTemplate: '/info.{_format}',
description: 'Basic information about Part-DB like version, title, etc.',
operations: [new Get()],
operations: [new Get(openapiContext: ['summary' => 'Get basic information about the installed Part-DB instance.'])],
provider: PartDBInfoProvider::class
)]
#[ApiFilter(PropertyFilter::class)]

View file

@ -40,6 +40,11 @@ use Symfony\Component\Validator\Constraints as Assert;
#[ORM\MappedSuperclass]
abstract class AbstractCompany extends AbstractPartsContainingDBElement
{
#[Groups(['company:read'])]
protected ?\DateTimeInterface $addedDate = null;
#[Groups(['company:read'])]
protected ?\DateTimeInterface $lastModified = null;
/**
* @var string The address of the company
*/

View file

@ -22,6 +22,7 @@ declare(strict_types=1);
namespace App\Entity\Base;
use ApiPlatform\Metadata\ApiProperty;
use App\Entity\Attachments\Attachment;
use App\Entity\Parameters\AbstractParameter;
use App\Repository\StructuralDBElementRepository;
@ -31,6 +32,7 @@ use Doctrine\DBAL\Types\Types;
use App\Entity\Attachments\AttachmentContainingDBElement;
use App\Entity\Parameters\ParametersTrait;
use App\Validator\Constraints\NoneOfItsChildren;
use Symfony\Component\Serializer\Annotation\SerializedName;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Constraints\Valid;
use function count;
@ -261,6 +263,8 @@ abstract class AbstractStructuralDBElement extends AttachmentContainingDBElement
*
* @return string the full path (incl. the name of this element), delimited by $delimiter
*/
#[Groups(['api:basic:read'])]
#[SerializedName('full_path')]
public function getFullPath(string $delimiter = self::PATH_DELIMITER_ARROW): string
{
if ($this->full_path_strings === []) {

View file

@ -22,10 +22,12 @@ declare(strict_types=1);
namespace App\Entity\Parts;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Link;
use ApiPlatform\Serializer\Filter\PropertyFilter;
use App\Entity\Attachments\Attachment;
use App\Entity\Attachments\AttachmentTypeAttachment;
use App\Repository\Parts\ManufacturerRepository;
@ -49,17 +51,18 @@ use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Index(name: 'manufacturer_name', columns: ['name'])]
#[ORM\Index(name: 'manufacturer_idx_parent_name', columns: ['parent_id', 'name'])]
#[ApiResource(
normalizationContext: ['groups' => ['manufacturer:read', 'company:read', 'api:basic:read']],
denormalizationContext: ['groups' => ['manufacturer:write', 'company:write', 'api:basic:write']],
normalizationContext: ['groups' => ['manufacturer:read', 'company:read', 'api:basic:read'], 'openapi_definition_name' => 'Read'],
denormalizationContext: ['groups' => ['manufacturer:write', 'company:write', 'api:basic:write'], 'openapi_definition_name' => 'Write'],
)]
#[ApiResource(
uriTemplate: '/manufacturers/{id}/children.{_format}',
operations: [new GetCollection()],
operations: [new GetCollection(openapiContext: ['summary' => 'Retrieves the children elements of a manufacturer.'])],
uriVariables: [
'id' => new Link(fromClass: Manufacturer::class, fromProperty: 'children')
],
normalizationContext: ['groups' => ['manufacturer:read', 'company:read', 'api:basic:read']]
normalizationContext: ['groups' => ['manufacturer:read', 'company:read', 'api:basic:read'], 'openapi_definition_name' => 'Read']
)]
#[ApiFilter(PropertyFilter::class)]
class Manufacturer extends AbstractCompany
{
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')]

View file

@ -83,10 +83,10 @@ use Jbtronics\TFAWebauthn\Model\TwoFactorInterface as WebauthnTwoFactorInterface
#[ApiResource(
shortName: 'User',
operations: [
new Get(),
new GetCollection(),
new Get(openapiContext: ['summary' => 'Get a specific user.']),
new GetCollection(openapiContext: ['summary' => 'Get all users defined in the system.']),
],
normalizationContext: ['groups' => ['user:read']],
normalizationContext: ['groups' => ['user:read'], 'openapi_definition_name' => 'Read'],
)]
#[ApiFilter(PropertyFilter::class)]
#[ApiFilter(SearchFilter::class, properties: ['name' => 'exact', 'email' => 'exact'])]