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

api-platform / core / 15133993414

20 May 2025 09:30AM UTC coverage: 26.313% (-1.2%) from 27.493%
15133993414

Pull #7161

github

web-flow
Merge e2c03d45f into 5459ba375
Pull Request #7161: fix(metadata): infer parameter string type from schema

0 of 2 new or added lines in 1 file covered. (0.0%)

11019 existing lines in 363 files now uncovered.

12898 of 49018 relevant lines covered (26.31%)

34.33 hits per line

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

92.77
/src/Metadata/HttpOperation.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 ApiPlatform\Metadata\Exception\ProblemExceptionInterface;
17
use ApiPlatform\OpenApi\Attributes\Webhook;
18
use ApiPlatform\OpenApi\Model\Operation as OpenApiOperation;
19
use ApiPlatform\State\OptionsInterface;
20
use Symfony\Component\WebLink\Link as WebLink;
21

22
class HttpOperation extends Operation
23
{
24
    public const METHOD_GET = 'GET';
25
    public const METHOD_POST = 'POST';
26
    public const METHOD_PUT = 'PUT';
27
    public const METHOD_PATCH = 'PATCH';
28
    public const METHOD_DELETE = 'DELETE';
29
    public const METHOD_HEAD = 'HEAD';
30
    public const METHOD_OPTIONS = 'OPTIONS';
31

32
    /**
33
     * @param string[]|null                                  $types         the RDF types of this property
34
     * @param array<int|string, string|string[]>|string|null $formats       {@see https://api-platform.com/docs/core/content-negotiation/#configuring-formats-for-a-specific-resource-or-operation}
35
     * @param array<int|string, string|string[]>|string|null $inputFormats  {@see https://api-platform.com/docs/core/content-negotiation/#configuring-formats-for-a-specific-resource-or-operation}
36
     * @param array<int|string, string|string[]>|string|null $outputFormats {@see https://api-platform.com/docs/core/content-negotiation/#configuring-formats-for-a-specific-resource-or-operation}
37
     * @param array<string,array{
38
     *     0: string,
39
     *     1: string
40
     * }|array{
41
     *     from_property?: string,
42
     *     to_property?: string,
43
     *     from_class?: string,
44
     *     to_class?: string,
45
     *     identifiers?: string[],
46
     *     composite_identifier?: bool,
47
     *     expanded_value?: string,
48
     * }|Link>|string[]|string|null $uriVariables {@see https://api-platform.com/docs/core/subresources/}
49
     * @param string|null     $routePrefix {@see https://api-platform.com/docs/core/operations/#prefixing-all-routes-of-all-operations}
50
     * @param string|null     $sunset      {@see https://api-platform.com/docs/core/deprecations/#setting-the-sunset-http-header-to-indicate-when-a-resource-or-an-operation-will-be-removed}
51
     * @param string|int|null $status      {@see https://api-platform.com/docs/core/operations/#configuring-operations}
52
     * @param array{
53
     *     max_age?: int,
54
     *     vary?: string|string[],
55
     *     public?: bool,
56
     *     shared_max_age?: int,
57
     *     stale_while_revalidate?: int,
58
     *     stale-if-error?: int,
59
     * }|null $cacheHeaders {@see https://api-platform.com/docs/core/performance/#setting-custom-http-cache-headers}
60
     * @param array<string, string>|null $headers
61
     * @param array{
62
     *     field: string,
63
     *     direction: string,
64
     * }|null $paginationViaCursor {@see https://api-platform.com/docs/core/pagination/#cursor-based-pagination}
65
     * @param array|null $normalizationContext   {@see https://api-platform.com/docs/core/serialization/#using-serialization-groups}
66
     * @param array|null $denormalizationContext {@see https://api-platform.com/docs/core/serialization/#using-serialization-groups}
67
     * @param array|null $hydraContext           {@see https://api-platform.com/docs/core/extending-jsonld-context/#hydra}
68
     * @param array{
69
     *     class?: string|null,
70
     *     name?: string,
71
     * }|string|false|null $input {@see https://api-platform.com/docs/core/dto/#specifying-an-input-or-an-output-data-representation}
72
     * @param array{
73
     *     class?: string|null,
74
     *     name?: string,
75
     * }|string|false|null $output {@see https://api-platform.com/docs/core/dto/#specifying-an-input-or-an-output-data-representation}
76
     * @param string|array|bool|null                              $mercure   {@see https://api-platform.com/docs/core/mercure}
77
     * @param string|bool|null                                    $messenger {@see https://api-platform.com/docs/core/messenger/#dispatching-a-resource-through-the-message-bus}
78
     * @param string|callable|null                                $provider  {@see https://api-platform.com/docs/core/state-providers/#state-providers}
79
     * @param string|callable|null                                $processor {@see https://api-platform.com/docs/core/state-processors/#state-processors}
80
     * @param WebLink[]|null                                      $links
81
     * @param array<class-string<ProblemExceptionInterface>>|null $errors
82
     */
83
    public function __construct(
84
        protected string $method = 'GET',
85
        protected ?string $uriTemplate = null,
86
        protected ?array $types = null,
87
        protected $formats = null,
88
        protected $inputFormats = null,
89
        protected $outputFormats = null,
90
        protected $uriVariables = null,
91
        protected ?string $routePrefix = null,
92
        protected ?string $routeName = null,
93
        protected ?array $defaults = null,
94
        protected ?array $requirements = null,
95
        protected ?array $options = null,
96
        protected ?bool $stateless = null,
97
        /**
98
         * The `sunset` option indicates when a deprecated operation will be removed.
99
         *
100
         * <div data-code-selector>
101
         *
102
         * ```php
103
         * <?php
104
         * // api/src/Entity/Parchment.php
105
         * use ApiPlatform\Metadata\Get;
106
         *
107
         * #[Get(deprecationReason: 'Create a Book instead', sunset: '01/01/2020')]
108
         * class Parchment
109
         * {
110
         *     // ...
111
         * }
112
         * ```
113
         *
114
         * ```yaml
115
         * # api/config/api_platform/resources.yaml
116
         * resources:
117
         *     App\Entity\Parchment:
118
         *         - operations:
119
         *               ApiPlatform\Metadata\Get:
120
         *                   deprecationReason: 'Create a Book instead'
121
         *                   sunset: '01/01/2020'
122
         * ```
123
         *
124
         * ```xml
125
         * <?xml version="1.0" encoding="UTF-8" ?>
126
         * <!-- api/config/api_platform/resources.xml -->
127
         *
128
         * <resources
129
         *         xmlns="https://api-platform.com/schema/metadata/resources-3.0"
130
         *         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
131
         *         xsi:schemaLocation="https://api-platform.com/schema/metadata/resources-3.0
132
         *         https://api-platform.com/schema/metadata/resources-3.0.xsd">
133
         *     <resource class="App\Entity\Parchment">
134
         *         <operations>
135
         *             <operation class="ApiPlatform\Metadata\Get" deprecationReason="Create a Book instead" sunset="01/01/2020" />
136
         *         <operations>
137
         *     </resource>
138
         * </resources>
139
         * ```
140
         *
141
         * </div>
142
         */
143
        protected ?string $sunset = null,
144
        protected ?string $acceptPatch = null,
145
        protected $status = null,
146
        protected ?string $host = null,
147
        protected ?array $schemes = null,
148
        protected ?string $condition = null,
149
        protected ?string $controller = null,
150
        protected ?array $headers = null,
151
        protected ?array $cacheHeaders = null,
152
        protected ?array $paginationViaCursor = null,
153
        protected ?array $hydraContext = null,
154
        protected bool|OpenApiOperation|Webhook|null $openapi = null,
155
        protected ?array $exceptionToStatus = null,
156
        protected ?array $links = null,
157
        protected ?array $errors = null,
158
        protected ?bool $strictQueryParameterValidation = null,
159
        protected ?bool $hideHydraOperation = null,
160

161
        ?string $shortName = null,
162
        ?string $class = null,
163
        ?bool $paginationEnabled = null,
164
        ?string $paginationType = null,
165
        ?int $paginationItemsPerPage = null,
166
        ?int $paginationMaximumItemsPerPage = null,
167
        ?bool $paginationPartial = null,
168
        ?bool $paginationClientEnabled = null,
169
        ?bool $paginationClientItemsPerPage = null,
170
        ?bool $paginationClientPartial = null,
171
        ?bool $paginationFetchJoinCollection = null,
172
        ?bool $paginationUseOutputWalkers = null,
173
        ?array $order = null,
174
        ?string $description = null,
175
        ?array $normalizationContext = null,
176
        ?array $denormalizationContext = null,
177
        ?bool $collectDenormalizationErrors = null,
178
        string|\Stringable|null $security = null,
179
        ?string $securityMessage = null,
180
        string|\Stringable|null $securityPostDenormalize = null,
181
        ?string $securityPostDenormalizeMessage = null,
182
        string|\Stringable|null $securityPostValidation = null,
183
        ?string $securityPostValidationMessage = null,
184
        ?string $deprecationReason = null,
185
        ?array $filters = null,
186
        ?array $validationContext = null,
187
        $input = null,
188
        $output = null,
189
        $mercure = null,
190
        $messenger = null,
191
        ?bool $elasticsearch = null,
192
        ?int $urlGenerationStrategy = null,
193
        ?bool $read = null,
194
        ?bool $deserialize = null,
195
        ?bool $validate = null,
196
        ?bool $write = null,
197
        ?bool $serialize = null,
198
        ?bool $fetchPartial = null,
199
        ?bool $forceEager = null,
200
        ?int $priority = null,
201
        ?string $name = null,
202
        $provider = null,
203
        $processor = null,
204
        ?OptionsInterface $stateOptions = null,
205
        array|Parameters|null $parameters = null,
206
        array|string|null $rules = null,
207
        ?string $policy = null,
208
        array|string|null $middleware = null,
209
        ?bool $queryParameterValidationEnabled = null,
210
        array $extraProperties = [],
211
    ) {
UNCOV
212
        parent::__construct(
977✔
UNCOV
213
            shortName: $shortName,
977✔
UNCOV
214
            class: $class,
977✔
UNCOV
215
            paginationEnabled: $paginationEnabled,
977✔
UNCOV
216
            paginationType: $paginationType,
977✔
UNCOV
217
            paginationItemsPerPage: $paginationItemsPerPage,
977✔
UNCOV
218
            paginationMaximumItemsPerPage: $paginationMaximumItemsPerPage,
977✔
UNCOV
219
            paginationPartial: $paginationPartial,
977✔
UNCOV
220
            paginationClientEnabled: $paginationClientEnabled,
977✔
UNCOV
221
            paginationClientItemsPerPage: $paginationClientItemsPerPage,
977✔
UNCOV
222
            paginationClientPartial: $paginationClientPartial,
977✔
UNCOV
223
            paginationFetchJoinCollection: $paginationFetchJoinCollection,
977✔
UNCOV
224
            paginationUseOutputWalkers: $paginationUseOutputWalkers,
977✔
UNCOV
225
            order: $order,
977✔
UNCOV
226
            description: $description,
977✔
UNCOV
227
            normalizationContext: $normalizationContext,
977✔
UNCOV
228
            denormalizationContext: $denormalizationContext,
977✔
UNCOV
229
            collectDenormalizationErrors: $collectDenormalizationErrors,
977✔
UNCOV
230
            security: $security,
977✔
UNCOV
231
            securityMessage: $securityMessage,
977✔
UNCOV
232
            securityPostDenormalize: $securityPostDenormalize,
977✔
UNCOV
233
            securityPostDenormalizeMessage: $securityPostDenormalizeMessage,
977✔
UNCOV
234
            securityPostValidation: $securityPostValidation,
977✔
UNCOV
235
            securityPostValidationMessage: $securityPostValidationMessage,
977✔
UNCOV
236
            deprecationReason: $deprecationReason,
977✔
UNCOV
237
            filters: $filters,
977✔
UNCOV
238
            validationContext: $validationContext,
977✔
UNCOV
239
            input: $input,
977✔
UNCOV
240
            output: $output,
977✔
UNCOV
241
            mercure: $mercure,
977✔
UNCOV
242
            messenger: $messenger,
977✔
UNCOV
243
            elasticsearch: $elasticsearch,
977✔
UNCOV
244
            urlGenerationStrategy: $urlGenerationStrategy,
977✔
UNCOV
245
            read: $read,
977✔
UNCOV
246
            deserialize: $deserialize,
977✔
UNCOV
247
            validate: $validate,
977✔
UNCOV
248
            write: $write,
977✔
UNCOV
249
            serialize: $serialize,
977✔
UNCOV
250
            fetchPartial: $fetchPartial,
977✔
UNCOV
251
            forceEager: $forceEager,
977✔
UNCOV
252
            priority: $priority,
977✔
UNCOV
253
            name: $name,
977✔
UNCOV
254
            provider: $provider,
977✔
UNCOV
255
            processor: $processor,
977✔
UNCOV
256
            stateOptions: $stateOptions,
977✔
UNCOV
257
            parameters: $parameters,
977✔
UNCOV
258
            rules: $rules,
977✔
UNCOV
259
            policy: $policy,
977✔
UNCOV
260
            middleware: $middleware,
977✔
UNCOV
261
            queryParameterValidationEnabled: $queryParameterValidationEnabled,
977✔
UNCOV
262
            strictQueryParameterValidation: $strictQueryParameterValidation,
977✔
UNCOV
263
            hideHydraOperation: $hideHydraOperation,
977✔
UNCOV
264
            extraProperties: $extraProperties
977✔
UNCOV
265
        );
977✔
266
    }
267

268
    public function getMethod(): string
269
    {
UNCOV
270
        return $this->method;
1,017✔
271
    }
272

273
    public function withMethod(string $method): static
274
    {
UNCOV
275
        $self = clone $this;
1✔
UNCOV
276
        $self->method = $method;
1✔
277

UNCOV
278
        return $self;
1✔
279
    }
280

281
    public function getUriTemplate(): ?string
282
    {
UNCOV
283
        return $this->uriTemplate;
974✔
284
    }
285

286
    public function withUriTemplate(?string $uriTemplate = null)
287
    {
UNCOV
288
        $self = clone $this;
67✔
UNCOV
289
        $self->uriTemplate = $uriTemplate;
67✔
290

UNCOV
291
        return $self;
67✔
292
    }
293

294
    public function getTypes(): ?array
295
    {
UNCOV
296
        return $this->types;
834✔
297
    }
298

299
    /**
300
     * @param string[]|string $types
301
     */
302
    public function withTypes($types): static
303
    {
UNCOV
304
        $self = clone $this;
5✔
UNCOV
305
        $self->types = (array) $types;
5✔
306

UNCOV
307
        return $self;
5✔
308
    }
309

310
    public function getFormats()
311
    {
UNCOV
312
        return $this->formats;
68✔
313
    }
314

315
    public function withFormats($formats = null): static
316
    {
UNCOV
317
        $self = clone $this;
2✔
UNCOV
318
        $self->formats = $formats;
2✔
319

UNCOV
320
        return $self;
2✔
321
    }
322

323
    public function getInputFormats()
324
    {
UNCOV
325
        return $this->inputFormats;
279✔
326
    }
327

328
    public function withInputFormats($inputFormats = null): static
329
    {
UNCOV
330
        $self = clone $this;
67✔
UNCOV
331
        $self->inputFormats = $inputFormats;
67✔
332

UNCOV
333
        return $self;
67✔
334
    }
335

336
    public function getOutputFormats()
337
    {
UNCOV
338
        return $this->outputFormats;
830✔
339
    }
340

341
    public function withOutputFormats($outputFormats = null): static
342
    {
UNCOV
343
        $self = clone $this;
65✔
UNCOV
344
        $self->outputFormats = $outputFormats;
65✔
345

UNCOV
346
        return $self;
65✔
347
    }
348

349
    public function getUriVariables()
350
    {
UNCOV
351
        return $this->uriVariables;
948✔
352
    }
353

354
    public function withUriVariables($uriVariables): static
355
    {
UNCOV
356
        $self = clone $this;
68✔
UNCOV
357
        $self->uriVariables = $uriVariables;
68✔
358

UNCOV
359
        return $self;
68✔
360
    }
361

362
    public function getRoutePrefix(): ?string
363
    {
UNCOV
364
        return $this->routePrefix;
93✔
365
    }
366

367
    public function withRoutePrefix(string $routePrefix): static
368
    {
UNCOV
369
        $self = clone $this;
2✔
UNCOV
370
        $self->routePrefix = $routePrefix;
2✔
371

UNCOV
372
        return $self;
2✔
373
    }
374

375
    public function getRouteName(): ?string
376
    {
UNCOV
377
        return $this->routeName;
907✔
378
    }
379

380
    public function withRouteName(?string $routeName): static
381
    {
382
        $self = clone $this;
×
383
        $self->routeName = $routeName;
×
384

385
        return $self;
×
386
    }
387

388
    public function getDefaults(): ?array
389
    {
UNCOV
390
        return $this->defaults;
92✔
391
    }
392

393
    public function withDefaults(array $defaults): static
394
    {
UNCOV
395
        $self = clone $this;
2✔
UNCOV
396
        $self->defaults = $defaults;
2✔
397

UNCOV
398
        return $self;
2✔
399
    }
400

401
    public function getRequirements(): ?array
402
    {
UNCOV
403
        return $this->requirements;
92✔
404
    }
405

406
    public function withRequirements(array $requirements): static
407
    {
UNCOV
408
        $self = clone $this;
4✔
UNCOV
409
        $self->requirements = $requirements;
4✔
410

UNCOV
411
        return $self;
4✔
412
    }
413

414
    public function getOptions(): ?array
415
    {
UNCOV
416
        return $this->options;
92✔
417
    }
418

419
    public function withOptions(array $options): static
420
    {
UNCOV
421
        $self = clone $this;
1✔
UNCOV
422
        $self->options = $options;
1✔
423

UNCOV
424
        return $self;
1✔
425
    }
426

427
    public function getStateless(): ?bool
428
    {
UNCOV
429
        return $this->stateless;
92✔
430
    }
431

432
    public function withStateless($stateless): static
433
    {
UNCOV
434
        $self = clone $this;
1✔
UNCOV
435
        $self->stateless = $stateless;
1✔
436

UNCOV
437
        return $self;
1✔
438
    }
439

440
    public function getSunset(): ?string
441
    {
UNCOV
442
        return $this->sunset;
802✔
443
    }
444

445
    public function withSunset(string $sunset): static
446
    {
UNCOV
447
        $self = clone $this;
2✔
UNCOV
448
        $self->sunset = $sunset;
2✔
449

UNCOV
450
        return $self;
2✔
451
    }
452

453
    public function getAcceptPatch(): ?string
454
    {
UNCOV
455
        return $this->acceptPatch;
802✔
456
    }
457

458
    public function withAcceptPatch(string $acceptPatch): static
459
    {
UNCOV
460
        $self = clone $this;
27✔
UNCOV
461
        $self->acceptPatch = $acceptPatch;
27✔
462

UNCOV
463
        return $self;
27✔
464
    }
465

466
    public function getStatus(): ?int
467
    {
UNCOV
468
        return $this->status;
929✔
469
    }
470

471
    public function withStatus(int $status): static
472
    {
UNCOV
473
        $self = clone $this;
112✔
UNCOV
474
        $self->status = $status;
112✔
475

UNCOV
476
        return $self;
112✔
477
    }
478

479
    public function getHost(): ?string
480
    {
UNCOV
481
        return $this->host;
92✔
482
    }
483

484
    public function withHost(string $host): static
485
    {
UNCOV
486
        $self = clone $this;
1✔
UNCOV
487
        $self->host = $host;
1✔
488

UNCOV
489
        return $self;
1✔
490
    }
491

492
    public function getSchemes(): ?array
493
    {
UNCOV
494
        return $this->schemes;
92✔
495
    }
496

497
    public function withSchemes(array $schemes): static
498
    {
UNCOV
499
        $self = clone $this;
1✔
UNCOV
500
        $self->schemes = $schemes;
1✔
501

UNCOV
502
        return $self;
1✔
503
    }
504

505
    public function getCondition(): ?string
506
    {
UNCOV
507
        return $this->condition;
92✔
508
    }
509

510
    public function withCondition(string $condition): static
511
    {
UNCOV
512
        $self = clone $this;
1✔
UNCOV
513
        $self->condition = $condition;
1✔
514

UNCOV
515
        return $self;
1✔
516
    }
517

518
    public function getController(): ?string
519
    {
UNCOV
520
        return $this->controller;
101✔
521
    }
522

523
    public function withController(string $controller): static
524
    {
UNCOV
525
        $self = clone $this;
67✔
UNCOV
526
        $self->controller = $controller;
67✔
527

UNCOV
528
        return $self;
67✔
529
    }
530

531
    public function getHeaders(): ?array
532
    {
UNCOV
533
        return $this->headers;
802✔
534
    }
535

536
    public function withHeaders(array $headers): static
537
    {
538
        $self = clone $this;
1✔
539
        $self->headers = $headers;
1✔
540

541
        return $self;
1✔
542
    }
543

544
    public function getCacheHeaders(): ?array
545
    {
UNCOV
546
        return $this->cacheHeaders;
575✔
547
    }
548

549
    public function withCacheHeaders(array $cacheHeaders): static
550
    {
UNCOV
551
        $self = clone $this;
63✔
UNCOV
552
        $self->cacheHeaders = $cacheHeaders;
63✔
553

UNCOV
554
        return $self;
63✔
555
    }
556

557
    public function getPaginationViaCursor(): ?array
558
    {
UNCOV
559
        return $this->paginationViaCursor;
253✔
560
    }
561

562
    public function withPaginationViaCursor(array $paginationViaCursor): static
563
    {
564
        $self = clone $this;
1✔
565
        $self->paginationViaCursor = $paginationViaCursor;
1✔
566

567
        return $self;
1✔
568
    }
569

570
    public function getHydraContext(): ?array
571
    {
UNCOV
572
        return $this->hydraContext;
72✔
573
    }
574

575
    public function withHydraContext(array $hydraContext): static
576
    {
577
        $self = clone $this;
1✔
578
        $self->hydraContext = $hydraContext;
1✔
579

580
        return $self;
1✔
581
    }
582

583
    public function getOpenapi(): bool|OpenApiOperation|Webhook|null
584
    {
UNCOV
585
        return $this->openapi;
88✔
586
    }
587

588
    public function withOpenapi(bool|OpenApiOperation|Webhook $openapi): static
589
    {
UNCOV
590
        $self = clone $this;
4✔
UNCOV
591
        $self->openapi = $openapi;
4✔
592

UNCOV
593
        return $self;
4✔
594
    }
595

596
    public function getExceptionToStatus(): ?array
597
    {
UNCOV
598
        return $this->exceptionToStatus;
159✔
599
    }
600

601
    public function withExceptionToStatus(array $exceptionToStatus): static
602
    {
603
        $self = clone $this;
×
604
        $self->exceptionToStatus = $exceptionToStatus;
×
605

606
        return $self;
×
607
    }
608

609
    public function getLinks(): ?array
610
    {
UNCOV
611
        return $this->links;
811✔
612
    }
613

614
    /**
615
     * @param WebLink[] $links
616
     */
617
    public function withLinks(array $links): static
618
    {
619
        $self = clone $this;
×
620
        $self->links = $links;
×
621

622
        return $self;
×
623
    }
624

625
    public function getErrors(): ?array
626
    {
UNCOV
627
        return $this->errors;
22✔
628
    }
629

630
    /**
631
     * @param class-string<ProblemExceptionInterface>[] $errors
632
     */
633
    public function withErrors(array $errors): static
634
    {
635
        $self = clone $this;
×
636
        $self->errors = $errors;
×
637

638
        return $self;
×
639
    }
640
}
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

© 2025 Coveralls, Inc