cnizzardini / cakephp-swagger-bake

Automatically generate OpenAPI, Swagger, and Redoc documentation from your existing CakePHP code.
http://cakephpswaggerbake.cnizz.com/
MIT License
60 stars 20 forks source link

Support for MySQL json field type #507

Closed sergioooo closed 1 year ago

sergioooo commented 1 year ago

In case a database table has a column with type json running bin/cake swagger bake will generate an error: [InvalidArgumentException] Schema type of json is invalid. Must be one of: array,boolean,integer,number,object,string, in /opt/repos/oc-be/vendor/cnizzardini/cakephp-swagger-bake/src/Lib/OpenApi/SchemaTrait.php on line 34

Mapping json to object seems to do the trick: src/Lib/OpenApi/SchemaTrait.php: public function setType(string $type) { if($type == 'json') $type = OpenApiDataType::OBJECT; ....

What would be the proper way of achieving this without modifying the plugin source code?

cnizzardini commented 1 year ago

You can submit a PR and I can work with you on getting a release out @sergioooo

cnizzardini commented 1 year ago

I have not use mysql json type in an API before. What is the expected return format? Is it a string or an object?

cnizzardini commented 1 year ago

I played around with this. CakePHP will return whatever type you have in the json column, which can be either object or array. Not exactly sure how to specify that correctly given this is essentially an adhoc field.

cnizzardini commented 1 year ago

@sergioooo See if #511 works in your application. You should be able to test locally by modifying your composer.json with this:

"cnizzardini/cakephp-swagger-bake": "dev-issue/507-json-sql-type",

And then running

composer update cnizzardini/cakephp-swagger-bake
cnizzardini commented 1 year ago

https://github.com/cnizzardini/cakephp-swagger-bake/releases/tag/v2.5.4

sergioooo commented 1 year ago

Man you are fast :D I just tested this and can confirm it works flawlessly. Thx! Great work!

cnizzardini commented 1 year ago

ty np