简体   繁体   English

如何使用NelmioApiDocBundle在POST请求中包含查询参数?

[英]How do I include a query parameter in a POST request using NelmioApiDocBundle?

I'm using (and new to) Symfony 3 and NelmioApiDocbundle. 我正在使用Symfony 3和NelmioApiDocbundle(并且是其中的新功能)。 I want to handle a POST request that has optional query parameters. 我想处理具有可选查询参数的POST请求。 The url would be something like: http://example.com/api/updateusers?token=some_long_value 该网址将类似于: http : //example.com/api/updateusers?token=some_long_value

This is what I've tried for my annotations: 这是我为注释尝试的内容:

/**
 * Returns a JSON object.
 *
 * @ApiDoc(
 *  resource=true,
 *  description="Update a user's information.",
 *  requirements={
 *      {
 *          "name"="userid",
 *          "dataType"="string",
 *          "requirement"=".+",
 *          "description"="the user to update"
 *      }
 *  },
 *  parameters={
 *    {"name"="data", "dataType"="text area", "required"=true, "description"="Free form xml data."}
 *  },
 *  filters={
 *    {"name"="token", "dataType"="string", "required"=true, "description"="auth token for current user - user that you're making the request on behalf of."},
 *  },
 * )
 * @Route("api/updateusers")
 * @Method("POST")
 */

Requirements, parameters, and filters are all showing up in the POST body in the API sandbox. 需求,参数和过滤器都显示在API沙箱的POST正文中。 Is there another definition type that I can use that will show a query parameter in the API sandbox? 我可以使用其他定义类型在API沙箱中显示查询参数吗? If I bypass the sandbox and send the request directly to the server, the token shows up properly as a GET value. 如果我绕过沙箱并将请求直接发送到服务器,则令牌将正确显示为GET值。 But I'd like to be able to use the API sandbox for testing and documentation. 但是我希望能够使用API​​沙箱进行测试和记录文档。

尝试将其添加到注释中,希望对您有所帮助。

@QueryParam(name="<your_name>", nullable=[true|false], requirements="\d+", description="<your_decription>")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM