Skip to content

Commit 0770472

Browse files
committed
fix(jsonschema): class shortname
1 parent 16a1a61 commit 0770472

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

src/JsonSchema/SchemaFactory.php

+26-22
Original file line numberDiff line numberDiff line change
@@ -269,28 +269,32 @@ private function getMetadata(string $className, string $type = Schema::TYPE_OUTP
269269
];
270270
}
271271

272-
// The best here is to use an Operation when calling `buildSchema`, we try to do a smart guess otherwise
273-
if (!$operation || !$operation->getClass()) {
274-
$resourceMetadataCollection = $this->resourceMetadataFactory->create($className);
275-
276-
if ($operation && $operation->getName()) {
277-
$operation = $resourceMetadataCollection->getOperation($operation->getName());
278-
} else {
279-
// Guess the operation and use the first one that matches criterias
280-
foreach ($resourceMetadataCollection as $resourceMetadata) {
281-
foreach ($resourceMetadata->getOperations() ?? [] as $op) {
282-
if ($operation instanceof CollectionOperationInterface && $op instanceof CollectionOperationInterface) {
283-
$operation = $op;
284-
break 2;
285-
}
286-
287-
if (Schema::TYPE_INPUT === $type && \in_array($op->getMethod(), ['POST', 'PATCH', 'PUT'], true)) {
288-
$operation = $op;
289-
break 2;
290-
}
291-
292-
if (!$operation) {
293-
$operation = new HttpOperation();
272+
if (null === $operation) {
273+
$operation = $this->resourceMetadataFactory->create($className)->getOperation();
274+
} else {
275+
// The best here is to use an Operation when calling `buildSchema`, we try to do a smart guess otherwise
276+
if (!$operation->getClass()) {
277+
$resourceMetadataCollection = $this->resourceMetadataFactory->create($className);
278+
279+
if ($operation->getName()) {
280+
$operation = $resourceMetadataCollection->getOperation($operation->getName());
281+
} else {
282+
// Guess the operation and use the first one that matches criterias
283+
foreach ($resourceMetadataCollection as $resourceMetadata) {
284+
foreach ($resourceMetadata->getOperations() ?? [] as $op) {
285+
if ($operation instanceof CollectionOperationInterface && $op instanceof CollectionOperationInterface) {
286+
$operation = $op;
287+
break 2;
288+
}
289+
290+
if (Schema::TYPE_INPUT === $type && \in_array($op->getMethod(), ['POST', 'PATCH', 'PUT'], true)) {
291+
$operation = $op;
292+
break 2;
293+
}
294+
295+
if (!$operation) {
296+
$operation = new HttpOperation();
297+
}
294298
}
295299
}
296300
}

0 commit comments

Comments
 (0)