Skip to content

Commit

Permalink
Merge pull request #873 from fredden/composer-repo-different-sort
Browse files Browse the repository at this point in the history
Sort objects according to the supplied schema
  • Loading branch information
localheinz authored May 2, 2023
2 parents 7a66e58 + c4b3db3 commit c775d80
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ For a full diff see [`4.0.2...main`][4.0.2...main].
### Fixed

- Adjusted `SchemaNormalizer` to account for objects with string and integer-like properties ([#868]), by [@alexis-saransig-lullabot] and [@fredden]
- Adjusted `SchemaNormalizer` to account for objects where schema describes additional properties ([#873]), by [@fredden] and [@localheinz]

## [`4.0.2`][4.0.2]

Expand Down Expand Up @@ -608,6 +609,7 @@ For a full diff see [`5d8b3e2...0.1.0`][5d8b3e2...0.1.0].
[#861]: https://github.com/ergebnis/json-normalizer/pull/861
[#863]: https://github.com/ergebnis/json-normalizer/pull/863
[#868]: https://github.com/ergebnis/json-normalizer/pull/868
[#873]: https://github.com/ergebnis/json-normalizer/pull/873
[#889]: https://github.com/ergebnis/json-normalizer/pull/889

[@alexis-saransig-lullabot]: https://github.com/alexis-saransig-lullabot
Expand Down
10 changes: 10 additions & 0 deletions src/SchemaNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,16 @@ private function normalizeObject(

$valueSchema = new \stdClass();

/**
* @see https://json-schema.org/understanding-json-schema/reference/object.html#additional-properties
*/
if (
\property_exists($schema, 'additionalProperties')
&& \is_object($schema->additionalProperties)
) {
$valueSchema = $schema->additionalProperties;
}

foreach ($additionalProperties as $name => $value) {
$normalized->{$name} = $this->normalizeData(
$value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
"repositories": [
{
"type": "composer",
"url": "http://packages.example.com"
"url": "http://packages.example.com",
"only": [
"example/*"
]
},
{
"type": "composer",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
"homepage": "https://getcomposer.org/doc/04-schema.md#repositories",
"repositories": [
{
"type": "composer",
"url": "http://packages.example.com"
"url": "http://packages.example.com",
"only": [ "example/*" ],
"type": "composer"
},
{
"type": "composer",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
"repositories": {
"foo": {
"type": "composer",
"url": "http://packages.foo.com"
"url": "http://packages.foo.com",
"only": [
"foo/*"
]
},
"bar": {
"type": "composer",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
"homepage": "https://getcomposer.org/doc/04-schema.md#repositories",
"repositories": {
"foo": {
"type": "composer",
"url": "http://packages.foo.com"
"url": "http://packages.foo.com",
"only": [ "foo/*" ],
"type": "composer"
},
"bar": {
"type": "composer",
Expand Down

0 comments on commit c775d80

Please sign in to comment.