Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #10575
Closed
Open
Issue created Oct 10, 2021 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

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

Created by: NickUfer

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: https://github.com/OpenAPITools/openapi-generator/blob/1d648223e6fdc1adad8967db05d86db9fc49a581/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache#L323-L327

Generated Line: https://github.com/OpenAPITools/openapi-generator/blob/1d648223e6fdc1adad8967db05d86db9fc49a581/samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php#L332-L336

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

https://github.com/OpenAPITools/openapi-generator/pull/10576

Suggest a fix

https://github.com/OpenAPITools/openapi-generator/pull/10576

Assignee
Assign to
Time tracking