fixed json schema recursion issues
This commit is contained in:
@@ -51,7 +51,7 @@ class Definition
|
||||
|
||||
private static function getRefPath(string $schemaName): string
|
||||
{
|
||||
return '#/$defs/' . $schemaName ;
|
||||
return '#/$defs/' . $schemaName;
|
||||
}
|
||||
|
||||
|
||||
@@ -78,13 +78,30 @@ class Definition
|
||||
}
|
||||
|
||||
if ($property instanceof RefProperty) {
|
||||
$newProperty[$property->type->value] = $property->_ref->map(function (string $ref) {
|
||||
return [
|
||||
'$ref' => self::getRefPath($ref)
|
||||
];
|
||||
});
|
||||
if ($property->maxItems->getOrElse(null) === 1) {
|
||||
$newProperty["type"] = "object";
|
||||
if ($property->_ref->count() == 1) {
|
||||
$newProperty['$ref'] = $property->_ref->map(fn($ref)=>self::getRefPath($ref))->first();
|
||||
} else {
|
||||
$newProperty["oneOf"] = $property->_ref->map(function (string $ref) {
|
||||
return [
|
||||
'$ref' => self::getRefPath($ref)
|
||||
];
|
||||
});
|
||||
}
|
||||
} else {
|
||||
$newProperty["type"] = "array";
|
||||
if ($property->_ref->count() == 1) {
|
||||
$newProperty["items"]['$ref'] = $property->_ref->map(fn($ref)=>self::getRefPath($ref))->first();
|
||||
} else {
|
||||
$newProperty["items"]["anyOf"] = $property->_ref->map(function (string $ref) {
|
||||
return [
|
||||
'$ref' => self::getRefPath($ref)
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
unset($newProperty["type"]);
|
||||
}
|
||||
}
|
||||
|
||||
$newProperties[$property->id] = $newProperty;
|
||||
|
||||
@@ -8,7 +8,6 @@ use PhpOption\Option;
|
||||
class RefProperty implements Property
|
||||
{
|
||||
/**
|
||||
* @param RefType $type
|
||||
* @param string $id
|
||||
* @param Option<string> $title
|
||||
* @param Option<string> $description
|
||||
@@ -18,7 +17,6 @@ class RefProperty implements Property
|
||||
* @param Option<string> $comment
|
||||
*/
|
||||
public function __construct(
|
||||
public RefType $type,
|
||||
public string $id,
|
||||
public Option $title,
|
||||
public Option $description,
|
||||
|
||||
@@ -60,7 +60,6 @@ class File implements FieldInterface, MinMaxInterface
|
||||
public function toJsonSchema(): Property
|
||||
{
|
||||
return new RefProperty(
|
||||
type: RefType::ANY_OF,
|
||||
id: $this->name,
|
||||
title: Option::fromValue($this->label),
|
||||
description: Option::fromValue($this->help, ""),
|
||||
|
||||
@@ -66,7 +66,6 @@ class Reference implements FieldInterface, MinMaxInterface
|
||||
public function toJsonSchema(): Property
|
||||
{
|
||||
return new RefProperty(
|
||||
type: RefType::ANY_OF,
|
||||
id: $this->name,
|
||||
title: Option::fromValue($this->label),
|
||||
description: Option::fromValue($this->help, ""),
|
||||
|
||||
Reference in New Issue
Block a user