Skip to content

Commit

Permalink
Allow recursive nesting of AdditionalProperties in Attributes (#1490)
Browse files Browse the repository at this point in the history
  • Loading branch information
rien-vroom-cquential authored Oct 26, 2023
1 parent bc6107f commit e67dfd9
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/reference/attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ schema defined by this property's value.</p></dd>
<dt><strong>oneOf</strong> : <span style="font-family: monospace;">array&lt;Schema|\OpenApi\Annotations\Schema&gt;</span></dt>
<dd><p>An instance validates successfully against this property if it validates successfully against exactly one schema<br />
defined by this property's value.</p></dd>
<dt><strong>additionalProperties</strong> : <span style="font-family: monospace;">OpenApi\Attributes\AdditionalProperties|bool|null</span></dt>
<dd><p>http://json-schema.org/latest/json-schema-validation.html#anchor64.</p></dd>
<dt><strong>x</strong> : <span style="font-family: monospace;">array&lt;string,mixed&gt;|null</span></dt>
<dd><p>While the OpenAPI Specification tries to accommodate most use cases, additional data can be added to extend the specification at certain points.<br />
For further details see https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#specificationExtensions<br />
Expand Down
3 changes: 2 additions & 1 deletion src/Attributes/AdditionalProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function __construct(
?array $allOf = null,
?array $anyOf = null,
?array $oneOf = null,
AdditionalProperties|bool|null $additionalProperties = null,
// annotation
?array $x = null,
?array $attachables = null
Expand Down Expand Up @@ -100,7 +101,7 @@ public function __construct(
'oneOf' => $oneOf ?? Generator::UNDEFINED,
'x' => $x ?? Generator::UNDEFINED,
'attachables' => $attachables ?? Generator::UNDEFINED,
'value' => $this->combine($items, $discriminator, $externalDocs, $attachables),
'value' => $this->combine($items, $discriminator, $externalDocs, $additionalProperties, $attachables),
]);
}
}
30 changes: 30 additions & 0 deletions tests/Fixtures/Scratch/NestedAdditionalProperties.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php declare(strict_types=1);

/**
* @license Apache 2.0
*/

namespace OpenApi\Tests\Fixtures\Scratch;

use OpenApi\Attributes as OAT;

#[OAT\Info(
title: 'Nested Additional Properties',
version: '1.0'
)]
#[OAT\Get(
path: '/api/endpoint',
description: 'An endpoint',
responses: [new OAT\Response(response: 200, description: 'OK')]
)]
#[OAT\Schema(
additionalProperties: new OAT\AdditionalProperties(
additionalProperties: new OAT\AdditionalProperties(
type: 'string',
)
),
type: 'object'
)]
class NestedAdditionalAttributes
{
}
18 changes: 18 additions & 0 deletions tests/Fixtures/Scratch/NestedAdditionalProperties.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
openapi: 3.0.0
info:
title: 'Nested Additional Properties'
version: '1.0'
paths:
/api/endpoint:
get:
description: 'An endpoint'
responses:
'200':
description: OK
components:
schemas:
NestedAdditionalAttributes:
type: object
additionalProperties:
additionalProperties:
type: string

0 comments on commit e67dfd9

Please sign in to comment.