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

DoclerLabs / api-client-generator / 21433352645

28 Jan 2026 09:50AM UTC coverage: 86.69% (-0.3%) from 86.973%
21433352645

push

github

web-flow
Merge pull request #131 from DoclerLabs/dependabot/composer/phpunit/phpunit-9.6.33

Bump phpunit/phpunit from 9.5.9 to 9.6.33

3465 of 3997 relevant lines covered (86.69%)

7.11 hits per line

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

53.13
/src/Input/Factory/OperationFactory.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace DoclerLabs\ApiClientGenerator\Input\Factory;
6

7
use cebe\openapi\spec\Operation as OpenApiOperation;
8
use cebe\openapi\spec\Reference;
9
use cebe\openapi\spec\RequestBody;
10
use cebe\openapi\spec\Responses;
11
use DoclerLabs\ApiClientGenerator\Entity\Operation;
12
use DoclerLabs\ApiClientGenerator\Input\InvalidSpecificationException;
13
use DoclerLabs\ApiClientGenerator\Naming\CaseCaster;
14
use InvalidArgumentException;
15
use Throwable;
16

17
class OperationFactory
18
{
19
    public function __construct(private RequestFactory $requestMapper, private ResponseFactory $responseMapper)
20
    {
21
    }
3✔
22

23
    public function create(
24
        OpenApiOperation $operation,
25
        string $path,
26
        string $method,
27
        array $commonParameters
28
    ): Operation {
29
        $operationId = $operation->operationId;
3✔
30
        /** @var string|null $operationId */
31
        if ($operationId === null) {
3✔
32
            $underscorePath = preg_replace(['/[{}]/', '@[/-]@'], ['', '_'], $path);
×
33
            if ($underscorePath === null) {
×
34
                throw new InvalidArgumentException('Error during preg_replace in ' . $path);
×
35
            }
36
            $operationId = sprintf('%s%s', strtolower($method), CaseCaster::toPascal($underscorePath));
×
37

38
            $warningMessage = sprintf(
×
39
                'Fallback operation naming used: %s. Consider adding operationId parameter to set the name explicitly.',
×
40
                $operationId
×
41
            );
×
42
            trigger_error($warningMessage, E_USER_WARNING);
×
43
        } elseif (str_contains($operationId, '-')) {
3✔
44
            $operationId = CaseCaster::toCamel($operationId);
×
45
        }
46

47
        $parameters  = array_merge($commonParameters, $operation->parameters ?? []);
3✔
48
        $requestBody = $operation->requestBody;
3✔
49
        if ($requestBody instanceof Reference) {
3✔
50
            $requestBody = $requestBody->resolve();
×
51
        }
52
        /** @var RequestBody $requestBody */
53

54
        /** @var Responses $responses */
55
        $responses = $operation->responses;
3✔
56

57
        try {
58
            return new Operation(
3✔
59
                $operationId,
3✔
60
                $operation->description ?? '',
3✔
61
                $this->requestMapper->create($operationId, $path, $method, $parameters, $requestBody),
3✔
62
                $this->responseMapper->createSuccessfulResponses($operationId, $responses->getResponses()),
3✔
63
                $this->responseMapper->createPossibleErrors($responses->getResponses()),
3✔
64
                $operation->tags,
3✔
65
                $operation->security ?? []
3✔
66
            );
3✔
67
        } catch (Throwable $exception) {
×
68
            throw new InvalidSpecificationException(
×
69
                sprintf('Error on mapping `%s`: %s', $operationId, $exception->getMessage())
×
70
            );
×
71
        }
72
    }
73
}
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