49 Commits

Author SHA1 Message Date
Grzegorz Kielar
121738f709 Adding support for Symofny Assert\Sequentially 2022-08-03 12:31:21 +02:00
Christopher Davis
235963df41
Merge pull request #1902 from chrisguitarguy/constraint_groups
Respect Constraint Validation Groups When Describing Models
2022-06-10 16:15:42 -05:00
Guilhem Niot
be8499ffdc
Merge pull request #1988 from nelmio/ROOTCONTEXT
Use the same root context everywhere
2022-06-10 20:52:06 +02:00
Christopher Davis
6b2ef45b24 Merge remote-tracking branch 'origin/master' into constraint_groups 2022-05-11 08:18:52 -05:00
Christopher Davis
da02f3ad33
Stop Model Property Description When a Schema Type or Ref is Already Defined (#1978)
* Return a Result Object from AnnotationsReader::updateDefinition

This is so we can make a decision on whether or not a schema's type or
ref has been manually defined by a user via an `@OA\Schema` annotation
as something other than an object.

If it has been defined, this bundle should not read model properties any
further as it causes errors.

I put this in AnnotationReader as it seemed the most flexible in the
long run. It could have gone in `OpenApiAnnotationsReader`, but then any
additional things added to `updateDefinition` could be left out of the
decision down the road. This is also a convenient place to decide this
once for `ObjectModelDescriber` and `JMSModelDescriber`.

* Stop Model Describer if a Schema Type or Ref Has Been Defined

Via the result object added in the previous commit.

This lets user "short circuit" the model describers by manually defining
the schema type or ref on a plain PHP object or form. For example,
a collection class could be defined like this:

    /**
     * @OA\Schema(type="array", @OA\Items(ref=@Model(type=SomeEntity::class)))
     */
     class SomeCollection implements \IteratorAggregate { }

Previously the model describer would error as it tries to merge the
`array` schema with the already defiend `object` schema. Now it will
prefer the array schema and skip reading all the properties of the
object.

* Add a Documentation Bit on Stopping Property Description

* Mark UpdateClassDefinitionResult as Internal
2022-04-30 20:28:05 +02:00
Guilhem Niot
5d747aefc3 fix CS 2022-04-30 20:10:00 +02:00
Guilhem Niot
52e7fc4de1 Use the same root context everywhere 2022-04-30 20:07:44 +02:00
Guilhem Niot
fca94057d2 Merge remote-tracking branch 'origin/master' into constraint_groups 2022-04-13 19:43:23 +02:00
Alex Kalineskou
cc97b0ba45
Add support for php attributes (#1932)
* 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>
2021-12-21 16:16:14 +01:00
Guilhem Niot
ade4b6c17c
Merge branch 'master' into constraint_groups 2021-12-19 11:38:47 +01:00
Alexey Alshenetsky
14383f4ee5
Add support for zircore/swagger-php 4.0 (#1916)
* add zircore/swagger-php v4 to composer.json

* fix incompatibilities

* add compatibility with 3.2

* Apply fixes from StyleCI

* mark SetsContextTrait as internal

* Bump php version

Co-authored-by: Alexey <alshenestky@icloud.com>
Co-authored-by: Alexey Alshenetsky <alshenetsky@users.noreply.github.com>
Co-authored-by: Guilhem Niot <guilhem@gniot.fr>
2021-12-11 14:39:04 +01:00
Christopher Davis
477442588a Fix CS 2021-11-06 07:42:38 -05:00
Christopher Davis
7357de9c16 Add a Configuration Option to Enable Validation Groups
If this was turned on by default, that seems like a _large_ BC break as
folks entire OpenAPI doc could change underneath them.

The config option defaults to false and users can enable it if they
desire.
2021-11-06 07:13:56 -05:00
Christopher Davis
cc962b72c8 Add Validation Group Support to SymfonyConstraintAnnotationReader
This support is gated behind a flag as turning it on seems like it would
be a large backwards incompatible change.
2021-11-06 07:13:41 -05:00
Martin Rademacher
74a440a2b1
Always provide a context to swagger-php (#1860)
The next swagger-php release will make `context` a required parameter
for `Analysis` and adding annotations to it.
2021-08-17 21:52:21 +02:00
Alexander Melihov
2df454c0c3
Compound validation rule support (#1818)
* Compound validation rule support

* Compound validation rule support

* Compound validation rule support

* Compound validation rule support

* Remove duplicated method

* error during merge

* wrong variable name

* Simplify PR

* Fix CS

* Use same indentation as before

Co-authored-by: Guilhem Niot <guilhem@gniot.fr>
Co-authored-by: Guilhem Niot <guilhem.niot@gmail.com>
2021-06-16 09:59:06 +02:00
Nicolas
bd952b170e
Add a check for Constraint class existing before using it
*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"?`
2021-06-11 07:23:54 +02:00
Christopher Davis
5f1645db40 Check min/max On Range Constraints Before Use
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.
2021-05-25 06:44:16 -05:00
Christopher Davis
7fd8c0ecfe Check if min and max Are Set on Count Constraints
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.
2021-05-25 06:44:09 -05:00
beerline
d8231024c3 feature: Add new validation from constraints.
- Add minimum for GreaterThanOrEqual
- add minimum and exclusiveMinimum LessThanOrEqual annotation
2021-05-07 14:18:44 +02:00
Alexander M. Turek
16221de418 Added support for constraint attributes 2021-03-12 10:57:40 +01:00
Christopher Davis
883d7b6c89
Apply enum from Choice Constraints to Items When Choice is Multiple (#1784)
* 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>
2021-02-19 09:41:32 +01:00
Christopher Davis
530311c489 Check Min and Max in Length Constraints Before Setting in Schemas
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
}
```
2021-02-10 10:33:55 -06:00
Alex Kalineskou
3f6afe54cd Fix property_exists for SymfonyConstraintAnnotationReader 2020-09-28 22:45:24 +03:00
Guilhem Niot
416d1f2d2a Merge branch '3.x' 2020-09-20 20:38:43 +02:00
Guilhem Niot
6faec06321
Fix the tests (#1720)
* Fix the tests

* Add a comment

* fix the tests

* cs
2020-09-20 20:38:26 +02:00
Guilhem Niot
865527b85b Merge branch '3.x' 2020-09-09 08:55:20 +02:00
Alex Kalineskou
0da1909cb9 Add support for allowNull for Assert\NotBlank 2020-09-09 08:45:53 +02:00
Guilhem Niot
ad4e5551f5 Merge remote-tracking branch 'origin/3.x' into HEAD 2020-07-12 15:07:56 +02:00
Guilhem Niot
8948d5418b
Add methods metadata support for models (#1678)
* Add methods metadata support for models

* fix cs
2020-07-12 14:54:39 +02:00
Guilhem Niot
d167685f42 Merge remote-tracking branch 'origin/3.x' into HEAD 2020-07-11 18:12:14 +02:00
Guilhem Niot
7d9573ddf6
Move the OpenApi processing to ApiDocGenerator (#1671)
* Move the OpenApi processing to ApiDocGenerator

* Temporary fix for https://github.com/zircote/swagger-php/pull/791

* Stop using the ModelRegistry in OpenApiPhpDescriber
2020-07-06 19:50:34 +02:00
pratyam
fe39acd6a8
Bugfix/remove pattern from property expression message error (#1670)
* 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
2020-07-04 16:27:40 +02:00
Mantis Development
5e6b894bdc
Fix User Warning: Multiple definitions for @OA\\Property()->title (#1630)
* Fix User Warning: Multiple definitions for @OA\\Property()->title

* Add test

* Pass CI..
2020-05-31 10:30:13 +02:00
Guilhem Niot
fb84e36fdf
Fix #1628 : annotations construction is context dependant (#1632)
* Fix #1628 : since annotations construction is context dependant, we cannot use the cached annotations reader

* CS

* Small improvement

* cs
2020-05-29 21:52:06 +02:00
Filip Benčo
78664ef9ec
OpenApi 3 Support (#1623)
* 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>
2020-05-28 13:19:11 +02:00
katinsv
82aa08e5ff Fix Assert\Choice when choices are object not array 2020-03-13 16:59:56 +03:00
Clément Lovergne
9ba4735b78 Fix invalid tag which doesn't has description 2020-03-05 13:39:58 +01:00
Romain BigZ Richard
9968027aad feature: Add new validation from constraints.
- 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.
2018-12-19 16:25:14 +01:00
Piotr Antosik
a9d6b3fd46
Fix choice annotation with callback method name without class 2018-09-26 16:51:43 +02:00
Pavel Batanov
995ade1c8d Respect property name for constraints 2018-09-11 13:42:50 +03:00
Guilhem N
fcb36d8e8d
AssertLength doesn't make the field required (#1389) 2018-08-30 00:32:11 +02:00
Palluel-Lafleur Frédéric
c2f036c159 fix(SymfonyConstraintAnnotationReader): fixed enum guessing in Assert… (#1325)
* fix(SymfonyConstraintAnnotationReader): fixed enum guessing in Assert\Choicewhen callback parameter is used

* fix(SymfonyConstraints): turn double quotes in single quotes
2018-05-20 15:59:52 +02:00
Jerzy Lekowski
3b2d9da6c2 Fix #1283: Invalid swagger.json generation - definition for entities with Assert\NotBlank and Assert\Length 2018-04-09 10:53:43 +01:00
Guilhem Niot
8026ff46eb Support `@Model` in in-object annotations 2018-03-22 19:14:01 +01:00
Guilhem Niot
7d99a96cf4 Allow to change a property name 2018-02-19 21:42:56 +01:00
Martijn van Kempen
dad7f77351 Nullable patterns no longer throw exceptions (#1210)
Nullable patterns no longer throw exceptions
2018-01-26 17:09:38 +01:00
Martijn van Kempen
b07043ce33 Added Symfony constraint annotation reader (#1202)
* Added Symfony constraint annotation reader

* StyleCI analysis changes

* StyleCI analysis

* StyleCI analysis

* No longer adding the constraint description for NotBlank and NotNull

* Updated doc comment

* Removed @param

* Removed the AbstractComparison condition

* Using Assert and removed unused method
2018-01-25 14:59:48 +01:00
Guilhem N
f193fdb1f1
Inject the AnnotationsReader in Model describers instead of internal classes (#1203) 2018-01-24 19:58:38 +01:00