14
14
namespace ApiPlatform \Metadata ;
15
15
16
16
use Symfony \Component \PropertyInfo \Type ;
17
+ use Symfony \Component \Serializer \Attribute \Context ;
18
+ use Symfony \Component \Serializer \Attribute \Groups ;
19
+ use Symfony \Component \Serializer \Attribute \Ignore ;
20
+ use Symfony \Component \Serializer \Attribute \MaxDepth ;
21
+ use Symfony \Component \Serializer \Attribute \SerializedName ;
22
+ use Symfony \Component \Serializer \Attribute \SerializedPath ;
17
23
18
24
/**
19
25
* ApiProperty annotation.
23
29
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::TARGET_PARAMETER | \Attribute::TARGET_CLASS_CONSTANT | \Attribute::TARGET_CLASS )]
24
30
final class ApiProperty
25
31
{
32
+ private ?array $ types ;
33
+ private ?array $ serialize ;
34
+
26
35
/**
27
- * @param bool|null $readableLink https://api-platform.com/docs/core/serialization/#force-iri-with-relations-of-the-same-type-parentchilds-relations
28
- * @param bool|null $writableLink https://api-platform.com/docs/core/serialization/#force-iri-with-relations-of-the-same-type-parentchilds-relations
29
- * @param bool|null $required https://api-platform.com/docs/admin/validation/#client-side-validation
30
- * @param bool|null $identifier https://api-platform.com/docs/core/identifiers/
31
- * @param mixed $example https://api-platform.com/docs/core/openapi/#using-the-openapi-and-swagger-contexts
32
- * @param string|null $deprecationReason https://api-platform.com/docs/core/deprecations/#deprecating-resource-classes-operations-and-properties
33
- * @param bool|null $fetchEager https://api-platform.com/docs/core/performance/#eager-loading
34
- * @param array|null $jsonldContext https://api-platform.com/docs/core/extending-jsonld-context/#extending-json-ld-and-hydra-contexts
35
- * @param array|null $openapiContext https://api-platform.com/docs/core/openapi/#using-the-openapi-and-swagger-contexts
36
- * @param bool|null $push https://api-platform.com/docs/core/push-relations/
37
- * @param string|\Stringable|null $security https://api-platform.com/docs/core/security
38
- * @param string|\Stringable|null $securityPostDenormalize https://api-platform.com/docs/core/security/#executing-access-control-rules-after-denormalization
39
- * @param string[] $types the RDF types of this property
40
- * @param string[] $iris
41
- * @param Type[] $builtinTypes
42
- * @param string|null $uriTemplate (experimental) whether to return the subRessource collection IRI instead of an iterable of IRI
43
- * @param string|null $property The property name
36
+ * @param bool|null $readableLink https://api-platform.com/docs/core/serialization/#force-iri-with-relations-of-the-same-type-parentchilds-relations
37
+ * @param bool|null $writableLink https://api-platform.com/docs/core/serialization/#force-iri-with-relations-of-the-same-type-parentchilds-relations
38
+ * @param bool|null $required https://api-platform.com/docs/admin/validation/#client-side-validation
39
+ * @param bool|null $identifier https://api-platform.com/docs/core/identifiers/
40
+ * @param mixed $example https://api-platform.com/docs/core/openapi/#using-the-openapi-and-swagger-contexts
41
+ * @param string|null $deprecationReason https://api-platform.com/docs/core/deprecations/#deprecating-resource-classes-operations-and-properties
42
+ * @param bool|null $fetchEager https://api-platform.com/docs/core/performance/#eager-loading
43
+ * @param array|null $jsonldContext https://api-platform.com/docs/core/extending-jsonld-context/#extending-json-ld-and-hydra-contexts
44
+ * @param array|null $openapiContext https://api-platform.com/docs/core/openapi/#using-the-openapi-and-swagger-contexts
45
+ * @param bool|null $push https://api-platform.com/docs/core/push-relations/
46
+ * @param string|\Stringable|null $security https://api-platform.com/docs/core/security
47
+ * @param string|\Stringable|null $securityPostDenormalize https://api-platform.com/docs/core/security/#executing-access-control-rules-after-denormalization
48
+ * @param string[] $types the RDF types of this property
49
+ * @param string[] $iris
50
+ * @param Type[] $builtinTypes
51
+ * @param string|null $uriTemplate (experimental) whether to return the subRessource collection IRI instead of an iterable of IRI
52
+ * @param string|null $property The property name
53
+ * @param Context|Groups|Ignore|SerializedName|SerializedPath|MaxDepth|array<array-key, Context|Groups|Ignore|SerializedName|SerializedPath|MaxDepth> $serialize Serializer attributes
44
54
*/
45
55
public function __construct (
46
56
private ?string $ description = null ,
@@ -193,7 +203,7 @@ public function __construct(
193
203
* </div>
194
204
*/
195
205
private string |\Stringable |null $ securityPostDenormalize = null ,
196
- private array |string |null $ types = null ,
206
+ array |string |null $ types = null ,
197
207
/*
198
208
* The related php types.
199
209
*/
@@ -205,11 +215,11 @@ public function __construct(
205
215
private ?string $ uriTemplate = null ,
206
216
private ?string $ property = null ,
207
217
private ?string $ policy = null ,
218
+ array |Context |Groups |Ignore |SerializedName |SerializedPath |MaxDepth |null $ serialize = null ,
208
219
private array $ extraProperties = [],
209
220
) {
210
- if (\is_string ($ types )) {
211
- $ this ->types = (array ) $ types ;
212
- }
221
+ $ this ->types = \is_string ($ types ) ? (array ) $ types : $ types ;
222
+ $ this ->serialize = \is_array ($ serialize ) ? $ serialize : (array ) $ serialize ;
213
223
}
214
224
215
225
public function getProperty (): ?string
@@ -600,4 +610,20 @@ public function withPolicy(?string $policy): static
600
610
601
611
return $ self ;
602
612
}
613
+
614
+ public function getSerialize (): ?array
615
+ {
616
+ return $ this ->serialize ;
617
+ }
618
+
619
+ /**
620
+ * @param Context|Groups|Ignore|SerializedName|SerializedPath|MaxDepth|array<array-key, Context|Groups|Ignore|SerializedName|SerializedPath|MaxDepth> $serialize
621
+ */
622
+ public function withSerialize (array |Context |Groups |Ignore |SerializedName |SerializedPath |MaxDepth $ serialize ): static
623
+ {
624
+ $ self = clone $ this ;
625
+ $ self ->serialize = (array ) $ serialize ;
626
+
627
+ return $ self ;
628
+ }
603
629
}
0 commit comments