Swagger-php: Support for example values

Created on 8 May 2018  路  4Comments  路  Source: zircote/swagger-php

As far as I have seen there is no support for example values described here.

Most helpful comment

I also has same problem. My code is:

/**
     * @OA\Parameter(
     *    name="Authorization",
     *    in="header",
     *    description="API Token. Format: `Bearer <api_token>`",
     *    required=true,
     *    @OA\Schema(
     *      type="string",
     *    ),
     *    example="Bearer VrHtRxsRxVlHkW4FCCm5bNfmzhtswQl7slGLcptjYG8VCxvCX1Z4SiNsve...."
     * )
     *

But my example is not showed in document

All 4 comments

@justicenode https://github.com/zircote/swagger-php/blob/3.x/src/Annotations/Parameter.php#L126
Supported.
Or tell more about your problem.

I get the following error message when I use the latest version installed from composer.

[INFO] Unexpected field "example" for @SWG\Parameter(name="password",in="formData"), expecting "ref", "parameter", "name", "in", "description", "required", "schema", "type", "format", "allowEmptyValue", "items", "collectionFormat", "default", "maximum", "exclusiveMaximum", "minimum", "exclusiveMinimum", "maxLength", "minLength", "pattern", "maxItems", "minItems", "uniqueItems", "enum", "multipleOf", "x" in \Auth->login() in ../api\Controllers\Auth.php on line 18

my code looks like the following

    /**
     * @SWG\Post(
     *     path="/auth/login",
     *     produces={"application/json"},
     *     tags={"auth"},
     *     @SWG\Parameter(
     *         name="username",
     *         in="formData",
     *         description="username of the user. I don't think there is a need for a description here but I put it here anyway",
     *         required=true,
     *         type="string",
     *         example="john.doe",
     *     ),
     *     @SWG\Parameter(
     *         name="password",
     *         in="formData",
     *         description="password of the user",
     *         required=true,
     *         type="string",
     *         example="a safe password",
     *     ),
     *     @SWG\Response(
     *         response="200",
     *         description="Correct parameters"
     *     ),
     *     @SWG\Response(
     *         response="400",
     *         description="Invalid or missing Parameters"
     *     )
     * )
     */

Do I maybe need to download the latest version manually or is just my code wrong?

You have a trailing comma in both of your example lines. swagger-php does not like that at all.

I run into the same problem all the time.

I also has same problem. My code is:

/**
     * @OA\Parameter(
     *    name="Authorization",
     *    in="header",
     *    description="API Token. Format: `Bearer <api_token>`",
     *    required=true,
     *    @OA\Schema(
     *      type="string",
     *    ),
     *    example="Bearer VrHtRxsRxVlHkW4FCCm5bNfmzhtswQl7slGLcptjYG8VCxvCX1Z4SiNsve...."
     * )
     *

But my example is not showed in document

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DerManoMann picture DerManoMann  路  3Comments

beeradmoore picture beeradmoore  路  5Comments

aqlx86 picture aqlx86  路  3Comments

birendragurung picture birendragurung  路  3Comments

xiehan picture xiehan  路  5Comments