Skip to content

Commit 4ba42aa

Browse files
Don't skip ref expanding for property called enum when child of property called properties (#851)
This PR will: - No longer skip ref expanding for a property called `enum` if the parent property is called `properties`. This is used in the open api spec. - Remove test from skipping which are passing and skipping is no longer needed. - Resolves #849 --------- Co-authored-by: Dezső BICZÓ <mxr576@users.noreply.github.com>
1 parent cf4f130 commit 4ba42aa

File tree

4 files changed

+10
-32
lines changed

4 files changed

+10
-32
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## [Unreleased]
99
### Changed
1010
- Rename master to main ([#848](https://github.com/jsonrainbow/json-schema/pull/848))
11+
### Fixed
12+
- Don't skip ref expanding for property called enum when child of property called properties ([#851](https://github.com/jsonrainbow/json-schema/pull/851))
1113

1214
## [6.6.0] - 2025-10-10
1315
### Added

src/JsonSchema/SchemaStorage.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@ public function addSchema(string $id, $schema = null): void
8181
/**
8282
* Recursively resolve all references against the provided base
8383
*
84-
* @param mixed $schema
84+
* @param mixed $schema
85+
* @param list<string> $propertyStack
8586
*/
86-
private function expandRefs(&$schema, ?string $parentId = null): void
87+
private function expandRefs(&$schema, ?string $parentId = null, array $propertyStack = []): void
8788
{
8889
if (!is_object($schema)) {
8990
if (is_array($schema)) {
@@ -100,8 +101,9 @@ private function expandRefs(&$schema, ?string $parentId = null): void
100101
$schema->{'$ref'} = (string) $refPointer;
101102
}
102103

104+
$parentProperty = array_slice($propertyStack, -1)[0] ?? '';
103105
foreach ($schema as $propertyName => &$member) {
104-
if (in_array($propertyName, ['enum', 'const'])) {
106+
if ($parentProperty !== 'properties' && in_array($propertyName, ['enum', 'const'])) {
105107
// Enum and const don't allow $ref as a keyword, see https://github.com/json-schema-org/JSON-Schema-Test-Suite/pull/445
106108
continue;
107109
}
@@ -112,7 +114,9 @@ private function expandRefs(&$schema, ?string $parentId = null): void
112114
$childId = $this->uriResolver->resolve($schemaId, $childId);
113115
}
114116

115-
$this->expandRefs($member, $childId);
117+
$clonedPropertyStack = $propertyStack;
118+
$clonedPropertyStack[] = $propertyName;
119+
$this->expandRefs($member, $childId, $clonedPropertyStack);
116120
}
117121
}
118122

tests/Drafts/Draft3Test.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,7 @@ protected function getFilePaths(): array
7878

7979
public function getInvalidTests(): \Generator
8080
{
81-
$skip = [
82-
'ref.json / $ref prevents a sibling id from changing the base uri / $ref resolves to /definitions/base_foo, data does not validate'
83-
];
84-
8581
foreach (parent::getInvalidTests() as $name => $testcase) {
86-
if (in_array($name, $skip, true)) {
87-
continue;
88-
}
8982
yield $name => $testcase;
9083
}
9184
}
@@ -107,15 +100,7 @@ public function getInvalidForAssocTests(): \Generator
107100

108101
public function getValidForAssocTests(): \Generator
109102
{
110-
$skip = [
111-
'type.json / object type matches objects / an array is not an object',
112-
'type.json / array type matches arrays / an object is not an array',
113-
];
114-
115103
foreach (parent::getValidForAssocTests() as $name => $testcase) {
116-
if (in_array($name, $skip, true)) {
117-
continue;
118-
}
119104
yield $name => $testcase;
120105
}
121106
}
@@ -129,8 +114,6 @@ protected function getSkippedTests(): array
129114
// Optional
130115
'bignum.json',
131116
'ecmascript-regex.json',
132-
'format.json',
133-
'jsregex.json',
134117
'zeroTerminatedFloats.json'
135118
];
136119
}

tests/Drafts/Draft4Test.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,8 @@ protected function getFilePaths(): array
2323
public function getInvalidTests(): \Generator
2424
{
2525
$skip = [
26-
'id.json / id inside an enum is not a real identifier / no match on enum or $ref to id',
27-
'ref.json / $ref prevents a sibling id from changing the base uri / $ref resolves to /definitions/base_foo, data does not validate',
28-
'ref.json / Recursive references between schemas / invalid tree',
29-
'ref.json / refs with quote / object with strings is invalid',
3026
'ref.json / Location-independent identifier / mismatch',
3127
'ref.json / Location-independent identifier with base URI change in subschema / mismatch',
32-
'ref.json / empty tokens in $ref json-pointer / non-number is invalid',
3328
'ref.json / id must be resolved against nearest parent, not just immediate parent / non-number is invalid',
3429
'refRemote.json / Location-independent identifier in remote ref / string is invalid',
3530
'refRemote.json / base URI change - change folder / string is invalid'
@@ -46,7 +41,6 @@ public function getInvalidTests(): \Generator
4641
public function getInvalidForAssocTests(): \Generator
4742
{
4843
$skip = [
49-
'ref.json / Recursive references between schemas / valid tree',
5044
'type.json / object type matches objects / an array is not an object',
5145
'type.json / array type matches arrays / an object is not an array',
5246
];
@@ -62,13 +56,8 @@ public function getInvalidForAssocTests(): \Generator
6256
public function getValidTests(): \Generator
6357
{
6458
$skip = [
65-
'ref.json / $ref prevents a sibling id from changing the base uri / $ref resolves to /definitions/base_foo, data validates',
66-
'ref.json / Recursive references between schemas / valid tree',
67-
'ref.json / refs with quote / object with numbers is valid',
6859
'ref.json / Location-independent identifier / match',
6960
'ref.json / Location-independent identifier with base URI change in subschema / match',
70-
'ref.json / empty tokens in $ref json-pointer / number is valid',
71-
'ref.json / naive replacement of $ref with its destination is not correct / match the enum exactly',
7261
'ref.json / id must be resolved against nearest parent, not just immediate parent / number is valid',
7362
'refRemote.json / Location-independent identifier in remote ref / integer is valid',
7463
'refRemote.json / base URI change - change folder / number is valid',

0 commit comments

Comments
 (0)