Skip to content

Commit

Permalink
Merge bd04d93 into 7cea036
Browse files Browse the repository at this point in the history
  • Loading branch information
LoicBoursin committed Jun 8, 2021
2 parents 7cea036 + bd04d93 commit 3396b58
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 17 deletions.
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -71,6 +71,7 @@
"symfony/form": "^3.4 || ^4.4 || ^5.1",
"symfony/framework-bundle": "^4.4 || ^5.1",
"symfony/http-client": "^4.4 || ^5.1",
"symfony/intl": "^3.4 || ^4.4 || ^5.1",
"symfony/mercure-bundle": "*",
"symfony/messenger": "^4.4 || ^5.1",
"symfony/phpunit-bridge": "^5.1.7",
Expand Down
2 changes: 1 addition & 1 deletion features/openapi/docs.feature
Expand Up @@ -10,7 +10,7 @@ Feature: Documentation support
And the response should be in JSON
And the header "Content-Type" should be equal to "application/json; charset=utf-8"
# Context
And the JSON node "openapi" should be equal to "3.0.3"
And the JSON node "openapi" should be equal to "3.1.0"
# Root properties
And the JSON node "info.title" should be equal to "My Dummy API"
And the JSON node "info.description" should contain "This is a test API."
Expand Down
17 changes: 16 additions & 1 deletion src/OpenApi/Model/Components.php
Expand Up @@ -26,8 +26,9 @@ final class Components
private $securitySchemes;
private $links;
private $callbacks;
private $pathItems;

public function __construct(\ArrayObject $schemas = null, \ArrayObject $responses = null, \ArrayObject $parameters = null, \ArrayObject $examples = null, \ArrayObject $requestBodies = null, \ArrayObject $headers = null, \ArrayObject $securitySchemes = null, \ArrayObject $links = null, \ArrayObject $callbacks = null)
public function __construct(\ArrayObject $schemas = null, \ArrayObject $responses = null, \ArrayObject $parameters = null, \ArrayObject $examples = null, \ArrayObject $requestBodies = null, \ArrayObject $headers = null, \ArrayObject $securitySchemes = null, \ArrayObject $links = null, \ArrayObject $callbacks = null, \ArrayObject $pathItems = null)
{
$this->schemas = $schemas;
$this->responses = $responses;
Expand All @@ -38,6 +39,7 @@ public function __construct(\ArrayObject $schemas = null, \ArrayObject $response
$this->securitySchemes = $securitySchemes;
$this->links = $links;
$this->callbacks = $callbacks;
$this->pathItems = $pathItems;
}

public function getSchemas(): ?\ArrayObject
Expand Down Expand Up @@ -85,6 +87,11 @@ public function getCallbacks(): ?\ArrayObject
return $this->callbacks;
}

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

public function withSchemas(\ArrayObject $schemas): self
{
$clone = clone $this;
Expand Down Expand Up @@ -156,4 +163,12 @@ public function withCallbacks(\ArrayObject $callbacks): self

return $clone;
}

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

return $clone;
}
}
17 changes: 16 additions & 1 deletion src/OpenApi/Model/Info.php
Expand Up @@ -23,15 +23,17 @@ final class Info
private $contact;
private $license;
private $version;
private $summary;

public function __construct(string $title, string $version, string $description = '', string $termsOfService = null, Contact $contact = null, License $license = null)
public function __construct(string $title, string $version, string $description = '', string $termsOfService = null, Contact $contact = null, License $license = null, string $summary = null)
{
$this->title = $title;
$this->version = $version;
$this->description = $description;
$this->termsOfService = $termsOfService;
$this->contact = $contact;
$this->license = $license;
$this->summary = $summary;
}

public function getTitle(): string
Expand Down Expand Up @@ -64,6 +66,11 @@ public function getVersion(): string
return $this->version;
}

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

public function withTitle(string $title): self
{
$info = clone $this;
Expand Down Expand Up @@ -111,4 +118,12 @@ public function withVersion(string $version): self

return $clone;
}

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

return $clone;
}
}
17 changes: 16 additions & 1 deletion src/OpenApi/Model/License.php
Expand Up @@ -19,11 +19,13 @@ final class License

private $name;
private $url;
private $identifier;

public function __construct(string $name, string $url = null)
public function __construct(string $name, string $url = null, string $identifier = null)
{
$this->name = $name;
$this->url = $url;
$this->identifier = $identifier;
}

public function getName(): string
Expand All @@ -36,6 +38,11 @@ public function getUrl(): ?string
return $this->url;
}

public function getIdentifier(): ?string
{
return $this->identifier;
}

public function withName(string $name): self
{
$clone = clone $this;
Expand All @@ -51,4 +58,12 @@ public function withUrl(?string $url): self

return $clone;
}

public function withIdentifier(?string $identifier): self
{
$clone = clone $this;
$clone->identifier = $identifier;

return $clone;
}
}
7 changes: 5 additions & 2 deletions src/OpenApi/Model/Schema.php
Expand Up @@ -29,9 +29,12 @@ final class Schema extends \ArrayObject
private $deprecated;
private $schema;

public function __construct(bool $nullable = false, $discriminator = null, bool $readOnly = false, bool $writeOnly = false, string $xml = null, $externalDocs = null, $example = null, bool $deprecated = false)
public function __construct(bool $nullable = null, $discriminator = null, bool $readOnly = false, bool $writeOnly = false, string $xml = null, $externalDocs = null, $example = null, bool $deprecated = false)
{
$this->nullable = $nullable;
if (null !== $nullable) {
@trigger_error('The nullable keyword has been removed from the Schema Object (null can be used as a type value). This behaviour will not be possible anymore in API Platform 3.0.', \E_USER_DEPRECATED);
$this->nullable = $nullable;
}
$this->discriminator = $discriminator;
$this->readOnly = $readOnly;
$this->writeOnly = $writeOnly;
Expand Down
26 changes: 24 additions & 2 deletions src/OpenApi/OpenApi.php
Expand Up @@ -23,7 +23,7 @@ final class OpenApi implements DocumentationInterface
{
use ExtensionTrait;

public const VERSION = '3.0.3';
public const VERSION = '3.1.0';

private $openapi;
private $info;
Expand All @@ -33,8 +33,10 @@ final class OpenApi implements DocumentationInterface
private $security;
private $tags;
private $externalDocs;
private $jsonSchemaDialect;
private $webhooks;

public function __construct(Info $info, array $servers, Paths $paths, Components $components = null, array $security = [], array $tags = [], $externalDocs = null)
public function __construct(Info $info, array $servers, Paths $paths, Components $components = null, array $security = [], array $tags = [], $externalDocs = null, string $jsonSchemaDialect = null, \ArrayObject $webhooks = null)
{
$this->openapi = self::VERSION;
$this->info = $info;
Expand All @@ -44,6 +46,8 @@ public function __construct(Info $info, array $servers, Paths $paths, Components
$this->security = $security;
$this->tags = $tags;
$this->externalDocs = $externalDocs;
$this->jsonSchemaDialect = $jsonSchemaDialect;
$this->webhooks = $webhooks;
}

public function getOpenapi(): string
Expand Down Expand Up @@ -86,6 +90,16 @@ public function getExternalDocs(): ?array
return $this->externalDocs;
}

public function getJsonSchemaDialect(): ?string
{
return $this->jsonSchemaDialect;
}

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

public function withOpenapi(string $openapi): self
{
$clone = clone $this;
Expand Down Expand Up @@ -149,4 +163,12 @@ public function withExternalDocs(array $externalDocs): self

return $clone;
}

public function withJsonSchemaDialect(array $jsonSchemaDialect): self
{
$clone = clone $this;
$clone->jsonSchemaDialect = $jsonSchemaDialect;

return $clone;
}
}
Expand Up @@ -273,12 +273,14 @@ public function testCreateWithPropertyLengthRestriction(): void
$decoratedPropertyMetadataFactory = $this->prophesize(PropertyMetadataFactoryInterface::class);
$property = 'dummy';
$decoratedPropertyMetadataFactory->create(DummyValidatedEntity::class, $property, [])->willReturn(
new PropertyMetadata(new Type(Type::BUILTIN_TYPE_STRING))
)->shouldBeCalled();
new PropertyMetadata(new Type(Type::BUILTIN_TYPE_STRING))
)->shouldBeCalled();

$lengthRestrictions = new PropertySchemaLengthRestriction();
$validatorPropertyMetadataFactory = new ValidatorPropertyMetadataFactory(
$validatorMetadataFactory->reveal(), $decoratedPropertyMetadataFactory->reveal(), [$lengthRestrictions]
$validatorMetadataFactory->reveal(),
$decoratedPropertyMetadataFactory->reveal(),
[$lengthRestrictions]
);

$schema = $validatorPropertyMetadataFactory->create(DummyValidatedEntity::class, $property)->getSchema();
Expand All @@ -299,11 +301,12 @@ public function testCreateWithPropertyRegexRestriction(): void

$decoratedPropertyMetadataFactory = $this->prophesize(PropertyMetadataFactoryInterface::class);
$decoratedPropertyMetadataFactory->create(DummyValidatedEntity::class, 'dummy', [])->willReturn(
new PropertyMetadata()
)->shouldBeCalled();
new PropertyMetadata()
)->shouldBeCalled();

$validationPropertyMetadataFactory = new ValidatorPropertyMetadataFactory(
$validatorMetadataFactory->reveal(), $decoratedPropertyMetadataFactory->reveal(),
$validatorMetadataFactory->reveal(),
$decoratedPropertyMetadataFactory->reveal(),
[new PropertySchemaRegexRestriction()]
);

Expand Down Expand Up @@ -534,7 +537,8 @@ public function testCreateWithPropertyChoiceRestriction(PropertyMetadata $proper
)->shouldBeCalled();

$validationPropertyMetadataFactory = new ValidatorPropertyMetadataFactory(
$validatorMetadataFactory->reveal(), $decoratedPropertyMetadataFactory->reveal(),
$validatorMetadataFactory->reveal(),
$decoratedPropertyMetadataFactory->reveal(),
[new PropertySchemaChoiceRestriction()]
);

Expand Down Expand Up @@ -573,7 +577,8 @@ public function testCreateWithPropertyCountRestriction(string $property, array $
)->shouldBeCalled();

$validationPropertyMetadataFactory = new ValidatorPropertyMetadataFactory(
$validatorMetadataFactory->reveal(), $decoratedPropertyMetadataFactory->reveal(),
$validatorMetadataFactory->reveal(),
$decoratedPropertyMetadataFactory->reveal(),
[new PropertySchemaCountRestriction()]
);

Expand Down Expand Up @@ -671,7 +676,8 @@ public function testCreateWithPropertyNumericRestriction(PropertyMetadata $prope
)->shouldBeCalled();

$validationPropertyMetadataFactory = new ValidatorPropertyMetadataFactory(
$validatorMetadataFactory->reveal(), $decoratedPropertyMetadataFactory->reveal(),
$validatorMetadataFactory->reveal(),
$decoratedPropertyMetadataFactory->reveal(),
[
new PropertySchemaGreaterThanOrEqualRestriction(),
new PropertySchemaGreaterThanRestriction(),
Expand Down
33 changes: 33 additions & 0 deletions tests/OpenApi/Model/SchemaTest.php
@@ -0,0 +1,33 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* 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\Core\Tests\OpenApi\Model;

use ApiPlatform\Core\OpenApi\Model\Schema;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;

class SchemaTest extends TestCase
{
use ExpectDeprecationTrait;

/**
* @group legacy
*/
public function testLegacySchema()
{
$this->expectDeprecation('The nullable keyword has been removed from the Schema Object (null can be used as a type value). This behaviour will not be possible anymore in API Platform 3.0.');

$schema = new Schema(true);
}
}
1 change: 1 addition & 0 deletions tests/OpenApi/Serializer/OpenApiNormalizerTest.php
Expand Up @@ -178,6 +178,7 @@ public function testNormalize()
$this->assertArrayNotHasKey('extensionProperties', $openApiAsArray);
// this key is null, should not be in the output
$this->assertArrayNotHasKey('termsOfService', $openApiAsArray['info']);
$this->assertArrayNotHasKey('summary', $openApiAsArray['info']);
$this->assertArrayNotHasKey('paths', $openApiAsArray['paths']);
$this->assertArrayHasKey('/dummies/{id}', $openApiAsArray['paths']);
$this->assertArrayNotHasKey('servers', $openApiAsArray['paths']['/dummies/{id}']['get']);
Expand Down

0 comments on commit 3396b58

Please sign in to comment.