Swagger-php: Property required failing validation

Created on 24 Dec 2018  路  2Comments  路  Source: zircote/swagger-php

I know I am doing something wrong here. I'm sure it's a problem with my code, but ofr the life of me I cannot find it.

My Code:

 @OA\Property(property="username", type="string", required=true)

This fails the validation and returns me a:

@OA\Property()->required is a "boolean", expecting a "[string]" in src/Api/Portal/V1/Authentication/Routes.php on line 23

I dug into the source and found where it is defined:

src/Annotations/Schema.php:333

/**
     * @inheritdoc
     */
    public static $_types = [
        'description' => 'string',
        'required' => '[string]',
        'format' => 'string',
        'collectionFormat' => ['csv', 'ssv', 'tsv', 'pipes', 'multi'],
        'maximum' => 'number',
        'exclusiveMaximum' => 'boolean',
        'minimum' => 'number',
        'exclusiveMinimum' => 'boolean',
        'maxLength' => 'integer',
        'minLength' => 'integer',
        'pattern' => 'string',
        'maxItems' => 'integer',
        'minItems' => 'integer',
        'uniqueItems' => 'boolean',
        'multipleOf' => 'integer',
        'allOf' => '[' . Schema::class . ']',
        'oneOf' => '[' . Schema::class . ']',
        'anyOf' => '[' . Schema::class . ']'
    ];

Maybe it is because I do not fully understand the spec. The docs show :

parameters:
        - name: userId
          in: path
          required: true

I am trying to set that this parameter is required.

Any thoughts as to what I am doing wrong?

Cheers! :)
=C=

Most helpful comment

I had a same issue. The solution is define "require" as array with required properties.

@OA\Schema( required={"username"}, @OA\Property( property="username", type="string") )

All 2 comments

I had a same issue. The solution is define "require" as array with required properties.

@OA\Schema( required={"username"}, @OA\Property( property="username", type="string") )

Thank you. That fixed the problem. :)

Cheers!
=C=

Was this page helpful?
0 / 5 - 0 ratings