Skip to content

[BUG] Return type broken without properties for php #6566

Open
@neclimdul

Description

@neclimdul

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

When generating code from a spec that has a schema definition without properties, something is converting it to a generic object. I'm not sure if this affects other generators or just PHP.

This causes a problem for me generating code for Marketo's API which does this. Many of their Schema's are dynamic and populated with fields from your custom objects. This doesn't "work" out of the box with codegen but its not difficult at least in PHP to modify the model interfaces and Serialization to support this. It also looks like #6290 is starting to add this as a generic feature fixing this might be a requirement for supporting edge cases in that.

By flatting it like this though it becomes much more difficult because there isn't a model. Additionally this isn't ideal because the code diverges from the openapi documentation.

For example. in the 3.x branch the return looks like this:
* @return \OpenAPI\Client\Model\ModelResponse
in 4.x and beyond it looks like this:
* @return object

This is the value in returnType so its in docs, apis, etc and can't be fixed in a templates.

openapi-generator version

v4.0.0+

Tested with docker versions v3.3.4, 4.0.0, 4.3.1, and latest. it seems to exist in all releases after v4.0.0

OpenAPI declaration file content

ModelResponse object on https://developers.marketo.com/swagger/swagger-asset.json

Simplified.

swagger: '2.0'
info:
  title: test
  version: 1.0.0
consumes:
  - application/json
produces:
  - application/json
paths: 
  /person:
    post:
      operationId: createPerson
      responses:
        200:
          description: "Success"
          schema:
            "$ref": "#/definitions/ModelResponse"
definitions:
  ModelResponse:
    type: object
Command line used for generation
docker run --rm -v ${PWD}:/local/ openapitools/openapi-generator-cli:v4.3.1 generate \
    -i /local/object_bug.yaml -g php -o /local/.build 
Steps to reproduce
  1. generate code
  2. see object set as return type.
Related issues/PRs

?

Suggest a fix

Always return the documented model.

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