File tree Expand file tree Collapse file tree 3 files changed +38
-1
lines changed Expand file tree Collapse file tree 3 files changed +38
-1
lines changed Original file line number Diff line number Diff line change 14
14
15
15
trait Referencable
16
16
{
17
+ static $ buildReferencableSchemas = [];
18
+
17
19
public static function ref (?string $ objectId = null ): Schema
18
20
{
19
21
$ instance = app (static ::class);
@@ -38,6 +40,6 @@ public static function ref(?string $objectId = null): Schema
38
40
$ baseRef = '#/components/securitySchemes/ ' ;
39
41
}
40
42
41
- return Schema::ref ($ baseRef .$ instance ->build ()->objectId , $ objectId );
43
+ return self :: $ buildReferencableSchemas [ static ::class . " _ { $ objectId }" ] ??= Schema::ref ($ baseRef .$ instance ->build ()->objectId , $ objectId );
42
44
}
43
45
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Vyuldashev \LaravelOpenApi \Tests \Fixtures ;
4
+
5
+ use GoldSpecDigital \ObjectOrientedOAS \Contracts \SchemaContract ;
6
+ use GoldSpecDigital \ObjectOrientedOAS \Objects \Schema ;
7
+ use Vyuldashev \LaravelOpenApi \Contracts \Reusable ;
8
+ use Vyuldashev \LaravelOpenApi \Factories \SchemaFactory ;
9
+
10
+ class ExampleSchema extends SchemaFactory implements Reusable
11
+ {
12
+ public function build (): SchemaContract
13
+ {
14
+ return Schema::object ('ExampleSchema ' )
15
+ ->properties (
16
+ Schema::string ('example_string ' ),
17
+ Schema::integer ('example_integer ' ),
18
+ Schema::boolean ('example_boolean ' ),
19
+ );
20
+ }
21
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Vyuldashev \LaravelOpenApi \Tests ;
4
+
5
+ use Vyuldashev \LaravelOpenApi \Tests \Fixtures \ExampleSchema ;
6
+
7
+ class MemoizationTest extends TestCase
8
+ {
9
+ public function testReferencableInstanceBuildOnce (): void
10
+ {
11
+ self ::assertEquals ($ e1ObjectId = (new ExampleSchema )::ref ('e1 ' ), (new ExampleSchema )::ref ('e1 ' ));
12
+ self ::assertNotEquals ($ e1ObjectId , (new ExampleSchema )::ref ('e2 ' ));
13
+ }
14
+ }
You can’t perform that action at this time.
0 commit comments