Search code examples
phpjsonannotationsswagger-2.0swagger-php

Escape character for sqare brackets in php swagger annotation json property


I write API in Php Laravel and use swagger (2.0) annotations (lib: darkaonline/l5-swagger which use swagger-php) to generate swagger.json, however I have following problem - when I type:

/**
 *
 * Space Schema
 *
 * @SWG\Get(
 *     path="/api/v1/client/space/schema",
 *     @SWG\Response( 
 *        response=200, 
 *        description="OK",
 *        @SWG\Property(property="result", type="json", example={ "aa": [ "bb", "cc" ] }  )
 *      )
 * )

And try to gen swagger.json I get:

[Syntax Error] Expected PlainValue, got '[' in ...

But when I not use square brackets like for example:

@SWG\Property(property="result", type="json", example={ "ee": "ff" })

Then everything is fine. However I need to use square brackets so the question is:

What is escape character for [ (square bracket) in json string in swagger annotations?

I also wanna add that my example json is quite big and complicated


Solution

  • I accidentally found better solution:

    Change square brackets ([ and ]) in:

    @SWG\Property(property="result", type="json", example={ "aa": [ "bb", "cc" ] }  )
    

    to braces ({ and }):

    @SWG\Property(property="result", type="json", example={ "aa": { "bb", "cc" } }  )
    

    As you can see, we use braces, however we not use key:value conwention (only keys) so swagger is able to detect array.

    enter image description here

    And we have nice and easy formatted json in swagger-ui :)