Skip to content

Commit

Permalink
update jsonschema
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskapp committed Oct 9, 2024
1 parent bebcd79 commit 5d54a09
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
22 changes: 13 additions & 9 deletions src/Generator/JsonSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,11 @@ protected function generateType(TypeInterface $type, DefinitionsInterface $defin
}

if ($parent instanceof ReferencePropertyType) {
$target = $parent->getTarget();
unset($data['parent']);

$parentType = $definitions->getType($target);
$parent = $this->generateType($parentType, $definitions, $parent->getTemplate());

return [
'allOf' => [
$parent,
$this->generateType($parent, $definitions, $template),
$data,
]
];
Expand Down Expand Up @@ -153,11 +149,19 @@ protected function generateType(TypeInterface $type, DefinitionsInterface $defin

return $data;
} elseif ($type instanceof ReferencePropertyType) {
[$ns, $name] = TypeUtil::split($type->getTarget());
$targetType = $definitions->getType($type->getTarget());
$hasGenerics = TypeUtil::contains($targetType, GenericPropertyType::class);

if ($hasGenerics) {
// in case the referenced type has generics we resolve
return $this->generateType($targetType, $definitions, $type->getTemplate());
} else {
[$ns, $name] = TypeUtil::split($type->getTarget());

return [
'$ref' => $this->refBase . $name
];
return [
'$ref' => $this->refBase . $name
];
}
} elseif ($type instanceof AnyPropertyType) {
return (object) [];
} elseif ($type instanceof GenericPropertyType) {
Expand Down
10 changes: 1 addition & 9 deletions tests/Generator/resource/jsonschema/jsonschema_oop.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,7 @@
"Student": {
"allOf": [
{
"type": "object",
"properties": {
"firstName": {
"type": "string"
},
"parent": {
"$ref": "#/definitions/Human"
}
}
"$ref": "#/definitions/Human"
},
{
"type": "object",
Expand Down

0 comments on commit 5d54a09

Please sign in to comment.