Swagger-php: Array example

Created on 14 Aug 2020  路  6Comments  路  Source: zircote/swagger-php

Hi

@OA\Property(
    property="locations",
    type="array",
    example=["Germany", "France"],
    @OA\Items(
        type="string"
    )
)

Hi, this code sample returns an error when swagger docs say that it should be possible https://swagger.io/docs/specification/adding-examples/

Is there any way to provide an array as example for array data type?

Most helpful comment

In OpenAPI 3 you have example which is a totally freeform key you can put anything into, but you also have examples which has a slightly more strict format (for parameters for instance).

http://spec.openapis.org/oas/v3.0.3#fixed-fields-9

All 6 comments

the [] notation is wrong, it should use {} in PHPDOC.

Works, thanks

How do you handle example with multiple values ?

That works to me

@OA\Property(
    property="locations",
    type="array",
    example={"Germany", "France"},
    @OA\Items(
        type="string"
    )
)

ok ... and what about more example with multiple values ? :smiley: #inception

In OpenAPI 3 you have example which is a totally freeform key you can put anything into, but you also have examples which has a slightly more strict format (for parameters for instance).

http://spec.openapis.org/oas/v3.0.3#fixed-fields-9

Was this page helpful?
0 / 5 - 0 ratings