Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var/*
!var/.gitkeep
vendor/
etc/qa/.phpcs.cache
etc/qa/.phpunit.result.cache
34 changes: 20 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ else
"ghcr.io/wyrihaximusnet/php:${PHP_VERSION}-nts-alpine-slim-dev"
endif

ifneq (,$(findstring icrosoft,$(shell cat /proc/version)))
THREADS=1
else
THREADS=$(shell nproc)
endif

all: ## Runs everything ###
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | grep -v "###" | awk 'BEGIN {FS = ":.*?## "}; {printf "%s\n", $$1}' | xargs --open-tty $(MAKE)

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

unit-testing: ## Run tests
$(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
$(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

unit-testing-raw: ## Run tests ###
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
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

mutation-testing: ## Run mutation testing
$(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)

mutation-testing-raw: ## Run mutation testing ###
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)

backward-compatibility-check: ## Check code for backwards incompatible changes
$(DOCKER_RUN) vendor/bin/roave-backward-compatibility-check || true

Expand All @@ -56,17 +76,3 @@ task-list-ci: ## CI: Generate a JSON array of jobs to run, matches the commands
help: ## Show this help ###
@printf "\033[33mUsage:\033[0m\n make [target]\n\n\033[33mTargets:\033[0m\n"
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[32m%-32s\033[0m %s\n", $$1, $$2}' | tr -d '#'

generate-example-clients: generate-example-client-one generate-example-client-subsplit generate-example-client-miele

generate-example-client-one:
$(DOCKER_RUN) php ./bin/openapi-client-generator ./example/openapi-client-one.yaml

generate-example-client-subsplit:
$(DOCKER_RUN) php ./bin/openapi-client-generator ./example/openapi-client-subsplit.yaml

generate-example-client-miele:
$(DOCKER_RUN) php ./bin/openapi-client-generator ./example/openapi-client-miele.yaml

generate-test-client:
$(DOCKER_RUN) php ./bin/openapi-client-generator ./tests/openapi-client-petstore.yaml
1 change: 0 additions & 1 deletion etc/qa/.phpcs.cache

This file was deleted.

4 changes: 0 additions & 4 deletions etc/qa/phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
parameters:
ignoreErrors:
- '#Call to function in_array\(\) requires parameter \#3 to be true.#'

includes:
- ../../vendor/wyrihaximus/test-utilities/rules.neon
22 changes: 11 additions & 11 deletions etc/qa/phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="../../vendor/autoload.php" colors="true">
<testsuites>
<testsuite name="Test Suite">
<directory suffix=".php">../../tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">../../src/</directory>
</whitelist>
</filter>
<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">
<coverage>
<include>
<directory suffix=".php">../../src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Test Suite">
<directory suffix=".php">../../tests/</directory>
</testsuite>
</testsuites>
</phpunit>
12 changes: 12 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

namespace OpenAPITools\Representation;

use OpenAPITools\Utils\Namespace_;

use function array_map;

final class Client
{
/** @param array<Path> $paths */
Expand All @@ -13,4 +17,12 @@ public function __construct( /** @phpstan-ignore-line */
public readonly array $paths,
) {
}

public function namespace(Namespace_ $namespace): Namespaced\Client
{
return new Namespaced\Client(
$this->baseUrl,
array_map(static fn (Path $path): Namespaced\Path => $path->namespace($namespace), $this->paths),
);
}
}
13 changes: 13 additions & 0 deletions src/Contract.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

namespace OpenAPITools\Representation;

use OpenAPITools\Utils\ClassString;
use OpenAPITools\Utils\Namespace_;

use function array_map;

final class Contract
{
/** @param array<Property> $properties */
Expand All @@ -13,4 +18,12 @@ public function __construct(
public readonly array $properties,
) {
}

public function namespace(Namespace_ $namespace): Namespaced\Contract
{
return new Namespaced\Contract(
ClassString::factory($namespace, $this->className),
array_map(static fn (Property $property): Namespaced\Property => $property->namespace($namespace), $this->properties),
);
}
}
11 changes: 11 additions & 0 deletions src/Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace OpenAPITools\Representation;

use OpenAPITools\Utils\Namespace_;

final class Header
{
public function __construct(
Expand All @@ -12,4 +14,13 @@ public function __construct(
public readonly ExampleData $example,
) {
}

public function namespace(Namespace_ $namespace): Namespaced\Header
{
return new Namespaced\Header(
$this->name,
$this->schema->namespace($namespace),
$this->example,
);
}
}
14 changes: 14 additions & 0 deletions src/Hydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

namespace OpenAPITools\Representation;

use OpenAPITools\Utils\ClassString;
use OpenAPITools\Utils\Namespace_;

use function array_map;

final class Hydrator
{
/** @param array<Schema> $schemas */
Expand All @@ -14,4 +19,13 @@ public function __construct(
public readonly array $schemas,
) {
}

public function namespace(Namespace_ $namespace): Namespaced\Hydrator
{
return new Namespaced\Hydrator(
ClassString::factory($namespace, $this->className),
$this->methodName,
array_map(static fn (Schema $schema): Namespaced\Schema => $schema->namespace($namespace), $this->schemas),
);
}
}
16 changes: 16 additions & 0 deletions src/Namespaced/Client.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace OpenAPITools\Representation\Namespaced;

final class Client
{
/** @param array<Path> $paths */
public function __construct( /** @phpstan-ignore-line */
public readonly string|null $baseUrl,
/** @var array<Path> $paths */
public readonly array $paths,
) {
}
}
18 changes: 18 additions & 0 deletions src/Namespaced/Contract.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace OpenAPITools\Representation\Namespaced;

use OpenAPITools\Utils\ClassString;

final class Contract
{
/** @param array<Property> $properties */
public function __construct(
public readonly ClassString $className,
/** @var array<Property> $properties */
public readonly array $properties,
) {
}
}
17 changes: 17 additions & 0 deletions src/Namespaced/Header.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace OpenAPITools\Representation\Namespaced;

use OpenAPITools\Representation\ExampleData;

final class Header
{
public function __construct(
public readonly string $name,
public readonly Schema $schema,
public readonly ExampleData $example,
) {
}
}
19 changes: 19 additions & 0 deletions src/Namespaced/Hydrator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace OpenAPITools\Representation\Namespaced;

use OpenAPITools\Utils\ClassString;

final class Hydrator
{
/** @param array<Schema> $schemas */
public function __construct(
public readonly ClassString $className,
public readonly string $methodName,
/** @var array<Schema> $schemas */
public readonly array $schemas,
) {
}
}
53 changes: 53 additions & 0 deletions src/Namespaced/Operation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

declare(strict_types=1);

namespace OpenAPITools\Representation\Namespaced;

use cebe\openapi\spec\ExternalDocumentation;
use OpenAPITools\Representation\Namespaced\Operation\EmptyResponse;
use OpenAPITools\Representation\Namespaced\Operation\RequestBody;
use OpenAPITools\Representation\Namespaced\Operation\Response;
use OpenAPITools\Representation\Parameter;
use OpenAPITools\Utils\ClassString;

final readonly class Operation
{
/**
* @param array<mixed> $metaData
* @param array<string> $returnType
* @param array<Parameter> $parameters
* @param array<RequestBody> $requestBody
* @param array<Response> $response
* @param array<EmptyResponse> $empty
*/
public function __construct( /** @phpstan-ignore-line */
public ClassString $className,
public ClassString $classNameSanitized,
public ClassString $operatorClassName,
public string $operatorLookUpMethod,
public string $name,
public string $nameCamel,
public string|null $group,
public string|null $groupCamel,
public string $operationId,
public string $matchMethod,
public string $method,
public string $summary,
public ExternalDocumentation|null $externalDocs,
public string $path,
/** @var array<mixed> $metaData */
public array $metaData,
/** @var array<string> $returnType */
public array $returnType,
/** @var array<Parameter> $parameters */
public array $parameters,
/** @var array<RequestBody> $requestBody */
public array $requestBody,
/** @var array<Response> $response */
public array $response,
/** @var array<EmptyResponse> $empty */
public array $empty,
) {
}
}
19 changes: 19 additions & 0 deletions src/Namespaced/Operation/EmptyResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace OpenAPITools\Representation\Namespaced\Operation;

use OpenAPITools\Representation\Namespaced\Header;

final readonly class EmptyResponse
{
/** @param array<Header> $headers */
public function __construct(
public int $code,
public string $description,
/** @var array<Header> $headers */
public array $headers,
) {
}
}
16 changes: 16 additions & 0 deletions src/Namespaced/Operation/RequestBody.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace OpenAPITools\Representation\Namespaced\Operation;

use OpenAPITools\Representation\Namespaced\Schema;

final class RequestBody
{
public function __construct(
public readonly string $contentType,
public readonly Schema $schema,
) {
}
}
19 changes: 19 additions & 0 deletions src/Namespaced/Operation/Response.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace OpenAPITools\Representation\Namespaced\Operation;

use OpenAPITools\Representation\Namespaced\Property\Type;
use OpenAPITools\Representation\Namespaced\Schema;

final class Response
{
public function __construct(
public readonly int|string $code,
public readonly string $contentType,
public readonly string $description,
public readonly Schema|Type $content,
) {
}
}
19 changes: 19 additions & 0 deletions src/Namespaced/Path.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace OpenAPITools\Representation\Namespaced;

use OpenAPITools\Utils\ClassString;

final class Path
{
/** @param array<Operation> $operations */
public function __construct(
public readonly ClassString $className,
public readonly Hydrator $hydrator,
/** @var array<Operation> $operations */
public readonly array $operations,
) {
}
}
Loading