Thanks to visit codestin.com
Credit goes to github.com

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
12 changes: 12 additions & 0 deletions src/OpenApi/Model/Components.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ final class Components

private ?\ArrayObject $schemas;

/**
* @param \ArrayObject<string, Schema>|\ArrayObject<string, Reference> $schemas
* @param \ArrayObject<string, Response>|\ArrayObject<string, Reference> $responses
* @param \ArrayObject<string, Parameter>|\ArrayObject<string, Reference> $parameters
* @param \ArrayObject<string, Example>|\ArrayObject<string, Reference> $examples
* @param \ArrayObject<string, RequestBody>|\ArrayObject<string, Reference> $requestBodies
* @param \ArrayObject<string, Header>|\ArrayObject<string, Reference> $headers
* @param \ArrayObject<string, SecurityScheme>|\ArrayObject<string, Reference> $headers
* @param \ArrayObject<string, Link>|\ArrayObject<string, Reference> $links
* @param \ArrayObject<string, array<string, PathItem>>|\ArrayObject<string, array<string, Reference>> $callbacks
* @param \ArrayObject<string, PathItem>|\ArrayObject<string, Reference> $pathItems
*/
public function __construct(\ArrayObject $schemas = null, private ?\ArrayObject $responses = null, private ?\ArrayObject $parameters = null, private ?\ArrayObject $examples = null, private ?\ArrayObject $requestBodies = null, private ?\ArrayObject $headers = null, private ?\ArrayObject $securitySchemes = null, private ?\ArrayObject $links = null, private ?\ArrayObject $callbacks = null, private ?\ArrayObject $pathItems = null)
{
$schemas?->ksort();
Expand Down
75 changes: 75 additions & 0 deletions src/OpenApi/Model/Example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\OpenApi\Model;

final class Example
{
use ExtensionTrait;

public function __construct(private ?string $summary = null, private ?string $description = null, private mixed $value = null, private ?string $externalValue = null)
{
}

public function getSummary(): ?string
{
return $this->summary;
}

public function withSummary(string $summary): self
{
$clone = clone $this;
$clone->summary = $summary;

return $clone;
}

public function getDescription(): ?string
{
return $this->description;
}

public function withDescription(string $description): self
{
$clone = clone $this;
$clone->description = $description;

return $clone;
}

public function getValue(): mixed
{
return $this->value;
}

public function withValue(mixed $value): self
{
$clone = clone $this;
$clone->value = $value;

return $clone;
}

public function getExternalValue(): ?string
{
return $this->externalValue;
}

public function withExternalValue(string $externalValue): self
{
$clone = clone $this;
$clone->externalValue = $externalValue;

return $clone;
}
}
189 changes: 189 additions & 0 deletions src/OpenApi/Model/Header.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\OpenApi\Model;

final class Header
{
use ExtensionTrait;

public function __construct(private readonly string $in = 'header', private string $description = '', private bool $required = false, private bool $deprecated = false, private bool $allowEmptyValue = false, private array $schema = [], private ?string $style = null, private bool $explode = false, private bool $allowReserved = false, private $example = null, private ?\ArrayObject $examples = null, private ?\ArrayObject $content = null)
{
if (null === $style) {
$this->style = 'simple';
}
}

public function getIn(): string
{
return $this->in;
}

public function getDescription(): string
{
return $this->description;
}

public function getRequired(): bool
{
return $this->required;
}

public function getDeprecated(): bool
{
return $this->deprecated;
}

public function canAllowEmptyValue(): bool
{
return $this->allowEmptyValue;
}

public function getAllowEmptyValue(): bool
{
return $this->allowEmptyValue;
}

public function getSchema(): array
{
return $this->schema;
}

public function getStyle(): string
{
return $this->style;
}

public function canExplode(): bool
{
return $this->explode;
}

public function getExplode(): bool
{
return $this->explode;
}

public function canAllowReserved(): bool
{
return $this->allowReserved;
}

public function getAllowReserved(): bool
{
return $this->allowReserved;
}

public function getExample()
{
return $this->example;
}

public function getExamples(): ?\ArrayObject
{
return $this->examples;
}

public function getContent(): ?\ArrayObject
{
return $this->content;
}

public function withDescription(string $description): self
{
$clone = clone $this;
$clone->description = $description;

return $clone;
}

public function withRequired(bool $required): self
{
$clone = clone $this;
$clone->required = $required;

return $clone;
}

public function withDeprecated(bool $deprecated): self
{
$clone = clone $this;
$clone->deprecated = $deprecated;

return $clone;
}

public function withAllowEmptyValue(bool $allowEmptyValue): self
{
$clone = clone $this;
$clone->allowEmptyValue = $allowEmptyValue;

return $clone;
}

public function withSchema(array $schema): self
{
$clone = clone $this;
$clone->schema = $schema;

return $clone;
}

public function withStyle(string $style): self
{
$clone = clone $this;
$clone->style = $style;

return $clone;
}

public function withExplode(bool $explode): self
{
$clone = clone $this;
$clone->explode = $explode;

return $clone;
}

public function withAllowReserved(bool $allowReserved): self
{
$clone = clone $this;
$clone->allowReserved = $allowReserved;

return $clone;
}

public function withExample($example): self
{
$clone = clone $this;
$clone->example = $example;

return $clone;
}

public function withExamples(\ArrayObject $examples): self
{
$clone = clone $this;
$clone->examples = $examples;

return $clone;
}

public function withContent(\ArrayObject $content): self
{
$clone = clone $this;
$clone->content = $content;

return $clone;
}
}
65 changes: 65 additions & 0 deletions src/OpenApi/Model/Reference.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\OpenApi\Model;

use Symfony\Component\Serializer\Annotation\SerializedName;

final class Reference
{
use ExtensionTrait;

public function __construct(private string $ref, private ?string $summary = null, private ?string $description = null)
{
}

public function getSummary(): ?string
{
return $this->summary;
}

public function withSummary(string $summary): self
{
$clone = clone $this;
$clone->summary = $summary;

return $clone;
}

public function getDescription(): ?string
{
return $this->description;
}

public function withDescription(string $description): self
{
$clone = clone $this;
$clone->description = $description;

return $clone;
}

#[SerializedName('$ref')]
public function getRef(): string
{
return $this->ref;
}

public function withRef(string $ref): self
{
$clone = clone $this;
$clone->ref = $ref;

return $clone;
}
}
3 changes: 2 additions & 1 deletion src/OpenApi/Tests/Serializer/OpenApiNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use ApiPlatform\OpenApi\Model\Operation as OpenApiOperation;
use ApiPlatform\OpenApi\Model\Parameter;
use ApiPlatform\OpenApi\Model\Paths;
use ApiPlatform\OpenApi\Model\Schema;
use ApiPlatform\OpenApi\Model\Server;
use ApiPlatform\OpenApi\OpenApi;
use ApiPlatform\OpenApi\Options;
Expand Down Expand Up @@ -64,7 +65,7 @@ class OpenApiNormalizerTest extends TestCase

public function testNormalizeWithSchemas(): void
{
$openApi = new OpenApi(new Info('My API', '1.0.0', 'An amazing API'), [new Server('https://example.com')], new Paths(), new Components(new \ArrayObject(['z' => [], 'b' => []])));
$openApi = new OpenApi(new Info('My API', '1.0.0', 'An amazing API'), [new Server('https://example.com')], new Paths(), new Components(new \ArrayObject(['z' => new Schema(), 'b' => new Schema()])));
$encoders = [new JsonEncoder()];
$normalizers = [new ObjectNormalizer()];

Expand Down