@@ -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,30 +136,30 @@ 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){ |
|
| 141 | + }catch (\Exception $e) { |
|
| 142 | 142 | |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | //TODO status 重复怎么办 |
| 146 | 146 | if ($ins instanceof HttpExceptio) { |
| 147 | 147 | $status = $ins->getStatusCode(); |
| 148 | - } else { |
|
| 148 | + }else { |
|
| 149 | 149 | $status = 500; |
| 150 | 150 | } |
| 151 | 151 | if (isset($schemas[$status])) { |
| 152 | 152 | //$this->warnings[] = "status response $status has been used for $name, $desc"; |
| 153 | 153 | $res = $schemas[$status]; |
| 154 | - } else { |
|
| 154 | + }else { |
|
| 155 | 155 | $res = new ResponseObject(); |
| 156 | 156 | } |
| 157 | 157 | $shortName = self::getShortClassName($name); |
| 158 | 158 | $desc = "$shortName: $desc"; |
| 159 | 159 | $res->description = self::implode("\n", [$res->description, $desc]); |
| 160 | - if($ins){ |
|
| 160 | + if ($ins) { |
|
| 161 | 161 | $error = $app->get(ExceptionRenderer::class)->render($ins)->getContent(); |
| 162 | - if($error){ |
|
| 162 | + if ($error) { |
|
| 163 | 163 | $res->examples = [$shortName => $error]; |
| 164 | 164 | } |
| 165 | 165 | } |
@@ -219,9 +219,9 @@ discard block |
||
| 219 | 219 | { |
| 220 | 220 | if ($content instanceof ReturnMeta || $content instanceof ParamMeta) { |
| 221 | 221 | return $this->makeExample($content->container); |
| 222 | - }elseif ($content instanceof TypeContainerInterface){ |
|
| 222 | + }elseif ($content instanceof TypeContainerInterface) { |
|
| 223 | 223 | return $content->makeExample(); |
| 224 | - }elseif(is_array($content)) { |
|
| 224 | + }elseif (is_array($content)) { |
|
| 225 | 225 | $res = []; |
| 226 | 226 | foreach ($content as $k => $v) { |
| 227 | 227 | $res[$k] = $this->makeExample($v); |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | array $arr, $suffix) |
| 247 | 247 | { |
| 248 | 248 | $className = self::getShortClassName($controller->getClassName()); |
| 249 | - $name = $className . ucfirst($action) . $suffix; |
|
| 249 | + $name = $className.ucfirst($action).$suffix; |
|
| 250 | 250 | |
| 251 | 251 | $schema = new SimpleModelSchemaObject(); |
| 252 | 252 | |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | $schema->properties[$k] = $this->makeTempSchema($app, $controller, $action, $route, $v, $suffix); |
| 256 | 256 | } elseif ($v instanceof ReturnMeta) { |
| 257 | 257 | $sub = $this->getAnySchema($app, $controller, $action, $route, $v->container); |
| 258 | - if($sub){ |
|
| 258 | + if ($sub) { |
|
| 259 | 259 | $sub->description = $v->description; |
| 260 | 260 | } |
| 261 | 261 | $schema->properties[$k] = $sub; |
@@ -266,13 +266,13 @@ discard block |
||
| 266 | 266 | } elseif ($v->container instanceof EntityContainer) { |
| 267 | 267 | $sub = $this->getRefSchema($app, $controller, $action, $route, $v->container); |
| 268 | 268 | //TODO array for validation |
| 269 | - } else { |
|
| 269 | + }else { |
|
| 270 | 270 | $sub = new PrimitiveSchemaObject(); |
| 271 | 271 | $sub->type = self::mapType($v->type); |
| 272 | 272 | self::mapValidation($v->validation, $sub); |
| 273 | 273 | unset($sub->required); |
| 274 | 274 | } |
| 275 | - if($sub){ |
|
| 275 | + if ($sub) { |
|
| 276 | 276 | $sub->description = $v->description; |
| 277 | 277 | $sub->default = $v->default; |
| 278 | 278 | } |
@@ -280,14 +280,14 @@ discard block |
||
| 280 | 280 | $schema->required[] = $k; |
| 281 | 281 | } |
| 282 | 282 | $schema->properties[$k] = $sub; |
| 283 | - } else { |
|
| 283 | + }else { |
|
| 284 | 284 | //TODO how to do? |
| 285 | 285 | } |
| 286 | 286 | } |
| 287 | 287 | $unused = $name; |
| 288 | 288 | $tempId = 0; |
| 289 | 289 | while (isset($this->definitions[$unused])) { |
| 290 | - $unused = $name . $tempId; |
|
| 290 | + $unused = $name.$tempId; |
|
| 291 | 291 | $tempId++; |
| 292 | 292 | } |
| 293 | 293 | $this->definitions[$unused] = $schema; |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | $in = 'query'; |
| 327 | 327 | |
| 328 | 328 | $bodyType = 'body'; // 当有文件上传时, 必须是formData方式 |
| 329 | - if($this->hasFileParam($route)){ |
|
| 329 | + if ($this->hasFileParam($route)) { |
|
| 330 | 330 | $bodyType = 'formData'; |
| 331 | 331 | } |
| 332 | 332 | |
@@ -365,7 +365,7 @@ discard block |
||
| 365 | 365 | || $route->getMethod() == 'PATCH' |
| 366 | 366 | ) { |
| 367 | 367 | $in = $bodyType; |
| 368 | - } else { |
|
| 368 | + }else { |
|
| 369 | 369 | $in = 'query'; |
| 370 | 370 | } |
| 371 | 371 | } |
@@ -376,11 +376,11 @@ discard block |
||
| 376 | 376 | } elseif ($param->container instanceof EntityContainer) { |
| 377 | 377 | $paramSchema = $this->getRefSchema($app, $controller, $action, $route, $param->container); |
| 378 | 378 | //TODO array for validation |
| 379 | - } else { |
|
| 379 | + }else { |
|
| 380 | 380 | $paramSchema = new PrimitiveSchemaObject(); |
| 381 | - if($isFile){ |
|
| 381 | + if ($isFile) { |
|
| 382 | 382 | $paramSchema->type = 'file'; |
| 383 | - }else{ |
|
| 383 | + }else { |
|
| 384 | 384 | $paramSchema->type = self::mapType($param->type); |
| 385 | 385 | self::mapValidation($param->validation, $paramSchema); |
| 386 | 386 | } |
@@ -392,10 +392,10 @@ discard block |
||
| 392 | 392 | $paramSchema->default = $param->default; |
| 393 | 393 | $paramSchema->required = !$param->isOptional; |
| 394 | 394 | $parameters[] = $paramSchema; |
| 395 | - } else { |
|
| 395 | + }else { |
|
| 396 | 396 | if (!$name) { |
| 397 | 397 | $body = $param; |
| 398 | - } else { |
|
| 398 | + }else { |
|
| 399 | 399 | ArrayHelper::set($body, $name, $param); |
| 400 | 400 | } |
| 401 | 401 | |
@@ -408,7 +408,7 @@ discard block |
||
| 408 | 408 | $paramSchema->in = 'body'; |
| 409 | 409 | if (is_array($body)) { |
| 410 | 410 | $paramSchema->schema = $this->makeTempSchema($app, $controller, $action, $route, $body, 'Req'); |
| 411 | - } else { |
|
| 411 | + }else { |
|
| 412 | 412 | $paramSchema->schema = $this->getAnySchema($app, $controller, $action, $route, $body->container); |
| 413 | 413 | } |
| 414 | 414 | |
@@ -435,8 +435,8 @@ discard block |
||
| 435 | 435 | } elseif ($container instanceof ScalarTypeContainer) { |
| 436 | 436 | $schema = new PrimitiveSchemaObject(); |
| 437 | 437 | $schema->type = self::mapType($container->getType()); |
| 438 | - } elseif($container == null){ |
|
| 439 | - $schema = null ;//new PrimitiveSchemaObject(); |
|
| 438 | + } elseif ($container == null) { |
|
| 439 | + $schema = null; //new PrimitiveSchemaObject(); |
|
| 440 | 440 | //$schema->type = null; |
| 441 | 441 | }else { |
| 442 | 442 | $schema = new PrimitiveSchemaObject(); |
@@ -468,7 +468,7 @@ discard block |
||
| 468 | 468 | } elseif ($itemContainer instanceof ScalarTypeContainer) { |
| 469 | 469 | $itemSchema = new PrimitiveSchemaObject(); |
| 470 | 470 | $itemSchema->type = self::mapType($itemContainer->getType()); |
| 471 | - } else { |
|
| 471 | + }else { |
|
| 472 | 472 | $itemSchema = new PrimitiveSchemaObject(); |
| 473 | 473 | //$itemSchema->type = 'mixed'; |
| 474 | 474 | } |
@@ -494,7 +494,7 @@ discard block |
||
| 494 | 494 | $propertySchema = $this->getRefSchema($app, $controller, $action, $route, $property->container); |
| 495 | 495 | } elseif ($property->container instanceof ArrayContainer) { |
| 496 | 496 | $propertySchema = $this->getArraySchema($app, $controller, $action, $route, $property->container); |
| 497 | - } else { |
|
| 497 | + }else { |
|
| 498 | 498 | $propertySchema = new PrimitiveSchemaObject(); |
| 499 | 499 | $propertySchema->type = self::mapType($property->type); |
| 500 | 500 | $propertySchema->description = self::implode("\n", [$property->summary, $property->description]); |
@@ -511,7 +511,7 @@ discard block |
||
| 511 | 511 | { |
| 512 | 512 | $params = $route->getRequestHandler()->getParamMetas(); |
| 513 | 513 | foreach ($params as $name => $param) { |
| 514 | - if(strpos($param->source, 'request.files.')===0){ |
|
| 514 | + if (strpos($param->source, 'request.files.') === 0) { |
|
| 515 | 515 | return true; |
| 516 | 516 | } |
| 517 | 517 | } |
@@ -524,7 +524,7 @@ discard block |
||
| 524 | 524 | */ |
| 525 | 525 | static public function mapValidation($v, PrimitiveSchemaObject $schemaObject) |
| 526 | 526 | { |
| 527 | - if(!$v){ |
|
| 527 | + if (!$v) { |
|
| 528 | 528 | return $schemaObject; |
| 529 | 529 | } |
| 530 | 530 | $rules = explode('|', $v); |
@@ -540,15 +540,15 @@ discard block |
||
| 540 | 540 | } elseif ($rule == 'lengthBetween' && isset($params[0]) && isset($params[1])) { |
| 541 | 541 | $schemaObject->minLength = intval($params[0]); |
| 542 | 542 | $schemaObject->maxLength = intval($params[1]); |
| 543 | - } elseif ($rule == 'lengthMin'&& isset($params[0])) { |
|
| 543 | + } elseif ($rule == 'lengthMin' && isset($params[0])) { |
|
| 544 | 544 | $schemaObject->minLength = intval($params[0]); |
| 545 | - } elseif ($rule == 'lengthMax'&& isset($params[0])) { |
|
| 545 | + } elseif ($rule == 'lengthMax' && isset($params[0])) { |
|
| 546 | 546 | $schemaObject->maxLength = intval($params[0]); |
| 547 | - } elseif ($rule == 'min'&& isset($params[0])) { |
|
| 547 | + } elseif ($rule == 'min' && isset($params[0])) { |
|
| 548 | 548 | $schemaObject->minimum = floatval($params[0]); |
| 549 | - } elseif ($rule == 'max'&& isset($params[0])) { |
|
| 549 | + } elseif ($rule == 'max' && isset($params[0])) { |
|
| 550 | 550 | $schemaObject->maximum = floatval($params[0]); |
| 551 | - } elseif ($rule == 'regex'&& isset($params[0])) { |
|
| 551 | + } elseif ($rule == 'regex' && isset($params[0])) { |
|
| 552 | 552 | $schemaObject->pattern = $params[0]; |
| 553 | 553 | } elseif ($rule == 'optional') { |
| 554 | 554 | $schemaObject->required = false; |
@@ -587,9 +587,9 @@ discard block |
||
| 587 | 587 | return $className; |
| 588 | 588 | } |
| 589 | 589 | |
| 590 | - static public function implode($glue , array $pieces ) |
|
| 590 | + static public function implode($glue, array $pieces) |
|
| 591 | 591 | { |
| 592 | - $pieces = array_filter($pieces, function($i){return trim($i) !== '';}); |
|
| 592 | + $pieces = array_filter($pieces, function($i) {return trim($i) !== ''; }); |
|
| 593 | 593 | return implode($glue, $pieces); |
| 594 | 594 | } |
| 595 | 595 | } |
| 596 | 596 | \ No newline at end of file |