NelmioApiDocBundle icon indicating copy to clipboard operation
NelmioApiDocBundle copied to clipboard

Improve resolving symfony asserts

Open kirya-dev opened this issue 3 years ago • 4 comments

Resolving types by Type assert

kirya-dev avatar Jun 22 '21 09:06 kirya-dev

I'm not sure that's really safe, @Type can contain a lot of different values (see https://symfony.com/doc/current/reference/constraints/Type.html) and few are compatible with open api.

What about having an allow list to make sure we don't allow incompatible values?

GuilhemN avatar Jul 09 '21 17:07 GuilhemN

What about having an allow list to make sure we don't allow incompatible values?

Whats are your mean?

class Dto
{
/**
 * @type int|string
 * @Assert\Type(["float", "string"])
 */
 private $value;
}

kirya-dev avatar Jul 14 '21 08:07 kirya-dev

I mean the value wrapped by @Assert\Type is not necessarily a valid value for OpenApi so we must be cautious.

For instance, ["float", "string"] is an accepted value for @Assert\Type but it's not for OpenApi which only accepts a string. In case of an array the best we could do in OpenApi would probably just be to use mixed. And @Assert\Type can also contain class types which cannot be used directly in the OpenApi type field.

GuilhemN avatar Aug 03 '21 08:08 GuilhemN

We can use oneOf field? Im hasnt time to develop this. It have hard logic for me.

kirya-dev avatar Aug 03 '21 08:08 kirya-dev

Closing this because of inactivity :)

DjordyKoert avatar Mar 06 '24 18:03 DjordyKoert