Closed AptsiauriV closed 2 years ago
/**
* @OA\Info(title="My First API", version="0.1")
*/
Add in your base Controller
<?php
namespace App\Http\Controllers;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
/**
* @OA\Info(title="My First API", version="0.1")
*/
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}
I have docs and Controllers separated. I do have Info set up which was working perfectly fine until now for some reason
It's happing with me also. Only with version 8.2, downgrading to 8.1 fixes this error
That's why i posted it. I was wondering if anyone was having same issue, thanks i'll try downgrading
Downgrading to 8.1 Fixed the issue
Same here.. I would reopen the issue, this is a migration issue.
Thanks for the response, I accidentally closed it
Same here, thanks for reopening the issue. This is related to https://github.com/DarkaOnLine/L5-Swagger/pull/436. I understand the problem is in the upgrade to https://github.com/zircote/swagger-php 4.x
Yes, this is true, swagger-php 4.* requires to have each annotation as a class or method phpDoc. Example: https://github.com/DarkaOnLine/L5-Swagger/blob/master/tests/storage/annotations/OpenApi/L5SwaggerAnnotationsExampleInfo.php
Yes, this is true, swagger-php 4.* requires to have each annotation as a class or method phpDoc. Example: https://github.com/DarkaOnLine/L5-Swagger/blob/master/tests/storage/annotations/OpenApi/L5SwaggerAnnotationsExampleInfo.php
I'm don't use annotation on my base code, I have different PHP files just for this, and I'm still getting this issue.
Should I put OAInfo in each file?
Please read swagger-php migration docs to v4
Annotations now must be associated with either a class/trait/interface, method or property.
Please read swagger-php migration docs to v4
Annotations now must be associated with either a class/trait/interface, method or property.
Hi, as I said before:
I'm don't use annotation on my base code, I have different PHP files just for this, and I'm still getting this issue.
Should I put OAInfo in each file?
@Messhias this is fine if you are not using with code files. But still requirement for swagger-php:4 is that you must associate annotation with either a class/trait/interface, method or property.
So in swagger-php:3 we had this: https://github.com/DarkaOnLine/L5-Swagger/blob/8.1.0/tests/storage/annotations/OpenApi/Anotations.php
But with swagger-php:4 - you must do like this: https://github.com/DarkaOnLine/L5-Swagger/tree/8.3.0/tests/storage/annotations/OpenApi
So if you do not want to redo your annotation you can fall back to swagger-php:3 by requesting it in your composer.json
@Messhias I`ve just solved this issue: every my separate php file for swagger doc now looks like this:
<?php
namespace App\Http\Swagger\System;
/**
* @OA\Schema(
* schema="content",
* type="object",
* @OA\Property(property="id", type="integer", example=12),
* @OA\Property(property="slug", type="string", example="Some slug text"),
* @OA\Property(property="title", type="string", example="Some title text"),
* @OA\Property(property="type", type="string", example="Some type text"),
* @OA\Property(property="created_at", type="string", example="2020-02-14 13:43:15"),
* @OA\Property(property="updated_at", type="string", example="2020-02-14 13:43:15"),
* ),
* */
class Content
{
}
so just dummy classes :D
@Messhias I`ve just solved this issue: every my separate php file for swagger doc now looks like this:
<?php namespace App\Http\Swagger\System; /** * @OA\Schema( * schema="content", * type="object", * @OA\Property(property="id", type="integer", example=12), * @OA\Property(property="slug", type="string", example="Some slug text"), * @OA\Property(property="title", type="string", example="Some title text"), * @OA\Property(property="type", type="string", example="Some type text"), * @OA\Property(property="created_at", type="string", example="2020-02-14 13:43:15"), * @OA\Property(property="updated_at", type="string", example="2020-02-14 13:43:15"), * ), * */ class Content { }
so just dummy classes :D
I don't use swagger in my classes, it's for API software documentation.
I have a folder called documentation and point the swagger to there and wrote down only PHP comments.
Example:
<?php
/**
* @OA\Server(
* url=API_HOST,
* description=API_DESCRIPTION
* ),
* @OA\Info(
* title="API DOCUMENTATION",
* version="0.5",
* @OA\Contact(
* email="support@support.com"
* ),
*/
I did the same. Actually swagger docs was like this: App/Http/Swagger/Content.php - file with only comments:
/**
* @OA\Schema(
* schema="content",
* type="object",
* @OA\Property(property="id", type="integer", example=12),
* @OA\Property(property="slug", type="string", example="Some slug text"),
* @OA\Property(property="title", type="string", example="Some title text"),
* @OA\Property(property="type", type="string", example="Some type text"),
* @OA\Property(property="created_at", type="string", example="2020-02-14 13:43:15"),
* @OA\Property(property="updated_at", type="string", example="2020-02-14 13:43:15"),
* ),
*.....
I have some issue @DarkaOnLine
Fresh install laravel 9 on php 8.1, give Required @OA\Info() not found
even though @OA\Info is already exists, I used to use laravel 7 and there was no problem
Here my composer.json
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"php": "^8.0.2",
"darkaonline/l5-swagger": "^8.3",
"fruitcake/laravel-cors": "^2.0.5",
"guzzlehttp/guzzle": "^7.2",
"laravel/framework": "^9.0",
"laravel/sanctum": "^2.14",
"laravel/tinker": "^2.7"
},
"require-dev": {
"fakerphp/faker": "^1.9.1",
"laravel/sail": "^1.0.1",
"mockery/mockery": "^1.4.4",
"nunomaduro/collision": "^6.1",
"phpunit/phpunit": "^9.5.10",
"spatie/laravel-ignition": "^1.0"
},
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
],
"post-update-cmd": [
"@php artisan vendor:publish --tag=laravel-assets --ansi --force"
],
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"@php artisan key:generate --ansi"
]
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true
}
I have some issue @DarkaOnLine
Fresh install laravel 9 on php 8.1, give
Required @OA\Info() not found
even though @OA\Info is already exists, I used to use laravel 7 and there was no problem
Here my composer.json
{ "name": "laravel/laravel", "type": "project", "description": "The Laravel Framework.", "keywords": ["framework", "laravel"], "license": "MIT", "require": { "php": "^8.0.2", "darkaonline/l5-swagger": "^8.3", "fruitcake/laravel-cors": "^2.0.5", "guzzlehttp/guzzle": "^7.2", "laravel/framework": "^9.0", "laravel/sanctum": "^2.14", "laravel/tinker": "^2.7" }, "require-dev": { "fakerphp/faker": "^1.9.1", "laravel/sail": "^1.0.1", "mockery/mockery": "^1.4.4", "nunomaduro/collision": "^6.1", "phpunit/phpunit": "^9.5.10", "spatie/laravel-ignition": "^1.0" }, "autoload": { "psr-4": { "App\\": "app/", "Database\\Factories\\": "database/factories/", "Database\\Seeders\\": "database/seeders/" } }, "autoload-dev": { "psr-4": { "Tests\\": "tests/" } }, "scripts": { "post-autoload-dump": [ "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump", "@php artisan package:discover --ansi" ], "post-update-cmd": [ "@php artisan vendor:publish --tag=laravel-assets --ansi --force" ], "post-root-package-install": [ "@php -r \"file_exists('.env') || copy('.env.example', '.env');\"" ], "post-create-project-cmd": [ "@php artisan key:generate --ansi" ] }, "extra": { "laravel": { "dont-discover": [] } }, "config": { "optimize-autoloader": true, "preferred-install": "dist", "sort-packages": true }, "minimum-stability": "dev", "prefer-stable": true }
Have you checked this comment: https://github.com/DarkaOnLine/L5-Swagger/issues/443#issuecomment-1042790461 and changes for swagger-php:4
I have some issue @DarkaOnLine Fresh install laravel 9 on php 8.1, give
Required @OA\Info() not found
even though @OA\Info is already exists, I used to use laravel 7 and there was no problem Here my composer.json{ "name": "laravel/laravel", "type": "project", "description": "The Laravel Framework.", "keywords": ["framework", "laravel"], "license": "MIT", "require": { "php": "^8.0.2", "darkaonline/l5-swagger": "^8.3", "fruitcake/laravel-cors": "^2.0.5", "guzzlehttp/guzzle": "^7.2", "laravel/framework": "^9.0", "laravel/sanctum": "^2.14", "laravel/tinker": "^2.7" }, "require-dev": { "fakerphp/faker": "^1.9.1", "laravel/sail": "^1.0.1", "mockery/mockery": "^1.4.4", "nunomaduro/collision": "^6.1", "phpunit/phpunit": "^9.5.10", "spatie/laravel-ignition": "^1.0" }, "autoload": { "psr-4": { "App\\": "app/", "Database\\Factories\\": "database/factories/", "Database\\Seeders\\": "database/seeders/" } }, "autoload-dev": { "psr-4": { "Tests\\": "tests/" } }, "scripts": { "post-autoload-dump": [ "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump", "@php artisan package:discover --ansi" ], "post-update-cmd": [ "@php artisan vendor:publish --tag=laravel-assets --ansi --force" ], "post-root-package-install": [ "@php -r \"file_exists('.env') || copy('.env.example', '.env');\"" ], "post-create-project-cmd": [ "@php artisan key:generate --ansi" ] }, "extra": { "laravel": { "dont-discover": [] } }, "config": { "optimize-autoloader": true, "preferred-install": "dist", "sort-packages": true }, "minimum-stability": "dev", "prefer-stable": true }
Have you checked this comment: #443 (comment) and changes for swagger-php:4
I don't get this comment, there's no solution at all for my case and even for his case.
If anyone opens the link:
So, there are a lot of files and this is not suggestive for a "solution".
But I tried to go deeper to try to understand the solution behind it.
And one of the examples of files I found something like this:
1.
<?php
namespace Tests\storage\annotations\OpenApi;
/**
* @OA\Info(
* version="1.0.0",
* x={
* "logo": {
* "url": "https://via.placeholder.com/190x90.png?text=L5-Swagger"
* }
* },
* title="L5 OpenApi",
* description="L5 Swagger OpenApi description",
* @OA\Contact(
* email="darius@matulionis.lt"
* ),
* @OA\License(
* name="Apache 2.0",
* url="https://www.apache.org/licenses/LICENSE-2.0.html"
* )
* )
*/
class L5SwaggerAnnotationsExampleInfo
{
}
<?php
namespace Tests\storage\annotations\OpenApi;
/**
So what's the conclusion I found in your comment:
@OA\Info()
and the rest just going fine. So as I told you before, and I don't have annotations for documentation in code files (don't get me wrong, but attention to this because I didn't find a relation for my case).
So I did that (and this is my actual files):
1 - index.php
<?php
/**
* @OA\Server(
* url=API_HOST,
* description=API_DESCRIPTION
* ),
* @OA\Info(
* title="API DOCUMENTATION",
* version="0.5",
* description="Standard documentation for third companies’ use. In this API all the necessary endpoints to be used by third-party providers for the set-up, management of new contributions, and retrieval of all necessary information are shown. This API is being continuously improved. Some endpoints can be updated and reviewed on an ongoing basis. Please check the latest version of the documentation for the most updated up-to-date information.",
* )
*/
2 - A documentation page example (an auth request):
<?php
/**
* @OA\POST (
* path="/software/auth",
* summary="Retrieve your token to use the other endpoints.",
* tags={"software"},
* @OA\RequestBody(
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(
* @OA\Property(
* description="This is the request body encapsulation, it's necessary to send a valid request body.",
* property="software",
* type="object",
* @OA\Property(
* property="api_secret",
* description="Your api secret.",
* type="string",
* ),
* @OA\Property(
* description="Your api key.",
* property="api_key",
* type="string",
* ),
* ),
* ),
* ),
* ),
* @OA\Response(
* response=200,
* description="Response with token credentials.",
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(
* @OA\Property(
* property="message",
* description="API message response.",
* type="string"
* ),
* @OA\Property(
* description="The request ended date.",
* property="completed_at",
* type="string",
* format="date-time",
* ),
* @OA\Property(
* description="The HTTP status code response.",
* property="code",
* type="integer",
* default=200,
* ),
* @OA\Property(
* description="Indicates if your request is finalized with succes (2xx only returns this property to true).",
* property="success",
* type="boolean",
* default=true,
* ),
* @OA\Property(
* description="Indicates if your request is not finalized with some error (check the data / message property for mode details) (any 2xx different status response).",
* property="error",
* type="boolean",
* default=false,
* ),
* @OA\Property(
* description="This is the request body encapsulation response, returns the request resposne.",
* property="data",
* type="object",
* @OA\Property(
* description="Your request token.",
* property="token",
* type="string",
* ),
* @OA\Property(
* description="The token expiration date.",
* property="expiration_date",
* type="string",
* format="date-time"
* ),
* @OA\Property(
* description="The token creation date.",
* property="created_at",
* type="string",
* format="date-time",
* ),
* @OA\Property(
* description="Token expiration in miliseconds..",
* property="expires_in",
* type="integer",
* minimum=3600,
* ),
* ),
* ),
* ),
* ),
* ),
*/
On version 3+ works fine in 8, if we update to 4 stop working (even in L8 or 9, at least on my case), and I tried to do it in the fresh installation, 4+ broken.
Here screenshots working normally the version 3+ in the current laravel framework version (8+):
So I believe might be I expressed myself about the issue in the wrong way, but I believe now we have all the information. So, sorry about the confusion.
But I hope with this more detailed explanation you can track down the issue, and again, would be nice to you to create contribution conduct to everything try to fork the package and help you maintain it. Don't get me wrong, it seems you're maintaining it alone and for the volume of downloads and users would be nice for you to have some help.
@Messhias
So as I told you before, and I don't have annotations for documentation in code files (don't get me wrong, but attention to this because I didn't find a relation for my case).
So this is fine as I told you. You just need to provide dummy class names and method names. For example, your index.php
should look like this if you want to use swagger-php:4 and everything will start to work. If you do not want to do these changes, please use swagger-php:3
<?php
namespace My/Name/Space;
/**
* @OA\Server(
* url=API_HOST,
* description=API_DESCRIPTION
* ),
* @OA\Info(
* title="API DOCUMENTATION",
* version="0.5",
* description="Standard documentation for third companies’ use. In this API all the necessary endpoints to be used by third-party providers for the set-up, management of new contributions, and retrieval of all necessary information are shown. This API is being continuously improved. Some endpoints can be updated and reviewed on an ongoing basis. Please check the latest version of the documentation for the most updated up-to-date information.",
* )
*/
class MySwaggerDocsInfoDummyClassName {}
But I hope with this more detailed explanation you can track down the issue, and again, would be nice to you to create contribution conduct to everything try to fork the package and help you maintain it. Don't get me wrong, it seems you're maintaining it alone and for the volume of downloads and users would be nice for you to have some help.
You are always welcome to help end contribute, suggest better ways how to do that, help people by answering questions, dig deeper into how code works, etc. Complaining is the easiest path, try to take some actions. I would really appreciate any help ...
I've fixed it by downgrading to version 8.1 with all his dependencies using the command composer require darkaonline/l5-swagger:8.1 --with-all-dependencies
I've fixed it by downgrading to version 8.1 with all his dependencies using the command
composer require darkaonline/l5-swagger:8.1 --with-all-dependencies
Edit : apply https://github.com/DarkaOnLine/L5-Swagger/issues/443#issuecomment-1034665847 and it's ok with 8.3
Same problem
Configuration :
'annotations' => [
base_path('app') . '/Http/Controllers/Api/V1',
base_path('app') . '/Http/Resources/Api/V1',
base_path('app') . '/Http/Requests/Api/V1',
],
and a php file for general documentation app/Http/Controllers/Api/V1/SwaggerInfos.php
**
* @OA\Info(
* version="1.0.0",
* title="API V1",
* x={
* "logo": {
* "url": L5_SWAGGER_CONST_LOGO,
* "backgroundColor": "#FFFFFF"
* }
* },
.....
I had similar problem. My installation: laravel 8, l5-swagger: 8.*. In the main controller, I put in the following:
/**
* @OA\OpenApi(
* @OA\Info(
* title="Returns Services API",
* version="1.0.0",
* description="API documentation for Returns Service App",
* @OA\Contact(
* email="sushil@stepfront.com"
* )
* ),
* @OA\Server(
* description="Returns App API",
* url="https://localhost/api/"
* ),
* @OA\PathItem(
* path="/"
* )
* )
*/
Following this example did the job for me.
As per the example, we need to wrap @OA\Info with @OA\OpenApi first.
@gagansday tnx.It works for me
Thanks @honorezemagho
I've fixed it by downgrading to version 8.1 with all his dependencies using the command
composer require darkaonline/l5-swagger:8.1 --with-all-dependencies
It works for me
Error:
Required @OA\Info() not found
Laravel version: 8.75 "darkaonline/l5-swagger": "8.1" [ with all dependencies ]
Just in case anyone finds this in the future and still is running into this issue, I found out I had opcache.save_comments=1
enabled in my PHP config and it was causing the annotations to not be found. After removing it and trying again, everything worked correctly.
@Messhias this is fine if you are not using with code files. But still requirement for swagger-php:4 is that you must associate annotation with either a class/trait/interface, method or property.
So in swagger-php:3 we had this: https://github.com/DarkaOnLine/L5-Swagger/blob/8.1.0/tests/storage/annotations/OpenApi/Anotations.php
But with swagger-php:4 - you must do like this: https://github.com/DarkaOnLine/L5-Swagger/tree/8.3.0/tests/storage/annotations/OpenApi
So if you do not want to redo your annotation you can fall back to swagger-php:3 by requesting it in your
composer.json
How can we downgrade version ?
If anyone is still having this issue, I'm using
L5-Swagger version 8.3 (latest)
With Laravel version 9.19 (latest)
And in your Controller, you need to put it outside your class
Hello guys!
I got same issue, but in my case in base Controller there was bunch of separated PHP DocBlocks, like:
/**
* @OA\Info(
* title="Gigco REST API",
* version="1.0.0",
*
* @OA\Contact(
* email="support@gigqo.com",
* name="Support Team"
* )
* )
*
* @OA\Tag(
* name="Admin",
* description="API Endpoints of Admin"
* )
* @OA\Tag(
* name="User",
* )
* @OA\Tag(
* name="IDO",
* )
* @OA\Tag(
* name="Golden Ticket",
* )
* @OA\Tag(
* name="City",
* )
*/
/**
* @OA\SecurityScheme(
* type="apiKey",
* name="X-API-KEY",
* in="header",
* securityScheme="apiAuth"
* )
*/
/**
* @OA\SecurityScheme(
* type="apiKey",
* name="X-API-KEY",
* in="header",
* securityScheme="adminAuth"
* )
*/
which was working fine in previous versions, but failed with Swagger ^8.5 (+Laravel 10.13.5)
When I merged all PHP DocBlocks into single one block the problem was solved. Seems like current version only check latest annotation and don't see @OA\Info there.
Hopefully it will help! Thank you for your attention! :-)
Hi there,
I am facing the same issue with laravel 9.19 and php8.1. I was facing the same issue after i have change the annotation path to my custom api directory.
Hello there,
I have put the @OA\Info
inside my base controller:
than it needs @OA\PathItem
as shown in below screenshot:
when i am adding some path item than it again requires @OA\Info
@DarkaOnLine can you please update this with example how to fix it?
Damn, 8.5 causes error of Class "Prettus\Repository\Eloquent\BaseRepository" not found
@Messhias this is fine if you are not using with code files. But still requirement for swagger-php:4 is that you must associate annotation with either a class/trait/interface, method or property.
So in swagger-php:3 we had this: https://github.com/DarkaOnLine/L5-Swagger/blob/8.1.0/tests/storage/annotations/OpenApi/Anotations.php
But with swagger-php:4 - you must do like this: https://github.com/DarkaOnLine/L5-Swagger/tree/8.3.0/tests/storage/annotations/OpenApi
So if you do not want to redo your annotation you can fall back to swagger-php:3 by requesting it in your
composer.json
How can we downgrade version ?
By downgrading the version, the issue was solved for me.
Just downgrading:
composer require zircote/swagger-php:4.7.15 --with-all-dependencies
I know this is an old topic, but the error was resolved for me by moving the @OA\Info documentation above the base Controller class definition (was inside it previously).
Description:
Github actions throw [Required @OA\Info() not found] Error while it works perfectly fine on local. @OA\Info() is set of course and used to work on the server as well but it's not the case anymore. Any ideas why?