Completed
Pull Request — master (#617)
by Amrouche
06:16 queued 02:27
created

ApiDocumentationBuilder   C

Complexity

Total Complexity 56

Size/Duplication

Total Lines 382
Duplicated Lines 14.92 %

Coupling/Cohesion

Components 1
Dependencies 10

Importance

Changes 0
Metric Value
wmc 56
lcom 1
cbo 10
dl 57
loc 382
rs 6.5957
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 20 3
F getApiDocumentation() 45 149 28
C getSwaggerOperation() 12 131 12
C getRange() 0 48 13

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like ApiDocumentationBuilder often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ApiDocumentationBuilder, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ApiPlatform\Core\Swagger;
13
14
use ApiPlatform\Core\Api\IriConverterInterface;
15
use ApiPlatform\Core\Api\OperationMethodResolverInterface;
16
use ApiPlatform\Core\Api\ResourceClassResolverInterface;
17
use ApiPlatform\Core\Documentation\ApiDocumentationBuilderInterface;
18
use ApiPlatform\Core\Exception\InvalidArgumentException;
19
use ApiPlatform\Core\JsonLd\ContextBuilderInterface;
20
use ApiPlatform\Core\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
21
use ApiPlatform\Core\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
22
use ApiPlatform\Core\Metadata\Property\PropertyMetadata;
23
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
24
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceNameCollectionFactoryInterface;
25
use ApiPlatform\Core\Metadata\Resource\ResourceMetadata;
26
use Symfony\Component\PropertyInfo\Type;
27
28
/**
29
 * Creates a machine readable Swagger API documentation.
30
 *
31
 * @author Amrouche Hamza <[email protected]>
32
 * @author Kévin Dunglas <[email protected]>
33
 */
34
final class ApiDocumentationBuilder implements ApiDocumentationBuilderInterface
35
{
36
    const SWAGGER_VERSION = '2.0';
37
38
    private $resourceNameCollectionFactory;
39
    private $resourceMetadataFactory;
40
    private $propertyNameCollectionFactory;
41
    private $propertyMetadataFactory;
42
    private $contextBuilder;
43
    private $resourceClassResolver;
44
    private $operationMethodResolver;
45
    private $title;
46
    private $description;
47
    private $iriConverter;
48
    private $version;
49
    private $mimeTypes = [];
50
51
    public function __construct(ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory, ResourceMetadataFactoryInterface $resourceMetadataFactory, PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory, PropertyMetadataFactoryInterface $propertyMetadataFactory, ContextBuilderInterface $contextBuilder, ResourceClassResolverInterface $resourceClassResolver, OperationMethodResolverInterface $operationMethodResolver, IriConverterInterface $iriConverter, array $formats, string $title, string $description, string $version = null)
52
    {
53
        $this->resourceNameCollectionFactory = $resourceNameCollectionFactory;
54
        $this->resourceMetadataFactory = $resourceMetadataFactory;
55
        $this->propertyNameCollectionFactory = $propertyNameCollectionFactory;
56
        $this->propertyMetadataFactory = $propertyMetadataFactory;
57
        $this->contextBuilder = $contextBuilder;
58
        $this->resourceClassResolver = $resourceClassResolver;
59
        $this->operationMethodResolver = $operationMethodResolver;
60
        $this->title = $title;
61
        $this->description = $description;
62
        $this->iriConverter = $iriConverter;
63
        $this->version = $version;
64
65
        foreach ($formats as $format => $mimeTypes) {
66
            foreach ($mimeTypes as $mimeType) {
67
                $this->mimeTypes[] = $mimeType;
68
            }
69
        }
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75
    public function getApiDocumentation() : array
76
    {
77
        $classes = [];
78
        $operation = [];
79
        $customOperations = [];
80
        $itemOperationsDocs = [];
81
        $definitions = [];
82
83
        foreach ($this->resourceNameCollectionFactory->create() as $resourceClass) {
84
            $operation['item'] = [];
85
            $operation['collection'] = [];
86
            $customOperations['item'] = [];
87
            $customOperations['collection'] = [];
88
            $resourceMetadata = $this->resourceMetadataFactory->create($resourceClass);
89
90
            $shortName = $resourceMetadata->getShortName();
91
            $prefixedShortName = ($iri = $resourceMetadata->getIri()) ? $iri : '#'.$shortName;
92
93
            $class = [
94
                'name' => $shortName,
95
                'externalDocs' => ['url' => $prefixedShortName],
96
            ];
97
98
            if ($description = $resourceMetadata->getDescription()) {
99
                $class = [
100
                    'name' => $shortName,
101
                    'description' => $description,
102
                    'externalDocs' => ['url' => $prefixedShortName],
103
                ];
104
            }
105
106
            $attributes = $resourceMetadata->getAttributes();
107
            $context = [];
108
109
            if (isset($attributes['normalization_context']['groups'])) {
110
                $context['serializer_groups'] = $attributes['normalization_context']['groups'];
111
            }
112
113 View Code Duplication
            if (isset($attributes['denormalization_context']['groups'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
114
                $context['serializer_groups'] = isset($context['serializer_groups']) ? array_merge($context['serializer_groups'], $attributes['denormalization_context']['groups']) : $context['serializer_groups'];
115
            }
116
117
            $definitions[$shortName] = [
118
                'type' => 'object',
119
                'xml' => ['name' => 'response'],
120
            ];
121
122
            foreach ($this->propertyNameCollectionFactory->create($resourceClass, $context) as $propertyName) {
123
                $propertyMetadata = $this->propertyMetadataFactory->create($resourceClass, $propertyName);
124
125
                if ($propertyMetadata->isRequired()) {
126
                    $definitions[$shortName]['required'][] = $propertyName;
127
                }
128
129
                $range = $this->getRange($propertyMetadata);
130
                if (empty($range)) {
131
                    continue;
132
                }
133
134
                if ($propertyMetadata->getDescription()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $propertyMetadata->getDescription() of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
135
                    $definitions[$shortName]['properties'][$propertyName]['description'] = $propertyMetadata->getDescription();
136
                }
137
138
                if ($range['complex']) {
139
                    $definitions[$shortName]['properties'][$propertyName] = ['$ref' => $range['value']];
140
                } else {
141
                    $definitions[$shortName]['properties'][$propertyName] = ['type' => $range['value']];
142
143
                    if (isset($range['example'])) {
144
                        $definitions[$shortName]['properties'][$propertyName]['example'] = $range['example'];
145
                    }
146
                }
147
            }
148
149 View Code Duplication
            if ($operations = $resourceMetadata->getItemOperations()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
150
                foreach ($operations as $operationName => $itemOperation) {
151
                    $method = $this->operationMethodResolver->getItemOperationMethod($resourceClass, $operationName);
152
                    $swaggerOperation = $this->getSwaggerOperation($resourceClass, $resourceMetadata, $operationName, $itemOperation, $prefixedShortName, false, $definitions, $method);
153
                    $operation['item'] = array_merge($operation['item'], $swaggerOperation);
154
                    if ($operationName !== strtolower($method)) {
155
                        $customOperations['item'][] = $operationName;
156
                    }
157
                }
158
            }
159
160 View Code Duplication
            if ($operations = $resourceMetadata->getCollectionOperations()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
161
                foreach ($operations as $operationName => $collectionOperation) {
162
                    $method = $this->operationMethodResolver->getCollectionOperationMethod($resourceClass, $operationName);
163
                    $swaggerOperation = $this->getSwaggerOperation($resourceClass, $resourceMetadata, $operationName, $collectionOperation, $prefixedShortName, true, $definitions, $method);
164
                    $operation['collection'] = array_merge($operation['collection'], $swaggerOperation);
165
                    if ($operationName !== strtolower($method)) {
166
                        $customOperations['collection'][] = $operationName;
167
                    }
168
                }
169
            }
170
            try {
171
                $resourceClassIri = $this->iriConverter->getIriFromResourceClass($resourceClass);
172
                $itemOperationsDocs[$resourceClassIri] = $operation['collection'];
173
174 View Code Duplication
                if (!empty($customOperations['collection'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
175
                    foreach ($customOperations['collection'] as $customOperation) {
176
                        $path = $resourceMetadata->getCollectionOperationAttribute($customOperation, 'path');
177
                        if (null !== $path) {
178
                            $method = $this->operationMethodResolver->getCollectionOperationMethod($resourceClass, $customOperation);
179
                            $customSwaggerOperation = $this->getSwaggerOperation($resourceClass, $resourceMetadata, $customOperation, [$method], $prefixedShortName, true, $definitions, $method);
180
181
                            $itemOperationsDocs[$path] = $customSwaggerOperation;
182
                        }
183
                    }
184
                }
185
186
187
                $resourceClassIri .= '/{id}';
188
189
                $itemOperationsDocs[$resourceClassIri] = $operation['item'];
190
191 View Code Duplication
                if (!empty($customOperations['item'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
192
                    foreach ($customOperations['item'] as $customOperation) {
193
                        $path = $resourceMetadata->getItemOperationAttribute($customOperation, 'path');
194
                        if (null !== $path) {
195
                            $method = $this->operationMethodResolver->getItemOperationMethod($resourceClass, $customOperation);
196
                            $customSwaggerOperation = $this->getSwaggerOperation($resourceClass, $resourceMetadata, $customOperation, [$method], $prefixedShortName, true, $definitions, $method);
197
198
                            $itemOperationsDocs[$path] = $customSwaggerOperation;
199
                        }
200
                    }
201
                }
202
            } catch (InvalidArgumentException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
203
            }
204
205
            $classes[] = $class;
206
        }
207
208
        $doc['swagger'] = self::SWAGGER_VERSION;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$doc was never initialized. Although not strictly required by PHP, it is generally a good practice to add $doc = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
209
        if ('' !== $this->title) {
210
            $doc['info']['title'] = $this->title;
211
        }
212
213
        if ('' !== $this->description) {
214
            $doc['info']['description'] = $this->description;
215
        }
216
        $doc['info']['version'] = $this->version ?? '0.0.0';
217
        $doc['definitions'] = $definitions;
218
        $doc['externalDocs'] = ['description' => 'Find more about API Platform', 'url' => 'https://api-platform.com'];
219
        $doc['tags'] = $classes;
220
        $doc['paths'] = $itemOperationsDocs;
221
222
        return $doc;
223
    }
224
225
    /**
226
     * Gets and populates if applicable a Swagger operation.
227
     */
228
    private function getSwaggerOperation(string $resourceClass, ResourceMetadata $resourceMetadata, string $operationName, array $operation, string $prefixedShortName, bool $collection, array $properties, string $method) : array
0 ignored issues
show
Unused Code introduced by
The parameter $operationName is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $prefixedShortName is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $properties is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
229
    {
230
        $methodSwagger = strtolower($method);
231
        $swaggerOperation = $operation['swagger_context'] ?? [];
232
        $shortName = $resourceMetadata->getShortName();
233
        $swaggerOperation[$methodSwagger] = [];
234
        $swaggerOperation[$methodSwagger]['tags'] = [$shortName];
235
236
        switch ($method) {
237
            case 'GET':
0 ignored issues
show
Coding Style introduced by
CASE statements must be defined using a colon

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
238
                $swaggerOperation[$methodSwagger]['produces'] = $this->mimeTypes;
239
240
                if ($collection) {
241 View Code Duplication
                    if (!isset($swaggerOperation[$methodSwagger]['title'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
242
                        $swaggerOperation[$methodSwagger]['summary'] = sprintf('Retrieves the collection of %s resources.', $shortName);
243
                    }
244
245
                    $swaggerOperation[$methodSwagger]['responses'] = [
246
                        '200' => [
247
                            'description' => 'Successful operation',
248
                             'schema' => [
249
                                'type' => 'array',
250
                                'items' => ['$ref' => sprintf('#/definitions/%s', $shortName)],
251
                             ],
252
                        ],
253
                    ];
254
                    break;
255
                }
256
257 View Code Duplication
                if (!isset($swaggerOperation[$methodSwagger]['title'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
258
                    $swaggerOperation[$methodSwagger]['summary'] = sprintf('Retrieves %s resource.', $shortName);
259
                }
260
261
                $swaggerOperation[$methodSwagger]['parameters'][] = [
262
                    'name' => 'id',
263
                    'in' => 'path',
264
                    'required' => true,
265
                    'type' => 'integer',
266
                ];
267
268
                $swaggerOperation[$methodSwagger]['responses'] = [
269
                    '200' => [
270
                        'description' => 'Successful operation',
271
                        'schema' => ['$ref' => sprintf('#/definitions/%s', $shortName)],
272
                    ],
273
                    '404' => ['description' => 'Resource not found'],
274
                ];
275
                break;
276
277
            case 'POST':
0 ignored issues
show
Coding Style introduced by
CASE statements must be defined using a colon

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
278
                $swaggerOperation[$methodSwagger]['consumes'] = $swaggerOperation[$methodSwagger]['produces'] = $this->mimeTypes;
279
280 View Code Duplication
                if (!isset($swaggerOperation[$methodSwagger]['title'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
281
                    $swaggerOperation[$methodSwagger]['summary'] = sprintf('Creates a %s resource.', $shortName);
282
                }
283
284
                if ($this->resourceClassResolver->isResourceClass($resourceClass)) {
285
                    $swaggerOperation[$methodSwagger]['parameters'][] = [
286
                        'in' => 'body',
287
                        'name' => 'body',
288
                        'description' => sprintf('%s resource to be added', $shortName),
289
                        'schema' => [
290
                            '$ref' => sprintf('#/definitions/%s', $shortName),
291
                        ],
292
                    ];
293
                }
294
295
                $swaggerOperation[$methodSwagger]['responses'] = [
296
                        '201' => [
297
                            'description' => 'Successful operation',
298
                            'schema' => ['$ref' => sprintf('#/definitions/%s', $shortName)],
299
                        ],
300
                        '400' => ['description' => 'Invalid input'],
301
                        '404' => ['description' => 'Resource not found'],
302
                ];
303
            break;
304
305
            case 'PUT':
0 ignored issues
show
Coding Style introduced by
CASE statements must be defined using a colon

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
306
                $swaggerOperation[$methodSwagger]['consumes'] = $swaggerOperation[$methodSwagger]['produces'] = $this->mimeTypes;
307
308 View Code Duplication
                if (!isset($swaggerOperation[$methodSwagger]['title'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
309
                    $swaggerOperation[$methodSwagger]['summary'] = sprintf('Replaces the %s resource.', $shortName);
310
                }
311
312
                if ($this->resourceClassResolver->isResourceClass($resourceClass)) {
313
                    $swaggerOperation[$methodSwagger]['parameters'] = [
314
                        [
315
                            'name' => 'id',
316
                            'in' => 'path',
317
                            'required' => true,
318
                            'type' => 'integer',
319
                        ],
320
                        [
321
                            'in' => 'body',
322
                            'name' => 'body',
323
                            'description' => sprintf('%s resource to be added', $shortName),
324
                            'schema' => [
325
                                '$ref' => sprintf('#/definitions/%s', $shortName),
326
                            ],
327
                        ],
328
                    ];
329
                }
330
331
                $swaggerOperation[$methodSwagger]['responses'] = [
332
                    '200' => [
333
                        'description' => 'Successful operation',
334
                        'schema' => ['$ref' => sprintf('#/definitions/%s', $shortName)],
335
                    ],
336
                    '400' => ['description' => 'Invalid input'],
337
                    '404' => ['description' => 'Resource not found'],
338
                ];
339
            break;
340
341
            case 'DELETE':
342
                $swaggerOperation[$methodSwagger]['responses'] = [
343
                    '204' => ['description' => 'Deleted'],
344
                    '404' => ['description' => 'Resource not found'],
345
                ];
346
347
                $swaggerOperation[$methodSwagger]['parameters'] = [[
348
                    'name' => 'id',
349
                    'in' => 'path',
350
                    'required' => true,
351
                    'type' => 'integer',
352
                ]];
353
            break;
354
        }
355
        ksort($swaggerOperation);
356
357
        return $swaggerOperation;
358
    }
359
360
    /**
361
     * Gets the range of the property.
362
     *
363
     * @param PropertyMetadata $propertyMetadata
364
     *
365
     * @return array|null
366
     */
367
    private function getRange(PropertyMetadata $propertyMetadata) : array
368
    {
369
        $type = $propertyMetadata->getType();
370
        if (!$type) {
371
            return [];
372
        }
373
374
        if ($type->isCollection() && $collectionType = $type->getCollectionValueType()) {
375
            $type = $collectionType;
376
        }
377
378
        switch ($type->getBuiltinType()) {
379
            case Type::BUILTIN_TYPE_STRING:
380
                return ['complex' => false, 'value' => 'string'];
381
382
            case Type::BUILTIN_TYPE_INT:
383
                return ['complex' => false, 'value' => 'integer'];
384
385
            case Type::BUILTIN_TYPE_FLOAT:
386
                return ['complex' => false, 'value' => 'number'];
387
388
            case Type::BUILTIN_TYPE_BOOL:
389
                return ['complex' => false, 'value' => 'boolean'];
390
391
            case Type::BUILTIN_TYPE_OBJECT:
392
                $className = $type->getClassName();
393
                if (null === $className) {
394
                    return [];
395
                }
396
397
                if (is_subclass_of($className, \DateTimeInterface::class)) {
1 ignored issue
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \DateTimeInterface::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
398
                    return ['complex' => false, 'value' => 'string', 'example' => '1988-01-21T00:00:00+00:00'];
399
                }
400
401
                if (!$this->resourceClassResolver->isResourceClass($className)) {
402
                    return [];
403
                }
404
405
                if ($propertyMetadata->isReadableLink()) {
406
                    return ['complex' => true, 'value' => sprintf('#/definitions/%s', $this->resourceMetadataFactory->create($className)->getShortName())];
407
                }
408
409
                return ['complex' => false, 'value' => 'string', 'example' => '/my/iri'];
410
411
            default:
412
                return ['complex' => false, 'value' => 'null'];
413
        }
414
    }
415
}
416