Skip to content

Commit 72292fa

Browse files
committed
1 parent 6f4e76f commit 72292fa

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

src/RawSpecDataInterface.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (c) 2018 Carsten Brandt <[email protected]> and contributors
5+
* @license https://github.com/cebe/php-openapi/blob/master/LICENSE
6+
*/
7+
8+
namespace cebe\openapi;
9+
10+
/**
11+
* Make raw spec data available to the implementing classes
12+
*/
13+
interface RawSpecDataInterface
14+
{
15+
public function getRawSpecData(): array;
16+
}

src/SpecBaseObject.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
* Implements property management and validation basics.
2121
*
2222
*/
23-
abstract class SpecBaseObject implements SpecObjectInterface, DocumentContextInterface
23+
abstract class SpecBaseObject implements SpecObjectInterface, DocumentContextInterface, RawSpecDataInterface
2424
{
25+
private $_rawSpec;
2526
private $_properties = [];
2627
private $_errors = [];
2728

@@ -63,6 +64,7 @@ abstract protected function performValidation();
6364
*/
6465
public function __construct(array $data)
6566
{
67+
$this->_rawSpec = $data;
6668
foreach ($this->attributes() as $property => $type) {
6769
if (!isset($data[$property])) {
6870
continue;
@@ -525,4 +527,9 @@ public function getExtensions(): array
525527
}
526528
return $extensions;
527529
}
530+
531+
public function getRawSpecData(): array
532+
{
533+
return $this->_rawSpec;
534+
}
528535
}

src/spec/Reference.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@
88
namespace cebe\openapi\spec;
99

1010
use cebe\openapi\DocumentContextInterface;
11-
use cebe\openapi\exceptions\IOException;
1211
use cebe\openapi\exceptions\TypeErrorException;
1312
use cebe\openapi\exceptions\UnresolvableReferenceException;
1413
use cebe\openapi\json\InvalidJsonPointerSyntaxException;
1514
use cebe\openapi\json\JsonPointer;
1615
use cebe\openapi\json\JsonReference;
1716
use cebe\openapi\json\NonexistentJsonPointerReferenceException;
17+
use cebe\openapi\RawSpecDataInterface;
1818
use cebe\openapi\ReferenceContext;
1919
use cebe\openapi\SpecObjectInterface;
20-
use Symfony\Component\Yaml\Yaml;
2120

2221
/**
2322
* Reference Object
@@ -27,8 +26,14 @@
2726
* @link https://tools.ietf.org/html/rfc6901
2827
*
2928
*/
30-
class Reference implements SpecObjectInterface, DocumentContextInterface
29+
class Reference implements SpecObjectInterface, DocumentContextInterface, RawSpecDataInterface
3130
{
31+
/**
32+
* Holds raw spec data
33+
* @var array
34+
*/
35+
private $_rawSpec;
36+
3237
/**
3338
* @var string
3439
*/
@@ -61,11 +66,12 @@ class Reference implements SpecObjectInterface, DocumentContextInterface
6166
/**
6267
* Create an object from spec data.
6368
* @param array $data spec data read from YAML or JSON
64-
* @param string $to class name of the type referenced by this Reference
69+
* @param string|null $to class name of the type referenced by this Reference
6570
* @throws TypeErrorException in case invalid data is supplied.
6671
*/
6772
public function __construct(array $data, string $to = null)
6873
{
74+
$this->_rawSpec = $data;
6975
if (!isset($data['$ref'])) {
7076
throw new TypeErrorException(
7177
"Unable to instantiate Reference Object with data '" . print_r($data, true) . "'."
@@ -402,4 +408,9 @@ public function getDocumentPosition(): ?JsonPointer
402408
{
403409
return $this->_jsonPointer;
404410
}
411+
412+
public function getRawSpecData(): array
413+
{
414+
return $this->_rawSpec;
415+
}
405416
}

0 commit comments

Comments
 (0)