That issue occurs only on server side.
local.ERROR: ErrorException: Multiple @OA\Response() with the same response="200":
\App\Http\Controllers\Student\EventsController->update() in /var/www/html/app/Http/Controllers/Student/EventsController.php on line 136
\App\Http\Controllers\Student\EventsController->store() in /var/www/html/app/Http/Controllers/Student/EventsController.php on line 51 in /var/www/html/vendor/zircote/swagger-php/src/Logger.php:39
I tried api-docs generated on local in https://editor.swagger.io and that works very well. How that can be resolved?
Instead have one response="200" and use oneOf to provide information about the different possible payloads.
Can you provide an example that does work in SwaggerUI? Because neither JSON nor YAML allow for duplicate keys in an object/mapping.
Why does it work on local environment and don't on server side ?
Example with double - 200 responses - which work on local environment and swagger editor -https://github.com/DorelBesliu/swagger-example/blob/master/example.yaml
I know its a basic question, but are PHP and library versions the same for local and server?
Also I'd be curious if the local setup generates YAML with multiple 200 response entities for the endpoint or just one?
I think that the problem might be that you try to declare the @OA\Response outside of a @OA\Get/Post/etc context, and then it tries to add both at the same place but can't because of the collision of having the same response code.
Please provide a full example of your PHPDOC, because I think that is where your problem lies.
See https://github.com/zircote/swagger-php/blob/master/Examples/petstore-3.0/controllers/Pet.php#L66 as an example on how to declare a path and response in PHPDOC.
I think I know there is the problem. Firstly, I had this problem https://github.com/DarkaOnLine/L5-Swagger/issues/191 and I resolved it by put in the start of documentation:
@OA\Get(
path="/",
description="Home page",
@OA\Response(response="default", description="Welcome page")
)
And I think that generates the problem with two 200 responses. Why I have to put @OA\PathItem() as a starting point - if I don't need it ? Or I just forgot to put @OA\PathItem() somewhere? How can I set up my local environment to have the same errors?
It feels like you maybe do not entirely grasp how OpenAPI and by extension the PHPDOC for SwaggerPHP work.
Maybe it would be good to read up on the documentation at https://zircote.github.io/swagger-php/Getting-started.html and to have a look at the many examples at https://github.com/zircote/swagger-php/tree/master/Examples/petstore-3.0 to give you a basis on how to properly document the code.
Usually you start with a @OA\Info() block in some common entrypoint code (bootstrap, index, kernel, etc...), have a @OA\Get/Post/Put/Patch/etc... at each 'controller', and a @OA\Schema() at each 'model'.
@OA\PathItem() - From https://swagger.io/specification/ - A relative path to an individual endpoint. The field name MUST begin with a forward slash (/).
`
[2020-07-09 09:08:17] local.ERROR: Required @OA\PathItem() not found {"exception":"[object] (ErrorException(code: 0): Required @OA\PathItem() not found at /var/www/html/vendor/zircote/swagger-php/src/Logger.php:39)
[stacktrace]
"}
`
What does it mean - I forgot to put somewhere or I need to put it in a base controller as the main path?
Have you tried using @OA\Get/Put/Post/Patch instead? Normally you would start with an operation, not a path item object.
Is it possible to give maybe a more clear example of your code? Best would be a self contained codebase that shows the problem we can actually execute. Because the error messages you give unfortunately give very little to hunt down the actual source of your problem with.
I don't know if this pertains to the op's problem, but I had the same sort of error in production vs local dev, and in case someone else ends up here like I did, here was my mistake. I inadvertently had some of the @OA\Get/Put/Post items as @OA\GET/PUT/POST. Presumably this worked on my case-insensitive MacBook, but not on the Linux production server.
I don't know if this pertains to the op's problem, but I had the same sort of error in production vs local dev, and in case someone else ends up here like I did, here was my mistake. I inadvertently had some of the
@OA\Get/Put/Postitems as@OA\GET/PUT/POST. Presumably this worked on my case-insensitive MacBook, but not on the Linux production server.
@sublime392 Thank you. The same issue was on my side
I don't know if this pertains to the op's problem, but I had the same sort of error in production vs local dev, and in case someone else ends up here like I did, here was my mistake. I inadvertently had some of the
@OA\Get/Put/Postitems as@OA\GET/PUT/POST. Presumably, this worked on my case-insensitive MacBook, but not on the Linux production server.
The casing of @OA\Get, @OA\Post, @OA\Put etc. is really important, don't mistake it for their capitalized counterparts e.g @OA\GET, @OA\POST, @OA\PUT etc.
I have same problem.
The @OA annotation is case sensitivity,linux also case sensitivity,but windows case insensitivity,so must ensure capitalized is right.
This is not so much a Swagger-PHP thing but a PHP/composer autoload thing. Class names are case sensitive because it tries to load the file with the same name and thus casing on case-sensitive OS's (read: filesystems). These (doctrine) annotations are in the end just classes that are loaded so casing matters.
@DorelBesliu
Did you find solution yet, cause i am having same problem?
Most helpful comment
I don't know if this pertains to the op's problem, but I had the same sort of error in production vs local dev, and in case someone else ends up here like I did, here was my mistake. I inadvertently had some of the
@OA\Get/Put/Postitems as@OA\GET/PUT/POST. Presumably this worked on my case-insensitive MacBook, but not on the Linux production server.