Skip to content

Commit 45daa74

Browse files
committed
reading swagger
1 parent b546d7a commit 45daa74

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/Schema.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,13 @@ public function process($data, ProcessingOptions $options, $path = '#', $result
347347

348348

349349
if ($data instanceof \stdClass) {
350+
if ($this->required !== null) {
351+
foreach ($this->required as $item) {
352+
if (!property_exists($data, $item)) {
353+
$this->fail(new ObjectException('Required property missing: ' . $item, ObjectException::REQUIRED), $path);
354+
}
355+
}
356+
}
350357

351358
if ($import) {
352359
if ($this->useObjectAsArray) {
@@ -411,15 +418,6 @@ public function process($data, ProcessingOptions $options, $path = '#', $result
411418
});
412419
}
413420

414-
415-
if ($this->required !== null) {
416-
foreach ($this->required as $item) {
417-
if (!property_exists($data, $item)) {
418-
$this->fail(new ObjectException('Required property missing: ' . $item, ObjectException::REQUIRED), $path);
419-
}
420-
}
421-
}
422-
423421
if ($this->properties !== null) {
424422
/** @var Schema[] $properties */
425423
$properties = &$this->properties->toArray(); // TODO check performance of pointer

tests/src/PHPUnit/Swagger/SwaggerTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ public function testReadSwaggerSchema()
2020
$options = new ProcessingOptions();
2121
$options->setRemoteRefProvider($refProvider);
2222

23-
2423
$schema = JsonSchema::importToSchema($schemaData, $options);
24+
25+
$swaggerData = json_decode(file_get_contents(__DIR__ . '/../../../../spec/petstore-swagger.json'));
26+
$petstore = $schema->import($swaggerData);
2527
}
2628

2729
}

0 commit comments

Comments
 (0)