Skip to content

Add a deserialized Data Validator #6770

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
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -339,4 +339,29 @@ class ObjectSerializer
return $instance;
}
}

/**
* Verify the Data structure to make sure all the objects are validated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code seems to be using tabs? Spaces are used elsewhere.

* @param mided $data object to be validated
* @throws \InvalidArgumentException
*/
public static function verifyDeserializedData ($data) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about the design here: the data needs to be valid enough for the deserialization to take place. If that already happened, ObjectSerializer has nothing to do with it.

if (is_object ($data) && $data instanceof {{invokerPackage}}\Model\ModelInterface) {
$a_invalidProperties = $data->listInvalidProperties();

if (count($a_invalidProperties) != 0) {
throw new \InvalidArgumentException(implode (' ', $a_invalidProperties));
}

foreach($data->getters() as $sProperty => &$sGetter) {
self::verifyDeserializedData($data->{$sGetter}());
}

}
else if (is_array ($data)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline with previous closing brace.

foreach ($data as &$item) {
self::verifyDeserializedData($item);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -349,4 +349,29 @@ public static function deserialize($data, $class, $httpHeaders = null)
return $instance;
}
}

/**
* Verify the Data structure to make sure all the objects are validated
* @param mided $data object to be validated
* @throws \InvalidArgumentException
*/
public static function verifyDeserializedData ($data) {
if (is_object ($data) && $data instanceof OpenAPI\Client\Model\ModelInterface) {
$a_invalidProperties = $data->listInvalidProperties();

if (count($a_invalidProperties) != 0) {
throw new \InvalidArgumentException(implode (' ', $a_invalidProperties));
}

foreach($data->getters() as $sProperty => &$sGetter) {
self::verifyDeserializedData($data->{$sGetter}());
}

}
else if (is_array ($data)) {
foreach ($data as &$item) {
self::verifyDeserializedData($item);
}
}
}
}