OpenAPITools / OpenAPITools/openapi-generator

[BUG][PHP] oneOf produces type `OneOfModelAModelB` in Model $openAPITypes

Open
#2,011 6 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: PHP Feature: OAS 3.0 spec support Issue: Bug
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.