Skip to content

Commit e512e96

Browse files
committed
feat: adds validation classes
1 parent c7258a8 commit e512e96

File tree

6 files changed

+1627
-7
lines changed

6 files changed

+1627
-7
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[![Build Status][ico-travis]][link-travis]
66
[![Total Downloads][ico-downloads]][link-downloads]
77

8-
Open API 3.0 spec generator for PHP.
8+
Open API 3.0 builder and validation library for PHP that helps you write valid specs.
99

1010
[PSR-1]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md
1111
[PSR-2]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md
@@ -17,11 +17,13 @@ If you notice compliance oversights, please send a patch via pull request.
1717

1818
## Features
1919

20-
- Object-oriented representation of the
21-
[Open API 3.0+](https://github.com/OAI/OpenAPI-Specification/tree/master/versions) specification.
20+
- Fully documented object-oriented representation of the
21+
[Open API 3.0+](https://github.com/OAI/OpenAPI-Specification/tree/master/versions) specification with helper methods
22+
to write valid documents.
2223
- Supports Illuminate (Laravel) [`Jsonable`](https://github.com/illuminate/contracts/blob/v5.4.0/Support/Jsonable.php)
2324
and [`Arrayable`](https://github.com/illuminate/contracts/blob/v5.4.0/Support/Arrayable.php).
24-
- Generates an specification in plain PHP arrays, JSON or YAML.
25+
- Generates an specification in plain PHP arrays, plain objects, JSON or YAML.
26+
- Validates Open API documents against the Open API 3.0.x JSON Schema.
2527

2628

2729
## Install

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "erasys/openapi-php",
33
"type": "library",
4-
"description": "Open API 3.0 spec generator for PHP.",
4+
"description": "Open API 3.0 builder and validation library for PHP that helps you write valid specs.",
55
"keywords": [
66
"openapi",
77
"openapi3",
@@ -27,7 +27,8 @@
2727
"require": {
2828
"php": "^7.0",
2929
"illuminate/contracts": "^5.4",
30-
"symfony/yaml": "^3.4"
30+
"symfony/yaml": "^3.4",
31+
"justinrainbow/json-schema": "^5.2"
3132
},
3233
"require-dev": {
3334
"phpunit/phpunit": "^6.5",

src/Spec/v3/AbstractObject.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,19 @@
88
use Illuminate\Contracts\Support\Jsonable;
99
use JsonSerializable;
1010
use LogicException;
11+
use stdClass;
1112
use Symfony\Component\Yaml\Yaml;
1213

14+
/**
15+
* Base class for all Open API models.
16+
*
17+
* Note that defining or accessing properties dynamically is not supported by design
18+
* to avoid invalid schema generation. If you need to use specification extensions,
19+
* you can always extend the classes and add there your own properties.
20+
*
21+
*/
1322
abstract class AbstractObject implements ArrayAccess, Arrayable, Jsonable, JsonSerializable
1423
{
15-
1624
/**
1725
* @param array $properties
1826
*/
@@ -153,6 +161,16 @@ public function toJson($options = 0)
153161
return json_encode($this, $options);
154162
}
155163

164+
/**
165+
* Returns a plain object
166+
*
167+
* @return object|stdClass
168+
*/
169+
public function toObject(): stdClass
170+
{
171+
return json_decode($this->toJson());
172+
}
173+
156174
/**
157175
* @param int $inline
158176
* @param int $indentation

0 commit comments

Comments
 (0)