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

DoclerLabs / api-client-generator / 7855443689

10 Feb 2024 02:13PM UTC coverage: 88.421% (-0.02%) from 88.445%
7855443689

Pull #107

github

vsouz4
add explicit test case for operationId with dashes
Pull Request #107: fix operation id with dashes

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

2833 of 3204 relevant lines covered (88.42%)

3.98 hits per line

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

55.56
/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
    }
2✔
22

23
    public function create(
24
        OpenApiOperation $operation,
25
        string $path,
26
        string $method,
27
        array $commonParameters
28
    ): Operation {
29
        $operationId = $operation->operationId;
2✔
30
        /** @var string|null $operationId */
31
        if ($operationId === null) {
2✔
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, '-')) {
2✔
NEW
44
            $operationId = CaseCaster::toCamel($operationId);
×
45
        }
46

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

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

57
        try {
58
            return new Operation(
2✔
59
                $operationId,
60
                $operation->description ?? '',
2✔
61
                $this->requestMapper->create($operationId, $path, $method, $parameters, $requestBody),
2✔
62
                $this->responseMapper->createSuccessfulResponses($operationId, $responses->getResponses()),
2✔
63
                $this->responseMapper->createPossibleErrors($responses->getResponses()),
2✔
64
                $operation->tags,
2✔
65
                $operation->security ?? []
2✔
66
            );
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