77
88namespace cebe \openapi \spec ;
99
10- use cebe \openapi \exceptions \TypeErrorException ;
1110use cebe \openapi \SpecBaseObject ;
1211
1312/**
2827 */
2928class OpenApi extends SpecBaseObject
3029{
31- const VERSION_3_0 = ' 3.0 ' ;
32- const VERSION_3_1 = ' 3.1 ' ;
33- const VERSION_UNSUPPORTED = ' unsupported ' ;
30+ const VERSION_3_0 = " 3.0 " ;
31+ const VERSION_3_1 = " 3.1 " ;
32+ const VERSION_UNSUPPORTED = " unsupported " ;
3433
3534 /**
3635 * Pattern used to validate OpenAPI versions.
@@ -43,15 +42,15 @@ class OpenApi extends SpecBaseObject
4342 protected function attributes (): array
4443 {
4544 return [
46- ' openapi ' => Type::STRING ,
47- ' info ' => Info::class,
48- ' servers ' => [Server::class],
49- ' paths ' => Paths::class,
50- ' webhooks ' => [PathItem::class],
51- ' components ' => Components::class,
52- ' security ' => [SecurityRequirement::class],
53- ' tags ' => [Tag::class],
54- ' externalDocs ' => ExternalDocumentation::class,
45+ " openapi " => Type::STRING ,
46+ " info " => Info::class,
47+ " servers " => [Server::class],
48+ " paths " => Paths::class,
49+ " webhooks " => [PathItem::class],
50+ " components " => Components::class,
51+ " security " => [SecurityRequirement::class],
52+ " tags " => [Tag::class],
53+ " externalDocs " => ExternalDocumentation::class,
5554 ];
5655 }
5756
@@ -63,9 +62,7 @@ protected function attributeDefaults(): array
6362 return [
6463 // Spec: If the servers property is not provided, or is an empty array,
6564 // the default value would be a Server Object with a url value of /.
66- 'servers ' => [
67- new Server (['url ' => '/ ' ])
68- ],
65+ "servers " => [new Server (["url " => "/ " ])],
6966 ];
7067 }
7168
@@ -74,8 +71,8 @@ public function __get($name)
7471 $ ret = parent ::__get ($ name );
7572 // Spec: If the servers property is not provided, or is an empty array,
7673 // the default value would be a Server Object with a url value of /.
77- if ($ name === ' servers ' && $ ret === []) {
78- return $ this ->attributeDefaults ()[' servers ' ];
74+ if ($ name === " servers " && $ ret === []) {
75+ return $ this ->attributeDefaults ()[" servers " ];
7976 }
8077 return $ ret ;
8178 }
@@ -86,13 +83,19 @@ public function __get($name)
8683 public function performValidation ()
8784 {
8885 if ($ this ->getMajorVersion () === static ::VERSION_3_0 ) {
89- $ this ->requireProperties ([' openapi ' , ' info ' , ' paths ' ]);
86+ $ this ->requireProperties ([" openapi " , " info " , " paths " ]);
9087 } else {
91- $ this ->requireProperties (['openapi ' , 'info ' ], ['paths ' , 'webhooks ' , 'components ' ]);
88+ $ this ->requireProperties (
89+ ["openapi " , "info " ],
90+ ["paths " , "webhooks " , "components " ],
91+ );
9292 }
9393
94- if (!empty ($ this ->openapi ) && !preg_match (static ::PATTERN_VERSION , $ this ->openapi )) {
95- $ this ->addError ('Unsupported openapi version: ' . $ this ->openapi );
94+ if (
95+ !empty ($ this ->openapi ) &&
96+ !preg_match (static ::PATTERN_VERSION , $ this ->openapi )
97+ ) {
98+ $ this ->addError ("Unsupported openapi version: " . $ this ->openapi );
9699 }
97100 }
98101
@@ -112,9 +115,9 @@ public function getMajorVersion()
112115 }
113116 if (preg_match (static ::PATTERN_VERSION , $ this ->openapi , $ matches )) {
114117 switch ($ matches [1 ]) {
115- case ' 3.0 ' :
118+ case " 3.0 " :
116119 return static ::VERSION_3_0 ;
117- case ' 3.1 ' :
120+ case " 3.1 " :
118121 return static ::VERSION_3_1 ;
119122 }
120123 }
0 commit comments