swagger-php icon indicating copy to clipboard operation
swagger-php copied to clipboard

How to escape the " (double quotes) character on Parameter Description

Open praditha opened this issue 9 years ago • 3 comments

Hi all, I have a question about writing description on swagger-php. For example I have the following parameter description:

* ...
* @SWG\Parameter(
*          name="products",
*          in="formData",
*          type="string",
*          description="set of json from products eg:<br>'{ '0' : { 'id' : '1', 'sku' : 'SKU00614803', 'name' : 'Oncom Gondrong', 'image' : 'oncom.jpg', 'price' : '100000' }, '1' : { 'id' : '2', 'sku' : 'SKU00614804', 'name' : 'Tempe Bacem', 'image' : 'tempe.jpg', 'price' : '150000' }}'",
*          required=true
*      ),
* ...

I want to write the JSON sample to one of the parameter. Actually if I wrote the sample like above, the swagger can be generated successfully, but that is the wrong JSON format. JSON should be use " (double quotes) character instead of ' (single quote). But if I replace all the ' to ", I cannot generate the swagger. I says an error:

[Syntax Error] Expected Doctrine\Common\Annotations\DocLexer::T_CLOSE_PARENTHESIS, got 'id' in...

Anybody know how to solve my problem,.?

thanks

praditha avatar Jan 30 '17 06:01 praditha

Use " to escape a "

<br>'{ ""id"" : 0,

bfanger avatar Jan 30 '17 07:01 bfanger

how do you get rid of the backslash it adds to the example? example="{""code"":""3088"",""quantity"":""2""},{""code"":""3089"",""quantity"":""1""}",

ends up as

"items": "{"code":"3088","quantity":"2"},{"code":"3089","quantity":"1"}"

wraycode avatar Aug 22 '17 19:08 wraycode

I am running into the same issue.

Due to this the swagger ui generates the request like: { "query": { "params": "{ \"ci_id\": 12 }" } }

#327

rwese avatar Mar 26 '19 08:03 rwese