Skip to content

Commit

Permalink
Merge a932eaf into 55cd56d
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentchalamon committed Apr 22, 2021
2 parents 55cd56d + a932eaf commit 43648ac
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@
* OpenAPI: Fix notice/warning for `response` without `content` in the `openapi_context` (#4210)
* Serializer: Convert internal error to HTTP 400 in Ramsey uuid denormalization from invalid body string (#4200)
* Symfony: Add tests with Symfony Uuid (#4230)
* OpenAPI: Allow to set extensionProperties with YAML schema definition (#4228)

## 2.6.4

Expand Down
7 changes: 7 additions & 0 deletions features/openapi/docs.feature
Expand Up @@ -213,6 +213,13 @@ Feature: Documentation support
And I should see text matching "My Dummy API"
And I should see text matching "openapi"

Scenario: OpenAPI extension properties is enabled in JSON docs
Given I send a "GET" request to "/docs.json?spec_version=3"
Then the response status code should be 200
And the response should be in JSON
And the header "Content-Type" should be equal to "application/json; charset=utf-8"
And the JSON node "paths./dummy_addresses.get.x-visibility" should be equal to "hide"

Scenario: OpenAPI UI is enabled for an arbitrary endpoint
Given I add "Accept" header equal to "text/html"
And I send a "GET" request to "/dummies?spec_version=3"
Expand Down
5 changes: 4 additions & 1 deletion src/OpenApi/Factory/OpenApiFactory.php
Expand Up @@ -281,7 +281,10 @@ private function collectPaths(ResourceMetadata $resourceMetadata, string $resour
isset($operation['openapi_context']['callbacks']) ? new \ArrayObject($operation['openapi_context']['callbacks']) : null,
$operation['openapi_context']['deprecated'] ?? (bool) $resourceMetadata->getTypedOperationAttribute($operationType, $operationName, 'deprecation_reason', false, true),
$operation['openapi_context']['security'] ?? null,
$operation['openapi_context']['servers'] ?? null
$operation['openapi_context']['servers'] ?? null,
array_filter($operation['openapi_context'] ?? [], static function ($item) {
return preg_match('/^x-.*$/i', $item);
}, \ARRAY_FILTER_USE_KEY)
));

$paths->addPath($path, $pathItem);
Expand Down
3 changes: 2 additions & 1 deletion src/OpenApi/Model/Operation.php
Expand Up @@ -30,7 +30,7 @@ final class Operation
private $servers;
private $externalDocs;

public function __construct(string $operationId = null, array $tags = [], array $responses = [], string $summary = '', string $description = '', ExternalDocumentation $externalDocs = null, array $parameters = [], RequestBody $requestBody = null, \ArrayObject $callbacks = null, bool $deprecated = false, ?array $security = null, ?array $servers = null)
public function __construct(string $operationId = null, array $tags = [], array $responses = [], string $summary = '', string $description = '', ExternalDocumentation $externalDocs = null, array $parameters = [], RequestBody $requestBody = null, \ArrayObject $callbacks = null, bool $deprecated = false, ?array $security = null, ?array $servers = null, array $extensionProperties = [])
{
$this->tags = $tags;
$this->summary = $summary;
Expand All @@ -44,6 +44,7 @@ public function __construct(string $operationId = null, array $tags = [], array
$this->security = $security;
$this->servers = $servers;
$this->externalDocs = $externalDocs;
$this->extensionProperties = $extensionProperties;
}

public function addResponse(Response $response, $status = 'default'): self
Expand Down
Expand Up @@ -834,6 +834,7 @@ static function (string $path): string {
"{$testsDirectory}/Bridge/Symfony/Bundle/DependencyInjection/Fixtures/resources/c.yaml",
"{$testsDirectory}/Bridge/Symfony/Bundle/DependencyInjection/Fixtures/resources/c/a.yaml",
"{$testsDirectory}/Fixtures/TestBundle/Resources/config/api_resources.yml",
"{$testsDirectory}/Fixtures/TestBundle/Resources/config/api_resources/dummy_address.yml",
"{$testsDirectory}/Fixtures/TestBundle/Resources/config/api_resources/my_resource.yml",
]),
$normalizePaths($paths)
Expand Down
27 changes: 27 additions & 0 deletions tests/Fixtures/TestBundle/Model/DummyAddress.php
@@ -0,0 +1,27 @@
<?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\Fixtures\TestBundle\Model;

/**
* @author Vincent Chalamon <vincentchalamon@gmail.com>
*/
class DummyAddress
{
public $id;

/**
* @var string
*/
public $address;
}
@@ -0,0 +1,6 @@
resources:
ApiPlatform\Core\Tests\Fixtures\TestBundle\Model\DummyAddress:
collectionOperations:
get:
openapi_context:
x-visibility: hide
10 changes: 7 additions & 3 deletions tests/OpenApi/Factory/OpenApiFactoryTest.php
Expand Up @@ -75,6 +75,7 @@ public function testInvoke(): void
'put' => ['method' => 'PUT'] + self::OPERATION_FORMATS,
'delete' => ['method' => 'DELETE'] + self::OPERATION_FORMATS,
'custom' => ['method' => 'HEAD', 'path' => '/foo/{id}', 'openapi_context' => [
'x-visibility' => 'hide',
'description' => 'Custom description',
'parameters' => [
['description' => 'Test parameter', 'name' => 'param', 'in' => 'path', 'required' => true],
Expand Down Expand Up @@ -454,7 +455,12 @@ public function testInvoke(): void
],
],
],
]), true)
]), true),
null,
false,
null,
null,
['x-visibility' => 'hide']
));

$formattedPath = $paths->getPath('/formatted/{id}');
Expand Down Expand Up @@ -569,8 +575,6 @@ public function testInvoke(): void

public function testOverrideDocumentation()
{
$defaultContext = ['base_url' => '/app_dev.php/'];

$dummyMetadata = new ResourceMetadata(
'Dummy',
'This is a dummy.',
Expand Down

0 comments on commit 43648ac

Please sign in to comment.