-
Notifications
You must be signed in to change notification settings - Fork 96
Resolve: Better way to resolve allOf #208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SOHELAHMED7
wants to merge
24
commits into
cebe:master
Choose a base branch
from
SOHELAHMED7:165-better-way-to-resolve-allof
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
2984dc1
Tooling: dynamic container name to remove confusion created by multip…
SOHELAHMED7 b111f49
Tooling: dynamic container name to remove confusion created by multip…
SOHELAHMED7 27e2618
Remove Composer dev dependencies apis-guru/openapi-directory, nexmo/a…
SOHELAHMED7 b4c19c7
Temporary remove old PHPUnit config
SOHELAHMED7 bffeea7
Add failing test
SOHELAHMED7 99dd8be
Implement
SOHELAHMED7 35a9f90
Refactor + fix bug WIP
SOHELAHMED7 f5a6472
Fix bug related to improper array merging
SOHELAHMED7 a9b2dbd
Refactor and add more tests
SOHELAHMED7 b5c87a4
Refactor
SOHELAHMED7 fc75f0b
Add docs and tests
SOHELAHMED7 9805713
Add docs and fix bugs
SOHELAHMED7 a3a6421
Implement for JSON
SOHELAHMED7 b28249f
Revert "Remove Composer dev dependencies apis-guru/openapi-directory,…
SOHELAHMED7 74a7e03
Revert "Temporary remove old PHPUnit config"
SOHELAHMED7 d83af16
Mange TODOs
SOHELAHMED7 15faaba
Delete TODOs file
SOHELAHMED7 b68d0d1
Add a test for `description` for https://github.com/php-openapi/yii2-…
SOHELAHMED7 8698470
Add more tests
SOHELAHMED7 81ee4ed
Move `arrayMergeRecursiveDistinct()` to separate helper class
SOHELAHMED7 0bc15f5
Add test case explaining recursion in resolving `allOf`
SOHELAHMED7 8513118
Update src/SpecBaseObject.php. PR feedback
SOHELAHMED7 a95c9d1
Update src/SpecBaseObject.php. PR feedback
SOHELAHMED7 00e4669
Update src/SpecBaseObject.php. PR feedback
SOHELAHMED7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ | |
/.phpunit.result.cache | ||
|
||
php-cs-fixer.phar | ||
xdebug_remote.log |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
### array merge recursive distinct | ||
|
||
While resolving `allOf`s (pull request https://github.com/cebe/php-openapi/pull/208), if a duplicate property is found | ||
|
||
```yaml | ||
components: | ||
schemas: | ||
User: | ||
type: object | ||
required: | ||
- id | ||
- name # <-------------------------------------------------------------- | ||
properties: | ||
id: | ||
type: integer | ||
name: # <-------------------------------------------------------------- | ||
type: string | ||
maxLength: 10 # <-------------------------------------------------------------- | ||
Pet: | ||
type: object | ||
required: | ||
- id2 | ||
- name # <-------------------------------------------------------------- | ||
properties: | ||
id2: | ||
type: integer | ||
name: # <-------------------------------------------------------------- | ||
type: string | ||
maxLength: 12 # <-------------------------------------------------------------- | ||
Post: | ||
type: object | ||
properties: | ||
id: | ||
type: integer | ||
content: | ||
type: string | ||
user: | ||
allOf: | ||
- $ref: '#/components/schemas/User' | ||
- $ref: '#/components/schemas/Pet' | ||
- x-faker: true | ||
``` | ||
|
||
then property from the last component schema will be considered: | ||
|
||
```yaml | ||
Post: | ||
type: object | ||
properties: | ||
id: | ||
type: integer | ||
content: | ||
type: string | ||
user: | ||
type: object | ||
required: | ||
- id | ||
- name # <-------------------------------------------------------------- | ||
- id2 | ||
properties: | ||
id: | ||
type: integer | ||
name: # <-------------------------------------------------------------- | ||
type: string | ||
maxLength: 12 # <-------------------------------------------------------------- | ||
id2: | ||
type: integer | ||
x-faker: true | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (c) 2018 Carsten Brandt <mail@cebe.cc> and contributors | ||
* @license https://github.com/cebe/php-openapi/blob/master/LICENSE | ||
*/ | ||
|
||
namespace cebe\openapi; | ||
|
||
/** | ||
* Helper class containing widely used custom functions used in library | ||
*/ | ||
class Helper | ||
{ | ||
/** | ||
* Thanks https://www.php.net/manual/en/function.array-merge-recursive.php#96201 | ||
* | ||
* Merges any number of arrays / parameters recursively, replacing | ||
* entries with string keys with values from latter arrays. | ||
* If the entry or the next value to be assigned is an array, then it | ||
* automagically treats both arguments as an array. | ||
* Numeric entries are appended, not replaced, but only if they are | ||
* unique | ||
* | ||
* Function call example: `$result = array_merge_recursive_distinct(a1, a2, ... aN);` | ||
* More documentation is present at [array merge recursive distinct.md](../../../doc/array merge recursive distinct.md) file | ||
* @return array | ||
*/ | ||
public static function arrayMergeRecursiveDistinct() | ||
{ | ||
$arrays = func_get_args(); | ||
$base = array_shift($arrays); | ||
if (!is_array($base)) { | ||
$base = empty($base) ? [] : [$base]; | ||
} | ||
foreach ($arrays as $append) { | ||
if (!is_array($append)) { | ||
$append = [$append]; | ||
} | ||
foreach ($append as $key => $value) { | ||
if (!array_key_exists($key, $base) and !is_numeric($key)) { | ||
$base[$key] = $append[$key]; | ||
continue; | ||
} | ||
if (is_array($value) || is_array($base[$key])) { | ||
$base[$key] = static::arrayMergeRecursiveDistinct($base[$key], $append[$key]); | ||
} elseif (is_numeric($key)) { | ||
if (!in_array($value, $base)) { | ||
$base[] = $value; | ||
} | ||
} else { | ||
$base[$key] = $value; | ||
} | ||
} | ||
} | ||
return $base; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.