Skip to content

Commit

Permalink
Make isRoot() call on annotation safe (#1417)
Browse files Browse the repository at this point in the history
  • Loading branch information
DerManoMann authored Feb 19, 2023
1 parent 29e0378 commit 9983523
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Analysis.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ public function getSchemaForSource(string $fqdn): ?OA\Schema
$definition = $definitions[$fqdn];
if (is_iterable($definition['context']->annotations)) {
foreach (array_reverse($definition['context']->annotations) as $annotation) {
if ($annotation->isRoot(OA\Schema::class) && !$annotation->_context->is('generated')) {
if ($annotation instanceof OA\Schema && $annotation->isRoot(OA\Schema::class) && !$annotation->_context->is('generated')) {
return $annotation;
}
}
Expand Down
41 changes: 41 additions & 0 deletions tests/Fixtures/Scratch/ThirdPartyAnnotation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php declare(strict_types=1);

// intentionally none: namespace OpenApi\Tests\Fixtures\Scratch;

use OpenApi\Annotations as OA;

/**
* @Annotation
*/
class ThirdPartyAnnotation
{
}

/**
* @OA\Schema
* @ThirdPartyAnnotation
*/
class SomeParent
{
}

/**
* @OA\Schema
*/
class Child extends SomeParent
{
}

/**
* @OA\Info(title="API", version="1.0")
* @OA\Get(
* path="/api/endpoint",
* @OA\Response(
* response=200,
* description="successful operation"
* )
* )
*/
class ThirdPartyAnnotationEndpoint
{
}
17 changes: 17 additions & 0 deletions tests/Fixtures/Scratch/ThirdPartyAnnotation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
openapi: 3.0.0
info:
title: API
version: '1.0'
paths:
/api/endpoint:
get:
responses:
'200':
description: 'successful operation'
components:
schemas:
SomeParent: { }
Child:
allOf:
-
$ref: '#/components/schemas/SomeParent'

0 comments on commit 9983523

Please sign in to comment.