• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

api-platform / core / 3712739783

pending completion
3712739783

Pull #5254

github

GitHub
Merge 9dfa88fa6 into ac711530f
Pull Request #5254: [OpenApi] Add ApiResource::openapi and deprecate openapiContext

199 of 199 new or added lines in 6 files covered. (100.0%)

7494 of 12363 relevant lines covered (60.62%)

67.55 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.31
/src/Metadata/ApiProperty.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace ApiPlatform\Metadata;
15

16
use Symfony\Component\PropertyInfo\Type;
17

18
/**
19
 * ApiProperty annotation.
20
 *
21
 * @author Kévin Dunglas <dunglas@gmail.com>
22
 */
23
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::TARGET_PARAMETER | \Attribute::TARGET_CLASS_CONSTANT)]
24
final class ApiProperty
25
{
26
    /**
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 string|null $default
32
     * @param mixed       $example                 https://api-platform.com/docs/core/openapi/#using-the-openapi-and-swagger-contexts
33
     * @param string|null $deprecationReason       https://api-platform.com/docs/core/deprecations/#deprecating-resource-classes-operations-and-properties
34
     * @param bool|null   $fetchEager              https://api-platform.com/docs/core/performance/#eager-loading
35
     * @param array|null  $jsonldContext           https://api-platform.com/docs/core/extending-jsonld-context/#extending-json-ld-and-hydra-contexts
36
     * @param array|null  $openapiContext          https://api-platform.com/docs/core/openapi/#using-the-openapi-and-swagger-contexts
37
     * @param bool|null   $push                    https://api-platform.com/docs/core/push-relations/
38
     * @param string|null $security                https://api-platform.com/docs/core/security
39
     * @param string|null $securityPostDenormalize https://api-platform.com/docs/core/security/#executing-access-control-rules-after-denormalization
40
     * @param string[]    $types                   the RDF types of this property
41
     * @param string[]    $iris
42
     * @param Type[]      $builtinTypes
43
     */
44
    public function __construct(
45
        private ?string $description = null,
46
        private ?bool $readable = null,
47
        private ?bool $writable = null,
48
        private ?bool $readableLink = null,
49
        private ?bool $writableLink = null,
50
        private ?bool $required = null,
51
        private ?bool $identifier = null,
52
        private $default = null,
53
        private mixed $example = null,
54
        private ?string $deprecationReason = null,
55
        private ?bool $fetchable = null,
56
        private ?bool $fetchEager = null,
57
        private ?array $jsonldContext = null,
58
        private ?array $openapiContext = null,
59
        private ?array $jsonSchemaContext = null,
60
        private ?bool $push = null,
61
        private ?string $security = null,
62
        private ?string $securityPostDenormalize = null,
63
        private array|string|null $types = null,
64
        /**
65
         * The related php types.
66
         */
67
        private ?array $builtinTypes = null,
68
        private ?array $schema = null,
69
        private ?bool $initializable = null,
70
        private $iris = null,
71
        private ?bool $genId = null,
72
        private array $extraProperties = []
73
    ) {
74
        if (\is_string($types)) {
243✔
75
            $this->types = (array) $types;
×
76
        }
77
    }
78

79
    public function getDescription(): ?string
80
    {
81
        return $this->description;
328✔
82
    }
83

84
    public function withDescription(string $description): self
85
    {
86
        $self = clone $this;
119✔
87
        $self->description = $description;
119✔
88

89
        return $self;
119✔
90
    }
91

92
    public function isReadable(): ?bool
93
    {
94
        return $this->readable;
524✔
95
    }
96

97
    public function withReadable(bool $readable): self
98
    {
99
        $self = clone $this;
243✔
100
        $self->readable = $readable;
243✔
101

102
        return $self;
243✔
103
    }
104

105
    public function isWritable(): ?bool
106
    {
107
        return $this->writable;
334✔
108
    }
109

110
    public function withWritable(bool $writable): self
111
    {
112
        $self = clone $this;
243✔
113
        $self->writable = $writable;
243✔
114

115
        return $self;
243✔
116
    }
117

118
    public function isReadableLink(): ?bool
119
    {
120
        return $this->readableLink;
196✔
121
    }
122

123
    public function withReadableLink(bool $readableLink): self
124
    {
125
        $self = clone $this;
100✔
126
        $self->readableLink = $readableLink;
100✔
127

128
        return $self;
100✔
129
    }
130

131
    public function isWritableLink(): ?bool
132
    {
133
        return $this->writableLink;
151✔
134
    }
135

136
    public function withWritableLink(bool $writableLink): self
137
    {
138
        $self = clone $this;
100✔
139
        $self->writableLink = $writableLink;
100✔
140

141
        return $self;
100✔
142
    }
143

144
    public function isRequired(): ?bool
145
    {
146
        return $this->required;
247✔
147
    }
148

149
    public function withRequired(bool $required): self
150
    {
151
        $self = clone $this;
237✔
152
        $self->required = $required;
237✔
153

154
        return $self;
237✔
155
    }
156

157
    public function isIdentifier(): ?bool
158
    {
159
        return $this->identifier;
261✔
160
    }
161

162
    public function withIdentifier(bool $identifier): self
163
    {
164
        $self = clone $this;
230✔
165
        $self->identifier = $identifier;
230✔
166

167
        return $self;
230✔
168
    }
169

170
    public function getDefault()
171
    {
172
        return $this->default;
65✔
173
    }
174

175
    public function withDefault($default): self
176
    {
177
        $self = clone $this;
62✔
178
        $self->default = $default;
62✔
179

180
        return $self;
62✔
181
    }
182

183
    public function getExample(): mixed
184
    {
185
        return $this->example;
64✔
186
    }
187

188
    public function withExample(mixed $example): self
189
    {
190
        $self = clone $this;
×
191
        $self->example = $example;
×
192

193
        return $self;
×
194
    }
195

196
    public function getDeprecationReason(): ?string
197
    {
198
        return $this->deprecationReason;
172✔
199
    }
200

201
    public function withDeprecationReason($deprecationReason): self
202
    {
203
        $self = clone $this;
4✔
204
        $self->deprecationReason = $deprecationReason;
4✔
205

206
        return $self;
4✔
207
    }
208

209
    public function isFetchable(): ?bool
210
    {
211
        return $this->fetchable;
61✔
212
    }
213

214
    public function withFetchable($fetchable): self
215
    {
216
        $self = clone $this;
×
217
        $self->fetchable = $fetchable;
×
218

219
        return $self;
×
220
    }
221

222
    public function getFetchEager(): ?bool
223
    {
224
        return $this->fetchEager;
61✔
225
    }
226

227
    public function withFetchEager($fetchEager): self
228
    {
229
        $self = clone $this;
×
230
        $self->fetchEager = $fetchEager;
×
231

232
        return $self;
×
233
    }
234

235
    public function getJsonldContext(): ?array
236
    {
237
        return $this->jsonldContext;
91✔
238
    }
239

240
    public function withJsonldContext($jsonldContext): self
241
    {
242
        $self = clone $this;
3✔
243
        $self->jsonldContext = $jsonldContext;
3✔
244

245
        return $self;
3✔
246
    }
247

248
    public function getOpenapiContext(): ?array
249
    {
250
        return $this->openapiContext;
64✔
251
    }
252

253
    public function withOpenapiContext($openapiContext): self
254
    {
255
        $self = clone $this;
×
256
        $self->openapiContext = $openapiContext;
×
257

258
        return $self;
×
259
    }
260

261
    public function getJsonSchemaContext(): ?array
262
    {
263
        return $this->jsonSchemaContext;
61✔
264
    }
265

266
    public function withJsonSchemaContext($jsonSchemaContext): self
267
    {
268
        $self = clone $this;
×
269
        $self->jsonSchemaContext = $jsonSchemaContext;
×
270

271
        return $self;
×
272
    }
273

274
    public function getPush(): ?bool
275
    {
276
        return $this->push;
107✔
277
    }
278

279
    public function withPush($push): self
280
    {
281
        $self = clone $this;
1✔
282
        $self->push = $push;
1✔
283

284
        return $self;
1✔
285
    }
286

287
    public function getSecurity(): ?string
288
    {
289
        return $this->security;
525✔
290
    }
291

292
    public function withSecurity($security): self
293
    {
294
        $self = clone $this;
9✔
295
        $self->security = $security;
9✔
296

297
        return $self;
9✔
298
    }
299

300
    public function getSecurityPostDenormalize(): ?string
301
    {
302
        return $this->securityPostDenormalize;
191✔
303
    }
304

305
    public function withSecurityPostDenormalize($securityPostDenormalize): self
306
    {
307
        $self = clone $this;
9✔
308
        $self->securityPostDenormalize = $securityPostDenormalize;
9✔
309

310
        return $self;
9✔
311
    }
312

313
    public function getTypes(): ?array
314
    {
315
        return $this->types;
244✔
316
    }
317

318
    /**
319
     * @param string[]|string $types
320
     */
321
    public function withTypes(array|string $types = []): self
322
    {
323
        $self = clone $this;
28✔
324
        $self->types = (array) $types;
28✔
325

326
        return $self;
28✔
327
    }
328

329
    /**
330
     * @return Type[]
331
     */
332
    public function getBuiltinTypes(): ?array
333
    {
334
        return $this->builtinTypes;
560✔
335
    }
336

337
    /**
338
     * @param Type[] $builtinTypes
339
     */
340
    public function withBuiltinTypes(array $builtinTypes = []): self
341
    {
342
        $self = clone $this;
243✔
343
        $self->builtinTypes = $builtinTypes;
243✔
344

345
        return $self;
243✔
346
    }
347

348
    public function getSchema(): ?array
349
    {
350
        return $this->schema;
244✔
351
    }
352

353
    public function withSchema(array $schema = []): self
354
    {
355
        $self = clone $this;
3✔
356
        $self->schema = $schema;
3✔
357

358
        return $self;
3✔
359
    }
360

361
    public function withInitializable(?bool $initializable): self
362
    {
363
        $self = clone $this;
243✔
364
        $self->initializable = $initializable;
243✔
365

366
        return $self;
243✔
367
    }
368

369
    public function isInitializable(): ?bool
370
    {
371
        return $this->initializable;
292✔
372
    }
373

374
    public function getExtraProperties(): ?array
375
    {
376
        return $this->extraProperties;
61✔
377
    }
378

379
    public function withExtraProperties(array $extraProperties = []): self
380
    {
381
        $self = clone $this;
61✔
382
        $self->extraProperties = $extraProperties;
61✔
383

384
        return $self;
61✔
385
    }
386

387
    /**
388
     * Gets IRI of this property.
389
     */
390
    public function getIris()
391
    {
392
        return $this->iris;
91✔
393
    }
394

395
    /**
396
     * Returns a new instance with the given IRI.
397
     *
398
     * @param string|string[] $iris
399
     */
400
    public function withIris(string|array $iris): self
401
    {
402
        $metadata = clone $this;
16✔
403
        $metadata->iris = (array) $iris;
16✔
404

405
        return $metadata;
16✔
406
    }
407

408
    /**
409
     * Whether to generate a skolem iri on anonymous resources.
410
     */
411
    public function getGenId()
412
    {
413
        return $this->genId;
201✔
414
    }
415

416
    public function withGenId(bool $genId): self
417
    {
418
        $metadata = clone $this;
3✔
419
        $metadata->genId = $genId;
3✔
420

421
        return $metadata;
3✔
422
    }
423
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc