Skip to content

Commit ce6ff3f

Browse files
authored
Merge pull request #4107 from soyuka/fix/openapi-pathitem
Allow unset PathItem method
2 parents 7c6f96f + e270b03 commit ce6ff3f

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ jobs:
670670
- name: Update project dependencies
671671
run: composer update --no-interaction --no-progress --ansi
672672
- name: Require Symfony Uid
673-
run: composer require symfony/uid --dev --no-interaction --no-progress --ansi
673+
run: composer require symfony/uid symfony/intl --dev --no-interaction --no-progress --ansi
674674
- name: Flag held back Symfony packages
675675
env:
676676
symfony_version: ${{ matrix.symfony }}

src/OpenApi/Model/PathItem.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,31 +138,31 @@ public function withDescription(string $description): self
138138
return $clone;
139139
}
140140

141-
public function withGet(Operation $get): self
141+
public function withGet(?Operation $get): self
142142
{
143143
$clone = clone $this;
144144
$clone->get = $get;
145145

146146
return $clone;
147147
}
148148

149-
public function withPut(Operation $put): self
149+
public function withPut(?Operation $put): self
150150
{
151151
$clone = clone $this;
152152
$clone->put = $put;
153153

154154
return $clone;
155155
}
156156

157-
public function withPost(Operation $post): self
157+
public function withPost(?Operation $post): self
158158
{
159159
$clone = clone $this;
160160
$clone->post = $post;
161161

162162
return $clone;
163163
}
164164

165-
public function withDelete(Operation $delete): self
165+
public function withDelete(?Operation $delete): self
166166
{
167167
$clone = clone $this;
168168
$clone->delete = $delete;
@@ -186,7 +186,7 @@ public function withHead(Operation $head): self
186186
return $clone;
187187
}
188188

189-
public function withPatch(Operation $patch): self
189+
public function withPatch(?Operation $patch): self
190190
{
191191
$clone = clone $this;
192192
$clone->patch = $patch;

tests/OpenApi/Factory/OpenApiFactoryTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use ApiPlatform\Core\Metadata\Resource\ResourceNameCollection;
3131
use ApiPlatform\Core\OpenApi\Factory\OpenApiFactory;
3232
use ApiPlatform\Core\OpenApi\Model;
33+
use ApiPlatform\Core\OpenApi\Model\PathItem;
3334
use ApiPlatform\Core\OpenApi\OpenApi;
3435
use ApiPlatform\Core\OpenApi\Options;
3536
use ApiPlatform\Core\OpenApi\Serializer\OpenApiNormalizer;
@@ -745,4 +746,20 @@ public function testSubresourceDocumentation()
745746
$normalizer = new OpenApiNormalizer($normalizers[0]);
746747
$normalizer->normalize($openApi);
747748
}
749+
750+
public function testResetPathItem()
751+
{
752+
$pathItem = new PathItem();
753+
$pathItem->withGet(null);
754+
$pathItem->withDelete(null);
755+
$pathItem->withPost(null);
756+
$pathItem->withPut(null);
757+
$pathItem->withPatch(null);
758+
759+
$this->assertNull($pathItem->getGet());
760+
$this->assertNull($pathItem->getDelete());
761+
$this->assertNull($pathItem->getPost());
762+
$this->assertNull($pathItem->getPut());
763+
$this->assertNull($pathItem->getPatch());
764+
}
748765
}

0 commit comments

Comments
 (0)