Skip to content
Open
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
9 changes: 8 additions & 1 deletion src/Describer/DefaultDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,14 @@ public function describe(OA\OpenApi $api): void
continue;
}

if (Generator::UNDEFINED === $operation->responses || [] === $operation->responses) {
// Verificar si hay respuestas (cualquier tipo)
$hasAnyResponses = false;
if (Generator::UNDEFINED !== $operation->responses && [] !== $operation->responses && null !== $operation->responses) {
$hasAnyResponses = true;
}

// Solo agregar respuesta "default" si NO hay respuestas definidas
if (!$hasAnyResponses) {
/** @var OA\Response $response */
$response = Util::getIndexedCollectionItem($operation, OA\Response::class, 'default');
$response->description = '';
Expand Down
37 changes: 37 additions & 0 deletions src/Describer/OpenApiPhpDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,44 @@
continue;
}

// Procesar Attributes Post, Get, Put, Delete, etc.
$className = $annotation::class;
if (str_starts_with($className, 'OpenApi\\Attributes\\')) {
$shortName = substr($className, strrpos($className, '\\') + 1);
$httpMethodNames = ['Post', 'Get', 'Put', 'Delete', 'Patch'];
if (\in_array($shortName, $httpMethodNames, true)) {
$methodName = strtolower($shortName);
if (\in_array($methodName, $supportedHttpMethods, true)) {
// Verificar si el atributo tiene un path específico y coincide con el path actual
if (Generator::UNDEFINED !== $annotation->path && $path->path !== $annotation->path) {

Check failure on line 104 in src/Describer/OpenApiPhpDescriber.php

View workflow job for this annotation

GitHub Actions / PHPStan

Access to an undefined property OpenApi\Annotations\AbstractAnnotation::$path.
continue;
}

// Limpiar el path del atributo antes de hacer merge
// El path viene del contexto de la ruta, no del atributo
$originalPath = $annotation->path;
$annotation->path = Generator::UNDEFINED;

$operation = Util::getOperation($path, $methodName);
$operation->mergeProperties($annotation);

// Restaurar el path original del atributo (por si acaso)
$annotation->path = $originalPath;

Check failure on line 117 in src/Describer/OpenApiPhpDescriber.php

View workflow job for this annotation

GitHub Actions / PHPStan

Access to an undefined property OpenApi\Annotations\AbstractAnnotation::$path.
}
continue;
}
}

if ($annotation instanceof OA\Operation) {
// Skip OpenAPI Attributes that are already processed above
$className = $annotation::class;
if (str_starts_with($className, 'OpenApi\\Attributes\\')) {
$shortName = substr($className, strrpos($className, '\\') + 1);
$httpMethodNames = ['Post', 'Get', 'Put', 'Delete', 'Patch'];
if (\in_array($shortName, $httpMethodNames, true)) {
continue;
}
}
if (!\in_array($annotation->method, $supportedHttpMethods, true)) {
continue;
}
Expand Down
10 changes: 6 additions & 4 deletions tests/Functional/WebTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,12 @@ public function assertHasParameter(string $name, string $in, OA\AbstractAnnotati
*/
public function assertNotHasParameter(string $name, string $in, OA\AbstractAnnotation $annotation): void
{
$parameters = array_column(Generator::UNDEFINED !== $annotation->parameters ? $annotation->parameters : [], 'name', 'in');
static::assertNotContains(
$name,
$parameters[$in] ?? [],
$parameters = array_filter(Generator::UNDEFINED !== $annotation->parameters ? $annotation->parameters : [], function (OA\Parameter $parameter) use ($name, $in) {
return $parameter->name === $name && $parameter->in === $in;
});

static::assertEmpty(
$parameters,
\sprintf('Failed asserting that parameter "%s" in "%s" does not exist.', $name, $in)
);
}
Expand Down
Loading