DoclerLabs / api-client-generator

API client generator is a console application capable of generating an API client based on OpenAPI(Swagger) specification.
MIT License
34 stars 19 forks source link

Fix nullable issue #41

Closed vabalazs82 closed 3 years ago

vabalazs82 commented 3 years ago

Dear all,

When the schema`s property is nullable=true and the data which comes is null, then we have Argument 1 passed to ...Mapper::toSchema() must be of the type array, null given

Please check it.

vsouz4 commented 3 years ago

@vabalazs82 can you please provide an example? An yaml perhaps, bc we do have some tests with nullable properties which are working fine but maybe we're not covering this specific use case...

vabalazs82 commented 3 years ago

The config like this:

` TestSchema1: type: object required:

TestSchema4: type: object nullable: true properties: id: type: string required: -id

The http response contains : testProp4: null

JasonBenett commented 3 years ago

Hello @vabalazs82 Currently, if a schema property is nullable, we just don't define it as "required". As a quick solution this is what you should probably do imo. But you are right, we should probably handle this case too.

vsouz4 commented 3 years ago

Ok, indeed I'm able to reproduce it, here's the faulty generated code:

    public function toSchema(array $payload): TestSchema1
    {
...
        return new TestSchema1($this->testProp4Mapper->toSchema($payload['testProp4']));
    }

and

    /**
     * @throws UnexpectedResponseBodyException
     *
     * @return TestSchema4
     */
    public function toSchema(array $payload): ?TestSchema4
    {
...

checking how we can fix it

vabalazs82 commented 3 years ago

thanks