-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: add a JsonContent attributes
fill the content property of the request body
- Loading branch information
1 parent
d665c2f
commit eb4307b
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace KnpLabs\JsonSchemaBundle\OpenApi\Attributes; | ||
|
||
use KnpLabs\JsonSchema\JsonSchemaInterface; | ||
use OpenApi\Attributes\JsonContent as AttributesJsonContent; | ||
|
||
class JsonContent extends AttributesJsonContent | ||
{ | ||
/** | ||
* @param class-string $schema | ||
*/ | ||
public function __construct(string $schemaClass) | ||
{ | ||
/** | ||
* @var JsonSchemaInterface | ||
*/ | ||
$schema = new $schemaClass(); | ||
|
||
parent::__construct( | ||
schema: json_encode($schema->jsonSerialize()), | ||
example: iterator_to_array($schema->getExamples()), | ||
title: $schema->getTitle(), | ||
description: $schema->getDescription(), | ||
); | ||
} | ||
} |