php-json-schema-model-generator icon indicating copy to clipboard operation
php-json-schema-model-generator copied to clipboard

Inconsistency of generated code when using different methods to declare nullable structures

Open dktapps opened this issue 4 years ago • 1 comments

Describe the bug

The following diff:

diff --git a/schema/PluginListYml.json b/schema/PluginListYml.json
index 4500662..7d5fdea 100644
--- a/schema/PluginListYml.json
+++ b/schema/PluginListYml.json
@@ -14,17 +14,13 @@
                        "description": "The listed plugins will either be allowed or disallowed based on this setting"
                },
                "plugins": {
-                       "anyOf": [
-                               {
-                                       "type": "array",
-                                       "items": {
-                                               "type": "string"
-                                       }
-                               },
-                               {
-                                       "type": "null"
-                               }
+                       "type": [
+                               "array",
+                               "null"
                        ],
+                       "items": {
+                               "type": "string"
+                       },
                        "default": [],
                        "description": "List of plugins to allow or disallow"
                }

produces the following change: https://github.com/pmmp/DataModels/commit/46eab454f5e3c2498f3a84e8065ed9702f27a58f

You can see that there's much less generated code for some reason, but what bothers me more is that the ?array native types disappeared from both getters and setters.

Expected behavior The code should be the same in both cases, since they are semantically equivalent to the best of my understanding.

However, more importantly, the native types should not be missing after the change: the calculated types are exactly the same.

Schema https://github.com/pmmp/DataModels/blob/46eab454f5e3c2498f3a84e8065ed9702f27a58f/schema/PluginListYml.json

https://github.com/pmmp/DataModels/blob/46eab454f5e3c2498f3a84e8065ed9702f27a58f/generate-schemas.php

Version: 0.12.7.

dktapps avatar Nov 15 '21 23:11 dktapps

see https://github.com/wol-soft/php-json-schema-model-generator/issues/50#issuecomment-981798975

wol-soft avatar Nov 29 '21 16:11 wol-soft