Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Provider better context for failures #143

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading