John Davidson

l5-swagger/swagger-php - adding component to block makes it dissapear from the output

0 comments
Message:


If I add this response to my definition:


@OA\Response(
response="default",
description="unexpected error",
@OA\JsonContent(ref="#/components/schemas/ErrorModel"),
@OA\XmlContent(ref="#/components/schemas/ErrorModel"),
@OA\MediaType(
mediaType="text/xml",
@OA\Schema(ref="#/components/schemas/ErrorModel")
),
@OA\MediaType(
mediaType="text/html",
@OA\Schema(ref="#/components/schemas/ErrorModel")
)
)

And then I place the Schema underneath like so:


/**
* @OA\Schema(
* schema="ErrorModel",
* required={"code", "message"},
* @OA\Property(
* property="code",
* type="integer",
* format="int32"
* ),
* @OA\Property(
* property="message",
* type="string"
* )
* )
*/

The command: php artisan l5-swagger:generate does not error but the block that contains the Response Definition with the component no longer gets included in the json but the schema for the component does?


Did I do something really obvious that is wrong as my experience with the library so far is if you do something wrong it generally tells you.



My Answer:
"200",
description="Successful operation",
@OA\JsonContent(
@OA\Property(property="id", type="integer", format="int64"),
@OA\Property(property="name", type="string")
)
)

_It will not appear in the output. To fix this issue, you need to add the response to the `responses` block instead of directly to the definition. Here's how you can do it:_@OA\Schema(
schema="User",
@OA\Property(property="id", type="integer", format="int64"),
@OA\Property(property="name", type="string")
)

@OA\Response(
response="200",
description="Successful operation",
@OA\JsonContent(
@OA\Property(property="id", type="integer", format="int64"),
@OA\Property(property="name", type="string")
)
)

_This way, the response will be included in the output and will be properly displayed in the Swagger documentation._

Rate this post

3 of 5 based on 6723 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us