Skip to content

Commit 614d5aa

Browse files
author
RobertGroot
committed
Schemas fix
1 parent 3cd8272 commit 614d5aa

File tree

5 files changed

+29
-6
lines changed

5 files changed

+29
-6
lines changed

src/Data/OpenApi.php

+22-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ class OpenApi extends Data
1313
/** @var array<string,class-string<Data>> */
1414
protected static array $schemas = [];
1515

16+
/** @var array<string,class-string<Data>> */
17+
protected static array $temp_schemas = [];
18+
1619
public function __construct(
1720
public string $openapi,
1821
public Info $info,
@@ -26,7 +29,7 @@ public function __construct(
2629
*/
2730
public static function addClassSchema(string $name, $schema): void
2831
{
29-
static::$schemas[$name] = $schema;
32+
static::$temp_schemas[$name] = $schema;
3033
}
3134

3235
/** @return array<string,class-string<Data>> */
@@ -35,6 +38,12 @@ public static function getSchemas(): array
3538
return static::$schemas;
3639
}
3740

41+
/** @return array<string,class-string<Data>> */
42+
public static function getTempSchemas(): array
43+
{
44+
return static::$temp_schemas;
45+
}
46+
3847
/**
3948
* @param array<string,array<string,Route>> $routes
4049
*/
@@ -46,7 +55,11 @@ public static function fromRoutes(array $routes, Command $command): self
4655
foreach ($routes as $uri => $uri_routes) {
4756
foreach ($uri_routes as $method => $route) {
4857
try {
58+
self::$temp_schemas = [];
59+
4960
$paths[$uri][$method] = Operation::fromRoute($route);
61+
62+
self::addTempSchemas();
5063
} catch (\Throwable $th) {
5164
$command->error("Failed to generate Operation from route {$method} {$route->getName()} {$uri}: {$th->getMessage()}");
5265

@@ -93,6 +106,14 @@ public function toArray(): array
93106
);
94107
}
95108

109+
protected static function addTempSchemas(): void
110+
{
111+
static::$schemas = array_merge(
112+
static::$schemas,
113+
static::$temp_schemas,
114+
);
115+
}
116+
96117
/**
97118
* @return array<string,mixed>
98119
*/

tests/Unit/PropertyTest.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,13 @@
7575
],
7676
],
7777
[
78-
'type' => 'string',
78+
'type' => 'string',
79+
'format' => 'date-time',
7980
],
8081
[
8182
'type' => 'string',
8283
'nullable' => true,
84+
'format' => 'date-time',
8385
],
8486
]);
8587
});

tests/Unit/RequestBodyTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
],
5252
]);
5353

54-
expect(OpenApi::getSchemas())->toMatchArray(
54+
expect(OpenApi::getTempSchemas())->toMatchArray(
5555
['RequestData' => 'Xolvio\\OpenApiGenerator\\Test\\RequestData']
5656
);
5757
}

tests/Unit/ResponseTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
]);
2424
}
2525

26-
expect(OpenApi::getSchemas())->toMatchArray(
26+
expect(OpenApi::getTempSchemas())->toMatchArray(
2727
['ReturnData' => 'Xolvio\\OpenApiGenerator\\Test\\ReturnData']
2828
);
2929
});
@@ -49,7 +49,7 @@
4949
]);
5050
}
5151

52-
expect(OpenApi::getSchemas())->toMatchArray(
52+
expect(OpenApi::getTempSchemas())->toMatchArray(
5353
['ReturnData' => 'Xolvio\\OpenApiGenerator\\Test\\ReturnData']
5454
);
5555
});

tests/Unit/SchemaTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
'$ref' => '#/components/schemas/' . class_basename($class),
5555
]);
5656

57-
expect(OpenApi::getSchemas())->toMatchArray(
57+
expect(OpenApi::getTempSchemas())->toMatchArray(
5858
[class_basename($class) => $class]
5959
);
6060
}

0 commit comments

Comments
 (0)