Skip to content
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

[BUG][PHP] settype(): Argument #2 ($type) must be a valid type #10575

Closed
5 of 6 tasks
NickUfer opened this issue Oct 10, 2021 · 0 comments · Fixed by #10576
Closed
5 of 6 tasks

[BUG][PHP] settype(): Argument #2 ($type) must be a valid type #10575

NickUfer opened this issue Oct 10, 2021 · 0 comments · Fixed by #10576

Comments

@NickUfer
Copy link
Contributor

NickUfer commented Oct 10, 2021

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

The PHP generator sets a field type as mixed when the field can be one of at least 2 types. As seen in the following with value.

https://github.com/ory/kratos-client-php/blob/e072b3b5bd5abdde83b4197aae0ba87a79e44cb1/lib/Model/UiNodeAttributes.php#L62-L74

protected static $openAPITypes = [
    'disabled' => 'bool',
    'label' => '\Ory\Kratos\Client\Model\UiText',
    'name' => 'string',
    'pattern' => 'string',
    'required' => 'bool',
    'type' => 'string',
    'value' => 'mixed', <----- ## HERE ##
    'text' => '\Ory\Kratos\Client\Model\UiText',
    'src' => 'string',
    'href' => 'string',
    'title' => '\Ory\Kratos\Client\Model\UiText'
];

Here value can be one of these values.. string, number or boolean -> the generator makes it a mixed:

https://github.com/ory/kratos/blob/e3cf3da357dfbaa64181d7bfbfe42d1f00b6ef7b/.schema/openapi.json#L1080-L1096
https://github.com/ory/kratos/blob/e3cf3da357dfbaa64181d7bfbfe42d1f00b6ef7b/.schema/openapi.json#L1141-L1155

[...]
"value": {
  "description": "The input's value.",
  "nullable": true,
  "oneOf": [
    {
      "type": "string"
    },
    {
      "type": "number"
    },
    {
      "type": "boolean"
    }
  ]
}
[...]

Later in the generated ObjectSerializer it tries to use settype() for the current data with type mixed, but mixed is not valid for settype() and it never was valid for it either. I don't know how that code came in here. https://www.php.net/manual/en/function.settype.php#refsect1-function.settype-parameters

Line:

/** @psalm-suppress ParadoxicalCondition */
if (in_array($class, [{{&primitives}}], true)) {
settype($data, $class);
return $data;
}

Generated Line:

/** @psalm-suppress ParadoxicalCondition */
if (in_array($class, ['DateTime', 'bool', 'boolean', 'byte', 'double', 'float', 'int', 'integer', 'mixed', 'number', 'object', 'string', 'void'], true)) {
settype($data, $class);
return $data;
}

When he tries to use settype(<value of field 'value'>, 'mixed') it fails with:

settype(): Argument #2 ($type) must be a valid type

Because mixed is not a valid type: https://www.php.net/manual/en/function.settype.php#refsect1-function.settype-parameters

openapi-generator version

5.2.1

OpenAPI declaration file content or url

https://github.com/ory/kratos/blob/master/.schema/openapi.json

Generation Details
Steps to reproduce
Related issues/PRs

#10576

Suggest a fix

#10576

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant