1

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.

2 Answers 2

3

If this is a new projects changes are that you are now using swagger-php V4. In version 4 the analyser code uses reflection. This was done to make it possible to use either annotations or PHP 8 attributes.

One downside is that stand-alone docblocks are no longer detected as there is no reflection to access those.

In your case I think having two separate blocks of /** */ will mean only the last one is found.

One way around is to have all annotations preceding a class in a single /** */ block. Another option is to have (unused) dummy classes for cases like this.

Here, adding class ErrorModel {} fater your schema should work too, assuming there is a separate resonse class for the first annotation.

The same applies to other top level annotations like @OA\Info or others.

Sign up to request clarification or add additional context in comments.

1 Comment

@DemManoMann - thank you simply moving them into the same /** */ block fixed the problem of the entire block going missing.
1

The annotations cannot be separate, should be in the same block

example:

change this:

/** 
 * @OA\Info( 
 *      version="1.0.0", 
 *      title="Service",
 *      description="Service",
 *      @OA\Contact(
 *          email="[email protected]"
 *      ),
 *     @OA\License(
 *         name="Name"
 *     ),
 * ),
 */

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

for this:

/**
 * @OA\Info(
 *      version="1.0.0",
 *      title="Service",
 *      description="Service",
 *      @OA\Contact(
 *          email="[email protected]"
 *      ),
 *     @OA\License(
 *         name="Name"
 *     ),
 * ),
 *
 * @OA\Schema(
 *     schema="ErrorModel",
 *     required={"code", "message"},
 *     @OA\Property(
 *         property="code",
 *         type="integer",
 *         format="int32"
 *     ),
 *     @OA\Property(
 *         property="message",
 *         type="string"
 *     )
 * )
 */

1 Comment

This fixed my issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.