我使用@ApiDoc注释的@ApiDoc属性来指定属于表单字段的api参数。
* @ApiDoc(
* section="User",
* resource=true,
* input={
* "class"="Nik\UserBundle\Form\UserType",
* },
* ....表单的data_class是一个对属性具有约束验证的实体。
我希望nelmio文档指定参数格式作为实体的验证约束,但是格式是空的。

如何在nelmio ApiDocBundle中指定参数格式?
编辑:也许我写了一个糟糕的问题。
我们可以为input和output指定解析器,如果没有为这些解析器指定解析器,则调用input和output的所有解析器,然后调用UserType的所有解析器。
nelmio有一个名为ValidationParser的解析器,它有一个名为parseConstraint的方法,该方法将format设置为输入和输出,但是这个方法不是为我的文档调用的,为什么?
发布于 2016-02-24 12:38:52
我提交一个对format属性使用验证元数据的拉请求。
你可以看到这个PR 这里
发布于 2015-10-27 09:32:54
格式列仅为datetime、date和choice类型设计。
对于datetime和date,它表示日期格式(如Y-m-d H:i:s )和用于choice的选项数组。
我还没有找到任何关于它的文档,所以我不得不查看源代码。这是FormTypeParser类,实际上是解析FormType的地方,您可以看到格式化字段是如何设置的。
在FormTypeParserTest类中,您可以看到如何使用它。只需为其中一个可用类型传递具有format名称的字符串参数,解析器就会处理它。
更新:要在FormType类中定义约束的。
例如:
class TestType extends AbstractType
{
/**
* @Assert\Type("string")
* @Assert\Length(min="10", max="255")
* @Assert\Regex("/^[^<>]+$/i")
*/
private $title;
/**
* @Assert\Type("string")
* @Assert\Length(min="10", max="255")
* @Assert\Regex("/^[^<>]+$/i")
*/
private $content;
/**
* @Assert\Date()
*/
private $created;
public function getName()
{
return 'test';
}
}将被分析为:

ValidationParser在doParse()方法中查找在FormType类中定义的所有约束,然后对每个约束执行parseConstraint()方法。
您还可以像我前面所描述的那样使用FormTypeParser。例如:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('created', 'date', array('label' => 'Created', 'format' => 'yyyy-MM-dd'))
->add('color', 'choice', array('label' => 'Color', 'choices' => array('grey' => '#CCCCCC', 'red' => '#FF0000')))
->add('save', 'submit');
}将被解析为:

希望它能帮上忙!
发布于 2015-10-26 09:50:25
如您所见,这里可以在注释中指定过滤器,就像它所做的文档示例一样。
这里是这个例子的一部分:
/**
* This is the documentation description of your method, it will appear
* on a specific pane. It will read all the text until the first
* annotation.
*
* @ApiDoc(
* resource=true,
* description="This is a description of your API method",
* filters={
* {"name"="a-filter", "dataType"="integer"},
* {"name"="another-filter", "dataType"="string", "pattern"="(foo|bar) ASC|DESC"}
* }
* )
*/
public function getAction()
{
}https://stackoverflow.com/questions/33222064
复制相似问题