|
22 | 22 | use ApiPlatform\Metadata\Get; |
23 | 23 | use ApiPlatform\Metadata\GetCollection; |
24 | 24 | use ApiPlatform\Metadata\Operations; |
| 25 | +use ApiPlatform\Metadata\Patch; |
| 26 | +use ApiPlatform\Metadata\Post; |
25 | 27 | use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface; |
26 | 28 | use ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface; |
27 | 29 | use ApiPlatform\Metadata\Property\PropertyNameCollection; |
@@ -49,6 +51,7 @@ protected function setUp(): void |
49 | 51 | ); |
50 | 52 | $propertyNameCollectionFactory = $this->prophesize(PropertyNameCollectionFactoryInterface::class); |
51 | 53 | $propertyNameCollectionFactory->create(Dummy::class, ['enable_getter_setter_extraction' => true, 'schema_type' => Schema::TYPE_OUTPUT])->willReturn(new PropertyNameCollection()); |
| 54 | + $propertyNameCollectionFactory->create(Dummy::class, ['enable_getter_setter_extraction' => true, 'schema_type' => Schema::TYPE_INPUT])->willReturn(new PropertyNameCollection()); |
52 | 55 | $propertyMetadataFactory = $this->prophesize(PropertyMetadataFactoryInterface::class); |
53 | 56 |
|
54 | 57 | $definitionNameFactory = new DefinitionNameFactory(null); |
@@ -164,4 +167,26 @@ public function testSchemaTypeBuildSchema(): void |
164 | 167 | $forcedCollection = $this->schemaFactory->buildSchema(Dummy::class, 'jsonapi', Schema::TYPE_OUTPUT, forceCollection: true); |
165 | 168 | $this->assertEquals($resultSchema['allOf'][0]['$ref'], $forcedCollection['allOf'][0]['$ref']); |
166 | 169 | } |
| 170 | + |
| 171 | + public function testPostInputSchemaDoesNotRequireId(): void |
| 172 | + { |
| 173 | + $resultSchema = $this->schemaFactory->buildSchema(Dummy::class, 'jsonapi', Schema::TYPE_INPUT, new Post()); |
| 174 | + $definitions = $resultSchema->getDefinitions(); |
| 175 | + $rootDefinitionKey = $resultSchema->getRootDefinitionKey(); |
| 176 | + |
| 177 | + $this->assertTrue(isset($definitions[$rootDefinitionKey]['properties']['data'])); |
| 178 | + $data = $definitions[$rootDefinitionKey]['properties']['data']; |
| 179 | + $this->assertArrayHasKey('required', $data); |
| 180 | + $this->assertSame(['type'], $data['required']); |
| 181 | + } |
| 182 | + |
| 183 | + public function testPatchInputSchemaRequiresId(): void |
| 184 | + { |
| 185 | + $resultSchema = $this->schemaFactory->buildSchema(Dummy::class, 'jsonapi', Schema::TYPE_INPUT, new Patch()); |
| 186 | + $definitions = $resultSchema->getDefinitions(); |
| 187 | + $rootDefinitionKey = $resultSchema->getRootDefinitionKey(); |
| 188 | + |
| 189 | + $data = $definitions[$rootDefinitionKey]['properties']['data']; |
| 190 | + $this->assertSame(['type', 'id'], $data['required']); |
| 191 | + } |
167 | 192 | } |
0 commit comments