*Context*: NelmioApiDocBundle does not require clients to have the symfony/validator package. However it requires it in its dev dependencies.
*Problem*: If client of library does not have symfony/validator and uses PHP8, NelmioApiDocBundle will assume that symfony/validator is installed, in `SymfonyConstraintAnnotationReader.php`
*Solution*: We should not assume that client has symfony/validator. So before reading attributes of this class, we now try to see if class exists.
- Tests still run.
- Tested in a project without symfony/validator and requiring this version, it now works.
The error before this fix was :
Exception: `ClassNotFound`
Message for me: `Attempted to load class "Constraint" from namespace "Symfony\Component\Validator".
Did you forget a "use" statement for e.g. "JsonSchema\Constraints\Constraint" or "Doctrine\DBAL\Schema\Constraint"?`
Previously it was possible to set only one of the min or max values and
get a schema like:
"property": {
"type": "integer",
"minimum": 1,
"maximum": 0
}
Also possible that `Range` would be used with {min,max}PropertyPath and
you'd get a schema with both minimum and max set to zero.
With the checks in place, that's no longer the case.
It's possible to set a count constraint with a min but no max, which
would generate an OpenAPI Schema like...
"property": {
"type": "array",
"minItems": 1,
"maxItems": 0
}
With this change the schema will only set `minItems` in that example.
* Apply `enum` from Choice Constraints to Items When Choice is Multiple
Otherwise JSON schema like this is generated:
```
"property": {
"type": "array",
"enum": ["one", "two", "three"],
"items": {
"type": "string"
}
}
```
With this change, however, this schema is generated:
```
"property": {
"type": "array",
"items": {
"type": "string",
"enum": ["one", "two", "three"]
}
}
```
A possible downside here is that the symfony constraint stuff happens
before types are figured out from PHPDoc. So it's _possible_ to end up
with something that won't validated. Take something like this:
```
/**
* @Assert\Choice(multiple=true, choices={"..."})
* @var string
*/
```
This would generate:
```
"property": {
"type": "string",
"items": {
"enum": ["..."]
}
}
```
* Fix CS
* cs
* more cs
* fix tests
Co-authored-by: Guilhem Niot <guilhem@gniot.fr>
Sometimes folks will set a `min` length without a max, for instance and
the generated open api schema would previously have been nonsense:
```
"property": {
"type":"string",
"maxLength":0,
"minLength":1
}
```
* remove pattern added from the Expression Violation message.
This string confuses the API client showing a violation message instead of having a Regex. Any informatory message for the client should be placed in "description"
* fix tests
* fix typo
* Initial pass for OA3 upgrade
* Fix Util Tests
* Fix first batch of Unit Tests. Up to Model
* Another batch of fixed tests
* Update annotations
* Convert Model & Property Describers
* Update tests, Fix RouteDescribers, FIx additional bugs
* Another batch of updates
* Another batch of fixed Functional Tests
* Fix FunctionalTest tests
* Fix Bazinga Tests
* FIx FOS Rest
* Fix JMS TEsts & describers
* Fix all Tests
* Fix few stuff from own CR
* CS Fixes
* CS Fixes 2
* CS Fixes 3
* CS Fixes 4
* Remove collection bug
* Updates after first CRs
* CS
* Drop support for SF3
* Update the docs
* Add an upgrade guide
* misc doc fixes
* Configurable media types
* Code Style Fixes
* Don't use ::$ref for @Response and @RequestBody
* Fix upgrading guide
* Fix OA case
Co-authored-by: Filip Benčo <filip.benco@websupport.sk>
Co-authored-by: Guilhem Niot <guilhem.niot@gmail.com>
Co-authored-by: Mantis Development <mantis@users.noreply.github.com>
- Add minimum and maximum from the range annotation
- Add maximum from the LessThan and LessThanOrEqual annotation
FIX: remove the extra date-time format, which was not standard and not in sync with what symfony exposes
Swagger specifies that date-time should follow the RFC3339, and this is what symfony does as default.
* fix(SymfonyConstraintAnnotationReader): fixed enum guessing in Assert\Choicewhen callback parameter is used
* fix(SymfonyConstraints): turn double quotes in single quotes