From b5022e2a4bec0eb45f8dc6a7f2d10585c42fdf0e Mon Sep 17 00:00:00 2001 From: DjordyKoert Date: Fri, 17 Nov 2023 20:34:57 +0100 Subject: [PATCH] Add validate schema tests --- tests/Annotations/NullableTest.php | 24 +++++++++++++++++++++ tests/Annotations/TypeTest.php | 34 ++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 tests/Annotations/NullableTest.php create mode 100644 tests/Annotations/TypeTest.php diff --git a/tests/Annotations/NullableTest.php b/tests/Annotations/NullableTest.php new file mode 100644 index 000000000..46740cb8a --- /dev/null +++ b/tests/Annotations/NullableTest.php @@ -0,0 +1,24 @@ +annotationsFromDocBlockParser('@OA\Schema(type="string", nullable=true)'); + $annotations[0]->validate(); + + $annotations = $this->annotationsFromDocBlockParser('@OA\Schema(type="string", nullable=true)'); + $annotations[0]->_context = $this->getContext([], OA\OpenApi::VERSION_3_1_0); + $this->assertOpenApiLogEntryContains('@OA\Schema() must not have the "nullable" property when using OpenApi version 3.1.0 in '); + $annotations[0]->validate(); + } +} diff --git a/tests/Annotations/TypeTest.php b/tests/Annotations/TypeTest.php new file mode 100644 index 000000000..c6a888e83 --- /dev/null +++ b/tests/Annotations/TypeTest.php @@ -0,0 +1,34 @@ +annotationsFromDocBlockParser('@OA\Schema(type="string")'); + $annotations[0]->validate(); + + $annotations = $this->annotationsFromDocBlockParser('@OA\Schema(type="string")'); + $annotations[0]->_context = $this->getContext([], OA\OpenApi::VERSION_3_1_0); + $annotations[0]->validate(); + } + + public function testTypeOfArray(): void + { + $annotations = $this->annotationsFromDocBlockParser('@OA\Schema(type={"string", "null"})'); + $this->assertOpenApiLogEntryContains('@OA\Schema() "type" must be of type string in OpenApi version 3.0.0, array given in '); + $annotations[0]->validate(); + + $annotations = $this->annotationsFromDocBlockParser('@OA\Schema(type={"string", "null"})'); + $annotations[0]->_context = $this->getContext([], OA\OpenApi::VERSION_3_1_0); + $annotations[0]->validate(); + } +}