Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read @Assert annotations to determine required fields #125

Closed
duanegran opened this issue Jan 3, 2013 · 13 comments
Closed

Read @Assert annotations to determine required fields #125

duanegran opened this issue Jan 3, 2013 · 13 comments

Comments

@duanegran
Copy link

Suppose you use an entity for your input class, it would be nice if the "required" flag on the documentation would read from the @Orm annotation. For example, I have a property like the following:

    /**
     * @var string $recordType
     *
     * @ORM\Column(name="record_type", type="integer", nullable=false)
     * @JMS\Type("integer");
     * @JMS\SerializedName("record_type");
     * @Assert\NotBlank()
     * @Assert\Choice(choices = {"distributions", "diversifications", "dividends", "oia_dividends", "restricted_stock"}, message = "Choose a valid record type")
     */
    private $recordType;

It would be really nice if the "nullable" attribute was read. I could also see the "Assert\NotBlank()" doing this. If we had a way to utilize the "Assert\Choice" list that would be especially nice.

I didn't see a way to set the description for input parameters using an entity with JMS.

@willdurand
Copy link
Collaborator

Saying that the column is nullable in the database doesn't mean your API expects a value.

You should use a Form to manage your incoming data. What should be done is a Parser for the validation layer (your Assert annotations), but not for the ORM part.

@duanegran
Copy link
Author

Good point. I had not thought of it that way. I've revised the title of this issue to reflect that Assert should be parsed. I presume this would be an enhancement. I'm happy to help on this. Any pointers where I would start to put something like this together?

@fieg
Copy link

fieg commented Feb 26, 2013

+1 for reading @Assert annonation

@drgomesp
Copy link
Contributor

I agree with @willdurand .

@pkruithof
Copy link

👍

1 similar comment
@kallosz
Copy link

kallosz commented Mar 18, 2013

+1

@willdurand
Copy link
Collaborator

It's marked as "Easy Pick", dear upvoters, who wants to work on this?

@maxpowel
Copy link

For output data would be useful.

I have the following attribute:
/**
* Application valoration from 0 to 5
* @Assert\Max(limit = 5)
* @Assert\Min(limit = 0)
* @jms\Type("double")
*/
private $valoration;

At the moment I am writing the max and min in the description, but would be great if this information could be fetched from Assert

@willdurand
Copy link
Collaborator

anyone willing to write a PR?

@magnetik
Copy link
Collaborator

magnetik commented Feb 2, 2015

Looks like it's working now ?

@catchamonkey
Copy link

Confirmed, We use @Assert at entity level, and the docs are pulling that through.

The only problem I can see is that it doesn't support validation groups.

@sromano88
Copy link

The Nelmio\ApiDocBundle\Parser\ValidationParser is taking care of the @Assert annotations, but does not consider the groups defined in it.

The problem of not supporting validation groups is that validations that are only part of a specific group, are handled as if they are in the Default group. Excluding them would be a better (not final) solution.

The Nelmio\ApiDocBundle\Parser\JmsMetadataParser consider the @jms\Serializer\Annotation\JMS\Groups annotation.
The Nelmio\ApiDocBundle\Parser\ValidationParser does not consider Symfony asserts groups (@symfony\Component\Validator\Constraints\Assert) nor JMS groups (@jms\Serializer\Annotation\JMS\Groups).

Does anyone knows how to solve it?

@dbu
Copy link
Collaborator

dbu commented Dec 22, 2017

version 3 is a complete rewrite. please check if this is still a problem with version 3 and a recent symfony version.

@dbu dbu closed this as completed Dec 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests