|
16 | 16 | use OpenApiGenerator\Attributes\PropertyInterface; |
17 | 17 | use OpenApiGenerator\Attributes\PropertyItems; |
18 | 18 | use OpenApiGenerator\Attributes\PUT; |
19 | | -use OpenApiGenerator\Attributes\RefProperty; |
20 | 19 | use OpenApiGenerator\Attributes\RequestBody; |
21 | 20 | use OpenApiGenerator\Attributes\Response; |
22 | 21 | use OpenApiGenerator\Attributes\Route; |
@@ -113,42 +112,32 @@ public function append(ReflectionClass $reflectionClass): void |
113 | 112 |
|
114 | 113 | /** |
115 | 114 | * OPAG supports Symfony Request class. This method will build the RequestBody from the Symfony Request class |
116 | | - * |
117 | | - * @throws ReflectionException|IllegalFieldException |
| 115 | + * The request object will be added as a reference to the RequestBody |
118 | 116 | */ |
119 | 117 | private function buildRequestBodyFromSymfonyRequest(ReflectionMethod $method): ?RequestBody |
120 | 118 | { |
121 | 119 | $requestBody = new RequestBody(); |
122 | 120 |
|
123 | 121 | // Get the first parameter that is a subclass of Symfony Request |
124 | | - $requestClass = array_filter( |
| 122 | + $symfonyRequests = array_filter( |
125 | 123 | $method->getParameters(), |
126 | | - static fn(ReflectionParameter $parameter): bool => is_subclass_of( |
127 | | - $parameter->getType()->getName(), |
128 | | - Request::class |
129 | | - ) |
| 124 | + fn(ReflectionParameter $parameter): bool => is_subclass_of($parameter->getType()->getName(), Request::class) |
130 | 125 | ); |
131 | | - $requestClass = reset($requestClass); |
132 | | - if (!$requestClass) { |
| 126 | + if (!count($symfonyRequests)) { |
133 | 127 | return null; |
134 | 128 | } |
135 | 129 |
|
136 | | - // Get the Schema attribute from the Symfony Request class |
137 | | - $requestReflection = new ReflectionClass($requestClass->getType()->getName()); |
138 | | - $schemaAttributes = $requestReflection->getAttributes(Schema::class); |
139 | | - $schemaAttribute = reset($schemaAttributes); |
140 | | - if (!$schemaAttribute) { |
| 130 | + $symfonyRequest = reset($symfonyRequests); |
| 131 | + if (empty((new ReflectionClass($symfonyRequest->getType()->getName()))->getAttributes(Schema::class))) { |
141 | 132 | return null; |
142 | 133 | } |
143 | 134 |
|
144 | | - // Build the schema |
145 | | - $schema = $schemaAttribute->newInstance(); |
146 | | - $builder = new SchemaBuilder(false); |
147 | | - $builder->addSchema($schema, $requestClass->getType()->getName()); |
148 | | - $builder->addProperty(new RefProperty($schema->getName())); |
149 | | - |
150 | | - // Set the schema to the RequestBody and return it |
151 | | - $requestBody->setSchema($builder->getComponent()); |
| 135 | + $schema = new Schema(); |
| 136 | + $schema->setNoMedia(true); |
| 137 | + $requestBody->setSchema($schema); |
| 138 | + $property = new RefProperty($symfonyRequest->getType()->getName()); |
| 139 | + $property->setComponentRoutePrefix("#/components/requestBodies/"); |
| 140 | + $requestBody->addProperty($property); |
152 | 141 |
|
153 | 142 | return $requestBody; |
154 | 143 | } |
|
0 commit comments