How specify parameter's format in Nelmio ApiDocBundle
Format column is designed only for datetime
, date
and choice
types.
For datetime
and date
it represents the date format like Y-m-d H:i:s
and the array of choices for choice
.
I haven't found any documentation about it, so I had to look through the source code. This is FormTypeParser class, the place where FormType
is actually parsed and and you can see how format field is set.
In FormTypeParserTest class you can see how to use it. Just pass the string parameter with format
name for one of the available types and the parser will handle it.
UPDATE: You are to define your constrains inside your FormType
class.
For example:
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'; }}
will be parsed into:
ValidationParser
in doParse() method finds all constrains defined in your FormType
class and then executes parseConstraint()
method for each of them.
You can also use FormTypeParser
as I described above. For example:
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');}
will be parsed as:
Hope it helps now!
As you can see here you can specify filter in annotation like it done documentation example.
Here part of this example:
/** * 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(){}