OpenAPITools / OpenAPITools/openapi-generator
[BUG][PHP] oneOf produces type `OneOfModelAModelB` in Model $openAPITypes
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?script-client-produces-a-wrong-object-for-a-string-enum-type-that-is-used-with-ref))
Description
PHP model is generated with OneOfModelAModelB as type for $openAPITypes for
foo:
oneOf:
- $ref: 'modelA'
- $ref: 'modelB'
openapi-generator version
master at 046db19a8590f3557ae1e04be75792bbeb39cb69
Suggest a fix
I think that it would be possible to create a type string like oneOf[ModeA, ModelB] in AbstractPhpCodegen.getTypeDeclaration and then deal with that in deserialiser like is done with map[K, V] types. Ie match the type string to oneOf[there and try to deserialize all the enclosed options until a valid deserialization is found.
If this seems like a legit approach I might be willing to do it as I need some reasonable way to handle this. Or if this has been considered before but the plan lacks implementation that would be something I could do also.
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
Start with AbstractPhpCodegen.getTypeDeclaration and the PHP deserializer, using the provided oneOf specification to reproduce the generated OneOfModelAModelB type. Compare the generated $openAPITypes value with the expected oneOf handling and verify that deserialization works for either referenced model.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, php
- Domain
- devtools, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100