|
16 | 16 | use Hyperf\DTO\ApiAnnotation; |
17 | 17 | use Hyperf\DTO\DtoConfig; |
18 | 18 | use Hyperf\DTO\Scan\MethodParametersManager; |
| 19 | +use Hyperf\DTO\Scan\Property; |
19 | 20 | use Hyperf\DTO\Scan\PropertyManager; |
20 | 21 | use OpenApi\Attributes as OA; |
21 | 22 | use Psr\Container\ContainerInterface; |
@@ -67,12 +68,19 @@ public function generate(): array |
67 | 68 | continue; |
68 | 69 | } |
69 | 70 |
|
| 71 | + $methodParameter = $this->methodParametersManager->getMethodParameter($this->controller, $this->action, $paramName); |
| 72 | + if ($parameterClassName === 'array' && $methodParameter->isRequestBody()) { |
| 73 | + $requestBody = new OA\RequestBody(); |
| 74 | + $requestBody->required = true; |
| 75 | + $property = $this->methodParametersManager->getProperty($this->controller, $this->action, $paramName); |
| 76 | + $requestBody->content = $this->getContent($property->arrClassName ?? '', property: $property); |
| 77 | + $result['requestBody'] = $requestBody; |
| 78 | + } |
| 79 | + |
70 | 80 | if ($this->container->has($parameterClassName)) { |
71 | | - $methodParameter = $this->methodParametersManager->getMethodParameter($this->controller, $this->action, $paramName); |
72 | 81 | if ($methodParameter == null) { |
73 | 82 | continue; |
74 | 83 | } |
75 | | - |
76 | 84 | if ($methodParameter->isRequestBody()) { |
77 | 85 | $requestBody = new OA\RequestBody(); |
78 | 86 | $requestBody->required = true; |
@@ -177,21 +185,32 @@ public function getParameterArrByClass(string $parameterClassName, string $in): |
177 | 185 | return $parameters; |
178 | 186 | } |
179 | 187 |
|
180 | | - protected function getContent(string $className, string $mediaTypeStr = 'application/json'): array |
| 188 | + protected function getContent(string $className, string $mediaTypeStr = 'application/json', ?Property $property = null): array |
181 | 189 | { |
182 | 190 | $arr = []; |
183 | 191 | $mediaType = new OA\MediaType(); |
184 | 192 | $mediaType->mediaType = $mediaTypeStr; |
185 | | - $mediaType->schema = $this->getJsonContent($className); |
| 193 | + $mediaType->schema = $this->getJsonContent($className, $property); |
186 | 194 | $arr[] = $mediaType; |
187 | 195 | return $arr; |
188 | 196 | } |
189 | 197 |
|
190 | | - protected function getJsonContent(string $className): OA\JsonContent |
| 198 | + protected function getJsonContent(string $className, ?Property $property = null): OA\JsonContent |
191 | 199 | { |
192 | 200 | $jsonContent = new OA\JsonContent(); |
193 | 201 | $this->swaggerComponents->generateSchemas($className); |
194 | | - $jsonContent->ref = $this->common->getComponentsName($className); |
| 202 | + if ($property?->phpSimpleType == 'array') { |
| 203 | + $jsonContent->type = 'array'; |
| 204 | + $items = new OA\Items(); |
| 205 | + if ($property->arrClassName) { |
| 206 | + $items->ref = $this->common->getComponentsName($property->arrClassName); |
| 207 | + } else { |
| 208 | + $items->type = $this->common->getSwaggerType($property->arrSimpleType); |
| 209 | + } |
| 210 | + $jsonContent->items = $items; |
| 211 | + } else { |
| 212 | + $jsonContent->ref = $this->common->getComponentsName($className); |
| 213 | + } |
195 | 214 | return $jsonContent; |
196 | 215 | } |
197 | 216 |
|
|
0 commit comments