* Add support for php attributes
* Fix tests for php 8.1
* Simplify the annotations
* Revert the changes to the tests
* CS
* Test FOSRest parsing of attributes
* CS
* typo
* CS
* Test fetchArticle php 8.1 attributes
* Fix namespaces
Co-authored-by: Guilhem Niot <guilhem@gniot.fr>
*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"?`
*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