Skip to content

Commit

Permalink
Rationalise attribute parameters for types that inherit from Schema (#…
Browse files Browse the repository at this point in the history
…1037)

Also clean up a few things we've missed during the annotation/attribute split.
  • Loading branch information
DerManoMann authored Dec 23, 2021
1 parent c2665e0 commit faafa35
Show file tree
Hide file tree
Showing 40 changed files with 576 additions and 289 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
"autoload-dev": {
"psr-4": {
"OpenApi\\Tests\\": "tests/",
"AnotherNamespace\\": "tests/Fixtures/AnotherNamespace"
"AnotherNamespace\\": "tests/Fixtures/AnotherNamespace",
"OpenApi\\Tests\\Fixtures\\Annotations\\": "tests/Fixtures/Annotations"
}
},
"scripts": {
Expand Down
6 changes: 0 additions & 6 deletions src/Annotations/JsonContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@
*/
class JsonContent extends Schema
{

/**
* @var object
*/
public $example = Generator::UNDEFINED;

/**
* @var object
*/
Expand Down
47 changes: 1 addition & 46 deletions src/Annotations/Parameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
* @Annotation
*/
abstract class AbstractParameter extends AbstractAnnotation
class Parameter extends AbstractAnnotation
{
/**
* $ref See https://swagger.io/docs/specification/using-ref/.
Expand Down Expand Up @@ -264,48 +264,3 @@ public function identity(): string
return parent::_identity(['name', 'in']);
}
}

if (\PHP_VERSION_ID >= 80100) {
/**
* @Annotation
*/
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY | \Attribute::IS_REPEATABLE)]
class Parameter extends AbstractParameter
{
public function __construct(
array $properties = [],
string $parameter = Generator::UNDEFINED,
string $name = Generator::UNDEFINED,
string $description = Generator::UNDEFINED,
string $in = Generator::UNDEFINED,
?bool $required = null,
string $ref = Generator::UNDEFINED,
?Schema $schema = null,
?array $examples = null,
?array $x = null,
?array $attachables = null
) {
parent::__construct($properties + [
'parameter' => $parameter,
'name' => $name,
'description' => $description,
'in' => $this->in !== Generator::UNDEFINED ? $this->in : $in,
'required' => $this->required !== Generator::UNDEFINED ? $this->required : ($required ?? Generator::UNDEFINED),
'ref' => $ref,
'x' => $x ?? Generator::UNDEFINED,
'value' => $this->combine($schema, $examples, $attachables),
]);
}
}
} else {
/**
* @Annotation
*/
class Parameter extends AbstractParameter
{
public function __construct(array $properties)
{
parent::__construct($properties);
}
}
}
7 changes: 0 additions & 7 deletions src/Annotations/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ class Property extends Schema
*/
public $property = Generator::UNDEFINED;

/**
* Indicates the property is nullable.
*
* @var bool
*/
public $nullable = Generator::UNDEFINED;

/**
* @inheritdoc
*/
Expand Down
54 changes: 51 additions & 3 deletions src/Attributes/AdditionalProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,60 @@
class AdditionalProperties extends \OpenApi\Annotations\AdditionalProperties
{
public function __construct(
// schema
string|object|null $ref = null,
?string $schema = null,
?string $title = null,
?string $description = null,
?array $required = null,
?array $properties = null,
?string $type = null,
?string $format = null,
?Items $items = null,
?string $collectionFormat = null,
$default = null,
?string $pattern = null,
?array $enum = null,
?Discriminator $discriminator = null,
?bool $readOnly = null,
?bool $writeOnly = null,
?Xml $xml = null,
?ExternalDocumentation $externalDocs = null,
$example = null,
?bool $nullable = null,
?bool $deprecated = null,
?array $allOf = null,
?array $anyOf = null,
?array $oneOf = null,
// annotation
?array $x = null,
?array $attachables = null
) {
parent::__construct([
'x' => $x ?? Generator::UNDEFINED,
'value' => $this->combine($attachables),
]);
'ref' => $ref ?? Generator::UNDEFINED,
'schema' => $schema ?? Generator::UNDEFINED,
'title' => $title ?? Generator::UNDEFINED,
'description' => $description ?? Generator::UNDEFINED,
'required' => $required ?? Generator::UNDEFINED,
'properties' => $properties ?? Generator::UNDEFINED,
'type' => $type ?? Generator::UNDEFINED,
'format' => $format ?? Generator::UNDEFINED,
'collectionFormat' => $collectionFormat ?? Generator::UNDEFINED,
'default' => $default ?? Generator::UNDEFINED,
'pattern' => $pattern ?? Generator::UNDEFINED,
'enum' => $enum ?? Generator::UNDEFINED,
'readOnly' => $readOnly ?? Generator::UNDEFINED,
'writeOnly' => $writeOnly ?? Generator::UNDEFINED,
'xml' => $xml ?? Generator::UNDEFINED,
'example' => $example ?? Generator::UNDEFINED,
'nullable' => $nullable ?? Generator::UNDEFINED,
'deprecated' => $deprecated ?? Generator::UNDEFINED,
'allOf' => $allOf ?? Generator::UNDEFINED,
'anyOf' => $anyOf ?? Generator::UNDEFINED,
'oneOf' => $oneOf ?? Generator::UNDEFINED,
'x' => $x ?? Generator::UNDEFINED,
'attachables' => $attachables ?? Generator::UNDEFINED,
'value' => $this->combine($items, $discriminator, $externalDocs, $attachables),
]);
}
}
19 changes: 10 additions & 9 deletions src/Attributes/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@
class Contact extends \OpenApi\Annotations\Contact
{
public function __construct(
string $name = Generator::UNDEFINED,
string $url = Generator::UNDEFINED,
string $email = Generator::UNDEFINED,
?string $name = null,
?string $url = null,
?string $email = null,
// annotation
?array $x = null,
?array $attachables = null
) {
parent::__construct([
'name' => $name,
'url' => $url,
'email' => $email,
'x' => $x ?? Generator::UNDEFINED,
'value' => $this->combine($attachables),
]);
'name' => $name ?? Generator::UNDEFINED,
'url' => $url ?? Generator::UNDEFINED,
'email' => $email ?? Generator::UNDEFINED,
'x' => $x ?? Generator::UNDEFINED,
'value' => $this->combine($attachables),
]);
}
}
15 changes: 8 additions & 7 deletions src/Attributes/Discriminator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@
class Discriminator extends \OpenApi\Annotations\Discriminator
{
public function __construct(
string $propertyName = Generator::UNDEFINED,
string $mapping = Generator::UNDEFINED,
?string $propertyName = null,
?string $mapping = null,
// annotation
?array $x = null,
?array $attachables = null
) {
parent::__construct([
'propertyName' => $propertyName,
'mapping' => $mapping,
'x' => $x ?? Generator::UNDEFINED,
'value' => $this->combine($attachables),
]);
'propertyName' => $propertyName ?? Generator::UNDEFINED,
'mapping' => $mapping ?? Generator::UNDEFINED,
'x' => $x ?? Generator::UNDEFINED,
'value' => $this->combine($attachables),
]);
}
}
25 changes: 13 additions & 12 deletions src/Attributes/Examples.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,23 @@
class Examples extends \OpenApi\Annotations\Examples
{
public function __construct(
string $summary = Generator::UNDEFINED,
string $description = Generator::UNDEFINED,
string $value = Generator::UNDEFINED,
string $externalValue = Generator::UNDEFINED,
string $ref = Generator::UNDEFINED,
?string $summary = null,
?string $description = null,
?string $value = null,
?string $externalValue = null,
string|object|null $ref = null,
// annotation
?array $x = null,
?array $attachables = null
) {
parent::__construct([
'summary' => $summary,
'description' => $description,
'value' => $value,
'externalValue' => $externalValue,
'ref' => $ref,
'x' => $x ?? Generator::UNDEFINED,
]);
'summary' => $summary ?? Generator::UNDEFINED,
'description' => $description ?? Generator::UNDEFINED,
'value' => $value ?? Generator::UNDEFINED,
'externalValue' => $externalValue ?? Generator::UNDEFINED,
'ref' => $ref ?? Generator::UNDEFINED,
'x' => $x ?? Generator::UNDEFINED,
]);
if ($attachables) {
$this->merge($attachables);
}
Expand Down
9 changes: 5 additions & 4 deletions src/Attributes/ExternalDocumentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
class ExternalDocumentation extends \OpenApi\Annotations\ExternalDocumentation
{
public function __construct(
string $description = Generator::UNDEFINED,
string $url = Generator::UNDEFINED,
?string $description = null,
?string $url = null,
// annotation
?array $x = null,
?array $attachables = null
) {
parent::__construct([
'description' => $description,
'url' => $url,
'description' => $description ?? Generator::UNDEFINED,
'url' => $url ?? Generator::UNDEFINED,
'x' => $x ?? Generator::UNDEFINED,
'value' => $this->combine($attachables),
]);
Expand Down
17 changes: 9 additions & 8 deletions src/Attributes/Flow.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@
class Flow extends \OpenApi\Annotations\Flow
{
public function __construct(
string $authorizationUrl = Generator::UNDEFINED,
string $tokenUrl = Generator::UNDEFINED,
string $refreshUrl = Generator::UNDEFINED,
string $flow = Generator::UNDEFINED,
?string $authorizationUrl = null,
?string $tokenUrl = null,
?string $refreshUrl = null,
?string $flow = null,
?array $scopes = null,
// annotation
?array $x = null,
?array $attachables = null
) {
parent::__construct([
'authorizationUrl' => $authorizationUrl,
'tokenUrl' => $tokenUrl,
'refreshUrl' => $refreshUrl,
'flow' => $flow,
'authorizationUrl' => $authorizationUrl ?? Generator::UNDEFINED,
'tokenUrl' => $tokenUrl ?? Generator::UNDEFINED,
'refreshUrl' => $refreshUrl ?? Generator::UNDEFINED,
'flow' => $flow ?? Generator::UNDEFINED,
'scopes' => $scopes ?? Generator::UNDEFINED,
'x' => $x ?? Generator::UNDEFINED,
'value' => $this->combine($attachables),
Expand Down
1 change: 1 addition & 0 deletions src/Attributes/Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
class Header extends \OpenApi\Annotations\Header
{
public function __construct(
// annotation
?array $x = null,
?array $attachables = null
) {
Expand Down
17 changes: 9 additions & 8 deletions src/Attributes/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@
class Info extends \OpenApi\Annotations\Info
{
public function __construct(
string $version = Generator::UNDEFINED,
string $description = Generator::UNDEFINED,
string $title = Generator::UNDEFINED,
string $termsOfService = Generator::UNDEFINED,
?string $version = null,
?string $description = null,
?string $title = null,
?string $termsOfService = null,
?Contact $contact = null,
?License $license = null,
// annotation
?array $x = null,
?array $attachables = null
) {
parent::__construct([
'version' => $version,
'description' => $description,
'title' => $title,
'termsOfService' => $termsOfService,
'version' => $version ?? Generator::UNDEFINED,
'description' => $description ?? Generator::UNDEFINED,
'title' => $title ?? Generator::UNDEFINED,
'termsOfService' => $termsOfService ?? Generator::UNDEFINED,
'x' => $x ?? Generator::UNDEFINED,
'value' => $this->combine($contact, $license, $attachables),
]);
Expand Down
Loading

0 comments on commit faafa35

Please sign in to comment.