Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple @OA\Response() with the same response="200": #350

Closed
buildsomethingdifferent opened this issue Dec 16, 2020 · 14 comments
Closed

Multiple @OA\Response() with the same response="200": #350

buildsomethingdifferent opened this issue Dec 16, 2020 · 14 comments

Comments

@buildsomethingdifferent
Copy link

buildsomethingdifferent commented Dec 16, 2020

Description: I'm facing this issue when generating docs. On my local this is working fine but I get an exception on server.

Steps To Reproduce:

php artisan l5-swagger:generate

image


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@buildsomethingdifferent
Copy link
Author

@bfanger any solution to this ?

@DarkaOnLine
Copy link
Owner

From the screenshot, I see that this is an issue in swagger-php, at least error log comes from this part of code

@bfanger
Copy link

bfanger commented Dec 16, 2020

You can only have one response="200" as that is used as key in the generated json

"responses":{
  "200": {
      // ...
  }
}

The schema inside the 200 response can contain multiple schema's using oneOf

@buildsomethingdifferent
Copy link
Author

@bfanger I have only one response of 200 and this is format for all of my methods inside controller but it's working on local and giving error on server.
/**
* @OA\GET(
* path="/api/company",
* operationId="getCompaniesList",
* tags={"Company"},
*security={
*{
*"passport": {}},
*},
* summary="Get list of Companies",
* description="Returns list of Companies",
* @OA\Response(
* response=200,
* description="Successful operation",
* @OA\MediaType(
* mediaType="application/json",
* )
* ),
* @OA\Response(
* response=401,
* description="Unauthenticated",
* @OA\JsonContent(
* @OA\Property(property="message", type="string", example="Not authorized"),
* )
* ),
* @OA\Response(
* response=403,
* description="Forbidden"
* ),
* )
*/
public function index (){
}

@bfanger
Copy link

bfanger commented Dec 16, 2020

swagger-php detects 2 one for index() line 12 (posted above) and one for show() line 123.
I'm not sure why or who merges the @OA\Responses into a single operation.

Extra weird that it only happens on the server, not locally. (version differences?)

@Messhias
Copy link

This is only happens on server and it's breaking the others api endpoints... This is doesn't make any sense, why my api's cannot have multiples 200 responses?

@bfanger
Copy link

bfanger commented Jan 23, 2021

@Messhias Because of the openapi json structure.

      "responses": {
          "200": {
            "description": "Doing stuff",
            "content": {
              "application/json": {
                "schema": 

You can't add another "200" key, therefore you can't have multiple 200 responses.
Your api can have different 200 responses and you can still document them with the openapi spec, but you need to create a schema that points to multiple schema's with oneOf

swagger/openapi only creates (interactive) documentation, so I can't "break" any endpoints, at worst the implementation doesn't match the generated documentation.

@kanokHossain
Copy link

is anybody got solution cause i am having same problem

@nythzville
Copy link

All caps gives you headache, use @OA\Get instead of @OA\GET. You may visit this issue for solution reference.
zircote/swagger-php#888

@DePalmo
Copy link

DePalmo commented Jul 30, 2021

This resolves the issue, thank you @nythzville !

@Messhias
Copy link

This resolves the issue, thank you @nythzville !

You can merge this?

@DarkaOnLine
Copy link
Owner

Closing due to no activity for a very long time

@lucenarenato
Copy link

All caps gives you headache, use @OA\Get instead of @OA\GET. You may visit this issue for solution reference. zircote/swagger-php#888

Top... It helped me a lot. It cost!

@khasanshadiyarov
Copy link

If you are using any route definition in attributions/annotations, then you might be missing path definition, which causes OA\Response to point to the same request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants