Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/ModelDescriber/JMSModelDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,10 @@ public function describeItem(array $type, OA\Schema $property, Context $context,
$modelRef = $this->modelRegistry->register($model);

$customFields = (array) $property->jsonSerialize();
unset($customFields['property']);
unset(
$customFields['property'],
$customFields['nullable'],
);
if ([] === $customFields) { // no custom fields
$property->ref = $modelRef;
} else {
Expand Down
6 changes: 6 additions & 0 deletions tests/Functional/Entity/JMSUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use JMS\Serializer\Annotation as Serializer;
use OpenApi\Attributes as OA;
use Symfony\Component\Validator\Constraints as Assert;

/**
* User.
Expand Down Expand Up @@ -95,6 +96,11 @@ class JMSUser
#[Serializer\Expose]
private $bestFriend;

#[Serializer\Type(User::class)]
#[Serializer\Expose]
#[Assert\NotNull]
private ?User $notNullFriend = null;

/**
* Whether this user is enabled or disabled.
*
Expand Down
6 changes: 6 additions & 0 deletions tests/Functional/Fixtures/JmsOptOutController.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
"VirtualTypeClassDoesNotExistsHandlerDefined": {},
"VirtualTypeClassDoesNotExistsHandlerNotDefined": {},
"JMSUser": {
"required": [
"not_null_friend"
],
"properties": {
"id": {
"title": "userid",
Expand Down Expand Up @@ -130,6 +133,9 @@
"best_friend": {
"$ref": "#/components/schemas/User"
},
"not_null_friend": {
"$ref": "#/components/schemas/User"
},
"status": {
"title": "Whether this user is enabled or disabled.",
"description": "Only enabled users may be used in actions.",
Expand Down
4 changes: 4 additions & 0 deletions tests/Functional/JMSFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ public function testModelDocumentation(): void
'best_friend' => [
'$ref' => '#/components/schemas/User',
],
'not_null_friend' => [
'$ref' => '#/components/schemas/User',
],
'status' => [
'type' => 'string',
'title' => 'Whether this user is enabled or disabled.',
Expand Down Expand Up @@ -215,6 +218,7 @@ public function testModelDocumentation(): void
'type' => 'integer',
],
],
'required' => ['not_null_friend'],
'schema' => 'JMSUser',
], json_decode($this->getModel('JMSUser')->toJson(), true));

Expand Down
Loading