Skip to content

Commit ab05885

Browse files
authored
Merge pull request #1 from php-openapi-tools/add-support-for-namespaced-representation
Add support for namespaced representation
2 parents 12ee1a1 + f6960d5 commit ab05885

32 files changed

+838
-31
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var/*
22
!var/.gitkeep
33
vendor/
4+
etc/qa/.phpcs.cache
45
etc/qa/.phpunit.result.cache

Makefile

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ else
2626
"ghcr.io/wyrihaximusnet/php:${PHP_VERSION}-nts-alpine-slim-dev"
2727
endif
2828

29+
ifneq (,$(findstring icrosoft,$(shell cat /proc/version)))
30+
THREADS=1
31+
else
32+
THREADS=$(shell nproc)
33+
endif
34+
2935
all: ## Runs everything ###
3036
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | grep -v "###" | awk 'BEGIN {FS = ":.*?## "}; {printf "%s\n", $$1}' | xargs --open-tty $(MAKE)
3137

@@ -44,6 +50,20 @@ stan: ## Run static analysis (PHPStan)
4450
psalm: ## Run static analysis (Psalm)
4551
$(DOCKER_RUN) vendor/bin/psalm --threads=$(shell nproc) --shepherd --stats --config=./etc/qa/psalm.xml
4652

53+
unit-testing: ## Run tests
54+
$(DOCKER_RUN) vendor/bin/phpunit --colors=always -c ./etc/qa/phpunit.xml --coverage-text --coverage-html ./var/tests-unit-coverage-html --coverage-clover ./var/tests-unit-clover-coverage.xml
55+
$(DOCKER_RUN) test -n "$(COVERALLS_REPO_TOKEN)" && test -n "$(COVERALLS_RUN_LOCALLY)" && test -f ./var/tests-unit-clover-coverage.xml && vendor/bin/php-coveralls -v --coverage_clover ./build/logs/clover.xml --json_path ./var/tests-unit-clover-coverage-upload.json || true
56+
57+
unit-testing-raw: ## Run tests ###
58+
php vendor/phpunit/phpunit/phpunit --colors=always -c ./etc/qa/phpunit.xml --coverage-text --coverage-html ./var/tests-unit-coverage-html --coverage-clover ./var/tests-unit-clover-coverage.xml
59+
test -n "$(COVERALLS_REPO_TOKEN)" && test -n "$(COVERALLS_RUN_LOCALLY)" && test -f ./var/tests-unit-clover-coverage.xml && ./vendor/bin/php-coveralls -v --coverage_clover ./build/logs/clover.xml --json_path ./var/tests-unit-clover-coverage-upload.json || true
60+
61+
mutation-testing: ## Run mutation testing
62+
$(DOCKER_RUN) vendor/bin/roave-infection-static-analysis-plugin --ansi --log-verbosity=all --threads=$(THREADS) --psalm-config etc/qa/psalm.xml || (cat ./var/infection.log && false)
63+
64+
mutation-testing-raw: ## Run mutation testing ###
65+
php vendor/roave/infection-static-analysis-plugin/bin/roave-infection-static-analysis-plugin --ansi --log-verbosity=all --threads=$(THREADS) --psalm-config etc/qa/psalm.xml || (cat ./var/infection.log && false)
66+
4767
backward-compatibility-check: ## Check code for backwards incompatible changes
4868
$(DOCKER_RUN) vendor/bin/roave-backward-compatibility-check || true
4969

@@ -56,17 +76,3 @@ task-list-ci: ## CI: Generate a JSON array of jobs to run, matches the commands
5676
help: ## Show this help ###
5777
@printf "\033[33mUsage:\033[0m\n make [target]\n\n\033[33mTargets:\033[0m\n"
5878
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[32m%-32s\033[0m %s\n", $$1, $$2}' | tr -d '#'
59-
60-
generate-example-clients: generate-example-client-one generate-example-client-subsplit generate-example-client-miele
61-
62-
generate-example-client-one:
63-
$(DOCKER_RUN) php ./bin/openapi-client-generator ./example/openapi-client-one.yaml
64-
65-
generate-example-client-subsplit:
66-
$(DOCKER_RUN) php ./bin/openapi-client-generator ./example/openapi-client-subsplit.yaml
67-
68-
generate-example-client-miele:
69-
$(DOCKER_RUN) php ./bin/openapi-client-generator ./example/openapi-client-miele.yaml
70-
71-
generate-test-client:
72-
$(DOCKER_RUN) php ./bin/openapi-client-generator ./tests/openapi-client-petstore.yaml

etc/qa/.phpcs.cache

Lines changed: 0 additions & 1 deletion
This file was deleted.

etc/qa/phpstan.neon

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
1-
parameters:
2-
ignoreErrors:
3-
- '#Call to function in_array\(\) requires parameter \#3 to be true.#'
4-
51
includes:
62
- ../../vendor/wyrihaximus/test-utilities/rules.neon

etc/qa/phpunit.xml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit bootstrap="../../vendor/autoload.php" colors="true">
3-
<testsuites>
4-
<testsuite name="Test Suite">
5-
<directory suffix=".php">../../tests/</directory>
6-
</testsuite>
7-
</testsuites>
8-
<filter>
9-
<whitelist>
10-
<directory suffix=".php">../../src/</directory>
11-
</whitelist>
12-
</filter>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="../../vendor/autoload.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
3+
<coverage>
4+
<include>
5+
<directory suffix=".php">../../src/</directory>
6+
</include>
7+
</coverage>
8+
<testsuites>
9+
<testsuite name="Test Suite">
10+
<directory suffix=".php">../../tests/</directory>
11+
</testsuite>
12+
</testsuites>
1313
</phpunit>

src/Client.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
namespace OpenAPITools\Representation;
66

7+
use OpenAPITools\Utils\Namespace_;
8+
9+
use function array_map;
10+
711
final class Client
812
{
913
/** @param array<Path> $paths */
@@ -13,4 +17,12 @@ public function __construct( /** @phpstan-ignore-line */
1317
public readonly array $paths,
1418
) {
1519
}
20+
21+
public function namespace(Namespace_ $namespace): Namespaced\Client
22+
{
23+
return new Namespaced\Client(
24+
$this->baseUrl,
25+
array_map(static fn (Path $path): Namespaced\Path => $path->namespace($namespace), $this->paths),
26+
);
27+
}
1628
}

src/Contract.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
namespace OpenAPITools\Representation;
66

7+
use OpenAPITools\Utils\ClassString;
8+
use OpenAPITools\Utils\Namespace_;
9+
10+
use function array_map;
11+
712
final class Contract
813
{
914
/** @param array<Property> $properties */
@@ -13,4 +18,12 @@ public function __construct(
1318
public readonly array $properties,
1419
) {
1520
}
21+
22+
public function namespace(Namespace_ $namespace): Namespaced\Contract
23+
{
24+
return new Namespaced\Contract(
25+
ClassString::factory($namespace, $this->className),
26+
array_map(static fn (Property $property): Namespaced\Property => $property->namespace($namespace), $this->properties),
27+
);
28+
}
1629
}

src/Header.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace OpenAPITools\Representation;
66

7+
use OpenAPITools\Utils\Namespace_;
8+
79
final class Header
810
{
911
public function __construct(
@@ -12,4 +14,13 @@ public function __construct(
1214
public readonly ExampleData $example,
1315
) {
1416
}
17+
18+
public function namespace(Namespace_ $namespace): Namespaced\Header
19+
{
20+
return new Namespaced\Header(
21+
$this->name,
22+
$this->schema->namespace($namespace),
23+
$this->example,
24+
);
25+
}
1526
}

src/Hydrator.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
namespace OpenAPITools\Representation;
66

7+
use OpenAPITools\Utils\ClassString;
8+
use OpenAPITools\Utils\Namespace_;
9+
10+
use function array_map;
11+
712
final class Hydrator
813
{
914
/** @param array<Schema> $schemas */
@@ -14,4 +19,13 @@ public function __construct(
1419
public readonly array $schemas,
1520
) {
1621
}
22+
23+
public function namespace(Namespace_ $namespace): Namespaced\Hydrator
24+
{
25+
return new Namespaced\Hydrator(
26+
ClassString::factory($namespace, $this->className),
27+
$this->methodName,
28+
array_map(static fn (Schema $schema): Namespaced\Schema => $schema->namespace($namespace), $this->schemas),
29+
);
30+
}
1731
}

src/Namespaced/Client.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OpenAPITools\Representation\Namespaced;
6+
7+
final class Client
8+
{
9+
/** @param array<Path> $paths */
10+
public function __construct( /** @phpstan-ignore-line */
11+
public readonly string|null $baseUrl,
12+
/** @var array<Path> $paths */
13+
public readonly array $paths,
14+
) {
15+
}
16+
}

src/Namespaced/Contract.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OpenAPITools\Representation\Namespaced;
6+
7+
use OpenAPITools\Utils\ClassString;
8+
9+
final class Contract
10+
{
11+
/** @param array<Property> $properties */
12+
public function __construct(
13+
public readonly ClassString $className,
14+
/** @var array<Property> $properties */
15+
public readonly array $properties,
16+
) {
17+
}
18+
}

src/Namespaced/Header.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OpenAPITools\Representation\Namespaced;
6+
7+
use OpenAPITools\Representation\ExampleData;
8+
9+
final class Header
10+
{
11+
public function __construct(
12+
public readonly string $name,
13+
public readonly Schema $schema,
14+
public readonly ExampleData $example,
15+
) {
16+
}
17+
}

src/Namespaced/Hydrator.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OpenAPITools\Representation\Namespaced;
6+
7+
use OpenAPITools\Utils\ClassString;
8+
9+
final class Hydrator
10+
{
11+
/** @param array<Schema> $schemas */
12+
public function __construct(
13+
public readonly ClassString $className,
14+
public readonly string $methodName,
15+
/** @var array<Schema> $schemas */
16+
public readonly array $schemas,
17+
) {
18+
}
19+
}

src/Namespaced/Operation.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OpenAPITools\Representation\Namespaced;
6+
7+
use cebe\openapi\spec\ExternalDocumentation;
8+
use OpenAPITools\Representation\Namespaced\Operation\EmptyResponse;
9+
use OpenAPITools\Representation\Namespaced\Operation\RequestBody;
10+
use OpenAPITools\Representation\Namespaced\Operation\Response;
11+
use OpenAPITools\Representation\Parameter;
12+
use OpenAPITools\Utils\ClassString;
13+
14+
final readonly class Operation
15+
{
16+
/**
17+
* @param array<mixed> $metaData
18+
* @param array<string> $returnType
19+
* @param array<Parameter> $parameters
20+
* @param array<RequestBody> $requestBody
21+
* @param array<Response> $response
22+
* @param array<EmptyResponse> $empty
23+
*/
24+
public function __construct( /** @phpstan-ignore-line */
25+
public ClassString $className,
26+
public ClassString $classNameSanitized,
27+
public ClassString $operatorClassName,
28+
public string $operatorLookUpMethod,
29+
public string $name,
30+
public string $nameCamel,
31+
public string|null $group,
32+
public string|null $groupCamel,
33+
public string $operationId,
34+
public string $matchMethod,
35+
public string $method,
36+
public string $summary,
37+
public ExternalDocumentation|null $externalDocs,
38+
public string $path,
39+
/** @var array<mixed> $metaData */
40+
public array $metaData,
41+
/** @var array<string> $returnType */
42+
public array $returnType,
43+
/** @var array<Parameter> $parameters */
44+
public array $parameters,
45+
/** @var array<RequestBody> $requestBody */
46+
public array $requestBody,
47+
/** @var array<Response> $response */
48+
public array $response,
49+
/** @var array<EmptyResponse> $empty */
50+
public array $empty,
51+
) {
52+
}
53+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OpenAPITools\Representation\Namespaced\Operation;
6+
7+
use OpenAPITools\Representation\Namespaced\Header;
8+
9+
final readonly class EmptyResponse
10+
{
11+
/** @param array<Header> $headers */
12+
public function __construct(
13+
public int $code,
14+
public string $description,
15+
/** @var array<Header> $headers */
16+
public array $headers,
17+
) {
18+
}
19+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OpenAPITools\Representation\Namespaced\Operation;
6+
7+
use OpenAPITools\Representation\Namespaced\Schema;
8+
9+
final class RequestBody
10+
{
11+
public function __construct(
12+
public readonly string $contentType,
13+
public readonly Schema $schema,
14+
) {
15+
}
16+
}

src/Namespaced/Operation/Response.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OpenAPITools\Representation\Namespaced\Operation;
6+
7+
use OpenAPITools\Representation\Namespaced\Property\Type;
8+
use OpenAPITools\Representation\Namespaced\Schema;
9+
10+
final class Response
11+
{
12+
public function __construct(
13+
public readonly int|string $code,
14+
public readonly string $contentType,
15+
public readonly string $description,
16+
public readonly Schema|Type $content,
17+
) {
18+
}
19+
}

src/Namespaced/Path.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OpenAPITools\Representation\Namespaced;
6+
7+
use OpenAPITools\Utils\ClassString;
8+
9+
final class Path
10+
{
11+
/** @param array<Operation> $operations */
12+
public function __construct(
13+
public readonly ClassString $className,
14+
public readonly Hydrator $hydrator,
15+
/** @var array<Operation> $operations */
16+
public readonly array $operations,
17+
) {
18+
}
19+
}

0 commit comments

Comments
 (0)