158 Commits

Author SHA1 Message Date
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
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
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
Guilhem Niot
478fb2efe0 Merge branch 3.x 2021-08-03 10:25:50 +02:00
Fabien Salathe
74036e974a Remove dead code
Removed an unused property
2021-08-03 10:24:24 +02:00
Guilhem Niot
c097e27b69
Merge pull request #1804 from JeResilieMonContrat-com/form_child_documentation
Display non native form type childs description and title properly
2021-08-03 09:37:16 +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
27e6599b1a 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-14 13:24:45 +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
Guilhem Niot
75794a74ec
Adapt https://github.com/nelmio/NelmioApiDocBundle/pull/1814 to 3.x 2021-05-09 17:32:00 +02: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
Yoann Laissus
7858afec09 Display form type childs description and title properly 2021-03-30 14:42:47 +02:00
Alexander M. Turek
12ac91bfcd Added support for constraint attributes 2021-03-14 17:02:52 +01: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
Christopher Davis
87004fc428 Don't Use ref in Discriminator mapping
Instead just include the schema ref directly per the documentation.
2021-02-08 15:39:14 -06:00
Christopher Davis
ac7e29da21 Fix CS 2021-02-01 09:50:15 -06:00
Christopher Davis
9299c0e52e Support OpenAPI Polymorphism in ObjectModelDescriber
This is the default "symfony support" class, so seems like the right
place.
2021-02-01 08:56:31 -06:00
Christopher Davis
d8626c2735 Introduce a Trait to Build OpenAPI Discriminators
See https://swagger.io/docs/specification/data-models/inheritance-and-polymorphism/

This is the adapter layer that will be included in the various model
describers. The creation of the discriminator and the `oneOf` values is
a little finicky and I wanted it to be tested and centralized.
2021-02-01 08:37:20 -06:00
Guilhem Niot
ba3fe1cdfa Merge branch '3.x' 2020-12-17 00:06:17 +01:00
Guilhem Niot
3895e17fe4 Fix exposure of private/protected methods 2020-12-16 23:46:29 +01:00
Guilhem Niot
363fd26f7c Merge branch '3.x' 2020-12-10 22:28:55 +01:00
Guilhem Niot
90f835f1ef
Allow to not document form types fields (#1752)
* Allow the usage of `@SWG\Definition` on form types

* Allow to not document form types fields

* Reduce the number of changes
2020-12-02 15:38:38 +01:00
Guilhem Niot
68bf1670f3 Fix CS 2020-11-20 17:10:21 +01:00
Guilhem Niot
0912c85a0d Improve error when the items type of an array is not specified 2020-11-20 17:06:56 +01:00
Alex Kalineskou
290df23dc0 Fix property_exists for SymfonyConstraintAnnotationReader 2020-09-29 12:30:21 +02:00
Alex Kalineskou
3f6afe54cd Fix property_exists for SymfonyConstraintAnnotationReader 2020-09-28 22:45:24 +03:00
Guilhem Niot
4436c468f1 Fix the tests broken by zircote/swagger-php 2020-09-27 22:20:04 +02: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
c1903db109 Fix the JMSModelDescriber 2020-09-09 08:38:25 +02:00
Paul Dugas
429d809f41 Ignore ReflectionException for "magic" JMS\Accessor methods (#1715)
* Update JMSModelDescriber.php

Ignore ReflectionException thrown when getter or setter from JMS\ Accessor are "magic" methods.

* Add tests to avoid future regressions

* CS

Co-authored-by: Guilhem Niot <guilhem.niot@gmail.com>
2020-09-09 08:38:08 +02:00
Guilhem Niot
5b6983e179 Fix the JMSModelDescriber 2020-09-09 08:35:01 +02:00
Paul Dugas
fcb52246b2
Ignore ReflectionException for "magic" JMS\Accessor methods (#1715)
* Update JMSModelDescriber.php

Ignore ReflectionException thrown when getter or setter from JMS\ Accessor are "magic" methods.

* Add tests to avoid future regressions

* CS

Co-authored-by: Guilhem Niot <guilhem.niot@gmail.com>
2020-09-09 08:27:47 +02:00
Guilhem Niot
eeb4a8b90e
Fix ServerVariable management (#1694)
* Fix ServerVariable management

* Fix cs

* Apply StyleCI fixes
2020-08-11 16:44:05 +02:00
Guilhem Niot
23fdbf0412 Merge branch '3.x' 2020-08-06 10:29:17 +02:00
Guilhem Niot
edf6b70175 Apply StyleCI fixes 2020-08-06 10:26:59 +02:00
Guilhem Niot
523d28e955
Add annotations support at methods level when using the JMS serializer (#1682) 2020-07-18 13:31:41 +02:00
Guilhem Niot
545432f7ec Support annotations for virtual properties 2020-07-18 10:10:37 +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
Guilhem Niot
8e0713be53
Always use the SerializerExtractor (from the PropertyInfo component) (#1665)
* Always use the SerializerExtractor (from the PropertyInfo component)

* typo
2020-06-22 16:37:32 +02:00