cebe / php-openapi

Read and write OpenAPI yaml/json files and make the content accessible in PHP objects.
MIT License
466 stars 88 forks source link

Fix PathItem::resolveReferences() for array fields #87

Closed rv1971 closed 3 years ago

rv1971 commented 3 years ago

With the previous code $this->$attribute[$k] = $referencedObject, PHP issues Notice: Indirect modification of overloaded property cebe\openapi\spec\PathItem::$parameters has no effect.

The simplest fix I could think of is $this->$attribute = [ $k => $referencedObject ] + $this->$attribute.

cebe commented 3 years ago

Sorry, I don't understand what you are trying to fix here. Would you be able to add failing test case for this?

rv1971 commented 3 years ago

The attached testcase.zip (3 files) is the simplest test case I could derive from my data. If you run php-openapi convert --write-json openapi.json on it, the result is

PHP Notice: Indirect modification of overloaded property cebe\openapi\spec\PathItem::$parameters has no effect in /home/rve/src/php-openapi/src/spec/PathItem.php on line 177 Notice: Indirect modification of overloaded property cebe\openapi\spec\PathItem::$parameters has no effect in /home/rve/src/php-openapi/src/spec/PathItem.php on line 177 { "openapi": "3.0.3", "info": { "title": "Foo", "version": "0.42.0" }, "paths": { "\/foo": { "servers": [], "parameters": [ { "name": "X-Param", "in": "header" } ] } } }

Actually, despite of the notices, the result seems to be correct. To be honest, I did never check the result as such because I think this kind of notices, which suggest there is something wrong in the code, is misleading and should be avoided.

cebe commented 3 years ago

Thank you!