Skip to content

Commit

Permalink
Merge pull request #4 from KnpLabs/feature/json-content-attribute
Browse files Browse the repository at this point in the history
feature: add a JsonContent attributes
  • Loading branch information
Antoine Lelaisant authored Dec 8, 2022
2 parents d665c2f + eb4307b commit 24cf884
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 24cf884

Please sign in to comment.