OpenAPITools / OpenAPITools/openapi-generator
[BUG] Return type broken without properties for php
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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
- generate code
- see object set as return type.
Related issues/PRs
?
Suggest a fix
Always return the documented model.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the provided Docker generation command and simplified OpenAPI definition, then trace how the PHP generator derives returnType for the ModelResponse schema. Check the generated docs and APIs; done means a schema without properties still uses the documented ModelResponse model rather than object.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100