diff --git a/src/Attribute/Channel.php b/src/Attribute/Channel.php new file mode 100644 index 0000000..54e5585 --- /dev/null +++ b/src/Attribute/Channel.php @@ -0,0 +1,18 @@ + $this->name, - 'channel' => $this->channel, 'properties' => array_map(static fn(PropertyInterface $property) => $property->toArray(), $this->properties), - 'channelType' => $this->channelType->value, ]; } } diff --git a/src/Attribute/Operation.php b/src/Attribute/Operation.php new file mode 100644 index 0000000..c162007 --- /dev/null +++ b/src/Attribute/Operation.php @@ -0,0 +1,18 @@ + $this->title, - 'version' => $this->version, - 'description' => $this->description, + 'title' => $document['title'], + 'version' => $document['version'], + 'description' => $document['description'], ]; } } diff --git a/tests/Unit/Schema/V3/InfoRendererTest.php b/tests/Unit/Schema/V3/InfoRendererTest.php new file mode 100644 index 0000000..a98ad7c --- /dev/null +++ b/tests/Unit/Schema/V3/InfoRendererTest.php @@ -0,0 +1,28 @@ +render($document); + + $expected = [ + 'version' => '2.6.0', + 'title' => 'Async API Title', + 'description' => 'Async API Description', + ]; + + $this->assertEquals($expected, $actual); + } +} diff --git a/tests/Unit/Schema/V3/MessageRendererTest.php b/tests/Unit/Schema/V3/MessageRendererTest.php new file mode 100644 index 0000000..dbdbe30 --- /dev/null +++ b/tests/Unit/Schema/V3/MessageRendererTest.php @@ -0,0 +1,148 @@ + 'UserSignedUp', + 'properties' => [ + [ + 'name' => 'name', + 'type' => 'string', + 'required' => true, + ], + [ + 'name' => 'email', + 'type' => 'string', + 'required' => true, + ], + [ + 'name' => 'age', + 'type' => 'int', + 'required' => true, + ], + [ + 'name' => 'isCitizen', + 'type' => 'bool', + 'required' => true, + ], + ], + ]; + + $schema = new MessageRenderer(); + + $specification = $schema->render($document); + + $expectedSpecification = <<assertEquals($expectedSpecification, Yaml::dump($specification, 10, 2)); + } + + public function testAttributes(): void + { + $document = [ + 'name' => 'UserSignedUp', + 'properties' => [ + [ + 'name' => 'name', + 'type' => 'string', + 'description' => 'Name of the user', + 'example' => 'John', + 'format' => 'string', + 'required' => true, + ], + [ + 'name' => 'email', + 'type' => 'string', + 'description' => 'Email of the user', + 'format' => 'email', + 'example' => 'john@example.com', + 'required' => true, + ], + [ + 'name' => 'age', + 'type' => 'integer', + 'description' => 'Age of the user', + 'format' => 'int', + 'example' => '18', + 'required' => true, + ], + [ + 'name' => 'isCitizen', + 'type' => 'boolean', + 'description' => 'Is user a citizen', + 'format' => 'boolean', + 'example' => 'true', + 'required' => true, + ], + ], + ]; + + $schema = new MessageRenderer(); + + $specification = $schema->render($document); + + $expectedSpecification = <<assertEquals($expectedSpecification, Yaml::dump($specification, 10, 2)); + } +} diff --git a/tests/Unit/Schema/V3/SchemaRendererTest.php b/tests/Unit/Schema/V3/SchemaRendererTest.php new file mode 100644 index 0000000..c8269e9 --- /dev/null +++ b/tests/Unit/Schema/V3/SchemaRendererTest.php @@ -0,0 +1,22 @@ +generate(); + + $expected = []; + + $this->assertEquals($expected, $actual); + } +}