Skip to content

Commit e557043

Browse files
committed
initial implementation
1 parent c9c7762 commit e557043

20 files changed

+695
-5
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/vendor
2+
/composer.lock
3+

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
all:
3+
4+
style:
5+
vendor/bin/indent --tabs composer.json
6+

composer.json

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
{
1010
"name": "Carsten Brandt",
1111
"email": "mail@cebe.cc",
12-
"homepage": "http://cebe.cc/",
12+
"homepage": "https://cebe.cc/",
1313
"role": "Creator"
1414
}
1515
],
@@ -18,19 +18,41 @@
1818
"source": "https://github.com/cebe/php-openapi"
1919
},
2020
"require": {
21-
"php": ">=7.0.0"
21+
"php": ">=7.0.0",
22+
"symfony/yaml": "^3.3"
2223
},
2324
"require-dev": {
24-
"cebe/indent": "*"
25+
"cebe/indent": "*",
26+
"phpunit/phpunit": "^6.5",
27+
"oai/openapi-specification": "3.0.2"
2528
},
2629
"autoload": {
2730
"psr-4": {
28-
"cebe\\openapi\\": ""
31+
"cebe\\openapi\\": "src/"
32+
}
33+
},
34+
"config": {
35+
"platform": {
36+
"php": "7.0.0"
2937
}
3038
},
3139
"extra": {
3240
"branch-alias": {
3341
"dev-master": "1.0.x-dev"
3442
}
35-
}
43+
},
44+
"repositories": [
45+
{
46+
"type": "package",
47+
"package": {
48+
"name": "oai/openapi-specification",
49+
"version": "3.0.2",
50+
"source": {
51+
"url": "https://github.com/OAI/OpenAPI-Specification",
52+
"type": "git",
53+
"reference": "3.0.2"
54+
}
55+
}
56+
}
57+
]
3658
}

phpunit.xml.dist

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<phpunit bootstrap="./tests/bootstrap.php"
3+
colors="true"
4+
convertErrorsToExceptions="true"
5+
convertNoticesToExceptions="true"
6+
convertWarningsToExceptions="true"
7+
stopOnFailure="false">
8+
<testsuites>
9+
<testsuite name="Test Suite">
10+
<directory suffix="Test.php">./tests</directory>
11+
</testsuite>
12+
</testsuites>
13+
<filter>
14+
<blacklist>
15+
<directory>./vendor</directory>
16+
<directory>./tests</directory>
17+
</blacklist>
18+
</filter>
19+
</phpunit>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace cebe\openapi\exceptions;
4+
5+
/**
6+
*
7+
*
8+
* @author Carsten Brandt <mail@cebe.cc>
9+
*/
10+
class ReadonlyPropertyException extends \Exception
11+
{
12+
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace cebe\openapi\exceptions;
4+
5+
/**
6+
*
7+
*
8+
* @author Carsten Brandt <mail@cebe.cc>
9+
*/
10+
class UnknownPropertyException extends \Exception
11+
{
12+
13+
}

src/spec/Components.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace cebe\openapi\spec;
4+
5+
/**
6+
* Holds a set of reusable objects for different aspects of the OAS.
7+
*
8+
* All objects defined within the components object will have no effect on the API unless they are explicitly referenced
9+
* from properties outside the components object.
10+
*
11+
* @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#componentsObject
12+
*
13+
* @author Carsten Brandt <mail@cebe.cc>
14+
*/
15+
class Components
16+
{
17+
// TODO implement
18+
19+
}

src/spec/Contact.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace cebe\openapi\spec;
4+
5+
/**
6+
* Contact information for the exposed API.
7+
*
8+
* @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#contactObject
9+
*
10+
* @property-read string $name
11+
* @property-read string $url
12+
* @property-read string $email
13+
*
14+
* @author Carsten Brandt <mail@cebe.cc>
15+
*/
16+
class Contact extends SpecBaseObject
17+
{
18+
/**
19+
* @return array array of attributes available in this object.
20+
*/
21+
protected function attributes(): array
22+
{
23+
return [
24+
'name' => 'string',
25+
'url' => 'string',
26+
'email' => 'string',
27+
];
28+
}
29+
30+
/**
31+
* Perform validation on this object, check data against OpenAPI Specification rules.
32+
*
33+
* Call `addError()` in case of validation errors.
34+
*/
35+
protected function performValidation()
36+
{
37+
$this->validateEmail('email');
38+
$this->validateUrl('url');
39+
}
40+
}

src/spec/ExternalDocumentation.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace cebe\openapi\spec;
4+
5+
/**
6+
* Allows referencing an external resource for extended documentation.
7+
*
8+
* @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#externalDocumentationObject
9+
*
10+
* @property-read string $description
11+
* @property-read string $url
12+
*
13+
* @author Carsten Brandt <mail@cebe.cc>
14+
*/
15+
class ExternalDocumentation extends SpecBaseObject
16+
{
17+
/**
18+
* @return array array of attributes available in this object.
19+
*/
20+
protected function attributes(): array
21+
{
22+
return [
23+
'description' => 'string',
24+
'url' => 'string',
25+
];
26+
}
27+
28+
/**
29+
* Perform validation on this object, check data against OpenAPI Specification rules.
30+
*
31+
* Call `addError()` in case of validation errors.
32+
*/
33+
protected function performValidation()
34+
{
35+
$this->requireProperties(['url']);
36+
$this->validateUrl('url');
37+
}
38+
}

src/spec/Info.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace cebe\openapi\spec;
4+
5+
/**
6+
* The object provides metadata about the API.
7+
*
8+
* The metadata MAY be used by the clients if needed, and MAY be presented in editing or documentation generation tools for convenience.
9+
*
10+
* @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#infoObject
11+
*
12+
* @property-read string $title
13+
* @property-read string $description
14+
* @property-read string $termsOfService
15+
* @property-read Contact|null $contact
16+
* @property-read License|null $license
17+
* @property-read string $version
18+
*
19+
* @author Carsten Brandt <mail@cebe.cc>
20+
*/
21+
class Info extends SpecBaseObject
22+
{
23+
/**
24+
* @return array array of attributes available in this object.
25+
*/
26+
protected function attributes(): array
27+
{
28+
return [
29+
'title' => 'string',
30+
'description' => 'string',
31+
'termsOfService' => 'string',
32+
'contact' => Contact::class,
33+
'license' => License::class,
34+
'version' => 'string',
35+
];
36+
}
37+
38+
/**
39+
* Perform validation on this object, check data against OpenAPI Specification rules.
40+
*
41+
* Call `addError()` in case of validation errors.
42+
*/
43+
protected function performValidation()
44+
{
45+
$this->requireProperties(['title', 'version']);
46+
}
47+
}

0 commit comments

Comments
 (0)