Skip to content

Commit bf2720f

Browse files
committed
fix(jsonshcema): make sure that the shortName is used
1 parent 86f4386 commit bf2720f

File tree

4 files changed

+76
-4
lines changed

4 files changed

+76
-4
lines changed

features/openapi/docs.feature

+21
Original file line numberDiff line numberDiff line change
@@ -299,3 +299,24 @@ Feature: Documentation support
299299
And the JSON node "components.schemas.RamseyUuidDummy.properties.id.description" should be equal to "The dummy id."
300300
And the JSON node "components.schemas.RelatedDummy-barcelona" should not exist
301301
And the JSON node "components.schemas.RelatedDummybarcelona" should exist
302+
303+
@!mongodb
304+
Scenario: Retrieve the OpenAPI documentation to see if shortName property is used
305+
Given I send a "GET" request to "/docs.json"
306+
Then the response status code should be 200
307+
And the response should be in JSON
308+
And the header "Content-Type" should be equal to "application/json; charset=utf-8"
309+
And the OpenAPI class "Resource" exists
310+
And the OpenAPI class "RelatedResource" exists
311+
And the "resourceRelated" property for the OpenAPI class "Resource" should be equal to:
312+
"""
313+
{
314+
"readOnly":true,
315+
"anyOf":[
316+
{
317+
"$ref":"#/components/schemas/RelatedResource"
318+
}
319+
],
320+
"nullable":true
321+
}
322+
"""

src/JsonSchema/SchemaFactory.php

-4
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,6 @@ private function getMetadata(string $className, string $type = Schema::TYPE_OUTP
291291
$operation = $op;
292292
break 2;
293293
}
294-
295-
if (!$operation) {
296-
$operation = new HttpOperation();
297-
}
298294
}
299295
}
300296
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace ApiPlatform\Tests\Fixtures\TestBundle\Entity;
15+
16+
use ApiPlatform\Metadata\ApiProperty;
17+
use ApiPlatform\Metadata\ApiResource;
18+
19+
#[ApiResource(
20+
shortName: 'Resource',
21+
)]
22+
class JsonSchemaResource
23+
{
24+
#[ApiProperty(identifier: true)]
25+
public $id;
26+
27+
#[ApiProperty(writable: false, readableLink: true)]
28+
public ?JsonSchemaResourceRelated $resourceRelated = null;
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace ApiPlatform\Tests\Fixtures\TestBundle\Entity;
15+
16+
use ApiPlatform\Metadata\ApiProperty;
17+
use ApiPlatform\Metadata\ApiResource;
18+
19+
#[ApiResource(
20+
shortName: 'RelatedResource',
21+
)]
22+
class JsonSchemaResourceRelated
23+
{
24+
#[ApiProperty(identifier: true)]
25+
public $id;
26+
}

0 commit comments

Comments
 (0)