swagger-php: Warning Skipping unknown & Required @OA\Info() not found in zircote/swagger-php/src/Loggers/DefaultLogger.php

  1. My Own PHP Framework
  2. PHP Version : 8.2.4
  3. OS: Mac and Linux

I was previously using an older version of Swagger, which was functioning well. Recently, I upgraded to the latest version, for both:

composer require zircote/swagger-php;
composer require doctrine/annotations;

and

composer update zircote/swagger-php;
composer update doctrine/annotations;

The JSON file was successfully loaded and is displaying correctly in the Swagger UI, However, I’m encountering an issue that I’ve been unable to resolve despite trying multiple solutions. Before reaching out, I attempted various troubleshooting steps, but none were successful. Getting now warning displayed below

Warning: Skipping unknown \new_form in /Users/mike/Sites/localhost/vendor/zircote/swagger-php/src/Loggers/DefaultLogger.php on line 23 Warning: Required @OA\PathItem() not found in /Users/mike/Sites/localhost/vendor/zircote/swagger-php/src/Loggers/DefaultLogger.php on line 23 Warning: Required @OA\Info() not found in /Users/mike/Sites/localhost/vendor/zircote/swagger-php/src/Loggers/DefaultLogger.php on line 23 { “openapi”: “3.0.0” }

Could you kindly let me know if there are any specific steps or configurations I should follow to ensure everything works seamlessly after the upgrade? taking into consideration that the json file was loaded and showing in the swagger ui well

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 19

Most upvoted comments

Ok, first of all there are a couple minor issues with your annotations:

  • annotations are separated by ,, not ;
  • PathItem requires a path property

So, here is the corrected file (other.php) I used

<?php
////////////////////////////////////////////////////////////////////////////////
use OpenApi\Annotations as OA;
//////////////////////////////////////////////////////////////////////////////
/**
 * @OA\Tag(
 *     name="user",
 *     description="User related operations"
 * )
 * @OA\Info(
 *     title="Data API Document",
 *     version="1.0.7",
 *     description="All endpoints related to this website",
 *     @OA\License(name="Apache 2.0",url="http://www.apache.org/licenses/LICENSE-2.0.html"),
 *     @OA\Contact(email="support@mysite.com"),
 *     @OA\Attachable()
 * )
 * @OA\PathItem(path="/api")
 * @OA\Server(
 *     url="https://mysite.com/api/",
 *     description="mysite Secured API"
 * )
 * @OA\SecurityScheme(
 *     type="http",
 *     description="Use the generated bearer code to get the token",
 *     scheme="bearer",
 *     bearerFormat="JWT",
 *     securityScheme="bearerAuth"
 * )
 */
class OpenApiSpec
{
}

Secondly, you have two choices to generate the spec from the file. For both, the key is that your code/annotations need to be either autoloaded or manually be loaded before processing. Typically when using composer your code would be autoloaded automatically (if configured properly); for single file experiments or small apps you are responsible for that yourself.

  1. Use the openapi command line tool (assuming swagger-php is installed via composer) and other.php is inside a src folder. The -b option means that other.php is included before processing starts…
./vendor/bin/openapi -b src/other.php src/other.php
  1. Using code. Please note that here also other.php is require’d before processing.
<?php
////////////////////////////////////////////////////////////////////////////////
require("../../vendor/autoload.php");
require 'src/other.php';
$openapi = \OpenApi\Generator::scan(["./src/other.php"]);
header("Content-Type: application/json; charset=UTF-8");
echo $openapi->toJson();
//header("Content-Type: application/x-yaml");
//echo $openapi->toYaml();