8000 Ignore property docblock type when items set (#1765) · zircote/swagger-php@86ba87c · GitHub
[go: up one dir, main page]

Skip to content

Commit 86ba87c

Browse files
authored
Ignore property docblock type when items set (#1765)
1 parent def5058 commit 86ba87c

File tree

4 files changed

+170
-1
lines changed

4 files changed

+170
-1
lines changed

src/Processors/AugmentProperties.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ protected function augmentType(Analysis $analysis, OA\Property $property, Contex
7878
$type = $typeMatches[1];
7979

8080
// finalise property type/ref
81-
if (!$this->mapNativeType($property, $type)) {
81+
if (!$this->mapNativeType($property, $type) && Generator::isDefault($property->items)) {
8282
$schema = $analysis->getSchemaForSource($context->fullyQualifiedName($type));
8383
if (Generator::isDefault($property->ref) && $schema) {
8484
$property->ref = OA\Components::ref($schema);
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php declare(strict_types=1);
2+
3+
/**
4+
* @license Apache 2.0
5+
*/
6+
7+
namespace OpenApi\Tests\Fixtures\Scratch;
8+
9+
use OpenApi\Attributes as OAT;
10+
11+
#[OAT\Schema(
12+
title: 'Item Dto',
13+
required: [
14+
'name',
15+
],
16+
)]
17+
class ItemDto
18+
{
19+
#[OAT\Property(example: 'Car')]
20+
public string $name;
21+
}
22+
23+
#[OAT\Schema(
24+
title: 'Property Items',
25+
required: [
26+
'list1',
27+
],
28+
)]
29+
class PropertyItems
30+
{
31+
#[OAT\Property(
32+
description: 'Missing docblock',
33+
items: new OAT\Items(type: ItemDto::class),
34+
minItems: 2,
35+
)]
36+
public array $list1;
37+
38+
/**
39+
* @var ItemDto[] $list2
40+
*/
41+
#[OAT\Property(
42+
description: 'With docblock',
43+
items: new OAT\Items(type: ItemDto::class),
44+
minItems: 1,
45+
)]
46+
public array $list2;
47+
48+
/**
49+
* @var string[] $list3
50+
*/
51+
#[OAT\Property(
52+
description: 'Simple type',
53+
items: new OAT\Items(type: 'string', minLength: 2),
54+
maxItems: 5,
55+
minItems: 0,
56+
)]
57+
public array $list3;
58+
}
59+
60+
#[OAT\Info(
61+
title: 'Property Items Scratch',
62+
version: '1.0'
63+
)]
64+
#[OAT\Get(
65+
path: '/api/endpoint',
66+
description: 'An endpoint',
67+
responses: [new OAT\Response(response: 200, description: 'OK')]
68+
)]
69+
class PropertyItemsEndpoint
70+
{
71+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
openapi: 3.0.0
2+
info:
3+
title: 'Property Items Scratch'
4+
version: '1.0'
5+
paths:
6+
/api/endpoint:
7+
get:
8+
description: 'An endpoint'
9+
operationId: 22e79d8d650659ed1ced1f375c7e723d
10+
responses:
11+
'200':
12+
description: OK
13+
components:
14+
schemas:
15+
ItemDto:
16+
title: 'Item Dto'
17+
required:
18+
- name
19+
properties:
20+
name:
21+
type: string
22+
example: Car
23+
type: object
24+
PropertyItems:
25+
title: 'Property Items'
26+
required:
27+
- list1
28+
properties:
29+
list1:
30+
description: 'Missing docblock'
31+
type: array
32+
items:
33+
$ref: '#/components/schemas/ItemDto'
34+
minItems: 2
35+
list2:
36+
description: 'With docblock'
37+
type: array
38+
items:
39+
$ref: '#/components/schemas/ItemDto'
40+
minItems: 1
41+
list3:
42+
description: 'Simple type'
43+
type: array
44+
items:
45+
type: string
46+
minLength: 2
47+
maxItems: 5
48+
minItems: 0
49+
type: object
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
openapi: 3.1.0
2+
info:
3+
title: 'Property Items Scratch'
4+
version: '1.0'
5+
paths:
6+
/api/endpoint:
7+
get:
8+
description: 'An endpoint'
9+
operationId: 22e79d8d650659ed1ced1f375c7e723d
10+
responses:
11+
'200':
12+
description: OK
13+
components:
14+
schemas:
15+
ItemDto:
16+
title: 'Item Dto'
17+
required:
18+
- name
19+
properties:
20+
name:
21+
type: string
22+
example: Car
23+
type: object
24+
PropertyItems:
25+
title: 'Property Items'
26+
required:
27+
- list1
28+
properties:
29+
list1:
30+
description: 'Missing docblock'
31+
type: array
32+
items:
33+
$ref: '#/components/schemas/ItemDto'
34+
minItems: 2
35+
list2:
36+
description: 'With docblock'
37+
type: array
38+
items:
39+
$ref: '#/components/schemas/ItemDto'
40+
minItems: 1
41+
list3:
42+
description: 'Simple type'
43+
type: array
44+
items:
45+
type: string
46+
minLength: 2
47+
maxItems: 5
48+
minItems: 0
49+
type: object

0 commit comments

Comments
 (0)
0