Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

swagger-php says the OpenAPI Info is missing

ErrorRequired @OA\Info() not found

Short answer

swagger-php reads annotations or attributes only through PHP reflection. The Info block is global, so it is easily placed where nothing reads it. Put it on a dedicated class, install doctrine/annotations if you use docblocks, and make sure the scan path you pass to the generator includes that file.

  • Applies to PHP 8.3, swagger-php 5, Composer 2
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Run the generator on the folder that holds your annotated classes and read the first message. This also shows which scan path you are really using.

    ./vendor/bin/openapi app -o openapi.yaml
  2. 2Match what you see, then jump to its fix

    1. 1Annotations on your controllers work, but Info is reported missingThe Info annotation sits where reflection never looksFix
    2. 2No annotations are found at all, and the same Info message appearsYou use docblock annotations but doctrine/annotations is not installedFix
    3. 3The Info class exists, but the generator never loads itThe scan path does not include the file with the InfoFix

What does the error look like?

  • Required @OA\Info() not found
  • Document is missing info

Cause 1 of 3

The Info annotation sits where reflection never looks

1Check

swagger-php finds annotations on a class, interface, trait, method, property or class constant. A docblock on its own, or one in a plain file, is ignored. OA\Info belongs to the whole document, so it has no natural home.

grep -rn "OA\\\\Info" app/

2Fix

Create a dummy class and put the global annotations on it.

<?php
use OpenApi\Attributes as OA;

#[OA\Info(title: 'My API', version: '1.0.0')]
class OpenApiSpec
{
}

3Verify

Run the generator again; the Info message is gone.

./vendor/bin/openapi app -o openapi.yaml

Confirmed by zircote.com

Did this fix it?

Cause 2 of 3

You use docblock annotations but doctrine/annotations is not installed

1Check

The FAQ says docblock annotations need doctrine/annotations, and that swagger-php does not install it for you. Without it, annotations are not read.

composer show doctrine/annotations

2Fix

Install the package, or move to PHP attributes, which need no extra package.

composer require doctrine/annotations

3Verify

Generate the document again.

./vendor/bin/openapi app -o openapi.yaml

Confirmed by zircote.com

Did this fix it?

Cause 3 of 3

The scan path does not include the file with the Info

1Check

The generator scans only the source paths you give it. If the dummy class lives in another folder, it is not read.

./vendor/bin/openapi --help

2Fix

Pass every folder involved, or move the Info class under the scanned folder. Several paths are allowed.

./vendor/bin/openapi app src -o openapi.yaml

3Verify

Open the output file and look for the info section.

head -n 8 openapi.yaml

Confirmed by zircote.com

Did this fix it?

How do I stop it coming back?

  • Keep one OpenApiSpec class for Info, Server and Tag, in a folder that is always scanned.
  • Prefer PHP attributes over docblocks so no extra package is needed.
  • Run the generator in CI so a missing Info fails the build.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

Apache returns 403 when a URL contains %3F

a request like /page%3Fname=test is refused while /page?name=test works

Recent Apache httpd blocks a rewrite when the request contains an encoded question mark (%3F) and the rewritten target has a literal ?.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.