lichunqiang / yii2-swagger

yii2 with swagger-php
https://packagist.org/packages/light/yii2-swagger
MIT License
151 stars 47 forks source link

Error 500 Zircote in swagger in new version 3.0.3 #32

Open matiasr2503 opened 2 years ago

matiasr2503 commented 2 years ago
yii\base\ErrorException: Skipping unknown \__Application in /app/vendor/zircote/swagger-php/src/Loggers/DefaultLogger.php:31
Stack trace:
#0 [internal function]: yii\base\ErrorHandler->handleError(512, 'Skipping unknow...', '/app/vendor/zir...', 31, Array)
#1 /app/vendor/zircote/swagger-php/src/Loggers/DefaultLogger.php(31): trigger_error('Skipping unknow...', 512)
#2 /app/vendor/psr/log/Psr/Log/AbstractLogger.php(85): OpenApi\Loggers\DefaultLogger->log('warning', 'Skipping unknow...', Array)
#3 /app/vendor/zircote/swagger-php/src/Analysers/ReflectionAnalyser.php(80): Psr\Log\AbstractLogger->warning('Skipping unknow...')
#4 /app/vendor/zircote/swagger-php/src/Analysers/ReflectionAnalyser.php(54): OpenApi\Analysers\ReflectionAnalyser->analyzeFqdn('\\__Application', Object(OpenApi\Analysis), Array)
#5 /app/vendor/zircote/swagger-php/src/Generator.php(433): OpenApi\Analysers\ReflectionAnalyser->fromFile('/app/config/__a...', Object(OpenApi\Context))
#6 /app/vendor/zircote/swagger-php/src/Generator.php(396): OpenApi\Generator->scanSources(Object(Symfony\Component\Finder\Finder), Object(OpenApi\Analysis), Object(OpenApi\Context))
#7 /app/vendor/zircote/swagger-php/src/Generator.php(348): OpenApi\Generator->generate(Object(Symfony\Component\Finder\Finder), Object(OpenApi\Analysis), true)
#8 /app/vendor/light/yii2-swagger/src/SwaggerApiAction.php(156): OpenApi\Generator::scan(Object(Symfony\Component\Finder\Finder), Array)
#9 /app/vendor/light/yii2-swagger/src/SwaggerApiAction.php(110): light\swagger\SwaggerApiAction->getSwagger()
#10 [internal function]: light\swagger\SwaggerApiAction->run()
#11 /app/vendor/yiisoft/yii2/base/Action.php(93): call_user_func_array(Array, Array)
#12 /app/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\Action->runWithParams(Array)
#13 /app/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('api', Array)
#14 /app/vendor/yiisoft/yii2/web/Application.php(103): yii\base\Module->runAction('default/api', Array)
#15 /app/vendor/yiisoft/yii2/base/Application.php(384): yii\web\Application->handleRequest(Object(yii\web\Request))
#16 /app/api/index.php(16): yii\base\Application->run()
#17 {main}

Fail to open swagger app: PHP version: 7.4.30 Yii version 2.0.45 light/yii2-swagger v3.0.3

image

wa1kb0y commented 2 years ago

Similar issue after update up to 3.0.3. Downgrade to 3.0.2 helps. composer require light/yii2-swagger 3.0.2 -W

Krakozaber commented 2 years ago

Check out the migration process to version 4. https://zircote.github.io/swagger-php/guide/migrating-to-v4.html

Annotations now must be associated with a structural element (class, trait, interface), a method, property or const.

@lichunqiang perhaps the package version should have been upgraded to 4.0.0. #30 zircote/swagger-php v4 is fine and much more convenient, but it breaks backward compatibility :-(

zebraf1 commented 1 month ago

I ran into a similar issue and it turned out to be a naming issue for the underlying class.

The file name and the class name inside must match, otherwise it would return "Skipping unknown namespace/to/class".

Basicly class_exists('Namespace/To/Class') will be false if the class isn't autoloaded. This is what ReflectionAnalyzer->analyzeFqdn() checks.