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] Return type broken without properties for php #6566

Open
4 of 6 tasks
neclimdul opened this issue Jun 5, 2020 · 1 comment
Open
4 of 6 tasks

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

neclimdul opened this issue Jun 5, 2020 · 1 comment

Comments

@neclimdul
Copy link
Contributor

neclimdul commented Jun 5, 2020

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.

@neclimdul
Copy link
Contributor Author

Actually finally figured out where this is happening and it seems this is a "feature" introduced in #1315 and #1338.

I'm leaving this open though because I think this is a pretty big bug.

  1. It breaks code alignment with the documentation
  2. Makes API's inconsistent
  3. In my opinion harder to implement additional property behaviors for dynamic objects
  4. It makes the code prone to BC breaks. If the documentation ever adds a single property all signatures break making it a lot harder to support.

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

No branches or pull requests

2 participants