Skip to content

[BUG] [PHP] Response models not using namespaces #3136

Description

@darren-potter

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

Some of the PHP code generated by the openapi-generator seems to be references response models incorrectly, resulting in classes not being found.

openapi-generator version

I am using version 4.0.1 on the openapi-generator on Mac OS 10.14.5.

OpenAPI declaration file content or url
    200UserAuthenticatedResponse:
      description: Successful user login response
      headers:
        X-Request-Id:
          $ref: "#/components/headers/X-Request-Id"
      content:
        application/json:
          schema:
            allOf:
              - $ref: "#/components/schemas/ApiResponseCommonValues"
              - type: object
                required:
                  - details
                properties:
                  details:
                    $ref: "#/components/schemas/LoginAuthenticatedResponse"
            switch($statusCode) {
                case 200:
                    if ('ApiResponseCommonValues' === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                    }

                    return [
                        ObjectSerializer::deserialize($content, 'ApiResponseCommonValues', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 400:
                    if ('\TheSupportGroup\easyfundraising\ApiClient\Model\ApiBadResponseError' === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\TheSupportGroup\easyfundraising\ApiClient\Model\ApiBadResponseError', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 401:
                    if ('\TheSupportGroup\easyfundraising\ApiClient\Model\ApiBadResponseError' === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\TheSupportGroup\easyfundraising\ApiClient\Model\ApiBadResponseError', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 404:
                    if ('\TheSupportGroup\easyfundraising\ApiClient\Model\ApiSimpleResponseError' === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\TheSupportGroup\easyfundraising\ApiClient\Model\ApiSimpleResponseError', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
                case 500:
                    if ('\TheSupportGroup\easyfundraising\ApiClient\Model\ApiResponseError' === '\SplFileObject') {
                        $content = $responseBody; //stream goes to serializer
                    } else {
                        $content = $responseBody->getContents();
                    }

                    return [
                        ObjectSerializer::deserialize($content, '\TheSupportGroup\easyfundraising\ApiClient\Model\ApiResponseError', []),
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
            }

Many of the response models are ok, but the reference to ApiResponseCommonValues is invalid. The class should be references as '\TheSupportGroup\easyfundraising\ApiClient\Model\ApiResponseCommonValues' the same way as all other response models.

Command line used for generation

docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli generate
-i /local/openapi.yaml
-g php
-o /local/out/php
--skip-validate-spec
--package-name "easyfundraising APIv3 PHP Client"
--invoker-package TheSupportGroup\easyfundraising\ApiClient
--additional-properties variableNamingConvention=camelCase

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions