Skip to content

Commit eb88771

Browse files
authored
Merge pull request api-platform#4427 from dunglas/fix/api-property-types
feat(medata): ApiProperty: fix types and improve docs
2 parents 334914a + c4beb99 commit eb88771

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

src/Metadata/ApiProperty.php

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ final class ApiProperty
8383
private $securityPostDenormalize;
8484

8585
/**
86-
* The related schemas.
87-
*
8886
* @var string[]
8987
*/
9088
private $types;
@@ -108,20 +106,21 @@ final class ApiProperty
108106
* @param string $description
109107
* @param bool $readable
110108
* @param bool $writable
111-
* @param bool $readableLink
112-
* @param bool $writableLink
113-
* @param bool $required
114-
* @param bool $identifier
109+
* @param bool $readableLink https://api-platform.com/docs/core/serialization/#force-iri-with-relations-of-the-same-type-parentchilds-relations
110+
* @param bool $writableLink https://api-platform.com/docs/core/serialization/#force-iri-with-relations-of-the-same-type-parentchilds-relations
111+
* @param bool $required https://api-platform.com/docs/admin/validation/#client-side-validation
112+
* @param bool $identifier https://api-platform.com/docs/core/identifiers/
115113
* @param string|int|float|bool|array $default
116-
* @param string|int|float|bool|array $example
117-
* @param string $deprecationReason
114+
* @param string|int|float|bool|array $example https://api-platform.com/docs/core/openapi/#using-the-openapi-and-swagger-contexts
115+
* @param string $deprecationReason https://api-platform.com/docs/core/deprecations/#deprecating-resource-classes-operations-and-properties
118116
* @param bool $fetchable
119-
* @param bool $fetchEager
120-
* @param array $jsonldContext
121-
* @param array $openapiContext
122-
* @param bool $push
123-
* @param string $security
124-
* @param string $securityPostDenormalize
117+
* @param bool $fetchEager https://api-platform.com/docs/core/performance/#eager-loading
118+
* @param array $jsonldContext https://api-platform.com/docs/core/extending-jsonld-context/#extending-json-ld-and-hydra-contexts
119+
* @param array $openapiContext https://api-platform.com/docs/core/openapi/#using-the-openapi-and-swagger-contexts
120+
* @param bool $push https://api-platform.com/docs/core/push-relations/
121+
* @param string $security https://api-platform.com/docs/core/security
122+
* @param string $securityPostDenormalize https://api-platform.com/docs/core/security/#executing-access-control-rules-after-denormalization
123+
* @param string[]|string $types the RDF types of this property
125124
*/
126125
public function __construct(
127126
?string $description = null,
@@ -132,8 +131,8 @@ public function __construct(
132131
?bool $required = null,
133132
?bool $identifier = null,
134133

135-
$default = null,
136-
$example = null,
134+
$default = null,
135+
$example = null,
137136

138137
?string $deprecationReason = null,
139138
?bool $fetchable = null,
@@ -144,7 +143,7 @@ public function __construct(
144143
?string $security = null,
145144
?string $securityPostDenormalize = null,
146145

147-
?array $types = [],
146+
$types = [],
148147
?array $builtinTypes = [],
149148
?array $schema = [],
150149
?bool $initializable = null,
@@ -170,7 +169,7 @@ public function __construct(
170169
$this->security = $security;
171170
$this->openapiContext = $openapiContext;
172171
$this->securityPostDenormalize = $securityPostDenormalize;
173-
$this->types = $types;
172+
$this->types = (array) $types;
174173
$this->builtinTypes = $builtinTypes;
175174
$this->schema = $schema;
176175
$this->initializable = $initializable;
@@ -403,10 +402,13 @@ public function getTypes(): ?array
403402
return $this->types;
404403
}
405404

406-
public function withTypes(array $types = []): self
405+
/**
406+
* @param string[]|string $types
407+
*/
408+
public function withTypes($types = []): self
407409
{
408410
$self = clone $this;
409-
$self->types = $types;
411+
$self->types = (array) $types;
410412

411413
return $self;
412414
}

src/Metadata/ApiResource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ final class ApiResource
113113
* @param string $uriTemplate
114114
* @param string $shortName
115115
* @param string $description
116-
* @param string[]|string $types
116+
* @param string[]|string $types The RDF types of this resource
117117
* @param array|string $formats https://api-platform.com/docs/core/content-negotiation/#configuring-formats-for-a-specific-resource-or-operation
118118
* @param array|string $inputFormats https://api-platform.com/docs/core/content-negotiation/#configuring-formats-for-a-specific-resource-or-operation
119119
* @param array|string $outputFormats https://api-platform.com/docs/core/content-negotiation/#configuring-formats-for-a-specific-resource-or-operation

0 commit comments

Comments
 (0)