forked from vyuldashev/laravel-openapi
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(memoization): add memoization for build referencable schemas (#30)
- Loading branch information
Showing
3 changed files
with
38 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Vyuldashev\LaravelOpenApi\Tests\Fixtures; | ||
|
||
use GoldSpecDigital\ObjectOrientedOAS\Contracts\SchemaContract; | ||
use GoldSpecDigital\ObjectOrientedOAS\Objects\Schema; | ||
use Vyuldashev\LaravelOpenApi\Contracts\Reusable; | ||
use Vyuldashev\LaravelOpenApi\Factories\SchemaFactory; | ||
|
||
class ExampleSchema extends SchemaFactory implements Reusable | ||
{ | ||
public function build(): SchemaContract | ||
{ | ||
return Schema::object('ExampleSchema') | ||
->properties( | ||
Schema::string('example_string'), | ||
Schema::integer('example_integer'), | ||
Schema::boolean('example_boolean'), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Vyuldashev\LaravelOpenApi\Tests; | ||
|
||
use Vyuldashev\LaravelOpenApi\Tests\Fixtures\ExampleSchema; | ||
|
||
class MemoizationTest extends TestCase | ||
{ | ||
public function testReferencableInstanceBuildOnce(): void | ||
{ | ||
self::assertEquals($e1ObjectId = (new ExampleSchema)::ref('e1'), (new ExampleSchema)::ref('e1')); | ||
self::assertNotEquals($e1ObjectId, (new ExampleSchema)::ref('e2')); | ||
} | ||
} |