Skip to content

Commit

Permalink
feature: add a JsonContent attributes
Browse files Browse the repository at this point in the history
fill the content property of the request body
  • Loading branch information
clementvtrd committed Dec 8, 2022
1 parent d665c2f commit eb4307b
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/OpenApi/Attributes/JsonContent.php
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(),
);
}
}

0 comments on commit eb4307b

Please sign in to comment.