1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @file ATTENTION!!! The code below was carefully crafted by a mean machine. |
4
|
|
|
* Please consider to NOT put any emotional human-generated modifications as AI will throw them away with no mercy. |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace Swaggest\JsonSchema\SwaggerSchema; |
8
|
|
|
|
9
|
|
|
use Swaggest\JsonSchema\Constraint\Properties; |
10
|
|
|
use Swaggest\JsonSchema\Schema; |
|
|
|
|
11
|
|
|
use Swaggest\JsonSchema\Structure\ClassStructure; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
class FileSchema extends ClassStructure { |
15
|
|
|
/** @var string */ |
16
|
|
|
public $format; |
17
|
|
|
|
18
|
|
|
/** @var string */ |
19
|
|
|
public $title; |
20
|
|
|
|
21
|
|
|
/** @var string */ |
22
|
|
|
public $description; |
23
|
|
|
|
24
|
|
|
public $default; |
25
|
|
|
|
26
|
|
|
/** @var string[]|array */ |
27
|
|
|
public $required; |
28
|
|
|
|
29
|
|
|
/** @var string */ |
30
|
|
|
public $type; |
31
|
|
|
|
32
|
|
|
/** @var bool */ |
33
|
|
|
public $readOnly; |
34
|
|
|
|
35
|
|
|
/** @var ExternalDocs information about external documentation */ |
36
|
|
|
public $externalDocs; |
37
|
|
|
|
38
|
|
|
public $example; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param Properties|static $properties |
42
|
|
|
* @param Schema $ownerSchema |
43
|
|
|
*/ |
44
|
|
|
public static function setUpProperties($properties, Schema $ownerSchema) |
45
|
|
|
{ |
46
|
|
|
$properties->format = Schema::string(); |
47
|
|
|
$properties->title = Schema::string(); |
48
|
|
|
$properties->description = Schema::string(); |
49
|
|
|
$properties->default = new Schema(); |
50
|
|
|
$properties->required = Schema::arr(); |
51
|
|
|
$properties->required->items = Schema::string(); |
52
|
|
|
$properties->required->minItems = 1; |
53
|
|
|
$properties->required->uniqueItems = true; |
54
|
|
|
$properties->type = Schema::string(); |
55
|
|
|
$properties->type->enum = array ( |
56
|
|
|
0 => 'file', |
57
|
|
|
); |
58
|
|
|
$properties->readOnly = Schema::boolean(); |
59
|
|
|
$properties->readOnly->default = false; |
|
|
|
|
60
|
|
|
$properties->externalDocs = ExternalDocs::schema(); |
61
|
|
|
$properties->example = new Schema(); |
62
|
|
|
$ownerSchema->type = 'object'; |
|
|
|
|
63
|
|
|
$ownerSchema->additionalProperties = false; |
64
|
|
|
$ownerSchema->patternProperties['^x-'] = new Schema(); |
65
|
|
|
$ownerSchema->patternProperties['^x-']->description = 'Any property starting with x- is valid.'; |
|
|
|
|
66
|
|
|
$ownerSchema->description = 'A deterministic version of a JSON Schema object.'; |
|
|
|
|
67
|
|
|
$ownerSchema->required = array ( |
68
|
|
|
0 => 'type', |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
|
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: