Skip to content

Commit

Permalink
Merge pull request #4 from 77web/fix-object-serializer
Browse files Browse the repository at this point in the history
fixed ObjectSerializer template when requesting Enum values
  • Loading branch information
77web committed May 18, 2022
2 parents 72b18ce + 3562942 commit 0b53a9e
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions templates/ObjectSerializer.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,9 @@ class ObjectSerializer
$getter = $data::getters()[$property];
$value = $data->$getter();
if ($value !== null && !in_array($openAPIType, [{{&primitives}}], true)) {
$callable = [$openAPIType, 'getAllowableEnumValues'];
if (is_callable($callable)) {
/** array $callable */
$allowedEnumTypes = $callable();
if (!in_array($value, $allowedEnumTypes, true)) {
if (enum_exists($openAPIType) && $value instanceof \BackedEnum) {
if (!is_a($value, $openAPIType)) {
$allowedEnumTypes = call_user_func([$openAPIType, 'getAllowedEnumValues']);
$imploded = implode("', '", $allowedEnumTypes);
throw new \InvalidArgumentException("Invalid value for enum '$openAPIType', must be one of: '$imploded'");
}
Expand Down

0 comments on commit 0b53a9e

Please sign in to comment.