Skip to content

Commit

Permalink
Model new model describers
Browse files Browse the repository at this point in the history
  • Loading branch information
DjordyKoert committed Oct 18, 2024
1 parent 183eeff commit 54599b8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 71 deletions.
8 changes: 0 additions & 8 deletions config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,6 @@
<tag name="nelmio_api_doc.model_describer" priority="100"/>
</service>

<service id="nelmio_api_doc.model_describers.datetime" class="Nelmio\ApiDocBundle\ModelDescriber\DateTimeModelDescriber" public="false">
<tag name="nelmio_api_doc.model_describer" priority="100" />
</service>

<service id="nelmio_api_doc.model_describers.uuid" class="Nelmio\ApiDocBundle\ModelDescriber\UuidModelDescriber" public="false">
<tag name="nelmio_api_doc.model_describer" priority="100" />
</service>

<service id="nelmio_api_doc.model_describers.object_fallback" class="Nelmio\ApiDocBundle\ModelDescriber\FallbackObjectModelDescriber" public="false">
<tag name="nelmio_api_doc.model_describer" priority="-1000" />
</service>
Expand Down
31 changes: 0 additions & 31 deletions src/ModelDescriber/DateTimeModelDescriber.php

This file was deleted.

32 changes: 0 additions & 32 deletions src/ModelDescriber/UuidModelDescriber.php

This file was deleted.

15 changes: 15 additions & 0 deletions src/SchemaDescriber/ObjectClassDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Symfony\Component\TypeInfo\Type;
use Symfony\Component\TypeInfo\Type\ObjectType;
use Symfony\Component\TypeInfo\TypeIdentifier;
use Symfony\Component\Uid\AbstractUid;

/**
* @implements SchemaDescriberInterface<ObjectType>
Expand All @@ -31,6 +32,20 @@ final class ObjectClassDescriber implements SchemaDescriberInterface, ModelRegis

public function describe(Type $type, Schema $schema, array $context = []): void
{
if (is_a($type->getClassName(), AbstractUid::class, true)) {
$schema->type = 'string';
$schema->format = 'uuid';

return;
}

if (is_a($type->getClassName(), \DateTimeInterface::class, true)) {
$schema->type = 'string';
$schema->format = 'date-time';

return;
}

$schema->ref = $this->modelRegistry->register(
new Model(new LegacyType('object', false, $type->getClassName()), null, null, $context)
);
Expand Down

0 comments on commit 54599b8

Please sign in to comment.