5

I want to specify a default json value in swagger docs for POST. I am getting T_CLOSE_PARENTHESIS error. I have also tried escaping the ".

/**
     * @SWG\Api(path="/api/users",
     *   @SWG\Operation(
     *     method="POST",
     *     summary="Register a user",
     *     notes="Send a POST request along with required form parameters to add a new user",
     *     type="string",
     *     nickname="post-users",
     *     authorizations={},
     *     @SWG\Parameter(
     *       name="email",
     *       description="The email",
     *       required=true,
     *       type="json",
     *       paramType="body",
     *       allowMultiple=false,
     *       defaultValue = "{
  "email":"pradeep****@gmail.com",
  "first_name":"Pradeep",
  "last_name":"Kumar",
  "group":"subscriber",
  "password":"password"
}",
     *     ),
     *     
     *     @SWG\ResponseMessage(code=200,message="Success"),
     *     @SWG\ResponseMessage(code=400,message="Bad Request")
     *   )
     * )
     */
1
  • 5
    Sweet mother of god. Commented Mar 25, 2015 at 16:37

2 Answers 2

12

To escape a " in a doctrine/annotation use ""

defaultValue="{""email"":""p****@gmail.com"",""first_name"":""Pradeep""}" 
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect, just the answer I was looking for, this should be the accepted answer!
1

I'm guessing you should convert the defaultValue into a single line, and escape the quotes with a forward slash.

3 Comments

Fehguy, I have tried it and also mentioned in my question.
I have done this - defaultValue = "{\"email\":\"pradeep****@gmail.com\",\"first_name\":\"Pradeep\",\"last_name\":\"Kumar\",\"group\":\"subscriber\",\"password\":\"password\"}"
Hi, I think you'll need to open an issue in the swagger-php repository: github.com/zircote/swagger-php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.