Skip to content

Commit

Permalink
Merge pull request #143 from nextcloud/fix/context
Browse files Browse the repository at this point in the history
fix: Provider better context for failures
  • Loading branch information
nickvergessen authored Jul 23, 2024
2 parents e6a1936 + 7df422f commit d340014
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions src/ControllerMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ public static function parse(string $context, array $definitions, ClassMethod $m
if ($docNode->value instanceof ReturnTagValueNode) {
$type = $docNode->value->type;

$responses = array_merge($responses, ResponseType::resolve($context, $type));
$responses = array_merge($responses, ResponseType::resolve($context . ': @return', $type));
}

if ($docNode->value instanceof ThrowsTagValueNode) {
$type = $docNode->value->type;
$statusCode = StatusCodes::resolveException($context, $type);
$statusCode = StatusCodes::resolveException($context . ': @throws', $type);
if ($statusCode != null) {
if (!$allowMissingDocs && $docNode->value->description == "" && $statusCode < 500) {
Logger::error($context, "Missing description for exception '" . $type . "'");
Expand Down Expand Up @@ -117,7 +117,7 @@ public static function parse(string $context, array $definitions, ClassMethod $m
} elseif ($docParameterType == "@psalm-param") {
$psalmParamTag = $docParameter;
} else {
Logger::panic($context, "Unknown param type " . $docParameterType);
Logger::panic($context . ': @param', "Unknown param type " . $docParameterType);
}
}
}
Expand All @@ -136,7 +136,7 @@ public static function parse(string $context, array $definitions, ClassMethod $m

try {
$type = OpenApiType::resolve(
$context,
$context . ': @param: ' . $psalmParamTag->parameterName,
$definitions,
new ParamTagValueNode(
$psalmParamTag->type,
Expand All @@ -150,7 +150,7 @@ public static function parse(string $context, array $definitions, ClassMethod $m
Logger::debug($context, "Unable to parse parameter " . $methodParameterName . ": " . $e->message . "\n" . $e->getTraceAsString());
// Fallback to the @param annotation
$type = OpenApiType::resolve(
$context,
$context . ': @param: ' . $psalmParamTag->parameterName,
$definitions,
new ParamTagValueNode(
$paramTag->type,
Expand All @@ -164,10 +164,10 @@ public static function parse(string $context, array $definitions, ClassMethod $m

$param = new ControllerMethodParameter($context, $definitions, $methodParameterName, $methodParameter, $type);
} elseif ($psalmParamTag !== null) {
$type = OpenApiType::resolve($context, $definitions, $psalmParamTag);
$type = OpenApiType::resolve($context . ': @param: ' . $methodParameterName, $definitions, $psalmParamTag);
$param = new ControllerMethodParameter($context, $definitions, $methodParameterName, $methodParameter, $type);
} elseif ($paramTag !== null) {
$type = OpenApiType::resolve($context, $definitions, $paramTag);
$type = OpenApiType::resolve($context . ': @param: ' . $methodParameterName, $definitions, $paramTag);
$param = new ControllerMethodParameter($context, $definitions, $methodParameterName, $methodParameter, $type);
} elseif ($allowMissingDocs) {
$param = new ControllerMethodParameter($context, $definitions, $methodParameterName, $methodParameter, null);
Expand All @@ -177,7 +177,7 @@ public static function parse(string $context, array $definitions, ClassMethod $m
}

if (!$allowMissingDocs && $param->type->description == "") {
Logger::error($context, "Missing description for parameter '" . $methodParameterName . "'");
Logger::error($context . ': @param: ' . $methodParameterName, "Missing description");
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/ControllerMethodParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public function __construct(string $context, array $definitions, public string $
if ($docType != null) {
$this->type = $this->docType;
} else {
$this->type = OpenApiType::resolve($context, $definitions, $methodParameter->type);
$this->type = OpenApiType::resolve($context . ': @param: ' . $name, $definitions, $methodParameter->type);
}
if ($methodParameter->default != null) {
try {
Expand Down

0 comments on commit d340014

Please sign in to comment.