Skip to content

Commit 6e81df1

Browse files
committed
fixed cyclic reference
1 parent ad20c68 commit 6e81df1

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/Schema.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ class Schema extends ObjectItem
3131

3232
/*
3333
public $__seqId;
34+
public static $seq = 0;
3435
3536
public function __construct()
3637
{
37-
static $seq = 0;
38-
$seq++;
39-
$this->__seqId = $seq;
38+
self::$seq++;
39+
$this->__seqId = self::$seq;
4040
}
41-
*/
41+
//*/
4242

4343
/** @var Type */
4444
public $type;
@@ -392,14 +392,17 @@ public function process($data, ProcessingOptions $options, $path = '#', $result
392392
});
393393
$ref = $options->refResolver->resolveReference($refString);
394394
if ($ref->isImported()) {
395-
return $ref->getImported();
395+
$refResult = $ref->getImported();
396+
return $refResult;
396397
}
397398
$data = $ref->getData();
398399
if ($result instanceof Schema) {
399400
$result->fromRef = $refString;
400401
}
401402
$ref->setImported($result);
402-
return $this->process($data, $options, $path . '->ref:' . $refString, $result);
403+
$refResult = $this->process($data, $options, $path . '->ref:' . $refString, $result);
404+
$ref->setImported($refResult);
405+
return $refResult;
403406
}
404407
} catch (InvalidValue $exception) {
405408
$this->fail($exception, $path);
@@ -507,7 +510,7 @@ public function process($data, ProcessingOptions $options, $path = '#', $result
507510
$this->fail(new ObjectException('Additional properties not allowed'), $path . ':' . $key);
508511
}
509512

510-
$value = $this->additionalProperties->process($value, $options, $path . '->additionalProperties');
513+
$value = $this->additionalProperties->process($value, $options, $path . '->additionalProperties:' . $key);
511514
if ($import && !$this->useObjectAsArray) {
512515
$result->addAdditionalPropertyName($key);
513516
}

tests/src/PHPUnit/Swagger/SwaggerTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ public function testReadSwaggerSchema()
2121
$options->setRemoteRefProvider($refProvider);
2222

2323
$schema = JsonSchema::importToSchema($schemaData, $options);
24+
$ts = $schema->definitions['header']->properties['maximum'];
25+
$max = $schema->definitions['maximum'];
26+
$this->assertSame('number', $ts->type);
27+
2428

2529
$swaggerData = json_decode(file_get_contents(__DIR__ . '/../../../../spec/petstore-swagger.json'));
2630
$petstore = $schema->import($swaggerData);

0 commit comments

Comments
 (0)