1313
1414final class OpenApiFactory implements OpenApiFactoryInterface
1515{
16- public function __construct (private readonly OpenApiFactoryInterface $ decorated )
17- {
16+ public function __construct (
17+ private readonly OpenApiFactoryInterface $ decorated ,
18+ private readonly SchemasCollectionFactory $ schemaCollectionFactory ,
19+ ) {
1820 }
1921
2022 /**
@@ -24,59 +26,11 @@ public function __invoke(array $context = []): OpenApi
2426 {
2527 $ openApi = $ this ->decorated ->__invoke ($ context );
2628
27- /** @var \ArrayObject<string, mixed> $schemas */
28- $ schemas = new \ArrayObject ();
29- $ schemas ['BaseObject ' ] = [
30- 'type ' => 'object ' ,
31- 'required ' => ['_media-type ' , '_href ' ],
32- 'properties ' => [
33- '_media-type ' => [
34- 'type ' => 'string ' ,
35- ],
36- '_href ' => [
37- 'type ' => 'string ' ,
38- ],
39- ],
40- ];
41- $ schemas ['Language ' ] = [
42- 'allOf ' => [
43- [
44- '$ref ' => '#/components/schemas/BaseObject ' ,
45- ],
46- [
47- 'type ' => 'object ' ,
48- 'required ' => ['id ' , 'languageCode ' , 'name ' , 'enabled ' ],
49- 'properties ' => [
50- 'id ' => [
51- 'description ' => 'The language ID (auto generated). ' ,
52- 'type ' => 'integer ' ,
53- ],
54- 'languageCode ' => [
55- 'description ' => 'The languageCode code. ' ,
56- 'type ' => 'string ' ,
57- ],
58- 'name ' => [
59- 'description ' => 'Human readable name of the language. ' ,
60- 'type ' => 'string ' ,
61- ],
62- 'enabled ' => [
63- 'description ' => 'Indicates if the language is enabled or not. ' ,
64- 'type ' => 'boolean ' ,
65- ],
66- ],
67- ],
68- ],
69- ];
70- $ schemas ['LanguageList ' ] = [
71- 'description ' => ' List of languages. ' ,
72- 'type ' => 'array ' ,
73- 'items ' => [
74- '$ref ' => '#/components/schemas/Language ' ,
75- ],
76- ];
29+ $ schemasCollection = $ this ->schemaCollectionFactory ->create ();
30+ $ schemas = iterator_to_array ($ schemasCollection );
7731
7832 $ components = $ openApi ->getComponents ();
79- $ components = $ components ->withSchemas ($ schemas );
33+ $ components = $ components ->withSchemas (new \ ArrayObject ( $ schemas) );
8034
8135 $ openApi = $ openApi ->withComponents ($ components );
8236
0 commit comments