|
49 | 49 | use ApiPlatform\OpenApi\Model\Operation; |
50 | 50 | use ApiPlatform\OpenApi\Model\Operation as OpenApiOperation; |
51 | 51 | use ApiPlatform\OpenApi\Model\Parameter; |
| 52 | +use ApiPlatform\OpenApi\Model\PathItem; |
52 | 53 | use ApiPlatform\OpenApi\Model\RequestBody; |
53 | 54 | use ApiPlatform\OpenApi\Model\Response; |
54 | 55 | use ApiPlatform\OpenApi\Model\Response as OpenApiResponse; |
@@ -89,7 +90,7 @@ public function testInvoke(): void |
89 | 90 |
|
90 | 91 | $dummyResourceWebhook = (new ApiResource())->withOperations(new Operations([ |
91 | 92 | 'dummy webhook' => (new Get())->withUriTemplate('/dummy/{id}')->withShortName('short')->withOpenapi(new Webhook('first webhook')), |
92 | | - 'an other dummy webhook' => (new Post())->withUriTemplate('/dummies')->withShortName('short something')->withOpenapi(new Webhook('happy webhook', new Model\PathItem(post: new Operation( |
| 93 | + 'an other dummy webhook' => (new Post())->withUriTemplate('/dummies')->withShortName('short something')->withOpenapi(new Webhook('happy webhook', new PathItem(post: new Operation( |
93 | 94 | summary: 'well...', |
94 | 95 | description: 'I dont\'t know what to say', |
95 | 96 | )))), |
@@ -1438,4 +1439,134 @@ public function testGetExtensionPropertiesWithFalseValue(): void |
1438 | 1439 |
|
1439 | 1440 | $openApi = $factory->__invoke(); |
1440 | 1441 | } |
| 1442 | + |
| 1443 | + public function testResourcePathItemWithSummaryAndDescription(): void |
| 1444 | + { |
| 1445 | + $baseOperation = (new HttpOperation())->withTypes(['http://schema.example.com/Dummy'])->withInputFormats(self::OPERATION_FORMATS['input_formats'])->withOutputFormats(self::OPERATION_FORMATS['output_formats'])->withClass(Dummy::class)->withOutput([ |
| 1446 | + 'class' => OutputDto::class, |
| 1447 | + ])->withPaginationClientItemsPerPage(true)->withShortName('Dummy')->withDescription('This is a dummy'); |
| 1448 | + |
| 1449 | + $dummyResource = (new ApiResource())->withOperations( |
| 1450 | + new Operations([ |
| 1451 | + 'getDummyCollection' => (new GetCollection())->withUriTemplate('/dummies')->withOperation($baseOperation), |
| 1452 | + 'postDummy' => (new Post())->withUriTemplate('/dummies')->withOperation($baseOperation), |
| 1453 | + ]) |
| 1454 | + )->withOpenapi(new PathItem( |
| 1455 | + summary: 'Dummy collection endpoint', |
| 1456 | + description: 'Manage dummy resources' |
| 1457 | + )); |
| 1458 | + |
| 1459 | + $resourceNameCollectionFactoryProphecy = $this->prophesize(ResourceNameCollectionFactoryInterface::class); |
| 1460 | + $resourceNameCollectionFactoryProphecy->create()->shouldBeCalled()->willReturn(new ResourceNameCollection([Dummy::class])); |
| 1461 | + |
| 1462 | + $resourceMetadataFactoryProphecy = $this->prophesize(ResourceMetadataCollectionFactoryInterface::class); |
| 1463 | + $resourceMetadataFactoryProphecy->create(Dummy::class)->shouldBeCalled()->willReturn(new ResourceMetadataCollection(Dummy::class, [$dummyResource])); |
| 1464 | + $resourceMetadataFactoryProphecy->create(Error::class)->shouldBeCalled()->willReturn(new ResourceMetadataCollection(Error::class, [])); |
| 1465 | + $resourceMetadataFactoryProphecy->create(ValidationException::class)->shouldBeCalled()->willReturn(new ResourceMetadataCollection(ValidationException::class, [])); |
| 1466 | + |
| 1467 | + $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class); |
| 1468 | + $propertyNameCollectionFactoryProphecy->create(Dummy::class, Argument::any())->shouldBeCalled()->willReturn(new PropertyNameCollection(['id', 'name', 'description', 'dummyDate', 'enum'])); |
| 1469 | + $propertyNameCollectionFactoryProphecy->create(OutputDto::class, Argument::any())->shouldBeCalled()->willReturn(new PropertyNameCollection(['id', 'name', 'description', 'dummyDate', 'enum'])); |
| 1470 | + $propertyNameCollectionFactoryProphecy->create(Error::class, Argument::any())->shouldBeCalled()->willReturn(new PropertyNameCollection(['type', 'title', 'status', 'detail', 'instance'])); |
| 1471 | + |
| 1472 | + $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class); |
| 1473 | + $propertyMetadataFactoryProphecy->create(Argument::any(), Argument::any(), Argument::any())->willReturn(new ApiProperty()); |
| 1474 | + |
| 1475 | + $definitionNameFactory = new DefinitionNameFactory(); |
| 1476 | + $schemaFactory = new SchemaFactory( |
| 1477 | + resourceMetadataFactory: $resourceMetadataFactoryProphecy->reveal(), |
| 1478 | + propertyNameCollectionFactory: $propertyNameCollectionFactoryProphecy->reveal(), |
| 1479 | + propertyMetadataFactory: $propertyMetadataFactoryProphecy->reveal(), |
| 1480 | + nameConverter: new CamelCaseToSnakeCaseNameConverter(), |
| 1481 | + definitionNameFactory: $definitionNameFactory, |
| 1482 | + ); |
| 1483 | + |
| 1484 | + $factory = new OpenApiFactory( |
| 1485 | + $resourceNameCollectionFactoryProphecy->reveal(), |
| 1486 | + $resourceMetadataFactoryProphecy->reveal(), |
| 1487 | + $propertyNameCollectionFactoryProphecy->reveal(), |
| 1488 | + $propertyMetadataFactoryProphecy->reveal(), |
| 1489 | + $schemaFactory, |
| 1490 | + null, |
| 1491 | + [], |
| 1492 | + new Options('Test API', 'This is a test API.', '1.2.3'), |
| 1493 | + new PaginationOptions(), |
| 1494 | + null, |
| 1495 | + ['json' => ['application/problem+json']] |
| 1496 | + ); |
| 1497 | + |
| 1498 | + $openApi = $factory->__invoke(); |
| 1499 | + $paths = $openApi->getPaths(); |
| 1500 | + $dummyPath = $paths->getPath('/dummies'); |
| 1501 | + |
| 1502 | + $this->assertEquals('Dummy collection endpoint', $dummyPath->getSummary()); |
| 1503 | + $this->assertEquals('Manage dummy resources', $dummyPath->getDescription()); |
| 1504 | + |
| 1505 | + $this->assertNotNull($dummyPath->getGet()); |
| 1506 | + $this->assertNotNull($dummyPath->getPost()); |
| 1507 | + } |
| 1508 | + |
| 1509 | + public function testOperationPathItemOverridesResourcePathItem(): void |
| 1510 | + { |
| 1511 | + $baseOperation = (new HttpOperation())->withTypes(['http://schema.example.com/Dummy'])->withInputFormats(self::OPERATION_FORMATS['input_formats'])->withOutputFormats(self::OPERATION_FORMATS['output_formats'])->withClass(Dummy::class)->withOutput([ |
| 1512 | + 'class' => OutputDto::class, |
| 1513 | + ])->withPaginationClientItemsPerPage(true)->withShortName('Dummy')->withDescription('This is a dummy'); |
| 1514 | + |
| 1515 | + $dummyResource = (new ApiResource())->withOperations( |
| 1516 | + new Operations([ |
| 1517 | + 'getDummy' => (new Get())->withUriTemplate('/dummies/{id}')->withOperation($baseOperation)->withOpenapi(new PathItem( |
| 1518 | + summary: 'Operation-level PathItem', |
| 1519 | + get: new Operation(summary: 'Operation-level summary') |
| 1520 | + )), |
| 1521 | + ]) |
| 1522 | + )->withOpenapi(new PathItem( |
| 1523 | + summary: 'Resource-level PathItem', |
| 1524 | + description: 'This should be overridden' |
| 1525 | + )); |
| 1526 | + |
| 1527 | + $resourceNameCollectionFactoryProphecy = $this->prophesize(ResourceNameCollectionFactoryInterface::class); |
| 1528 | + $resourceNameCollectionFactoryProphecy->create()->shouldBeCalled()->willReturn(new ResourceNameCollection([Dummy::class])); |
| 1529 | + |
| 1530 | + $resourceMetadataFactoryProphecy = $this->prophesize(ResourceMetadataCollectionFactoryInterface::class); |
| 1531 | + $resourceMetadataFactoryProphecy->create(Dummy::class)->shouldBeCalled()->willReturn(new ResourceMetadataCollection(Dummy::class, [$dummyResource])); |
| 1532 | + $resourceMetadataFactoryProphecy->create(Error::class)->shouldBeCalled()->willReturn(new ResourceMetadataCollection(Error::class, [])); |
| 1533 | + $resourceMetadataFactoryProphecy->create(ValidationException::class)->shouldBeCalled()->willReturn(new ResourceMetadataCollection(ValidationException::class, [])); |
| 1534 | + |
| 1535 | + $propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class); |
| 1536 | + $propertyNameCollectionFactoryProphecy->create(Argument::cetera())->willReturn(new PropertyNameCollection(['id', 'name', 'description', 'dummyDate', 'enum'])); |
| 1537 | + |
| 1538 | + $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class); |
| 1539 | + $propertyMetadataFactoryProphecy->create(Argument::any(), Argument::any(), Argument::any())->willReturn(new ApiProperty()); |
| 1540 | + |
| 1541 | + $definitionNameFactory = new DefinitionNameFactory(); |
| 1542 | + $schemaFactory = new SchemaFactory( |
| 1543 | + resourceMetadataFactory: $resourceMetadataFactoryProphecy->reveal(), |
| 1544 | + propertyNameCollectionFactory: $propertyNameCollectionFactoryProphecy->reveal(), |
| 1545 | + propertyMetadataFactory: $propertyMetadataFactoryProphecy->reveal(), |
| 1546 | + nameConverter: new CamelCaseToSnakeCaseNameConverter(), |
| 1547 | + definitionNameFactory: $definitionNameFactory, |
| 1548 | + ); |
| 1549 | + |
| 1550 | + $factory = new OpenApiFactory( |
| 1551 | + $resourceNameCollectionFactoryProphecy->reveal(), |
| 1552 | + $resourceMetadataFactoryProphecy->reveal(), |
| 1553 | + $propertyNameCollectionFactoryProphecy->reveal(), |
| 1554 | + $propertyMetadataFactoryProphecy->reveal(), |
| 1555 | + $schemaFactory, |
| 1556 | + null, |
| 1557 | + [], |
| 1558 | + new Options('Test API', 'This is a test API.', '1.2.3'), |
| 1559 | + new PaginationOptions(), |
| 1560 | + null, |
| 1561 | + ['json' => ['application/problem+json']] |
| 1562 | + ); |
| 1563 | + |
| 1564 | + $openApi = $factory->__invoke(); |
| 1565 | + $paths = $openApi->getPaths(); |
| 1566 | + $dummyPath = $paths->getPath('/dummies/{id}'); |
| 1567 | + |
| 1568 | + $this->assertEquals('Operation-level PathItem', $dummyPath->getSummary()); |
| 1569 | + |
| 1570 | + $this->assertEquals('Operation-level summary', $dummyPath->getGet()->getSummary()); |
| 1571 | + } |
1441 | 1572 | } |
0 commit comments