@@ -8,7 +8,6 @@ discard block |
||
| 8 | 8 | use PhpBoot\Docgen\Swagger\Schemas\ArraySchemaObject; |
| 9 | 9 | use PhpBoot\Docgen\Swagger\Schemas\BodyParameterObject; |
| 10 | 10 | use PhpBoot\Docgen\Swagger\Schemas\OperationObject; |
| 11 | -use PhpBoot\Docgen\Swagger\Schemas\OtherParameterObject; |
|
| 12 | 11 | use PhpBoot\Docgen\Swagger\Schemas\PrimitiveSchemaObject; |
| 13 | 12 | use PhpBoot\Docgen\Swagger\Schemas\RefSchemaObject; |
| 14 | 13 | use PhpBoot\Docgen\Swagger\Schemas\ResponseObject; |
@@ -22,7 +21,6 @@ discard block |
||
| 22 | 21 | use PhpBoot\Metas\ParamMeta; |
| 23 | 22 | use PhpBoot\Metas\ReturnMeta; |
| 24 | 23 | use PhpBoot\Utils\ArrayHelper; |
| 25 | -use PhpBoot\Validator\Validator; |
|
| 26 | 24 | use Symfony\Component\HttpKernel\Exception\HttpException; |
| 27 | 25 | |
| 28 | 26 | class Swagger extends SwaggerObject |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | $op->description = $route->getDescription(); |
| 59 | 59 | |
| 60 | 60 | $op->parameters = $this->getParamsSchema($app, $controller, $action, $route); |
| 61 | - if($this->hasFileParam($route)){ |
|
| 61 | + if ($this->hasFileParam($route)) { |
|
| 62 | 62 | $op->consumes = ['multipart/form-data']; |
| 63 | 63 | } |
| 64 | 64 | |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | } |
| 109 | 109 | if (is_array($v) || is_object($v)) { |
| 110 | 110 | $res[$k] = self::objectToArray($v); |
| 111 | - } else { |
|
| 111 | + }else { |
|
| 112 | 112 | $res[$k] = $v; |
| 113 | 113 | } |
| 114 | 114 | } |
@@ -136,12 +136,12 @@ discard block |
||
| 136 | 136 | list($name, $desc) = $exception; |
| 137 | 137 | |
| 138 | 138 | $ins = null; |
| 139 | - try{ |
|
| 139 | + try { |
|
| 140 | 140 | $ins = $app->make($name); |
| 141 | - }catch (\Exception $e){ |
|
| 142 | - try{ |
|
| 141 | + }catch (\Exception $e) { |
|
| 142 | + try { |
|
| 143 | 143 | $ins = new $name(""); |
| 144 | - }catch (\Exception $e){ |
|
| 144 | + }catch (\Exception $e) { |
|
| 145 | 145 | |
| 146 | 146 | } |
| 147 | 147 | } |
@@ -149,21 +149,21 @@ discard block |
||
| 149 | 149 | //TODO status 重复怎么办 |
| 150 | 150 | if ($ins instanceof HttpException) { |
| 151 | 151 | $status = $ins->getStatusCode(); |
| 152 | - } else { |
|
| 152 | + }else { |
|
| 153 | 153 | $status = 500; |
| 154 | 154 | } |
| 155 | 155 | if (isset($schemas[$status])) { |
| 156 | 156 | //$this->warnings[] = "status response $status has been used for $name, $desc"; |
| 157 | 157 | $res = $schemas[$status]; |
| 158 | - } else { |
|
| 158 | + }else { |
|
| 159 | 159 | $res = new ResponseObject(); |
| 160 | 160 | } |
| 161 | 161 | $shortName = self::getShortClassName($name); |
| 162 | 162 | $desc = "$shortName: $desc"; |
| 163 | 163 | $res->description = self::implode("\n", [$res->description, $desc]); |
| 164 | - if($ins){ |
|
| 164 | + if ($ins) { |
|
| 165 | 165 | $error = $app->get(ExceptionRenderer::class)->render($ins)->getContent(); |
| 166 | - if($error){ |
|
| 166 | + if ($error) { |
|
| 167 | 167 | $res->examples = [$shortName => $error]; |
| 168 | 168 | } |
| 169 | 169 | } |
@@ -223,9 +223,9 @@ discard block |
||
| 223 | 223 | { |
| 224 | 224 | if ($content instanceof ReturnMeta || $content instanceof ParamMeta) { |
| 225 | 225 | return $this->makeExample($content->container); |
| 226 | - }elseif ($content instanceof TypeContainerInterface){ |
|
| 226 | + }elseif ($content instanceof TypeContainerInterface) { |
|
| 227 | 227 | return $content->makeExample(); |
| 228 | - }elseif(is_array($content)) { |
|
| 228 | + }elseif (is_array($content)) { |
|
| 229 | 229 | $res = []; |
| 230 | 230 | foreach ($content as $k => $v) { |
| 231 | 231 | $res[$k] = $this->makeExample($v); |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | array $arr, $suffix) |
| 251 | 251 | { |
| 252 | 252 | $className = self::getShortClassName($controller->getClassName()); |
| 253 | - $name = $className . ucfirst($action) . $suffix; |
|
| 253 | + $name = $className.ucfirst($action).$suffix; |
|
| 254 | 254 | |
| 255 | 255 | $schema = new SimpleModelSchemaObject(); |
| 256 | 256 | |
@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | $schema->properties[$k] = $this->makeTempSchema($app, $controller, $action, $route, $v, $suffix); |
| 260 | 260 | } elseif ($v instanceof ReturnMeta) { |
| 261 | 261 | $sub = $this->getAnySchema($app, $controller, $action, $route, $v->container); |
| 262 | - if($sub){ |
|
| 262 | + if ($sub) { |
|
| 263 | 263 | $sub->description = $v->description; |
| 264 | 264 | } |
| 265 | 265 | $schema->properties[$k] = $sub; |
@@ -270,13 +270,13 @@ discard block |
||
| 270 | 270 | } elseif ($v->container instanceof EntityContainer) { |
| 271 | 271 | $sub = $this->getRefSchema($app, $controller, $action, $route, $v->container); |
| 272 | 272 | //TODO array for validation |
| 273 | - } else { |
|
| 273 | + }else { |
|
| 274 | 274 | $sub = new PrimitiveSchemaObject(); |
| 275 | 275 | $sub->type = self::mapType($v->type); |
| 276 | 276 | self::mapValidation($v->validation, $sub); |
| 277 | 277 | unset($sub->required); |
| 278 | 278 | } |
| 279 | - if($sub){ |
|
| 279 | + if ($sub) { |
|
| 280 | 280 | $sub->description = $v->description; |
| 281 | 281 | $sub->default = $v->default; |
| 282 | 282 | } |
@@ -284,14 +284,14 @@ discard block |
||
| 284 | 284 | $schema->required[] = $k; |
| 285 | 285 | } |
| 286 | 286 | $schema->properties[$k] = $sub; |
| 287 | - } else { |
|
| 287 | + }else { |
|
| 288 | 288 | //TODO how to do? |
| 289 | 289 | } |
| 290 | 290 | } |
| 291 | 291 | $unused = $name; |
| 292 | 292 | $tempId = 0; |
| 293 | 293 | while (isset($this->definitions[$unused])) { |
| 294 | - $unused = $name . $tempId; |
|
| 294 | + $unused = $name.$tempId; |
|
| 295 | 295 | $tempId++; |
| 296 | 296 | } |
| 297 | 297 | $this->definitions[$unused] = $schema; |
@@ -330,7 +330,7 @@ discard block |
||
| 330 | 330 | $in = 'query'; |
| 331 | 331 | |
| 332 | 332 | $bodyType = 'body'; // 当有文件上传时, 必须是formData方式 |
| 333 | - if($this->hasFileParam($route)){ |
|
| 333 | + if ($this->hasFileParam($route)) { |
|
| 334 | 334 | $bodyType = 'formData'; |
| 335 | 335 | } |
| 336 | 336 | |
@@ -369,7 +369,7 @@ discard block |
||
| 369 | 369 | || $route->getMethod() == 'PATCH' |
| 370 | 370 | ) { |
| 371 | 371 | $in = $bodyType; |
| 372 | - } else { |
|
| 372 | + }else { |
|
| 373 | 373 | $in = 'query'; |
| 374 | 374 | } |
| 375 | 375 | } |
@@ -380,11 +380,11 @@ discard block |
||
| 380 | 380 | } elseif ($param->container instanceof EntityContainer) { |
| 381 | 381 | $paramSchema = $this->getRefSchema($app, $controller, $action, $route, $param->container); |
| 382 | 382 | //TODO array for validation |
| 383 | - } else { |
|
| 383 | + }else { |
|
| 384 | 384 | $paramSchema = new PrimitiveSchemaObject(); |
| 385 | - if($isFile){ |
|
| 385 | + if ($isFile) { |
|
| 386 | 386 | $paramSchema->type = 'file'; |
| 387 | - }else{ |
|
| 387 | + }else { |
|
| 388 | 388 | $paramSchema->type = self::mapType($param->type); |
| 389 | 389 | self::mapValidation($param->validation, $paramSchema); |
| 390 | 390 | } |
@@ -396,10 +396,10 @@ discard block |
||
| 396 | 396 | $paramSchema->default = $param->default; |
| 397 | 397 | $paramSchema->required = !$param->isOptional; |
| 398 | 398 | $parameters[] = $paramSchema; |
| 399 | - } else { |
|
| 399 | + }else { |
|
| 400 | 400 | if (!$name) { |
| 401 | 401 | $body = $param; |
| 402 | - } else { |
|
| 402 | + }else { |
|
| 403 | 403 | ArrayHelper::set($body, $name, $param); |
| 404 | 404 | } |
| 405 | 405 | |
@@ -412,7 +412,7 @@ discard block |
||
| 412 | 412 | $paramSchema->in = 'body'; |
| 413 | 413 | if (is_array($body)) { |
| 414 | 414 | $paramSchema->schema = $this->makeTempSchema($app, $controller, $action, $route, $body, 'Req'); |
| 415 | - } else { |
|
| 415 | + }else { |
|
| 416 | 416 | $paramSchema->schema = $this->getAnySchema($app, $controller, $action, $route, $body->container); |
| 417 | 417 | } |
| 418 | 418 | |
@@ -439,8 +439,8 @@ discard block |
||
| 439 | 439 | } elseif ($container instanceof ScalarTypeContainer) { |
| 440 | 440 | $schema = new PrimitiveSchemaObject(); |
| 441 | 441 | $schema->type = self::mapType($container->getType()); |
| 442 | - } elseif($container == null){ |
|
| 443 | - $schema = null ;//new PrimitiveSchemaObject(); |
|
| 442 | + } elseif ($container == null) { |
|
| 443 | + $schema = null; //new PrimitiveSchemaObject(); |
|
| 444 | 444 | //$schema->type = null; |
| 445 | 445 | }else { |
| 446 | 446 | $schema = new PrimitiveSchemaObject(); |
@@ -472,7 +472,7 @@ discard block |
||
| 472 | 472 | } elseif ($itemContainer instanceof ScalarTypeContainer) { |
| 473 | 473 | $itemSchema = new PrimitiveSchemaObject(); |
| 474 | 474 | $itemSchema->type = self::mapType($itemContainer->getType()); |
| 475 | - } else { |
|
| 475 | + }else { |
|
| 476 | 476 | $itemSchema = new PrimitiveSchemaObject(); |
| 477 | 477 | //$itemSchema->type = 'mixed'; |
| 478 | 478 | } |
@@ -498,7 +498,7 @@ discard block |
||
| 498 | 498 | $propertySchema = $this->getRefSchema($app, $controller, $action, $route, $property->container); |
| 499 | 499 | } elseif ($property->container instanceof ArrayContainer) { |
| 500 | 500 | $propertySchema = $this->getArraySchema($app, $controller, $action, $route, $property->container); |
| 501 | - } else { |
|
| 501 | + }else { |
|
| 502 | 502 | $propertySchema = new PrimitiveSchemaObject(); |
| 503 | 503 | $propertySchema->type = self::mapType($property->type); |
| 504 | 504 | $propertySchema->description = self::implode("\n", [$property->summary, $property->description]); |
@@ -515,7 +515,7 @@ discard block |
||
| 515 | 515 | { |
| 516 | 516 | $params = $route->getRequestHandler()->getParamMetas(); |
| 517 | 517 | foreach ($params as $name => $param) { |
| 518 | - if(strpos($param->source, 'request.files.')===0){ |
|
| 518 | + if (strpos($param->source, 'request.files.') === 0) { |
|
| 519 | 519 | return true; |
| 520 | 520 | } |
| 521 | 521 | } |
@@ -528,7 +528,7 @@ discard block |
||
| 528 | 528 | */ |
| 529 | 529 | static public function mapValidation($v, PrimitiveSchemaObject $schemaObject) |
| 530 | 530 | { |
| 531 | - if(!$v){ |
|
| 531 | + if (!$v) { |
|
| 532 | 532 | return $schemaObject; |
| 533 | 533 | } |
| 534 | 534 | $rules = explode('|', $v); |
@@ -544,15 +544,15 @@ discard block |
||
| 544 | 544 | } elseif ($rule == 'lengthBetween' && isset($params[0]) && isset($params[1])) { |
| 545 | 545 | $schemaObject->minLength = intval($params[0]); |
| 546 | 546 | $schemaObject->maxLength = intval($params[1]); |
| 547 | - } elseif ($rule == 'lengthMin'&& isset($params[0])) { |
|
| 547 | + } elseif ($rule == 'lengthMin' && isset($params[0])) { |
|
| 548 | 548 | $schemaObject->minLength = intval($params[0]); |
| 549 | - } elseif ($rule == 'lengthMax'&& isset($params[0])) { |
|
| 549 | + } elseif ($rule == 'lengthMax' && isset($params[0])) { |
|
| 550 | 550 | $schemaObject->maxLength = intval($params[0]); |
| 551 | - } elseif ($rule == 'min'&& isset($params[0])) { |
|
| 551 | + } elseif ($rule == 'min' && isset($params[0])) { |
|
| 552 | 552 | $schemaObject->minimum = floatval($params[0]); |
| 553 | - } elseif ($rule == 'max'&& isset($params[0])) { |
|
| 553 | + } elseif ($rule == 'max' && isset($params[0])) { |
|
| 554 | 554 | $schemaObject->maximum = floatval($params[0]); |
| 555 | - } elseif ($rule == 'regex'&& isset($params[0])) { |
|
| 555 | + } elseif ($rule == 'regex' && isset($params[0])) { |
|
| 556 | 556 | $schemaObject->pattern = $params[0]; |
| 557 | 557 | } elseif ($rule == 'optional') { |
| 558 | 558 | $schemaObject->required = false; |
@@ -591,9 +591,9 @@ discard block |
||
| 591 | 591 | return $className; |
| 592 | 592 | } |
| 593 | 593 | |
| 594 | - static public function implode($glue , array $pieces ) |
|
| 594 | + static public function implode($glue, array $pieces) |
|
| 595 | 595 | { |
| 596 | - $pieces = array_filter($pieces, function($i){return trim($i) !== '';}); |
|
| 596 | + $pieces = array_filter($pieces, function($i) {return trim($i) !== ''; }); |
|
| 597 | 597 | return implode($glue, $pieces); |
| 598 | 598 | } |
| 599 | 599 | } |
| 600 | 600 | \ No newline at end of file |