diff --git a/src/Concerns/Referencable.php b/src/Concerns/Referencable.php index fd36525..4dfb8fe 100644 --- a/src/Concerns/Referencable.php +++ b/src/Concerns/Referencable.php @@ -14,6 +14,8 @@ trait Referencable { + static $buildReferencableSchemas = []; + public static function ref(?string $objectId = null): Schema { $instance = app(static::class); @@ -38,6 +40,6 @@ public static function ref(?string $objectId = null): Schema $baseRef = '#/components/securitySchemes/'; } - return Schema::ref($baseRef.$instance->build()->objectId, $objectId); + return self::$buildReferencableSchemas[static::class . "_{$objectId}"] ??= Schema::ref($baseRef.$instance->build()->objectId, $objectId); } } diff --git a/tests/Fixtures/ExampleSchema.php b/tests/Fixtures/ExampleSchema.php new file mode 100644 index 0000000..4737e32 --- /dev/null +++ b/tests/Fixtures/ExampleSchema.php @@ -0,0 +1,21 @@ +properties( + Schema::string('example_string'), + Schema::integer('example_integer'), + Schema::boolean('example_boolean'), + ); + } +} diff --git a/tests/MemoizationTest.php b/tests/MemoizationTest.php new file mode 100644 index 0000000..eef9be0 --- /dev/null +++ b/tests/MemoizationTest.php @@ -0,0 +1,14 @@ +