Skip to content

Request for help serializing union types #81

@gijs-blanken

Description

@gijs-blanken

Hi!

I'm currently working on rewriting the PHP Laravel OpenAPI generator (merge request here). I was planning on using this package to handle serialization and deserialization. However, I'm running into an issue and I was hoping you could help me!

I am generating classes such as this one for OpenAPI schemas which specify an oneOf.

#[Serde\ClassSettings(renameWith: Cases::snake_case)]
class GetClientProducts200Response
{
    public function __construct(
        public \OpenAPI\Server\Model\ClientProduct|\OpenAPI\Server\Model\ClientCustomPackage $getClientProducts200ResponseInner,
    ) {}
}

And in my generated controller I will then try and serialize it using Serde:

if ($apiResult instanceof \OpenAPI\Server\Model\GetClientProducts200Response) {
    return response()->json($this->serde->serialize($apiResult, format: 'array'), 200);
}

However, Serde currently does not support serializing union types. Could you think of a workaround for this use case? I'd really like to use this package in the generator.

Thanks in advance!
Gijs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions