OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.8k stars 6.58k forks source link

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

Open sakari opened 5 years ago

sakari commented 5 years ago

Bug Report Checklist

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.

wing328 commented 5 years ago

@sakari thanks for offering help. Sure we can work together on that. Do you mind pinging me via https://gitter.im (ID: wing328) so that we can come up with a plan to add the support of oneOf (and potentially anyOf)?

jeffski commented 5 years ago

I'm running in to this problem also. For now the only way around it is for me to manually update the generated code (not a long term solution). In my situation if the generator could do this for me that would be great, not sure if this is the correct approach globally though.

Here is the work around that I put in place in my generated SDK: https://github.com/shotstack/shotstack-sdk-php/pull/2/commits/37770909704f162c359d4b241deceff33604091e

I added a parent type (Asset) and then have 3 classes (my oneOf types) extend the parent type (TitleAsset, ImageAsset and VideoAsset). In the Clip type I replaced the OneOfTitleAssetImageAssetVideoAsset type with my new class \Shotstack\Client\Model\Asset.

ksvirkou-hubspot commented 3 years ago

Hi everyone We have the same issue generator version is 5.1.0

compwright commented 2 years ago

Ditto, running into this here. v5.4.0

rderocle-gsoi commented 7 months ago

any news on the subject ? bug still present in v7.4.0

etshy commented 3 months ago

Any news on this ? After a change in nelmio/api-doc-bundle all allOf changed to oneOf ( nelmio/NelmioApiDocBundle#2156 ) and this messed up our typeHinting because of class name changes (with the same json expect for the allOf changed tooneOf of course)

For example, a class TwoDto used in property two in another OneDto class

class OneDto
{
    private ?TwoDto $two = null;
}

Generated with allOf will be : \App\My\Client\TwoDto and the same class generated with oneOf will be \App\My\Client\OneDtoTwo