From 489985d3be058757099b5d60ba02aa29a4cf617b Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Thu, 30 Apr 2020 12:34:56 -0700 Subject: [PATCH 01/48] Handle null type --- .../codegen/languages/PythonClientExperimentalCodegen.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java index 60a004b6bea8..5243a25c193a 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java @@ -897,6 +897,9 @@ public String getTypeString(Schema p, String prefix, String suffix) { if (")".equals(suffix)) { fullSuffix = "," + suffix; } + if (ModelUtils.isNullType(p)) { + return "none_type" + suffix; + } // Resolve $ref because ModelUtils.isXYZ methods do not automatically resolve references. if (ModelUtils.isNullable(ModelUtils.getReferencedSchema(this.openAPI, p))) { fullSuffix = ", none_type" + suffix; From c16089e080edc1baa529068a5a09fef3850778c1 Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Thu, 30 Apr 2020 13:54:12 -0700 Subject: [PATCH 02/48] Handle null type --- .../openapitools/codegen/languages/PythonClientCodegen.java | 1 + .../codegen/languages/PythonClientExperimentalCodegen.java | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java index 74796111afd9..a7e186c3735a 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java @@ -143,6 +143,7 @@ public PythonClientCodegen() { // map uuid to string for the time being typeMapping.put("UUID", "str"); typeMapping.put("URI", "str"); + typeMapping.put("null", "none_type"); // from https://docs.python.org/3/reference/lexical_analysis.html#keywords setReservedWordsLowerCase( diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java index 5243a25c193a..60a004b6bea8 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java @@ -897,9 +897,6 @@ public String getTypeString(Schema p, String prefix, String suffix) { if (")".equals(suffix)) { fullSuffix = "," + suffix; } - if (ModelUtils.isNullType(p)) { - return "none_type" + suffix; - } // Resolve $ref because ModelUtils.isXYZ methods do not automatically resolve references. if (ModelUtils.isNullable(ModelUtils.getReferencedSchema(this.openAPI, p))) { fullSuffix = ", none_type" + suffix; From 26865b3f58281b479609fd7826fe58166451d17b Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Thu, 30 Apr 2020 14:09:57 -0700 Subject: [PATCH 03/48] Handle null type. Add 'null' type in the OAS document for testing purpose --- ...ke-endpoints-models-for-testing-with-http-signature.yaml | 1 + .../petstore/go-experimental/go-petstore/api/openapi.yaml | 1 + .../petstore/go-experimental/go-petstore/model_fruit_req.go | 6 ++++++ .../python-experimental/petstore_api/models/fruit_req.py | 6 ++++++ 4 files changed, 14 insertions(+) diff --git a/modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml b/modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml index 74598c6ce709..69633315c6c6 100644 --- a/modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml @@ -1855,6 +1855,7 @@ components: - $ref: '#/components/schemas/banana' fruitReq: oneOf: + - type: 'null' - $ref: '#/components/schemas/appleReq' - $ref: '#/components/schemas/bananaReq' appleReq: diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/api/openapi.yaml b/samples/openapi3/client/petstore/go-experimental/go-petstore/api/openapi.yaml index 8f1a907787d2..b27754a8c93a 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/api/openapi.yaml +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/api/openapi.yaml @@ -1973,6 +1973,7 @@ components: type: string fruitReq: oneOf: + - type: "null" - $ref: '#/components/schemas/appleReq' - $ref: '#/components/schemas/bananaReq' x-one-of-name: FruitReq diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_fruit_req.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_fruit_req.go index 86320b7c9b8e..e5f4fbc32037 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_fruit_req.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_fruit_req.go @@ -37,6 +37,12 @@ func (s *FruitReq) UnmarshalJSON(src []byte) error { s.FruitReqInterface = unmarshaledBananaReq return nil } + var unmarshaledNull *Null = &Null{} + err = json.Unmarshal(src, unmarshaledNull) + if err == nil { + s.FruitReqInterface = unmarshaledNull + return nil + } return fmt.Errorf("No oneOf model could be deserialized from payload: %s", string(src)) } type NullableFruitReq struct { diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/fruit_req.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/fruit_req.py index 111326fcb4f6..7dd0a1492b22 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/fruit_req.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/fruit_req.py @@ -39,6 +39,11 @@ except ImportError: banana_req = sys.modules[ 'petstore_api.models.banana_req'] +try: + from petstore_api.models import none_type +except ImportError: + none_type = sys.modules[ + 'petstore_api.models.none_type'] class FruitReq(ModelComposed): @@ -196,5 +201,6 @@ def _composed_schemas(): 'oneOf': [ apple_req.AppleReq, banana_req.BananaReq, + none_type, ], } From 48c310e2acca71894b531445f3b6e99a7e7bb551 Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Thu, 30 Apr 2020 14:49:44 -0700 Subject: [PATCH 04/48] Handle null type. Add 'null' type in the OAS document for testing purpose --- .../codegen/languages/PythonClientExperimentalCodegen.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java index 60a004b6bea8..5ad274354d71 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java @@ -388,7 +388,9 @@ public Map postProcessAllModels(Map objs) { composedSchemaSets.add(cm.oneOf); for (Set importSet : composedSchemaSets) { for (String otherModelName : importSet) { - cm.imports.add(otherModelName); + if (!"none_type".equals(otherModelName)) { + cm.imports.add(otherModelName); + } } } From fddb63bdbb52e1efabacf1573ebe82e7167855cc Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Thu, 30 Apr 2020 15:01:48 -0700 Subject: [PATCH 05/48] Handle null type. Add 'null' type in the OAS document for testing purpose --- .../python-experimental/petstore_api/models/fruit_req.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/fruit_req.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/fruit_req.py index 7dd0a1492b22..c323521891a2 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/fruit_req.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/fruit_req.py @@ -39,11 +39,6 @@ except ImportError: banana_req = sys.modules[ 'petstore_api.models.banana_req'] -try: - from petstore_api.models import none_type -except ImportError: - none_type = sys.modules[ - 'petstore_api.models.none_type'] class FruitReq(ModelComposed): From cf4e9f84bd22c8a5d93c9060632338745ac1dae6 Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Thu, 30 Apr 2020 15:08:09 -0700 Subject: [PATCH 06/48] Handle null type. Add 'null' type in the OAS document for testing purpose --- .../codegen/languages/PythonClientExperimentalCodegen.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java index 5ad274354d71..95a8028f8889 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java @@ -388,7 +388,7 @@ public Map postProcessAllModels(Map objs) { composedSchemaSets.add(cm.oneOf); for (Set importSet : composedSchemaSets) { for (String otherModelName : importSet) { - if (!"none_type".equals(otherModelName)) { + if (!languageSpecificPrimitives.contains(otherModelName)) { cm.imports.add(otherModelName); } } From 3b59b47c183566efa5055eaae472b157cb7ae74e Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Thu, 30 Apr 2020 17:22:33 -0700 Subject: [PATCH 07/48] Handle null type. Add 'null' type in the OAS document for testing purpose --- .../python/python-experimental/model_utils.mustache | 10 ++++++++++ .../python-experimental/petstore_api/model_utils.py | 10 ++++++++++ .../python-experimental/test/test_fruit_req.py | 1 + 3 files changed, 21 insertions(+) diff --git a/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache b/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache index 58da408a19eb..615851a9dd0e 100644 --- a/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache +++ b/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache @@ -986,6 +986,11 @@ def get_oneof_instance(self, model_args, constant_args): # Iterate over each oneOf schema and determine if the input data # matches the oneOf schemas. for oneof_class in self._composed_schemas()['oneOf']: + if oneof_class is none_type: + if model_args is None: + # The input data matches the 'None' type. + oneof_instances.append(model_args) + continue # transform js keys from input data to python keys in fixed_model_args fixed_model_args = change_keys_js_to_python( model_args, oneof_class) @@ -1043,6 +1048,11 @@ def get_anyof_instances(self, model_args, constant_args): return anyof_instances for anyof_class in self._composed_schemas()['anyOf']: + if anyof_class is none_type: + if model_args is None: + # The input data matches the 'None' type. + oneof_instances.append(model_args) + continue # transform js keys to python keys in fixed_model_args fixed_model_args = change_keys_js_to_python(model_args, anyof_class) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py index b905f7d347a5..5faba01ec89f 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py @@ -1248,6 +1248,11 @@ def get_oneof_instance(self, model_args, constant_args): # Iterate over each oneOf schema and determine if the input data # matches the oneOf schemas. for oneof_class in self._composed_schemas()['oneOf']: + if oneof_class is none_type: + if model_args is None: + # The input data matches the 'None' type. + oneof_instances.append(model_args) + continue # transform js keys from input data to python keys in fixed_model_args fixed_model_args = change_keys_js_to_python( model_args, oneof_class) @@ -1305,6 +1310,11 @@ def get_anyof_instances(self, model_args, constant_args): return anyof_instances for anyof_class in self._composed_schemas()['anyOf']: + if anyof_class is none_type: + if model_args is None: + # The input data matches the 'None' type. + oneof_instances.append(model_args) + continue # transform js keys to python keys in fixed_model_args fixed_model_args = change_keys_js_to_python(model_args, anyof_class) diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_fruit_req.py b/samples/openapi3/client/petstore/python-experimental/test/test_fruit_req.py index 2fa26fac0aa5..f36597db4fec 100644 --- a/samples/openapi3/client/petstore/python-experimental/test/test_fruit_req.py +++ b/samples/openapi3/client/petstore/python-experimental/test/test_fruit_req.py @@ -70,6 +70,7 @@ def testFruitReq(self): 'oneOf': [ petstore_api.AppleReq, petstore_api.BananaReq, + type(None), ], } ) From b362f92a47253bc76b7bd59236adaa3a170b4e3c Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Thu, 30 Apr 2020 17:25:17 -0700 Subject: [PATCH 08/48] Handle null type. Add 'null' type in the OAS document for testing purpose --- .../resources/python/python-experimental/model_utils.mustache | 4 ++++ .../petstore/python-experimental/petstore_api/model_utils.py | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache b/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache index 615851a9dd0e..d10152393c14 100644 --- a/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache +++ b/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache @@ -987,6 +987,8 @@ def get_oneof_instance(self, model_args, constant_args): # matches the oneOf schemas. for oneof_class in self._composed_schemas()['oneOf']: if oneof_class is none_type: + # The only way the input data can match the 'None' type + # is if the input data is the 'null' value. if model_args is None: # The input data matches the 'None' type. oneof_instances.append(model_args) @@ -1049,6 +1051,8 @@ def get_anyof_instances(self, model_args, constant_args): for anyof_class in self._composed_schemas()['anyOf']: if anyof_class is none_type: + # The only way the input data can match the 'None' type + # is if the input data is the 'null' value. if model_args is None: # The input data matches the 'None' type. oneof_instances.append(model_args) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py index 5faba01ec89f..0a838d442f23 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py @@ -1249,6 +1249,8 @@ def get_oneof_instance(self, model_args, constant_args): # matches the oneOf schemas. for oneof_class in self._composed_schemas()['oneOf']: if oneof_class is none_type: + # The only way the input data can match the 'None' type + # is if the input data is the 'null' value. if model_args is None: # The input data matches the 'None' type. oneof_instances.append(model_args) @@ -1311,6 +1313,8 @@ def get_anyof_instances(self, model_args, constant_args): for anyof_class in self._composed_schemas()['anyOf']: if anyof_class is none_type: + # The only way the input data can match the 'None' type + # is if the input data is the 'null' value. if model_args is None: # The input data matches the 'None' type. oneof_instances.append(model_args) From ae93643e50532b056eec24d04234d129b9161ee6 Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Thu, 30 Apr 2020 18:15:07 -0700 Subject: [PATCH 09/48] improve documentation --- .../python-experimental/model_utils.mustache | 16 ++++++++++------ .../petstore_api/model_utils.py | 16 ++++++++++------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache b/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache index d10152393c14..e034c62f2b58 100644 --- a/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache +++ b/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache @@ -969,9 +969,10 @@ def get_oneof_instance(self, model_args, constant_args): schemas described by oneOf. Args: self: the class we are handling - model_args (dict): var_name to var_value + model_args (dict/None): var_name to var_value The input data, e.g. the payload that must match a oneOf schema - in the OpenAPI document. + in the OpenAPI document. If the input data is the null value, + model_args is None. constant_args (dict): var_name to var_value args that every model requires, including configuration, server and path to item. @@ -1037,10 +1038,13 @@ def get_anyof_instances(self, model_args, constant_args): """ Args: self: the class we are handling - model_args (dict): var_name to var_value - used to make instances + model_args (dict/None): var_name to var_value + The input data, e.g. the payload that must match at least one + anyOf child schema in the OpenAPI document. If the input data + is the null value, model_args is None. constant_args (dict): var_name to var_value - used to make instances + args that every model requires, including configuration, server + and path to item. Returns anyof_instances (list) @@ -1055,7 +1059,7 @@ def get_anyof_instances(self, model_args, constant_args): # is if the input data is the 'null' value. if model_args is None: # The input data matches the 'None' type. - oneof_instances.append(model_args) + anyof_instances.append(model_args) continue # transform js keys to python keys in fixed_model_args fixed_model_args = change_keys_js_to_python(model_args, anyof_class) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py index 0a838d442f23..97aa95ec12c7 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py @@ -1231,9 +1231,10 @@ def get_oneof_instance(self, model_args, constant_args): schemas described by oneOf. Args: self: the class we are handling - model_args (dict): var_name to var_value + model_args (dict/None): var_name to var_value The input data, e.g. the payload that must match a oneOf schema - in the OpenAPI document. + in the OpenAPI document. If the input data is the null value, + model_args is None. constant_args (dict): var_name to var_value args that every model requires, including configuration, server and path to item. @@ -1299,10 +1300,13 @@ def get_anyof_instances(self, model_args, constant_args): """ Args: self: the class we are handling - model_args (dict): var_name to var_value - used to make instances + model_args (dict/None): var_name to var_value + The input data, e.g. the payload that must match at least one + anyOf child schema in the OpenAPI document. If the input data + is the null value, model_args is None. constant_args (dict): var_name to var_value - used to make instances + args that every model requires, including configuration, server + and path to item. Returns anyof_instances (list) @@ -1317,7 +1321,7 @@ def get_anyof_instances(self, model_args, constant_args): # is if the input data is the 'null' value. if model_args is None: # The input data matches the 'None' type. - oneof_instances.append(model_args) + anyof_instances.append(model_args) continue # transform js keys to python keys in fixed_model_args fixed_model_args = change_keys_js_to_python(model_args, anyof_class) From f5acfba661b4751bfa31ff1a6950a2460580d8d5 Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Thu, 30 Apr 2020 19:52:28 -0700 Subject: [PATCH 10/48] Handle 'null' type --- .../resources/python/python-experimental/model_utils.mustache | 3 +-- .../petstore/python-experimental/petstore_api/model_utils.py | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache b/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache index e034c62f2b58..aa216c8a75e4 100644 --- a/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache +++ b/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache @@ -1058,8 +1058,7 @@ def get_anyof_instances(self, model_args, constant_args): # The only way the input data can match the 'None' type # is if the input data is the 'null' value. if model_args is None: - # The input data matches the 'None' type. - anyof_instances.append(model_args) + return None continue # transform js keys to python keys in fixed_model_args fixed_model_args = change_keys_js_to_python(model_args, anyof_class) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py index 97aa95ec12c7..817278a4f2f3 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py @@ -1320,8 +1320,7 @@ def get_anyof_instances(self, model_args, constant_args): # The only way the input data can match the 'None' type # is if the input data is the 'null' value. if model_args is None: - # The input data matches the 'None' type. - anyof_instances.append(model_args) + return None continue # transform js keys to python keys in fixed_model_args fixed_model_args = change_keys_js_to_python(model_args, anyof_class) From 6ba15238e57df1238cd4265eb91dfb0f7f6cecc5 Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Thu, 30 Apr 2020 21:29:58 -0700 Subject: [PATCH 11/48] Handle 'null' type. Add unit tests --- .../tests/test_deserialization.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/samples/openapi3/client/petstore/python-experimental/tests/test_deserialization.py b/samples/openapi3/client/petstore/python-experimental/tests/test_deserialization.py index f1a71a67378b..649ad75b821f 100644 --- a/samples/openapi3/client/petstore/python-experimental/tests/test_deserialization.py +++ b/samples/openapi3/client/petstore/python-experimental/tests/test_deserialization.py @@ -83,4 +83,16 @@ def test_deserialize_mammal(self): deserialized = self.deserialize(response, (petstore_api.Mammal,), True) self.assertTrue(isinstance(deserialized, petstore_api.Zebra)) self.assertEqual(deserialized.type, zebra_type) - self.assertEqual(deserialized.class_name, class_name) \ No newline at end of file + self.assertEqual(deserialized.class_name, class_name) + + def test_deserialize_fruit(self): + """ + deserialize fruit + fruitReq is a oneOf composed schema model with discriminator, including 'null' type. + """ + + # Unmarshal 'null' value + data = None + response = MockResponse(data=json.dumps(data)) + deserialized = self.deserialize(response, (petstore_api.FruitReq, type(None)), True) + self.assertEqual(type(deserialized), type(None)) From 2a6a87a0af80802f2246f688f01f4619135b643a Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Fri, 1 May 2020 17:56:44 -0700 Subject: [PATCH 12/48] Add NullType for go --- .../codegen/languages/AbstractGoCodegen.java | 5 +++++ .../utils/OneOfImplementorAdditionalData.java | 8 ++++--- .../resources/go-experimental/model.mustache | 1 + .../resources/go-experimental/utils.mustache | 21 +++++++++++++++++++ 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java index b018d22707a6..d6acf0ce68eb 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java @@ -131,6 +131,11 @@ public AbstractGoCodegen() { typeMapping.put("object", "map[string]interface{}"); typeMapping.put("interface{}", "interface{}"); typeMapping.put("AnyType", "interface{}"); + // Below is the entry to map the JSON 'null' type to golang. + // Note there is no built-in 'null' type in golang, and it's not possible + // to declare a variable whose only possible value is 'nil'. + // For example `a := nil` is not a valid go statement. + typeMapping.put("null", "NullType"); numberTypes = new HashSet( Arrays.asList( diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/OneOfImplementorAdditionalData.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/OneOfImplementorAdditionalData.java index c44c2134d141..3ba31200598c 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/OneOfImplementorAdditionalData.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/OneOfImplementorAdditionalData.java @@ -75,9 +75,11 @@ public void addFromInterfaceModel(CodegenModel cm, List> mod // note that we can't just toAdd.removeAll(m.vars) for every interfaceModel, // as they might have different value of `hasMore` and thus are not equal List omitAdding = new ArrayList(); - for (CodegenModel m : cm.interfaceModels) { - for (CodegenProperty v : m.vars) { - omitAdding.add(v.baseName); + if (cm.interfaceModels != null) { + for (CodegenModel m : cm.interfaceModels) { + for (CodegenProperty v : m.vars) { + omitAdding.add(v.baseName); + } } } for (CodegenProperty v : toAdd) { diff --git a/modules/openapi-generator/src/main/resources/go-experimental/model.mustache b/modules/openapi-generator/src/main/resources/go-experimental/model.mustache index 91a0d12b3149..848f145fbe75 100644 --- a/modules/openapi-generator/src/main/resources/go-experimental/model.mustache +++ b/modules/openapi-generator/src/main/resources/go-experimental/model.mustache @@ -326,6 +326,7 @@ func (s *{{classname}}) UnmarshalJSON(src []byte) error { {{/discriminator}} {{^discriminator}} {{#oneOf}} + {{! TODO: validate the payload against the JSON schema. Relying on golang JSON unmarshaling is not sufficient to determine the payload validates against the schema}} var unmarshaled{{{.}}} *{{{.}}} = &{{{.}}}{} err = json.Unmarshal(src, unmarshaled{{{.}}}) if err == nil { diff --git a/modules/openapi-generator/src/main/resources/go-experimental/utils.mustache b/modules/openapi-generator/src/main/resources/go-experimental/utils.mustache index 89e00e0267be..c355d98cd742 100644 --- a/modules/openapi-generator/src/main/resources/go-experimental/utils.mustache +++ b/modules/openapi-generator/src/main/resources/go-experimental/utils.mustache @@ -2,6 +2,7 @@ package {{packageName}} import ( + "bytes" "encoding/json" "time" ) @@ -30,6 +31,26 @@ func PtrString(v string) *string { return &v } // PtrTime is helper routine that returns a pointer to given Time value. func PtrTime(v time.Time) *time.Time { return &v } +// NullType is a type whose only value can be the golang nil value. +// It is used to model the JSON 'null' value. +// Note in golang there is no built-in type to represent the 'null' value. +type NullType interface{} + +func NewNullType() *NullType { + return nil +} + +func (v NullType) MarshalJSON() ([]byte, error) { + return "null", nil +} + +func (v *NullType) UnmarshalJSON(src []byte) error { + if bytes.Equal(bytes.TrimSpace([]byte("null")), src) { + *v = nil + } + return errors.New("Cannot unmarshal non-nil value into NullType") +} + type NullableBool struct { value *bool isSet bool From 86bc4c005aa4eedcf18ea816c61c760cf2aa142d Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Fri, 1 May 2020 18:45:07 -0700 Subject: [PATCH 13/48] Add NullType for go --- .../resources/go-experimental/utils.mustache | 36 ++++++++++++---- .../go-experimental/go-petstore/utils.go | 41 +++++++++++++++++++ .../go-petstore/model_fruit_req.go | 6 +-- .../go-experimental/go-petstore/utils.go | 41 +++++++++++++++++++ 4 files changed, 113 insertions(+), 11 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/go-experimental/utils.mustache b/modules/openapi-generator/src/main/resources/go-experimental/utils.mustache index c355d98cd742..83e3ee7e937a 100644 --- a/modules/openapi-generator/src/main/resources/go-experimental/utils.mustache +++ b/modules/openapi-generator/src/main/resources/go-experimental/utils.mustache @@ -4,6 +4,7 @@ package {{packageName}} import ( "bytes" "encoding/json" + "errors" "time" ) @@ -31,24 +32,43 @@ func PtrString(v string) *string { return &v } // PtrTime is helper routine that returns a pointer to given Time value. func PtrTime(v time.Time) *time.Time { return &v } -// NullType is a type whose only value can be the golang nil value. -// It is used to model the JSON 'null' value. -// Note in golang there is no built-in type to represent the 'null' value. -type NullType interface{} +var nullLiteral []byte = []byte("null") + +// NullType is a type whose only value can be the JSON 'null' value. +type NullType struct{ + isSet bool +} func NewNullType() *NullType { return nil } +func (v NullType) Get() interface{} { + return nil +} + +func (v *NullType) Set() { + v.isSet = true +} + +func (v NullType) IsSet() bool { + return v.isSet +} + +func (v *NullType) Unset() { + v.isSet = false +} + func (v NullType) MarshalJSON() ([]byte, error) { - return "null", nil + return nullLiteral, nil } func (v *NullType) UnmarshalJSON(src []byte) error { - if bytes.Equal(bytes.TrimSpace([]byte("null")), src) { - *v = nil + if bytes.Equal(bytes.TrimSpace(nullLiteral), src) { + v.isSet = true + return nil } - return errors.New("Cannot unmarshal non-nil value into NullType") + return errors.New("Cannot unmarshal value into 'null' type") } type NullableBool struct { diff --git a/samples/client/petstore/go-experimental/go-petstore/utils.go b/samples/client/petstore/go-experimental/go-petstore/utils.go index 9fb7a1847cd3..8bfc00ea74f1 100644 --- a/samples/client/petstore/go-experimental/go-petstore/utils.go +++ b/samples/client/petstore/go-experimental/go-petstore/utils.go @@ -10,7 +10,9 @@ package petstore import ( + "bytes" "encoding/json" + "errors" "time" ) @@ -38,6 +40,45 @@ func PtrString(v string) *string { return &v } // PtrTime is helper routine that returns a pointer to given Time value. func PtrTime(v time.Time) *time.Time { return &v } +var nullLiteral []byte = []byte("null") + +// NullType is a type whose only value can be the JSON 'null' value. +type NullType struct{ + isSet bool +} + +func NewNullType() *NullType { + return nil +} + +func (v NullType) Get() interface{} { + return nil +} + +func (v *NullType) Set() { + v.isSet = true +} + +func (v NullType) IsSet() bool { + return v.isSet +} + +func (v *NullType) Unset() { + v.isSet = false +} + +func (v NullType) MarshalJSON() ([]byte, error) { + return nullLiteral, nil +} + +func (v *NullType) UnmarshalJSON(src []byte) error { + if bytes.Equal(bytes.TrimSpace(nullLiteral), src) { + v.isSet = true + return nil + } + return errors.New("Cannot unmarshal value into 'null' type") +} + type NullableBool struct { value *bool isSet bool diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_fruit_req.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_fruit_req.go index e5f4fbc32037..3fdfbcf76008 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_fruit_req.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_fruit_req.go @@ -37,10 +37,10 @@ func (s *FruitReq) UnmarshalJSON(src []byte) error { s.FruitReqInterface = unmarshaledBananaReq return nil } - var unmarshaledNull *Null = &Null{} - err = json.Unmarshal(src, unmarshaledNull) + var unmarshaledNullType *NullType = &NullType{} + err = json.Unmarshal(src, unmarshaledNullType) if err == nil { - s.FruitReqInterface = unmarshaledNull + s.FruitReqInterface = unmarshaledNullType return nil } return fmt.Errorf("No oneOf model could be deserialized from payload: %s", string(src)) diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/utils.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/utils.go index 9fb7a1847cd3..8bfc00ea74f1 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/utils.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/utils.go @@ -10,7 +10,9 @@ package petstore import ( + "bytes" "encoding/json" + "errors" "time" ) @@ -38,6 +40,45 @@ func PtrString(v string) *string { return &v } // PtrTime is helper routine that returns a pointer to given Time value. func PtrTime(v time.Time) *time.Time { return &v } +var nullLiteral []byte = []byte("null") + +// NullType is a type whose only value can be the JSON 'null' value. +type NullType struct{ + isSet bool +} + +func NewNullType() *NullType { + return nil +} + +func (v NullType) Get() interface{} { + return nil +} + +func (v *NullType) Set() { + v.isSet = true +} + +func (v NullType) IsSet() bool { + return v.isSet +} + +func (v *NullType) Unset() { + v.isSet = false +} + +func (v NullType) MarshalJSON() ([]byte, error) { + return nullLiteral, nil +} + +func (v *NullType) UnmarshalJSON(src []byte) error { + if bytes.Equal(bytes.TrimSpace(nullLiteral), src) { + v.isSet = true + return nil + } + return errors.New("Cannot unmarshal value into 'null' type") +} + type NullableBool struct { value *bool isSet bool From 6b9c0cedbae345e4f6f40818121332ffd4913286 Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Sat, 2 May 2020 09:49:41 -0700 Subject: [PATCH 14/48] fix modeling of AnyType for go-experimental --- .../codegen/languages/AbstractGoCodegen.java | 13 ++-- .../resources/go-experimental/utils.mustache | 72 +++++++++++++++++++ 2 files changed, 79 insertions(+), 6 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java index d6acf0ce68eb..fbf1d62e0e8c 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java @@ -92,8 +92,8 @@ public AbstractGoCodegen() { "complex128", "rune", "byte", - "map[string]interface{}", - "interface{}" + "ObjectType", + "AnyType" ) ); @@ -128,9 +128,10 @@ public AbstractGoCodegen() { // map[string]interface{}, whereas an arbitrary type is implemented // in golang as interface{}. // See issue #5387 for more details. - typeMapping.put("object", "map[string]interface{}"); - typeMapping.put("interface{}", "interface{}"); - typeMapping.put("AnyType", "interface{}"); + typeMapping.put("object", "ObjectType"); + // A schema that does not specify the 'type' attribute. The value + // can be anything. + typeMapping.put("AnyType", "AnyType"); // Below is the entry to map the JSON 'null' type to golang. // Note there is no built-in 'null' type in golang, and it's not possible // to declare a variable whose only possible value is 'nil'. @@ -383,7 +384,7 @@ public String getSchemaType(Schema p) { type = openAPIType; } else if ("object".equals(openAPIType) && ModelUtils.isAnyTypeSchema(p)) { // Arbitrary type. Note this is not the same thing as free-form object. - type = "interface{}"; + type = "AnyType"; } else if (typeMapping.containsKey(openAPIType)) { type = typeMapping.get(openAPIType); if (languageSpecificPrimitives.contains(type)) diff --git a/modules/openapi-generator/src/main/resources/go-experimental/utils.mustache b/modules/openapi-generator/src/main/resources/go-experimental/utils.mustache index 83e3ee7e937a..e65f1c4d0ed9 100644 --- a/modules/openapi-generator/src/main/resources/go-experimental/utils.mustache +++ b/modules/openapi-generator/src/main/resources/go-experimental/utils.mustache @@ -71,6 +71,78 @@ func (v *NullType) UnmarshalJSON(src []byte) error { return errors.New("Cannot unmarshal value into 'null' type") } +// AnyType is a type whose value can anything. +type AnyType struct{ + value interface{} + isSet bool +} + +func NewAnyType(val interface{}) *AnyType { + return &AnyType{value: val, isSet: true} +} + +func (v AnyType) Get() interface{} { + return v.value +} + +func (v *AnyType) Set(val interface{}) { + v.value = val + v.isSet = true +} + +func (v AnyType) IsSet() bool { + return v.isSet +} + +func (v *AnyType) Unset() { + v.isSet = false +} + +func (v AnyType) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *AnyType) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +// ObjectType is a type whose value can be an object with undeclared properties. +type ObjectType struct{ + value map[string]interface{} + isSet bool +} + +func NewObjectType(val map[string]interface{}) *ObjectType { + return &ObjectType{value: val, isSet: true} +} + +func (v ObjectType) Get() map[string]interface{} { + return v.value +} + +func (v *ObjectType) Set(val map[string]interface{}) { + v.value = val + v.isSet = true +} + +func (v ObjectType) IsSet() bool { + return v.isSet +} + +func (v *ObjectType) Unset() { + v.isSet = false +} + +func (v ObjectType) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *ObjectType) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + type NullableBool struct { value *bool isSet bool From a302894c3cfa1ee7314876ebc5a8b021a64e21e8 Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Sun, 3 May 2020 09:15:43 -0700 Subject: [PATCH 15/48] execute scripts in bin directory --- .../docs/AdditionalPropertiesClass.md | 40 +++++------ .../model_additional_properties_class.go | 60 ++++++++-------- .../go-experimental/go-petstore/utils.go | 72 +++++++++++++++++++ .../docs/AdditionalPropertiesClass.md | 10 +-- .../model_additional_properties_class.go | 10 +-- .../petstore_api/model_utils.py | 27 +++++-- .../go-petstore/docs/NullableClass.md | 48 ++++++------- .../go-experimental/go-petstore/docs/User.md | 32 ++++----- .../go-petstore/model_nullable_class.go | 72 +++++++++---------- .../go-experimental/go-petstore/model_user.go | 48 ++++++------- .../go-experimental/go-petstore/utils.go | 72 +++++++++++++++++++ .../go/go-petstore/docs/NullableClass.md | 12 ++-- .../go/go-petstore/model_nullable_class.go | 12 ++-- 13 files changed, 338 insertions(+), 177 deletions(-) diff --git a/samples/client/petstore/go-experimental/go-petstore/docs/AdditionalPropertiesClass.md b/samples/client/petstore/go-experimental/go-petstore/docs/AdditionalPropertiesClass.md index 2f6d0c688fc9..25607757d82f 100644 --- a/samples/client/petstore/go-experimental/go-petstore/docs/AdditionalPropertiesClass.md +++ b/samples/client/petstore/go-experimental/go-petstore/docs/AdditionalPropertiesClass.md @@ -9,12 +9,12 @@ Name | Type | Description | Notes **MapInteger** | Pointer to **map[string]int32** | | [optional] **MapBoolean** | Pointer to **map[string]bool** | | [optional] **MapArrayInteger** | Pointer to [**map[string][]int32**](array.md) | | [optional] -**MapArrayAnytype** | Pointer to [**map[string][]map[string]interface{}**](array.md) | | [optional] +**MapArrayAnytype** | Pointer to [**map[string][]ObjectType**](array.md) | | [optional] **MapMapString** | Pointer to [**map[string]map[string]string**](map.md) | | [optional] -**MapMapAnytype** | Pointer to [**map[string]map[string]map[string]interface{}**](map.md) | | [optional] -**Anytype1** | Pointer to [**map[string]interface{}**](.md) | | [optional] -**Anytype2** | Pointer to [**map[string]interface{}**](.md) | | [optional] -**Anytype3** | Pointer to [**map[string]interface{}**](.md) | | [optional] +**MapMapAnytype** | Pointer to [**map[string]map[string]ObjectType**](map.md) | | [optional] +**Anytype1** | Pointer to [**ObjectType**](.md) | | [optional] +**Anytype2** | Pointer to [**ObjectType**](.md) | | [optional] +**Anytype3** | Pointer to [**ObjectType**](.md) | | [optional] ## Methods @@ -162,20 +162,20 @@ HasMapArrayInteger returns a boolean if a field has been set. ### GetMapArrayAnytype -`func (o *AdditionalPropertiesClass) GetMapArrayAnytype() map[string][]map[string]interface{}` +`func (o *AdditionalPropertiesClass) GetMapArrayAnytype() map[string][]ObjectType` GetMapArrayAnytype returns the MapArrayAnytype field if non-nil, zero value otherwise. ### GetMapArrayAnytypeOk -`func (o *AdditionalPropertiesClass) GetMapArrayAnytypeOk() (*map[string][]map[string]interface{}, bool)` +`func (o *AdditionalPropertiesClass) GetMapArrayAnytypeOk() (*map[string][]ObjectType, bool)` GetMapArrayAnytypeOk returns a tuple with the MapArrayAnytype field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetMapArrayAnytype -`func (o *AdditionalPropertiesClass) SetMapArrayAnytype(v map[string][]map[string]interface{})` +`func (o *AdditionalPropertiesClass) SetMapArrayAnytype(v map[string][]ObjectType)` SetMapArrayAnytype sets MapArrayAnytype field to given value. @@ -212,20 +212,20 @@ HasMapMapString returns a boolean if a field has been set. ### GetMapMapAnytype -`func (o *AdditionalPropertiesClass) GetMapMapAnytype() map[string]map[string]map[string]interface{}` +`func (o *AdditionalPropertiesClass) GetMapMapAnytype() map[string]map[string]ObjectType` GetMapMapAnytype returns the MapMapAnytype field if non-nil, zero value otherwise. ### GetMapMapAnytypeOk -`func (o *AdditionalPropertiesClass) GetMapMapAnytypeOk() (*map[string]map[string]map[string]interface{}, bool)` +`func (o *AdditionalPropertiesClass) GetMapMapAnytypeOk() (*map[string]map[string]ObjectType, bool)` GetMapMapAnytypeOk returns a tuple with the MapMapAnytype field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetMapMapAnytype -`func (o *AdditionalPropertiesClass) SetMapMapAnytype(v map[string]map[string]map[string]interface{})` +`func (o *AdditionalPropertiesClass) SetMapMapAnytype(v map[string]map[string]ObjectType)` SetMapMapAnytype sets MapMapAnytype field to given value. @@ -237,20 +237,20 @@ HasMapMapAnytype returns a boolean if a field has been set. ### GetAnytype1 -`func (o *AdditionalPropertiesClass) GetAnytype1() map[string]interface{}` +`func (o *AdditionalPropertiesClass) GetAnytype1() ObjectType` GetAnytype1 returns the Anytype1 field if non-nil, zero value otherwise. ### GetAnytype1Ok -`func (o *AdditionalPropertiesClass) GetAnytype1Ok() (*map[string]interface{}, bool)` +`func (o *AdditionalPropertiesClass) GetAnytype1Ok() (*ObjectType, bool)` GetAnytype1Ok returns a tuple with the Anytype1 field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetAnytype1 -`func (o *AdditionalPropertiesClass) SetAnytype1(v map[string]interface{})` +`func (o *AdditionalPropertiesClass) SetAnytype1(v ObjectType)` SetAnytype1 sets Anytype1 field to given value. @@ -262,20 +262,20 @@ HasAnytype1 returns a boolean if a field has been set. ### GetAnytype2 -`func (o *AdditionalPropertiesClass) GetAnytype2() map[string]interface{}` +`func (o *AdditionalPropertiesClass) GetAnytype2() ObjectType` GetAnytype2 returns the Anytype2 field if non-nil, zero value otherwise. ### GetAnytype2Ok -`func (o *AdditionalPropertiesClass) GetAnytype2Ok() (*map[string]interface{}, bool)` +`func (o *AdditionalPropertiesClass) GetAnytype2Ok() (*ObjectType, bool)` GetAnytype2Ok returns a tuple with the Anytype2 field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetAnytype2 -`func (o *AdditionalPropertiesClass) SetAnytype2(v map[string]interface{})` +`func (o *AdditionalPropertiesClass) SetAnytype2(v ObjectType)` SetAnytype2 sets Anytype2 field to given value. @@ -287,20 +287,20 @@ HasAnytype2 returns a boolean if a field has been set. ### GetAnytype3 -`func (o *AdditionalPropertiesClass) GetAnytype3() map[string]interface{}` +`func (o *AdditionalPropertiesClass) GetAnytype3() ObjectType` GetAnytype3 returns the Anytype3 field if non-nil, zero value otherwise. ### GetAnytype3Ok -`func (o *AdditionalPropertiesClass) GetAnytype3Ok() (*map[string]interface{}, bool)` +`func (o *AdditionalPropertiesClass) GetAnytype3Ok() (*ObjectType, bool)` GetAnytype3Ok returns a tuple with the Anytype3 field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetAnytype3 -`func (o *AdditionalPropertiesClass) SetAnytype3(v map[string]interface{})` +`func (o *AdditionalPropertiesClass) SetAnytype3(v ObjectType)` SetAnytype3 sets Anytype3 field to given value. diff --git a/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_class.go b/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_class.go index 9505c3e7e6d6..72a6df95c099 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_class.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_class.go @@ -20,12 +20,12 @@ type AdditionalPropertiesClass struct { MapInteger *map[string]int32 `json:"map_integer,omitempty"` MapBoolean *map[string]bool `json:"map_boolean,omitempty"` MapArrayInteger *map[string][]int32 `json:"map_array_integer,omitempty"` - MapArrayAnytype *map[string][]map[string]interface{} `json:"map_array_anytype,omitempty"` + MapArrayAnytype *map[string][]ObjectType `json:"map_array_anytype,omitempty"` MapMapString *map[string]map[string]string `json:"map_map_string,omitempty"` - MapMapAnytype *map[string]map[string]map[string]interface{} `json:"map_map_anytype,omitempty"` - Anytype1 *map[string]interface{} `json:"anytype_1,omitempty"` - Anytype2 *map[string]interface{} `json:"anytype_2,omitempty"` - Anytype3 *map[string]interface{} `json:"anytype_3,omitempty"` + MapMapAnytype *map[string]map[string]ObjectType `json:"map_map_anytype,omitempty"` + Anytype1 *ObjectType `json:"anytype_1,omitempty"` + Anytype2 *ObjectType `json:"anytype_2,omitempty"` + Anytype3 *ObjectType `json:"anytype_3,omitempty"` } // NewAdditionalPropertiesClass instantiates a new AdditionalPropertiesClass object @@ -206,9 +206,9 @@ func (o *AdditionalPropertiesClass) SetMapArrayInteger(v map[string][]int32) { } // GetMapArrayAnytype returns the MapArrayAnytype field value if set, zero value otherwise. -func (o *AdditionalPropertiesClass) GetMapArrayAnytype() map[string][]map[string]interface{} { +func (o *AdditionalPropertiesClass) GetMapArrayAnytype() map[string][]ObjectType { if o == nil || o.MapArrayAnytype == nil { - var ret map[string][]map[string]interface{} + var ret map[string][]ObjectType return ret } return *o.MapArrayAnytype @@ -216,7 +216,7 @@ func (o *AdditionalPropertiesClass) GetMapArrayAnytype() map[string][]map[string // GetMapArrayAnytypeOk returns a tuple with the MapArrayAnytype field value if set, nil otherwise // and a boolean to check if the value has been set. -func (o *AdditionalPropertiesClass) GetMapArrayAnytypeOk() (*map[string][]map[string]interface{}, bool) { +func (o *AdditionalPropertiesClass) GetMapArrayAnytypeOk() (*map[string][]ObjectType, bool) { if o == nil || o.MapArrayAnytype == nil { return nil, false } @@ -232,8 +232,8 @@ func (o *AdditionalPropertiesClass) HasMapArrayAnytype() bool { return false } -// SetMapArrayAnytype gets a reference to the given map[string][]map[string]interface{} and assigns it to the MapArrayAnytype field. -func (o *AdditionalPropertiesClass) SetMapArrayAnytype(v map[string][]map[string]interface{}) { +// SetMapArrayAnytype gets a reference to the given map[string][]ObjectType and assigns it to the MapArrayAnytype field. +func (o *AdditionalPropertiesClass) SetMapArrayAnytype(v map[string][]ObjectType) { o.MapArrayAnytype = &v } @@ -270,9 +270,9 @@ func (o *AdditionalPropertiesClass) SetMapMapString(v map[string]map[string]stri } // GetMapMapAnytype returns the MapMapAnytype field value if set, zero value otherwise. -func (o *AdditionalPropertiesClass) GetMapMapAnytype() map[string]map[string]map[string]interface{} { +func (o *AdditionalPropertiesClass) GetMapMapAnytype() map[string]map[string]ObjectType { if o == nil || o.MapMapAnytype == nil { - var ret map[string]map[string]map[string]interface{} + var ret map[string]map[string]ObjectType return ret } return *o.MapMapAnytype @@ -280,7 +280,7 @@ func (o *AdditionalPropertiesClass) GetMapMapAnytype() map[string]map[string]map // GetMapMapAnytypeOk returns a tuple with the MapMapAnytype field value if set, nil otherwise // and a boolean to check if the value has been set. -func (o *AdditionalPropertiesClass) GetMapMapAnytypeOk() (*map[string]map[string]map[string]interface{}, bool) { +func (o *AdditionalPropertiesClass) GetMapMapAnytypeOk() (*map[string]map[string]ObjectType, bool) { if o == nil || o.MapMapAnytype == nil { return nil, false } @@ -296,15 +296,15 @@ func (o *AdditionalPropertiesClass) HasMapMapAnytype() bool { return false } -// SetMapMapAnytype gets a reference to the given map[string]map[string]map[string]interface{} and assigns it to the MapMapAnytype field. -func (o *AdditionalPropertiesClass) SetMapMapAnytype(v map[string]map[string]map[string]interface{}) { +// SetMapMapAnytype gets a reference to the given map[string]map[string]ObjectType and assigns it to the MapMapAnytype field. +func (o *AdditionalPropertiesClass) SetMapMapAnytype(v map[string]map[string]ObjectType) { o.MapMapAnytype = &v } // GetAnytype1 returns the Anytype1 field value if set, zero value otherwise. -func (o *AdditionalPropertiesClass) GetAnytype1() map[string]interface{} { +func (o *AdditionalPropertiesClass) GetAnytype1() ObjectType { if o == nil || o.Anytype1 == nil { - var ret map[string]interface{} + var ret ObjectType return ret } return *o.Anytype1 @@ -312,7 +312,7 @@ func (o *AdditionalPropertiesClass) GetAnytype1() map[string]interface{} { // GetAnytype1Ok returns a tuple with the Anytype1 field value if set, nil otherwise // and a boolean to check if the value has been set. -func (o *AdditionalPropertiesClass) GetAnytype1Ok() (*map[string]interface{}, bool) { +func (o *AdditionalPropertiesClass) GetAnytype1Ok() (*ObjectType, bool) { if o == nil || o.Anytype1 == nil { return nil, false } @@ -328,15 +328,15 @@ func (o *AdditionalPropertiesClass) HasAnytype1() bool { return false } -// SetAnytype1 gets a reference to the given map[string]interface{} and assigns it to the Anytype1 field. -func (o *AdditionalPropertiesClass) SetAnytype1(v map[string]interface{}) { +// SetAnytype1 gets a reference to the given ObjectType and assigns it to the Anytype1 field. +func (o *AdditionalPropertiesClass) SetAnytype1(v ObjectType) { o.Anytype1 = &v } // GetAnytype2 returns the Anytype2 field value if set, zero value otherwise. -func (o *AdditionalPropertiesClass) GetAnytype2() map[string]interface{} { +func (o *AdditionalPropertiesClass) GetAnytype2() ObjectType { if o == nil || o.Anytype2 == nil { - var ret map[string]interface{} + var ret ObjectType return ret } return *o.Anytype2 @@ -344,7 +344,7 @@ func (o *AdditionalPropertiesClass) GetAnytype2() map[string]interface{} { // GetAnytype2Ok returns a tuple with the Anytype2 field value if set, nil otherwise // and a boolean to check if the value has been set. -func (o *AdditionalPropertiesClass) GetAnytype2Ok() (*map[string]interface{}, bool) { +func (o *AdditionalPropertiesClass) GetAnytype2Ok() (*ObjectType, bool) { if o == nil || o.Anytype2 == nil { return nil, false } @@ -360,15 +360,15 @@ func (o *AdditionalPropertiesClass) HasAnytype2() bool { return false } -// SetAnytype2 gets a reference to the given map[string]interface{} and assigns it to the Anytype2 field. -func (o *AdditionalPropertiesClass) SetAnytype2(v map[string]interface{}) { +// SetAnytype2 gets a reference to the given ObjectType and assigns it to the Anytype2 field. +func (o *AdditionalPropertiesClass) SetAnytype2(v ObjectType) { o.Anytype2 = &v } // GetAnytype3 returns the Anytype3 field value if set, zero value otherwise. -func (o *AdditionalPropertiesClass) GetAnytype3() map[string]interface{} { +func (o *AdditionalPropertiesClass) GetAnytype3() ObjectType { if o == nil || o.Anytype3 == nil { - var ret map[string]interface{} + var ret ObjectType return ret } return *o.Anytype3 @@ -376,7 +376,7 @@ func (o *AdditionalPropertiesClass) GetAnytype3() map[string]interface{} { // GetAnytype3Ok returns a tuple with the Anytype3 field value if set, nil otherwise // and a boolean to check if the value has been set. -func (o *AdditionalPropertiesClass) GetAnytype3Ok() (*map[string]interface{}, bool) { +func (o *AdditionalPropertiesClass) GetAnytype3Ok() (*ObjectType, bool) { if o == nil || o.Anytype3 == nil { return nil, false } @@ -392,8 +392,8 @@ func (o *AdditionalPropertiesClass) HasAnytype3() bool { return false } -// SetAnytype3 gets a reference to the given map[string]interface{} and assigns it to the Anytype3 field. -func (o *AdditionalPropertiesClass) SetAnytype3(v map[string]interface{}) { +// SetAnytype3 gets a reference to the given ObjectType and assigns it to the Anytype3 field. +func (o *AdditionalPropertiesClass) SetAnytype3(v ObjectType) { o.Anytype3 = &v } diff --git a/samples/client/petstore/go-experimental/go-petstore/utils.go b/samples/client/petstore/go-experimental/go-petstore/utils.go index 8bfc00ea74f1..7679b630ed84 100644 --- a/samples/client/petstore/go-experimental/go-petstore/utils.go +++ b/samples/client/petstore/go-experimental/go-petstore/utils.go @@ -79,6 +79,78 @@ func (v *NullType) UnmarshalJSON(src []byte) error { return errors.New("Cannot unmarshal value into 'null' type") } +// AnyType is a type whose value can anything. +type AnyType struct{ + value interface{} + isSet bool +} + +func NewAnyType(val interface{}) *AnyType { + return &AnyType{value: val, isSet: true} +} + +func (v AnyType) Get() interface{} { + return v.value +} + +func (v *AnyType) Set(val interface{}) { + v.value = val + v.isSet = true +} + +func (v AnyType) IsSet() bool { + return v.isSet +} + +func (v *AnyType) Unset() { + v.isSet = false +} + +func (v AnyType) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *AnyType) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +// ObjectType is a type whose value can be an object with undeclared properties. +type ObjectType struct{ + value map[string]interface{} + isSet bool +} + +func NewObjectType(val map[string]interface{}) *ObjectType { + return &ObjectType{value: val, isSet: true} +} + +func (v ObjectType) Get() map[string]interface{} { + return v.value +} + +func (v *ObjectType) Set(val map[string]interface{}) { + v.value = val + v.isSet = true +} + +func (v ObjectType) IsSet() bool { + return v.isSet +} + +func (v *ObjectType) Unset() { + v.isSet = false +} + +func (v ObjectType) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *ObjectType) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + type NullableBool struct { value *bool isSet bool diff --git a/samples/client/petstore/go/go-petstore/docs/AdditionalPropertiesClass.md b/samples/client/petstore/go/go-petstore/docs/AdditionalPropertiesClass.md index 877a5d45a316..e193ede86dc0 100644 --- a/samples/client/petstore/go/go-petstore/docs/AdditionalPropertiesClass.md +++ b/samples/client/petstore/go/go-petstore/docs/AdditionalPropertiesClass.md @@ -9,12 +9,12 @@ Name | Type | Description | Notes **MapInteger** | **map[string]int32** | | [optional] **MapBoolean** | **map[string]bool** | | [optional] **MapArrayInteger** | [**map[string][]int32**](array.md) | | [optional] -**MapArrayAnytype** | [**map[string][]map[string]interface{}**](array.md) | | [optional] +**MapArrayAnytype** | [**map[string][]ObjectType**](array.md) | | [optional] **MapMapString** | [**map[string]map[string]string**](map.md) | | [optional] -**MapMapAnytype** | [**map[string]map[string]map[string]interface{}**](map.md) | | [optional] -**Anytype1** | [**map[string]interface{}**](.md) | | [optional] -**Anytype2** | [**map[string]interface{}**](.md) | | [optional] -**Anytype3** | [**map[string]interface{}**](.md) | | [optional] +**MapMapAnytype** | [**map[string]map[string]ObjectType**](map.md) | | [optional] +**Anytype1** | [**ObjectType**](.md) | | [optional] +**Anytype2** | [**ObjectType**](.md) | | [optional] +**Anytype3** | [**ObjectType**](.md) | | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/go/go-petstore/model_additional_properties_class.go b/samples/client/petstore/go/go-petstore/model_additional_properties_class.go index 00ca7fb44061..ea4dcdfff22e 100644 --- a/samples/client/petstore/go/go-petstore/model_additional_properties_class.go +++ b/samples/client/petstore/go/go-petstore/model_additional_properties_class.go @@ -15,10 +15,10 @@ type AdditionalPropertiesClass struct { MapInteger map[string]int32 `json:"map_integer,omitempty"` MapBoolean map[string]bool `json:"map_boolean,omitempty"` MapArrayInteger map[string][]int32 `json:"map_array_integer,omitempty"` - MapArrayAnytype map[string][]map[string]interface{} `json:"map_array_anytype,omitempty"` + MapArrayAnytype map[string][]ObjectType `json:"map_array_anytype,omitempty"` MapMapString map[string]map[string]string `json:"map_map_string,omitempty"` - MapMapAnytype map[string]map[string]map[string]interface{} `json:"map_map_anytype,omitempty"` - Anytype1 map[string]interface{} `json:"anytype_1,omitempty"` - Anytype2 map[string]interface{} `json:"anytype_2,omitempty"` - Anytype3 map[string]interface{} `json:"anytype_3,omitempty"` + MapMapAnytype map[string]map[string]ObjectType `json:"map_map_anytype,omitempty"` + Anytype1 ObjectType `json:"anytype_1,omitempty"` + Anytype2 ObjectType `json:"anytype_2,omitempty"` + Anytype3 ObjectType `json:"anytype_3,omitempty"` } diff --git a/samples/client/petstore/python-experimental/petstore_api/model_utils.py b/samples/client/petstore/python-experimental/petstore_api/model_utils.py index b905f7d347a5..817278a4f2f3 100644 --- a/samples/client/petstore/python-experimental/petstore_api/model_utils.py +++ b/samples/client/petstore/python-experimental/petstore_api/model_utils.py @@ -1231,9 +1231,10 @@ def get_oneof_instance(self, model_args, constant_args): schemas described by oneOf. Args: self: the class we are handling - model_args (dict): var_name to var_value + model_args (dict/None): var_name to var_value The input data, e.g. the payload that must match a oneOf schema - in the OpenAPI document. + in the OpenAPI document. If the input data is the null value, + model_args is None. constant_args (dict): var_name to var_value args that every model requires, including configuration, server and path to item. @@ -1248,6 +1249,13 @@ def get_oneof_instance(self, model_args, constant_args): # Iterate over each oneOf schema and determine if the input data # matches the oneOf schemas. for oneof_class in self._composed_schemas()['oneOf']: + if oneof_class is none_type: + # The only way the input data can match the 'None' type + # is if the input data is the 'null' value. + if model_args is None: + # The input data matches the 'None' type. + oneof_instances.append(model_args) + continue # transform js keys from input data to python keys in fixed_model_args fixed_model_args = change_keys_js_to_python( model_args, oneof_class) @@ -1292,10 +1300,13 @@ def get_anyof_instances(self, model_args, constant_args): """ Args: self: the class we are handling - model_args (dict): var_name to var_value - used to make instances + model_args (dict/None): var_name to var_value + The input data, e.g. the payload that must match at least one + anyOf child schema in the OpenAPI document. If the input data + is the null value, model_args is None. constant_args (dict): var_name to var_value - used to make instances + args that every model requires, including configuration, server + and path to item. Returns anyof_instances (list) @@ -1305,6 +1316,12 @@ def get_anyof_instances(self, model_args, constant_args): return anyof_instances for anyof_class in self._composed_schemas()['anyOf']: + if anyof_class is none_type: + # The only way the input data can match the 'None' type + # is if the input data is the 'null' value. + if model_args is None: + return None + continue # transform js keys to python keys in fixed_model_args fixed_model_args = change_keys_js_to_python(model_args, anyof_class) diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/NullableClass.md b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/NullableClass.md index e24e64475153..e81e45f2d40a 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/NullableClass.md +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/NullableClass.md @@ -10,12 +10,12 @@ Name | Type | Description | Notes **StringProp** | Pointer to **NullableString** | | [optional] **DateProp** | Pointer to **NullableString** | | [optional] **DatetimeProp** | Pointer to [**NullableTime**](time.Time.md) | | [optional] -**ArrayNullableProp** | Pointer to **[]map[string]interface{}** | | [optional] -**ArrayAndItemsNullableProp** | Pointer to **[]map[string]interface{}** | | [optional] -**ArrayItemsNullable** | Pointer to **[]map[string]interface{}** | | [optional] -**ObjectNullableProp** | Pointer to **map[string]map[string]interface{}** | | [optional] -**ObjectAndItemsNullableProp** | Pointer to **map[string]map[string]interface{}** | | [optional] -**ObjectItemsNullable** | Pointer to **map[string]map[string]interface{}** | | [optional] +**ArrayNullableProp** | Pointer to **[]ObjectType** | | [optional] +**ArrayAndItemsNullableProp** | Pointer to **[]ObjectType** | | [optional] +**ArrayItemsNullable** | Pointer to **[]ObjectType** | | [optional] +**ObjectNullableProp** | Pointer to **map[string]ObjectType** | | [optional] +**ObjectAndItemsNullableProp** | Pointer to **map[string]ObjectType** | | [optional] +**ObjectItemsNullable** | Pointer to **map[string]ObjectType** | | [optional] ## Methods @@ -248,20 +248,20 @@ HasDatetimeProp returns a boolean if a field has been set. UnsetDatetimeProp ensures that no value is present for DatetimeProp, not even an explicit nil ### GetArrayNullableProp -`func (o *NullableClass) GetArrayNullableProp() []map[string]interface{}` +`func (o *NullableClass) GetArrayNullableProp() []ObjectType` GetArrayNullableProp returns the ArrayNullableProp field if non-nil, zero value otherwise. ### GetArrayNullablePropOk -`func (o *NullableClass) GetArrayNullablePropOk() (*[]map[string]interface{}, bool)` +`func (o *NullableClass) GetArrayNullablePropOk() (*[]ObjectType, bool)` GetArrayNullablePropOk returns a tuple with the ArrayNullableProp field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetArrayNullableProp -`func (o *NullableClass) SetArrayNullableProp(v []map[string]interface{})` +`func (o *NullableClass) SetArrayNullableProp(v []ObjectType)` SetArrayNullableProp sets ArrayNullableProp field to given value. @@ -283,20 +283,20 @@ HasArrayNullableProp returns a boolean if a field has been set. UnsetArrayNullableProp ensures that no value is present for ArrayNullableProp, not even an explicit nil ### GetArrayAndItemsNullableProp -`func (o *NullableClass) GetArrayAndItemsNullableProp() []map[string]interface{}` +`func (o *NullableClass) GetArrayAndItemsNullableProp() []ObjectType` GetArrayAndItemsNullableProp returns the ArrayAndItemsNullableProp field if non-nil, zero value otherwise. ### GetArrayAndItemsNullablePropOk -`func (o *NullableClass) GetArrayAndItemsNullablePropOk() (*[]map[string]interface{}, bool)` +`func (o *NullableClass) GetArrayAndItemsNullablePropOk() (*[]ObjectType, bool)` GetArrayAndItemsNullablePropOk returns a tuple with the ArrayAndItemsNullableProp field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetArrayAndItemsNullableProp -`func (o *NullableClass) SetArrayAndItemsNullableProp(v []map[string]interface{})` +`func (o *NullableClass) SetArrayAndItemsNullableProp(v []ObjectType)` SetArrayAndItemsNullableProp sets ArrayAndItemsNullableProp field to given value. @@ -318,20 +318,20 @@ HasArrayAndItemsNullableProp returns a boolean if a field has been set. UnsetArrayAndItemsNullableProp ensures that no value is present for ArrayAndItemsNullableProp, not even an explicit nil ### GetArrayItemsNullable -`func (o *NullableClass) GetArrayItemsNullable() []map[string]interface{}` +`func (o *NullableClass) GetArrayItemsNullable() []ObjectType` GetArrayItemsNullable returns the ArrayItemsNullable field if non-nil, zero value otherwise. ### GetArrayItemsNullableOk -`func (o *NullableClass) GetArrayItemsNullableOk() (*[]map[string]interface{}, bool)` +`func (o *NullableClass) GetArrayItemsNullableOk() (*[]ObjectType, bool)` GetArrayItemsNullableOk returns a tuple with the ArrayItemsNullable field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetArrayItemsNullable -`func (o *NullableClass) SetArrayItemsNullable(v []map[string]interface{})` +`func (o *NullableClass) SetArrayItemsNullable(v []ObjectType)` SetArrayItemsNullable sets ArrayItemsNullable field to given value. @@ -343,20 +343,20 @@ HasArrayItemsNullable returns a boolean if a field has been set. ### GetObjectNullableProp -`func (o *NullableClass) GetObjectNullableProp() map[string]map[string]interface{}` +`func (o *NullableClass) GetObjectNullableProp() map[string]ObjectType` GetObjectNullableProp returns the ObjectNullableProp field if non-nil, zero value otherwise. ### GetObjectNullablePropOk -`func (o *NullableClass) GetObjectNullablePropOk() (*map[string]map[string]interface{}, bool)` +`func (o *NullableClass) GetObjectNullablePropOk() (*map[string]ObjectType, bool)` GetObjectNullablePropOk returns a tuple with the ObjectNullableProp field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetObjectNullableProp -`func (o *NullableClass) SetObjectNullableProp(v map[string]map[string]interface{})` +`func (o *NullableClass) SetObjectNullableProp(v map[string]ObjectType)` SetObjectNullableProp sets ObjectNullableProp field to given value. @@ -378,20 +378,20 @@ HasObjectNullableProp returns a boolean if a field has been set. UnsetObjectNullableProp ensures that no value is present for ObjectNullableProp, not even an explicit nil ### GetObjectAndItemsNullableProp -`func (o *NullableClass) GetObjectAndItemsNullableProp() map[string]map[string]interface{}` +`func (o *NullableClass) GetObjectAndItemsNullableProp() map[string]ObjectType` GetObjectAndItemsNullableProp returns the ObjectAndItemsNullableProp field if non-nil, zero value otherwise. ### GetObjectAndItemsNullablePropOk -`func (o *NullableClass) GetObjectAndItemsNullablePropOk() (*map[string]map[string]interface{}, bool)` +`func (o *NullableClass) GetObjectAndItemsNullablePropOk() (*map[string]ObjectType, bool)` GetObjectAndItemsNullablePropOk returns a tuple with the ObjectAndItemsNullableProp field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetObjectAndItemsNullableProp -`func (o *NullableClass) SetObjectAndItemsNullableProp(v map[string]map[string]interface{})` +`func (o *NullableClass) SetObjectAndItemsNullableProp(v map[string]ObjectType)` SetObjectAndItemsNullableProp sets ObjectAndItemsNullableProp field to given value. @@ -413,20 +413,20 @@ HasObjectAndItemsNullableProp returns a boolean if a field has been set. UnsetObjectAndItemsNullableProp ensures that no value is present for ObjectAndItemsNullableProp, not even an explicit nil ### GetObjectItemsNullable -`func (o *NullableClass) GetObjectItemsNullable() map[string]map[string]interface{}` +`func (o *NullableClass) GetObjectItemsNullable() map[string]ObjectType` GetObjectItemsNullable returns the ObjectItemsNullable field if non-nil, zero value otherwise. ### GetObjectItemsNullableOk -`func (o *NullableClass) GetObjectItemsNullableOk() (*map[string]map[string]interface{}, bool)` +`func (o *NullableClass) GetObjectItemsNullableOk() (*map[string]ObjectType, bool)` GetObjectItemsNullableOk returns a tuple with the ObjectItemsNullable field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetObjectItemsNullable -`func (o *NullableClass) SetObjectItemsNullable(v map[string]map[string]interface{})` +`func (o *NullableClass) SetObjectItemsNullable(v map[string]ObjectType)` SetObjectItemsNullable sets ObjectItemsNullable field to given value. diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/User.md b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/User.md index f40be495a5ab..6b48fb85254e 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/User.md +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/User.md @@ -12,10 +12,10 @@ Name | Type | Description | Notes **Password** | Pointer to **string** | | [optional] **Phone** | Pointer to **string** | | [optional] **UserStatus** | Pointer to **int32** | User Status | [optional] -**ArbitraryObject** | Pointer to [**map[string]interface{}**](.md) | test code generation for objects Value must be a map of strings to values. It cannot be the 'null' value. | [optional] -**ArbitraryNullableObject** | Pointer to [**map[string]interface{}**](.md) | test code generation for nullable objects. Value must be a map of strings to values or the 'null' value. | [optional] -**ArbitraryTypeValue** | Pointer to [**interface{}**](.md) | test code generation for any type Value can be any type - string, number, boolean, array or object. | [optional] -**ArbitraryNullableTypeValue** | Pointer to [**interface{}**](.md) | test code generation for any type Value can be any type - string, number, boolean, array, object or the 'null' value. | [optional] +**ArbitraryObject** | Pointer to [**ObjectType**](.md) | test code generation for objects Value must be a map of strings to values. It cannot be the 'null' value. | [optional] +**ArbitraryNullableObject** | Pointer to [**ObjectType**](.md) | test code generation for nullable objects. Value must be a map of strings to values or the 'null' value. | [optional] +**ArbitraryTypeValue** | Pointer to [**AnyType**](.md) | test code generation for any type Value can be any type - string, number, boolean, array or object. | [optional] +**ArbitraryNullableTypeValue** | Pointer to [**AnyType**](.md) | test code generation for any type Value can be any type - string, number, boolean, array, object or the 'null' value. | [optional] ## Methods @@ -238,20 +238,20 @@ HasUserStatus returns a boolean if a field has been set. ### GetArbitraryObject -`func (o *User) GetArbitraryObject() map[string]interface{}` +`func (o *User) GetArbitraryObject() ObjectType` GetArbitraryObject returns the ArbitraryObject field if non-nil, zero value otherwise. ### GetArbitraryObjectOk -`func (o *User) GetArbitraryObjectOk() (*map[string]interface{}, bool)` +`func (o *User) GetArbitraryObjectOk() (*ObjectType, bool)` GetArbitraryObjectOk returns a tuple with the ArbitraryObject field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetArbitraryObject -`func (o *User) SetArbitraryObject(v map[string]interface{})` +`func (o *User) SetArbitraryObject(v ObjectType)` SetArbitraryObject sets ArbitraryObject field to given value. @@ -263,20 +263,20 @@ HasArbitraryObject returns a boolean if a field has been set. ### GetArbitraryNullableObject -`func (o *User) GetArbitraryNullableObject() map[string]interface{}` +`func (o *User) GetArbitraryNullableObject() ObjectType` GetArbitraryNullableObject returns the ArbitraryNullableObject field if non-nil, zero value otherwise. ### GetArbitraryNullableObjectOk -`func (o *User) GetArbitraryNullableObjectOk() (*map[string]interface{}, bool)` +`func (o *User) GetArbitraryNullableObjectOk() (*ObjectType, bool)` GetArbitraryNullableObjectOk returns a tuple with the ArbitraryNullableObject field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetArbitraryNullableObject -`func (o *User) SetArbitraryNullableObject(v map[string]interface{})` +`func (o *User) SetArbitraryNullableObject(v ObjectType)` SetArbitraryNullableObject sets ArbitraryNullableObject field to given value. @@ -298,20 +298,20 @@ HasArbitraryNullableObject returns a boolean if a field has been set. UnsetArbitraryNullableObject ensures that no value is present for ArbitraryNullableObject, not even an explicit nil ### GetArbitraryTypeValue -`func (o *User) GetArbitraryTypeValue() interface{}` +`func (o *User) GetArbitraryTypeValue() AnyType` GetArbitraryTypeValue returns the ArbitraryTypeValue field if non-nil, zero value otherwise. ### GetArbitraryTypeValueOk -`func (o *User) GetArbitraryTypeValueOk() (*interface{}, bool)` +`func (o *User) GetArbitraryTypeValueOk() (*AnyType, bool)` GetArbitraryTypeValueOk returns a tuple with the ArbitraryTypeValue field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetArbitraryTypeValue -`func (o *User) SetArbitraryTypeValue(v interface{})` +`func (o *User) SetArbitraryTypeValue(v AnyType)` SetArbitraryTypeValue sets ArbitraryTypeValue field to given value. @@ -323,20 +323,20 @@ HasArbitraryTypeValue returns a boolean if a field has been set. ### GetArbitraryNullableTypeValue -`func (o *User) GetArbitraryNullableTypeValue() interface{}` +`func (o *User) GetArbitraryNullableTypeValue() AnyType` GetArbitraryNullableTypeValue returns the ArbitraryNullableTypeValue field if non-nil, zero value otherwise. ### GetArbitraryNullableTypeValueOk -`func (o *User) GetArbitraryNullableTypeValueOk() (*interface{}, bool)` +`func (o *User) GetArbitraryNullableTypeValueOk() (*AnyType, bool)` GetArbitraryNullableTypeValueOk returns a tuple with the ArbitraryNullableTypeValue field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetArbitraryNullableTypeValue -`func (o *User) SetArbitraryNullableTypeValue(v interface{})` +`func (o *User) SetArbitraryNullableTypeValue(v AnyType)` SetArbitraryNullableTypeValue sets ArbitraryNullableTypeValue field to given value. diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_nullable_class.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_nullable_class.go index c9d8facc2a84..a465419c12d8 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_nullable_class.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_nullable_class.go @@ -22,12 +22,12 @@ type NullableClass struct { StringProp NullableString `json:"string_prop,omitempty"` DateProp NullableString `json:"date_prop,omitempty"` DatetimeProp NullableTime `json:"datetime_prop,omitempty"` - ArrayNullableProp []map[string]interface{} `json:"array_nullable_prop,omitempty"` - ArrayAndItemsNullableProp []map[string]interface{} `json:"array_and_items_nullable_prop,omitempty"` - ArrayItemsNullable *[]map[string]interface{} `json:"array_items_nullable,omitempty"` - ObjectNullableProp map[string]map[string]interface{} `json:"object_nullable_prop,omitempty"` - ObjectAndItemsNullableProp map[string]map[string]interface{} `json:"object_and_items_nullable_prop,omitempty"` - ObjectItemsNullable *map[string]map[string]interface{} `json:"object_items_nullable,omitempty"` + ArrayNullableProp []ObjectType `json:"array_nullable_prop,omitempty"` + ArrayAndItemsNullableProp []ObjectType `json:"array_and_items_nullable_prop,omitempty"` + ArrayItemsNullable *[]ObjectType `json:"array_items_nullable,omitempty"` + ObjectNullableProp map[string]ObjectType `json:"object_nullable_prop,omitempty"` + ObjectAndItemsNullableProp map[string]ObjectType `json:"object_and_items_nullable_prop,omitempty"` + ObjectItemsNullable *map[string]ObjectType `json:"object_items_nullable,omitempty"` } // NewNullableClass instantiates a new NullableClass object @@ -300,9 +300,9 @@ func (o *NullableClass) UnsetDatetimeProp() { } // GetArrayNullableProp returns the ArrayNullableProp field value if set, zero value otherwise (both if not set or set to explicit null). -func (o *NullableClass) GetArrayNullableProp() []map[string]interface{} { +func (o *NullableClass) GetArrayNullableProp() []ObjectType { if o == nil { - var ret []map[string]interface{} + var ret []ObjectType return ret } return o.ArrayNullableProp @@ -311,7 +311,7 @@ func (o *NullableClass) GetArrayNullableProp() []map[string]interface{} { // GetArrayNullablePropOk returns a tuple with the ArrayNullableProp field value if set, nil otherwise // and a boolean to check if the value has been set. // NOTE: If the value is an explicit nil, `nil, true` will be returned -func (o *NullableClass) GetArrayNullablePropOk() (*[]map[string]interface{}, bool) { +func (o *NullableClass) GetArrayNullablePropOk() (*[]ObjectType, bool) { if o == nil || o.ArrayNullableProp == nil { return nil, false } @@ -327,15 +327,15 @@ func (o *NullableClass) HasArrayNullableProp() bool { return false } -// SetArrayNullableProp gets a reference to the given []map[string]interface{} and assigns it to the ArrayNullableProp field. -func (o *NullableClass) SetArrayNullableProp(v []map[string]interface{}) { +// SetArrayNullableProp gets a reference to the given []ObjectType and assigns it to the ArrayNullableProp field. +func (o *NullableClass) SetArrayNullableProp(v []ObjectType) { o.ArrayNullableProp = v } // GetArrayAndItemsNullableProp returns the ArrayAndItemsNullableProp field value if set, zero value otherwise (both if not set or set to explicit null). -func (o *NullableClass) GetArrayAndItemsNullableProp() []map[string]interface{} { +func (o *NullableClass) GetArrayAndItemsNullableProp() []ObjectType { if o == nil { - var ret []map[string]interface{} + var ret []ObjectType return ret } return o.ArrayAndItemsNullableProp @@ -344,7 +344,7 @@ func (o *NullableClass) GetArrayAndItemsNullableProp() []map[string]interface{} // GetArrayAndItemsNullablePropOk returns a tuple with the ArrayAndItemsNullableProp field value if set, nil otherwise // and a boolean to check if the value has been set. // NOTE: If the value is an explicit nil, `nil, true` will be returned -func (o *NullableClass) GetArrayAndItemsNullablePropOk() (*[]map[string]interface{}, bool) { +func (o *NullableClass) GetArrayAndItemsNullablePropOk() (*[]ObjectType, bool) { if o == nil || o.ArrayAndItemsNullableProp == nil { return nil, false } @@ -360,15 +360,15 @@ func (o *NullableClass) HasArrayAndItemsNullableProp() bool { return false } -// SetArrayAndItemsNullableProp gets a reference to the given []map[string]interface{} and assigns it to the ArrayAndItemsNullableProp field. -func (o *NullableClass) SetArrayAndItemsNullableProp(v []map[string]interface{}) { +// SetArrayAndItemsNullableProp gets a reference to the given []ObjectType and assigns it to the ArrayAndItemsNullableProp field. +func (o *NullableClass) SetArrayAndItemsNullableProp(v []ObjectType) { o.ArrayAndItemsNullableProp = v } // GetArrayItemsNullable returns the ArrayItemsNullable field value if set, zero value otherwise. -func (o *NullableClass) GetArrayItemsNullable() []map[string]interface{} { +func (o *NullableClass) GetArrayItemsNullable() []ObjectType { if o == nil || o.ArrayItemsNullable == nil { - var ret []map[string]interface{} + var ret []ObjectType return ret } return *o.ArrayItemsNullable @@ -376,7 +376,7 @@ func (o *NullableClass) GetArrayItemsNullable() []map[string]interface{} { // GetArrayItemsNullableOk returns a tuple with the ArrayItemsNullable field value if set, nil otherwise // and a boolean to check if the value has been set. -func (o *NullableClass) GetArrayItemsNullableOk() (*[]map[string]interface{}, bool) { +func (o *NullableClass) GetArrayItemsNullableOk() (*[]ObjectType, bool) { if o == nil || o.ArrayItemsNullable == nil { return nil, false } @@ -392,15 +392,15 @@ func (o *NullableClass) HasArrayItemsNullable() bool { return false } -// SetArrayItemsNullable gets a reference to the given []map[string]interface{} and assigns it to the ArrayItemsNullable field. -func (o *NullableClass) SetArrayItemsNullable(v []map[string]interface{}) { +// SetArrayItemsNullable gets a reference to the given []ObjectType and assigns it to the ArrayItemsNullable field. +func (o *NullableClass) SetArrayItemsNullable(v []ObjectType) { o.ArrayItemsNullable = &v } // GetObjectNullableProp returns the ObjectNullableProp field value if set, zero value otherwise (both if not set or set to explicit null). -func (o *NullableClass) GetObjectNullableProp() map[string]map[string]interface{} { +func (o *NullableClass) GetObjectNullableProp() map[string]ObjectType { if o == nil { - var ret map[string]map[string]interface{} + var ret map[string]ObjectType return ret } return o.ObjectNullableProp @@ -409,7 +409,7 @@ func (o *NullableClass) GetObjectNullableProp() map[string]map[string]interface{ // GetObjectNullablePropOk returns a tuple with the ObjectNullableProp field value if set, nil otherwise // and a boolean to check if the value has been set. // NOTE: If the value is an explicit nil, `nil, true` will be returned -func (o *NullableClass) GetObjectNullablePropOk() (*map[string]map[string]interface{}, bool) { +func (o *NullableClass) GetObjectNullablePropOk() (*map[string]ObjectType, bool) { if o == nil || o.ObjectNullableProp == nil { return nil, false } @@ -425,15 +425,15 @@ func (o *NullableClass) HasObjectNullableProp() bool { return false } -// SetObjectNullableProp gets a reference to the given map[string]map[string]interface{} and assigns it to the ObjectNullableProp field. -func (o *NullableClass) SetObjectNullableProp(v map[string]map[string]interface{}) { +// SetObjectNullableProp gets a reference to the given map[string]ObjectType and assigns it to the ObjectNullableProp field. +func (o *NullableClass) SetObjectNullableProp(v map[string]ObjectType) { o.ObjectNullableProp = v } // GetObjectAndItemsNullableProp returns the ObjectAndItemsNullableProp field value if set, zero value otherwise (both if not set or set to explicit null). -func (o *NullableClass) GetObjectAndItemsNullableProp() map[string]map[string]interface{} { +func (o *NullableClass) GetObjectAndItemsNullableProp() map[string]ObjectType { if o == nil { - var ret map[string]map[string]interface{} + var ret map[string]ObjectType return ret } return o.ObjectAndItemsNullableProp @@ -442,7 +442,7 @@ func (o *NullableClass) GetObjectAndItemsNullableProp() map[string]map[string]in // GetObjectAndItemsNullablePropOk returns a tuple with the ObjectAndItemsNullableProp field value if set, nil otherwise // and a boolean to check if the value has been set. // NOTE: If the value is an explicit nil, `nil, true` will be returned -func (o *NullableClass) GetObjectAndItemsNullablePropOk() (*map[string]map[string]interface{}, bool) { +func (o *NullableClass) GetObjectAndItemsNullablePropOk() (*map[string]ObjectType, bool) { if o == nil || o.ObjectAndItemsNullableProp == nil { return nil, false } @@ -458,15 +458,15 @@ func (o *NullableClass) HasObjectAndItemsNullableProp() bool { return false } -// SetObjectAndItemsNullableProp gets a reference to the given map[string]map[string]interface{} and assigns it to the ObjectAndItemsNullableProp field. -func (o *NullableClass) SetObjectAndItemsNullableProp(v map[string]map[string]interface{}) { +// SetObjectAndItemsNullableProp gets a reference to the given map[string]ObjectType and assigns it to the ObjectAndItemsNullableProp field. +func (o *NullableClass) SetObjectAndItemsNullableProp(v map[string]ObjectType) { o.ObjectAndItemsNullableProp = v } // GetObjectItemsNullable returns the ObjectItemsNullable field value if set, zero value otherwise. -func (o *NullableClass) GetObjectItemsNullable() map[string]map[string]interface{} { +func (o *NullableClass) GetObjectItemsNullable() map[string]ObjectType { if o == nil || o.ObjectItemsNullable == nil { - var ret map[string]map[string]interface{} + var ret map[string]ObjectType return ret } return *o.ObjectItemsNullable @@ -474,7 +474,7 @@ func (o *NullableClass) GetObjectItemsNullable() map[string]map[string]interface // GetObjectItemsNullableOk returns a tuple with the ObjectItemsNullable field value if set, nil otherwise // and a boolean to check if the value has been set. -func (o *NullableClass) GetObjectItemsNullableOk() (*map[string]map[string]interface{}, bool) { +func (o *NullableClass) GetObjectItemsNullableOk() (*map[string]ObjectType, bool) { if o == nil || o.ObjectItemsNullable == nil { return nil, false } @@ -490,8 +490,8 @@ func (o *NullableClass) HasObjectItemsNullable() bool { return false } -// SetObjectItemsNullable gets a reference to the given map[string]map[string]interface{} and assigns it to the ObjectItemsNullable field. -func (o *NullableClass) SetObjectItemsNullable(v map[string]map[string]interface{}) { +// SetObjectItemsNullable gets a reference to the given map[string]ObjectType and assigns it to the ObjectItemsNullable field. +func (o *NullableClass) SetObjectItemsNullable(v map[string]ObjectType) { o.ObjectItemsNullable = &v } diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_user.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_user.go index 9a9bd7dcfdac..ffa722e3bc24 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_user.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_user.go @@ -25,13 +25,13 @@ type User struct { // User Status UserStatus *int32 `json:"userStatus,omitempty"` // test code generation for objects Value must be a map of strings to values. It cannot be the 'null' value. - ArbitraryObject *map[string]interface{} `json:"arbitraryObject,omitempty"` + ArbitraryObject *ObjectType `json:"arbitraryObject,omitempty"` // test code generation for nullable objects. Value must be a map of strings to values or the 'null' value. - ArbitraryNullableObject map[string]interface{} `json:"arbitraryNullableObject,omitempty"` + ArbitraryNullableObject ObjectType `json:"arbitraryNullableObject,omitempty"` // test code generation for any type Value can be any type - string, number, boolean, array or object. - ArbitraryTypeValue *interface{} `json:"arbitraryTypeValue,omitempty"` + ArbitraryTypeValue *AnyType `json:"arbitraryTypeValue,omitempty"` // test code generation for any type Value can be any type - string, number, boolean, array, object or the 'null' value. - ArbitraryNullableTypeValue interface{} `json:"arbitraryNullableTypeValue,omitempty"` + ArbitraryNullableTypeValue AnyType `json:"arbitraryNullableTypeValue,omitempty"` } // NewUser instantiates a new User object @@ -308,9 +308,9 @@ func (o *User) SetUserStatus(v int32) { } // GetArbitraryObject returns the ArbitraryObject field value if set, zero value otherwise. -func (o *User) GetArbitraryObject() map[string]interface{} { +func (o *User) GetArbitraryObject() ObjectType { if o == nil || o.ArbitraryObject == nil { - var ret map[string]interface{} + var ret ObjectType return ret } return *o.ArbitraryObject @@ -318,7 +318,7 @@ func (o *User) GetArbitraryObject() map[string]interface{} { // GetArbitraryObjectOk returns a tuple with the ArbitraryObject field value if set, nil otherwise // and a boolean to check if the value has been set. -func (o *User) GetArbitraryObjectOk() (*map[string]interface{}, bool) { +func (o *User) GetArbitraryObjectOk() (*ObjectType, bool) { if o == nil || o.ArbitraryObject == nil { return nil, false } @@ -334,15 +334,15 @@ func (o *User) HasArbitraryObject() bool { return false } -// SetArbitraryObject gets a reference to the given map[string]interface{} and assigns it to the ArbitraryObject field. -func (o *User) SetArbitraryObject(v map[string]interface{}) { +// SetArbitraryObject gets a reference to the given ObjectType and assigns it to the ArbitraryObject field. +func (o *User) SetArbitraryObject(v ObjectType) { o.ArbitraryObject = &v } // GetArbitraryNullableObject returns the ArbitraryNullableObject field value if set, zero value otherwise (both if not set or set to explicit null). -func (o *User) GetArbitraryNullableObject() map[string]interface{} { +func (o *User) GetArbitraryNullableObject() ObjectType { if o == nil { - var ret map[string]interface{} + var ret ObjectType return ret } return o.ArbitraryNullableObject @@ -351,7 +351,7 @@ func (o *User) GetArbitraryNullableObject() map[string]interface{} { // GetArbitraryNullableObjectOk returns a tuple with the ArbitraryNullableObject field value if set, nil otherwise // and a boolean to check if the value has been set. // NOTE: If the value is an explicit nil, `nil, true` will be returned -func (o *User) GetArbitraryNullableObjectOk() (*map[string]interface{}, bool) { +func (o *User) GetArbitraryNullableObjectOk() (*ObjectType, bool) { if o == nil || o.ArbitraryNullableObject == nil { return nil, false } @@ -367,15 +367,15 @@ func (o *User) HasArbitraryNullableObject() bool { return false } -// SetArbitraryNullableObject gets a reference to the given map[string]interface{} and assigns it to the ArbitraryNullableObject field. -func (o *User) SetArbitraryNullableObject(v map[string]interface{}) { +// SetArbitraryNullableObject gets a reference to the given ObjectType and assigns it to the ArbitraryNullableObject field. +func (o *User) SetArbitraryNullableObject(v ObjectType) { o.ArbitraryNullableObject = v } // GetArbitraryTypeValue returns the ArbitraryTypeValue field value if set, zero value otherwise. -func (o *User) GetArbitraryTypeValue() interface{} { +func (o *User) GetArbitraryTypeValue() AnyType { if o == nil || o.ArbitraryTypeValue == nil { - var ret interface{} + var ret AnyType return ret } return *o.ArbitraryTypeValue @@ -383,7 +383,7 @@ func (o *User) GetArbitraryTypeValue() interface{} { // GetArbitraryTypeValueOk returns a tuple with the ArbitraryTypeValue field value if set, nil otherwise // and a boolean to check if the value has been set. -func (o *User) GetArbitraryTypeValueOk() (*interface{}, bool) { +func (o *User) GetArbitraryTypeValueOk() (*AnyType, bool) { if o == nil || o.ArbitraryTypeValue == nil { return nil, false } @@ -399,15 +399,15 @@ func (o *User) HasArbitraryTypeValue() bool { return false } -// SetArbitraryTypeValue gets a reference to the given interface{} and assigns it to the ArbitraryTypeValue field. -func (o *User) SetArbitraryTypeValue(v interface{}) { +// SetArbitraryTypeValue gets a reference to the given AnyType and assigns it to the ArbitraryTypeValue field. +func (o *User) SetArbitraryTypeValue(v AnyType) { o.ArbitraryTypeValue = &v } // GetArbitraryNullableTypeValue returns the ArbitraryNullableTypeValue field value if set, zero value otherwise (both if not set or set to explicit null). -func (o *User) GetArbitraryNullableTypeValue() interface{} { +func (o *User) GetArbitraryNullableTypeValue() AnyType { if o == nil { - var ret interface{} + var ret AnyType return ret } return o.ArbitraryNullableTypeValue @@ -416,7 +416,7 @@ func (o *User) GetArbitraryNullableTypeValue() interface{} { // GetArbitraryNullableTypeValueOk returns a tuple with the ArbitraryNullableTypeValue field value if set, nil otherwise // and a boolean to check if the value has been set. // NOTE: If the value is an explicit nil, `nil, true` will be returned -func (o *User) GetArbitraryNullableTypeValueOk() (*interface{}, bool) { +func (o *User) GetArbitraryNullableTypeValueOk() (*AnyType, bool) { if o == nil || o.ArbitraryNullableTypeValue == nil { return nil, false } @@ -432,8 +432,8 @@ func (o *User) HasArbitraryNullableTypeValue() bool { return false } -// SetArbitraryNullableTypeValue gets a reference to the given interface{} and assigns it to the ArbitraryNullableTypeValue field. -func (o *User) SetArbitraryNullableTypeValue(v interface{}) { +// SetArbitraryNullableTypeValue gets a reference to the given AnyType and assigns it to the ArbitraryNullableTypeValue field. +func (o *User) SetArbitraryNullableTypeValue(v AnyType) { o.ArbitraryNullableTypeValue = v } diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/utils.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/utils.go index 8bfc00ea74f1..7679b630ed84 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/utils.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/utils.go @@ -79,6 +79,78 @@ func (v *NullType) UnmarshalJSON(src []byte) error { return errors.New("Cannot unmarshal value into 'null' type") } +// AnyType is a type whose value can anything. +type AnyType struct{ + value interface{} + isSet bool +} + +func NewAnyType(val interface{}) *AnyType { + return &AnyType{value: val, isSet: true} +} + +func (v AnyType) Get() interface{} { + return v.value +} + +func (v *AnyType) Set(val interface{}) { + v.value = val + v.isSet = true +} + +func (v AnyType) IsSet() bool { + return v.isSet +} + +func (v *AnyType) Unset() { + v.isSet = false +} + +func (v AnyType) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *AnyType) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +// ObjectType is a type whose value can be an object with undeclared properties. +type ObjectType struct{ + value map[string]interface{} + isSet bool +} + +func NewObjectType(val map[string]interface{}) *ObjectType { + return &ObjectType{value: val, isSet: true} +} + +func (v ObjectType) Get() map[string]interface{} { + return v.value +} + +func (v *ObjectType) Set(val map[string]interface{}) { + v.value = val + v.isSet = true +} + +func (v ObjectType) IsSet() bool { + return v.isSet +} + +func (v *ObjectType) Unset() { + v.isSet = false +} + +func (v ObjectType) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *ObjectType) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + type NullableBool struct { value *bool isSet bool diff --git a/samples/openapi3/client/petstore/go/go-petstore/docs/NullableClass.md b/samples/openapi3/client/petstore/go/go-petstore/docs/NullableClass.md index a5758169c98d..1628c3c91c73 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/docs/NullableClass.md +++ b/samples/openapi3/client/petstore/go/go-petstore/docs/NullableClass.md @@ -10,12 +10,12 @@ Name | Type | Description | Notes **StringProp** | Pointer to **string** | | [optional] **DateProp** | Pointer to **string** | | [optional] **DatetimeProp** | Pointer to [**time.Time**](time.Time.md) | | [optional] -**ArrayNullableProp** | Pointer to **[]map[string]interface{}** | | [optional] -**ArrayAndItemsNullableProp** | Pointer to **[]map[string]interface{}** | | [optional] -**ArrayItemsNullable** | **[]map[string]interface{}** | | [optional] -**ObjectNullableProp** | Pointer to **map[string]map[string]interface{}** | | [optional] -**ObjectAndItemsNullableProp** | Pointer to **map[string]map[string]interface{}** | | [optional] -**ObjectItemsNullable** | **map[string]map[string]interface{}** | | [optional] +**ArrayNullableProp** | Pointer to **[]ObjectType** | | [optional] +**ArrayAndItemsNullableProp** | Pointer to **[]ObjectType** | | [optional] +**ArrayItemsNullable** | **[]ObjectType** | | [optional] +**ObjectNullableProp** | Pointer to **map[string]ObjectType** | | [optional] +**ObjectAndItemsNullableProp** | Pointer to **map[string]ObjectType** | | [optional] +**ObjectItemsNullable** | **map[string]ObjectType** | | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_nullable_class.go b/samples/openapi3/client/petstore/go/go-petstore/model_nullable_class.go index 952129120f9a..86155d24b797 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_nullable_class.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_nullable_class.go @@ -19,10 +19,10 @@ type NullableClass struct { StringProp *string `json:"string_prop,omitempty"` DateProp *string `json:"date_prop,omitempty"` DatetimeProp *time.Time `json:"datetime_prop,omitempty"` - ArrayNullableProp *[]map[string]interface{} `json:"array_nullable_prop,omitempty"` - ArrayAndItemsNullableProp *[]map[string]interface{} `json:"array_and_items_nullable_prop,omitempty"` - ArrayItemsNullable []map[string]interface{} `json:"array_items_nullable,omitempty"` - ObjectNullableProp *map[string]map[string]interface{} `json:"object_nullable_prop,omitempty"` - ObjectAndItemsNullableProp *map[string]map[string]interface{} `json:"object_and_items_nullable_prop,omitempty"` - ObjectItemsNullable map[string]map[string]interface{} `json:"object_items_nullable,omitempty"` + ArrayNullableProp *[]ObjectType `json:"array_nullable_prop,omitempty"` + ArrayAndItemsNullableProp *[]ObjectType `json:"array_and_items_nullable_prop,omitempty"` + ArrayItemsNullable []ObjectType `json:"array_items_nullable,omitempty"` + ObjectNullableProp *map[string]ObjectType `json:"object_nullable_prop,omitempty"` + ObjectAndItemsNullableProp *map[string]ObjectType `json:"object_and_items_nullable_prop,omitempty"` + ObjectItemsNullable map[string]ObjectType `json:"object_items_nullable,omitempty"` } From 1e14c94136190027c78c11cc6c901573ef4394c0 Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Mon, 4 May 2020 08:28:34 -0700 Subject: [PATCH 16/48] Add review comments --- .../python-experimental/model_utils.mustache | 25 ++++--------------- .../petstore_api/model_utils.py | 25 ++++--------------- .../petstore_api/model_utils.py | 25 ++++--------------- .../petstore_api/models/fruit_req.py | 1 - 4 files changed, 15 insertions(+), 61 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache b/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache index 182eb07508b7..686173802c22 100644 --- a/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache +++ b/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache @@ -1024,16 +1024,15 @@ def get_oneof_instance(self, model_args, constant_args): schemas described by oneOf. Args: self: the class we are handling - model_args (dict/None): var_name to var_value + model_args (dict): var_name to var_value The input data, e.g. the payload that must match a oneOf schema - in the OpenAPI document. If the input data is the null value, - model_args is None. + in the OpenAPI document. constant_args (dict): var_name to var_value args that every model requires, including configuration, server and path to item. Returns - oneof_instance (instance/None) + oneof_instance (instance) """ if len(self._composed_schemas['oneOf']) == 0: return None @@ -1042,13 +1041,6 @@ def get_oneof_instance(self, model_args, constant_args): # Iterate over each oneOf schema and determine if the input data # matches the oneOf schemas. for oneof_class in self._composed_schemas['oneOf']: - if oneof_class is none_type: - # The only way the input data can match the 'None' type - # is if the input data is the 'null' value. - if model_args is None: - # The input data matches the 'None' type. - oneof_instances.append(model_args) - continue # transform js keys from input data to python keys in fixed_model_args fixed_model_args = change_keys_js_to_python( model_args, oneof_class) @@ -1093,10 +1085,9 @@ def get_anyof_instances(self, model_args, constant_args): """ Args: self: the class we are handling - model_args (dict/None): var_name to var_value + model_args (dict): var_name to var_value The input data, e.g. the payload that must match at least one - anyOf child schema in the OpenAPI document. If the input data - is the null value, model_args is None. + anyOf child schema in the OpenAPI document. constant_args (dict): var_name to var_value args that every model requires, including configuration, server and path to item. @@ -1109,12 +1100,6 @@ def get_anyof_instances(self, model_args, constant_args): return anyof_instances for anyof_class in self._composed_schemas['anyOf']: - if anyof_class is none_type: - # The only way the input data can match the 'None' type - # is if the input data is the 'null' value. - if model_args is None: - return None - continue # transform js keys to python keys in fixed_model_args fixed_model_args = change_keys_js_to_python(model_args, anyof_class) diff --git a/samples/client/petstore/python-experimental/petstore_api/model_utils.py b/samples/client/petstore/python-experimental/petstore_api/model_utils.py index 677fb2dd909c..ee328e57a311 100644 --- a/samples/client/petstore/python-experimental/petstore_api/model_utils.py +++ b/samples/client/petstore/python-experimental/petstore_api/model_utils.py @@ -1285,16 +1285,15 @@ def get_oneof_instance(self, model_args, constant_args): schemas described by oneOf. Args: self: the class we are handling - model_args (dict/None): var_name to var_value + model_args (dict): var_name to var_value The input data, e.g. the payload that must match a oneOf schema - in the OpenAPI document. If the input data is the null value, - model_args is None. + in the OpenAPI document. constant_args (dict): var_name to var_value args that every model requires, including configuration, server and path to item. Returns - oneof_instance (instance/None) + oneof_instance (instance) """ if len(self._composed_schemas['oneOf']) == 0: return None @@ -1303,13 +1302,6 @@ def get_oneof_instance(self, model_args, constant_args): # Iterate over each oneOf schema and determine if the input data # matches the oneOf schemas. for oneof_class in self._composed_schemas['oneOf']: - if oneof_class is none_type: - # The only way the input data can match the 'None' type - # is if the input data is the 'null' value. - if model_args is None: - # The input data matches the 'None' type. - oneof_instances.append(model_args) - continue # transform js keys from input data to python keys in fixed_model_args fixed_model_args = change_keys_js_to_python( model_args, oneof_class) @@ -1354,10 +1346,9 @@ def get_anyof_instances(self, model_args, constant_args): """ Args: self: the class we are handling - model_args (dict/None): var_name to var_value + model_args (dict): var_name to var_value The input data, e.g. the payload that must match at least one - anyOf child schema in the OpenAPI document. If the input data - is the null value, model_args is None. + anyOf child schema in the OpenAPI document. constant_args (dict): var_name to var_value args that every model requires, including configuration, server and path to item. @@ -1370,12 +1361,6 @@ def get_anyof_instances(self, model_args, constant_args): return anyof_instances for anyof_class in self._composed_schemas['anyOf']: - if anyof_class is none_type: - # The only way the input data can match the 'None' type - # is if the input data is the 'null' value. - if model_args is None: - return None - continue # transform js keys to python keys in fixed_model_args fixed_model_args = change_keys_js_to_python(model_args, anyof_class) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py index 677fb2dd909c..ee328e57a311 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py @@ -1285,16 +1285,15 @@ def get_oneof_instance(self, model_args, constant_args): schemas described by oneOf. Args: self: the class we are handling - model_args (dict/None): var_name to var_value + model_args (dict): var_name to var_value The input data, e.g. the payload that must match a oneOf schema - in the OpenAPI document. If the input data is the null value, - model_args is None. + in the OpenAPI document. constant_args (dict): var_name to var_value args that every model requires, including configuration, server and path to item. Returns - oneof_instance (instance/None) + oneof_instance (instance) """ if len(self._composed_schemas['oneOf']) == 0: return None @@ -1303,13 +1302,6 @@ def get_oneof_instance(self, model_args, constant_args): # Iterate over each oneOf schema and determine if the input data # matches the oneOf schemas. for oneof_class in self._composed_schemas['oneOf']: - if oneof_class is none_type: - # The only way the input data can match the 'None' type - # is if the input data is the 'null' value. - if model_args is None: - # The input data matches the 'None' type. - oneof_instances.append(model_args) - continue # transform js keys from input data to python keys in fixed_model_args fixed_model_args = change_keys_js_to_python( model_args, oneof_class) @@ -1354,10 +1346,9 @@ def get_anyof_instances(self, model_args, constant_args): """ Args: self: the class we are handling - model_args (dict/None): var_name to var_value + model_args (dict): var_name to var_value The input data, e.g. the payload that must match at least one - anyOf child schema in the OpenAPI document. If the input data - is the null value, model_args is None. + anyOf child schema in the OpenAPI document. constant_args (dict): var_name to var_value args that every model requires, including configuration, server and path to item. @@ -1370,12 +1361,6 @@ def get_anyof_instances(self, model_args, constant_args): return anyof_instances for anyof_class in self._composed_schemas['anyOf']: - if anyof_class is none_type: - # The only way the input data can match the 'None' type - # is if the input data is the 'null' value. - if model_args is None: - return None - continue # transform js keys to python keys in fixed_model_args fixed_model_args = change_keys_js_to_python(model_args, anyof_class) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/fruit_req.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/fruit_req.py index 130f8781a7f3..a1836e551c0e 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/fruit_req.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/fruit_req.py @@ -218,6 +218,5 @@ def _composed_schemas(): 'oneOf': [ apple_req.AppleReq, banana_req.BananaReq, - none_type, ], } From 747803e4e00cd73043e1f8d08f38d41ea3c8bcb5 Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Mon, 4 May 2020 08:33:10 -0700 Subject: [PATCH 17/48] Add 'null' type in oneOf --- ...th-fake-endpoints-models-for-testing-with-http-signature.yaml | 1 + .../python-experimental/petstore_api/models/fruit_req.py | 1 + 2 files changed, 2 insertions(+) diff --git a/modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml b/modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml index 066d7f295127..784e47d60b2d 100644 --- a/modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml @@ -1855,6 +1855,7 @@ components: - $ref: '#/components/schemas/banana' fruitReq: oneOf: + - type: 'null' - $ref: '#/components/schemas/appleReq' - $ref: '#/components/schemas/bananaReq' appleReq: diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/fruit_req.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/fruit_req.py index a1836e551c0e..130f8781a7f3 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/fruit_req.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/fruit_req.py @@ -218,5 +218,6 @@ def _composed_schemas(): 'oneOf': [ apple_req.AppleReq, banana_req.BananaReq, + none_type, ], } From aa06a8940565754eee6058ca90b41c1fbd4568c8 Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Mon, 4 May 2020 11:30:21 -0700 Subject: [PATCH 18/48] Improve OAS YAML file for golang openapi3 samples --- ...odels-for-testing-with-http-signature.yaml | 23 ++- .../go-petstore/api/openapi.yaml | 36 ++-- .../go-petstore/docs/FakeApi.md | 2 +- .../go-experimental/go-petstore/docs/User.md | 154 +++++++++------- .../go-petstore/docs/UserApi.md | 4 +- .../go-experimental/go-petstore/model_user.go | 173 +++++++++++------- 6 files changed, 237 insertions(+), 155 deletions(-) diff --git a/modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml b/modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml index 69633315c6c6..a3379d5e4650 100644 --- a/modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml @@ -1250,22 +1250,31 @@ components: type: integer format: int32 description: User Status - arbitraryObject: + objectWithNoDeclaredProps: type: object description: test code generation for objects Value must be a map of strings to values. It cannot be the 'null' value. - arbitraryNullableObject: + objectWithNoDeclaredPropsNullable: type: object description: test code generation for nullable objects. Value must be a map of strings to values or the 'null' value. nullable: true - arbitraryTypeValue: + anyTypeProp: description: test code generation for any type - Value can be any type - string, number, boolean, array or object. - arbitraryNullableTypeValue: + Here the 'type' attribute is not specified, which means the value can be anything, + including the null value, string, number, boolean, array or object. + See https://github.com/OAI/OpenAPI-Specification/issues/1389 + anyTypeExceptNullProp: + description: any type except 'null' + Here the 'type' attribute is not specified, which means the value can be anything, + including the null value, string, number, boolean, array or object. + not: + type: 'null' + anyTypePropNullable: description: test code generation for any type - Value can be any type - string, number, boolean, array, object or - the 'null' value. + Here the 'type' attribute is not specified, which means the value can be anything, + including the null value, string, number, boolean, array or object. + The 'nullable' attribute does not change the allowed values. nullable: true xml: name: User diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/api/openapi.yaml b/samples/openapi3/client/petstore/go-experimental/go-petstore/api/openapi.yaml index b27754a8c93a..762d0966ab93 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/api/openapi.yaml +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/api/openapi.yaml @@ -1295,17 +1295,18 @@ components: name: Category User: example: - firstName: firstName lastName: lastName - password: password userStatus: 6 - arbitraryTypeValue: "" - arbitraryNullableTypeValue: "" + objectWithNoDeclaredPropsNullable: '{}' + anyTypeExceptNullProp: "" + firstName: firstName + password: password phone: phone + objectWithNoDeclaredProps: '{}' id: 0 - arbitraryObject: '{}' + anyTypePropNullable: "" email: email - arbitraryNullableObject: '{}' + anyTypeProp: "" username: username properties: id: @@ -1328,21 +1329,30 @@ components: description: User Status format: int32 type: integer - arbitraryObject: + objectWithNoDeclaredProps: description: test code generation for objects Value must be a map of strings to values. It cannot be the 'null' value. type: object - arbitraryNullableObject: + objectWithNoDeclaredPropsNullable: description: test code generation for nullable objects. Value must be a map of strings to values or the 'null' value. nullable: true type: object - arbitraryTypeValue: - description: test code generation for any type Value can be any type - string, + anyTypeProp: + description: test code generation for any type Here the 'type' attribute + is not specified, which means the value can be anything, including the + null value, string, number, boolean, array or object. See https://github.com/OAI/OpenAPI-Specification/issues/1389 + anyTypeExceptNullProp: + description: any type except 'null' Here the 'type' attribute is not specified, + which means the value can be anything, including the null value, string, number, boolean, array or object. - arbitraryNullableTypeValue: - description: test code generation for any type Value can be any type - string, - number, boolean, array, object or the 'null' value. + not: + type: "null" + anyTypePropNullable: + description: test code generation for any type Here the 'type' attribute + is not specified, which means the value can be anything, including the + null value, string, number, boolean, array or object. The 'nullable' attribute + does not change the allowed values. nullable: true type: object xml: diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/FakeApi.md b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/FakeApi.md index ba556cb8ea45..ddc157ba045a 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/FakeApi.md +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/FakeApi.md @@ -428,7 +428,7 @@ import ( func main() { query := "query_example" // string | - user := openapiclient.User{Id: int64(123), Username: "Username_example", FirstName: "FirstName_example", LastName: "LastName_example", Email: "Email_example", Password: "Password_example", Phone: "Phone_example", UserStatus: 123, ArbitraryObject: "TODO", ArbitraryNullableObject: "TODO", ArbitraryTypeValue: "TODO", ArbitraryNullableTypeValue: "TODO"} // User | + user := openapiclient.User{Id: int64(123), Username: "Username_example", FirstName: "FirstName_example", LastName: "LastName_example", Email: "Email_example", Password: "Password_example", Phone: "Phone_example", UserStatus: 123, ObjectWithNoDeclaredProps: "TODO", ObjectWithNoDeclaredPropsNullable: "TODO", AnyTypeProp: "TODO", AnyTypeExceptNullProp: 123, AnyTypePropNullable: "TODO"} // User | configuration := openapiclient.NewConfiguration() api_client := openapiclient.NewAPIClient(configuration) diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/User.md b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/User.md index 6b48fb85254e..86acd98001dd 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/User.md +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/User.md @@ -12,10 +12,11 @@ Name | Type | Description | Notes **Password** | Pointer to **string** | | [optional] **Phone** | Pointer to **string** | | [optional] **UserStatus** | Pointer to **int32** | User Status | [optional] -**ArbitraryObject** | Pointer to [**ObjectType**](.md) | test code generation for objects Value must be a map of strings to values. It cannot be the 'null' value. | [optional] -**ArbitraryNullableObject** | Pointer to [**ObjectType**](.md) | test code generation for nullable objects. Value must be a map of strings to values or the 'null' value. | [optional] -**ArbitraryTypeValue** | Pointer to [**AnyType**](.md) | test code generation for any type Value can be any type - string, number, boolean, array or object. | [optional] -**ArbitraryNullableTypeValue** | Pointer to [**AnyType**](.md) | test code generation for any type Value can be any type - string, number, boolean, array, object or the 'null' value. | [optional] +**ObjectWithNoDeclaredProps** | Pointer to [**ObjectType**](.md) | test code generation for objects Value must be a map of strings to values. It cannot be the 'null' value. | [optional] +**ObjectWithNoDeclaredPropsNullable** | Pointer to [**ObjectType**](.md) | test code generation for nullable objects. Value must be a map of strings to values or the 'null' value. | [optional] +**AnyTypeProp** | Pointer to [**AnyType**](.md) | test code generation for any type Here the 'type' attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. See https://github.com/OAI/OpenAPI-Specification/issues/1389 | [optional] +**AnyTypeExceptNullProp** | Pointer to **ObjectType** | any type except 'null' Here the 'type' attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. | [optional] +**AnyTypePropNullable** | Pointer to [**AnyType**](.md) | test code generation for any type Here the 'type' attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. The 'nullable' attribute does not change the allowed values. | [optional] ## Methods @@ -236,126 +237,151 @@ SetUserStatus sets UserStatus field to given value. HasUserStatus returns a boolean if a field has been set. -### GetArbitraryObject +### GetObjectWithNoDeclaredProps -`func (o *User) GetArbitraryObject() ObjectType` +`func (o *User) GetObjectWithNoDeclaredProps() ObjectType` -GetArbitraryObject returns the ArbitraryObject field if non-nil, zero value otherwise. +GetObjectWithNoDeclaredProps returns the ObjectWithNoDeclaredProps field if non-nil, zero value otherwise. -### GetArbitraryObjectOk +### GetObjectWithNoDeclaredPropsOk -`func (o *User) GetArbitraryObjectOk() (*ObjectType, bool)` +`func (o *User) GetObjectWithNoDeclaredPropsOk() (*ObjectType, bool)` -GetArbitraryObjectOk returns a tuple with the ArbitraryObject field if it's non-nil, zero value otherwise +GetObjectWithNoDeclaredPropsOk returns a tuple with the ObjectWithNoDeclaredProps field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. -### SetArbitraryObject +### SetObjectWithNoDeclaredProps -`func (o *User) SetArbitraryObject(v ObjectType)` +`func (o *User) SetObjectWithNoDeclaredProps(v ObjectType)` -SetArbitraryObject sets ArbitraryObject field to given value. +SetObjectWithNoDeclaredProps sets ObjectWithNoDeclaredProps field to given value. -### HasArbitraryObject +### HasObjectWithNoDeclaredProps -`func (o *User) HasArbitraryObject() bool` +`func (o *User) HasObjectWithNoDeclaredProps() bool` -HasArbitraryObject returns a boolean if a field has been set. +HasObjectWithNoDeclaredProps returns a boolean if a field has been set. -### GetArbitraryNullableObject +### GetObjectWithNoDeclaredPropsNullable -`func (o *User) GetArbitraryNullableObject() ObjectType` +`func (o *User) GetObjectWithNoDeclaredPropsNullable() ObjectType` -GetArbitraryNullableObject returns the ArbitraryNullableObject field if non-nil, zero value otherwise. +GetObjectWithNoDeclaredPropsNullable returns the ObjectWithNoDeclaredPropsNullable field if non-nil, zero value otherwise. -### GetArbitraryNullableObjectOk +### GetObjectWithNoDeclaredPropsNullableOk -`func (o *User) GetArbitraryNullableObjectOk() (*ObjectType, bool)` +`func (o *User) GetObjectWithNoDeclaredPropsNullableOk() (*ObjectType, bool)` -GetArbitraryNullableObjectOk returns a tuple with the ArbitraryNullableObject field if it's non-nil, zero value otherwise +GetObjectWithNoDeclaredPropsNullableOk returns a tuple with the ObjectWithNoDeclaredPropsNullable field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. -### SetArbitraryNullableObject +### SetObjectWithNoDeclaredPropsNullable -`func (o *User) SetArbitraryNullableObject(v ObjectType)` +`func (o *User) SetObjectWithNoDeclaredPropsNullable(v ObjectType)` -SetArbitraryNullableObject sets ArbitraryNullableObject field to given value. +SetObjectWithNoDeclaredPropsNullable sets ObjectWithNoDeclaredPropsNullable field to given value. -### HasArbitraryNullableObject +### HasObjectWithNoDeclaredPropsNullable -`func (o *User) HasArbitraryNullableObject() bool` +`func (o *User) HasObjectWithNoDeclaredPropsNullable() bool` -HasArbitraryNullableObject returns a boolean if a field has been set. +HasObjectWithNoDeclaredPropsNullable returns a boolean if a field has been set. -### SetArbitraryNullableObjectNil +### SetObjectWithNoDeclaredPropsNullableNil -`func (o *User) SetArbitraryNullableObjectNil(b bool)` +`func (o *User) SetObjectWithNoDeclaredPropsNullableNil(b bool)` - SetArbitraryNullableObjectNil sets the value for ArbitraryNullableObject to be an explicit nil + SetObjectWithNoDeclaredPropsNullableNil sets the value for ObjectWithNoDeclaredPropsNullable to be an explicit nil -### UnsetArbitraryNullableObject -`func (o *User) UnsetArbitraryNullableObject()` +### UnsetObjectWithNoDeclaredPropsNullable +`func (o *User) UnsetObjectWithNoDeclaredPropsNullable()` -UnsetArbitraryNullableObject ensures that no value is present for ArbitraryNullableObject, not even an explicit nil -### GetArbitraryTypeValue +UnsetObjectWithNoDeclaredPropsNullable ensures that no value is present for ObjectWithNoDeclaredPropsNullable, not even an explicit nil +### GetAnyTypeProp -`func (o *User) GetArbitraryTypeValue() AnyType` +`func (o *User) GetAnyTypeProp() AnyType` -GetArbitraryTypeValue returns the ArbitraryTypeValue field if non-nil, zero value otherwise. +GetAnyTypeProp returns the AnyTypeProp field if non-nil, zero value otherwise. -### GetArbitraryTypeValueOk +### GetAnyTypePropOk -`func (o *User) GetArbitraryTypeValueOk() (*AnyType, bool)` +`func (o *User) GetAnyTypePropOk() (*AnyType, bool)` -GetArbitraryTypeValueOk returns a tuple with the ArbitraryTypeValue field if it's non-nil, zero value otherwise +GetAnyTypePropOk returns a tuple with the AnyTypeProp field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. -### SetArbitraryTypeValue +### SetAnyTypeProp -`func (o *User) SetArbitraryTypeValue(v AnyType)` +`func (o *User) SetAnyTypeProp(v AnyType)` -SetArbitraryTypeValue sets ArbitraryTypeValue field to given value. +SetAnyTypeProp sets AnyTypeProp field to given value. -### HasArbitraryTypeValue +### HasAnyTypeProp -`func (o *User) HasArbitraryTypeValue() bool` +`func (o *User) HasAnyTypeProp() bool` -HasArbitraryTypeValue returns a boolean if a field has been set. +HasAnyTypeProp returns a boolean if a field has been set. -### GetArbitraryNullableTypeValue +### GetAnyTypeExceptNullProp -`func (o *User) GetArbitraryNullableTypeValue() AnyType` +`func (o *User) GetAnyTypeExceptNullProp() ObjectType` -GetArbitraryNullableTypeValue returns the ArbitraryNullableTypeValue field if non-nil, zero value otherwise. +GetAnyTypeExceptNullProp returns the AnyTypeExceptNullProp field if non-nil, zero value otherwise. -### GetArbitraryNullableTypeValueOk +### GetAnyTypeExceptNullPropOk -`func (o *User) GetArbitraryNullableTypeValueOk() (*AnyType, bool)` +`func (o *User) GetAnyTypeExceptNullPropOk() (*ObjectType, bool)` -GetArbitraryNullableTypeValueOk returns a tuple with the ArbitraryNullableTypeValue field if it's non-nil, zero value otherwise +GetAnyTypeExceptNullPropOk returns a tuple with the AnyTypeExceptNullProp field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. -### SetArbitraryNullableTypeValue +### SetAnyTypeExceptNullProp -`func (o *User) SetArbitraryNullableTypeValue(v AnyType)` +`func (o *User) SetAnyTypeExceptNullProp(v ObjectType)` -SetArbitraryNullableTypeValue sets ArbitraryNullableTypeValue field to given value. +SetAnyTypeExceptNullProp sets AnyTypeExceptNullProp field to given value. -### HasArbitraryNullableTypeValue +### HasAnyTypeExceptNullProp -`func (o *User) HasArbitraryNullableTypeValue() bool` +`func (o *User) HasAnyTypeExceptNullProp() bool` -HasArbitraryNullableTypeValue returns a boolean if a field has been set. +HasAnyTypeExceptNullProp returns a boolean if a field has been set. -### SetArbitraryNullableTypeValueNil +### GetAnyTypePropNullable -`func (o *User) SetArbitraryNullableTypeValueNil(b bool)` +`func (o *User) GetAnyTypePropNullable() AnyType` - SetArbitraryNullableTypeValueNil sets the value for ArbitraryNullableTypeValue to be an explicit nil +GetAnyTypePropNullable returns the AnyTypePropNullable field if non-nil, zero value otherwise. -### UnsetArbitraryNullableTypeValue -`func (o *User) UnsetArbitraryNullableTypeValue()` +### GetAnyTypePropNullableOk -UnsetArbitraryNullableTypeValue ensures that no value is present for ArbitraryNullableTypeValue, not even an explicit nil +`func (o *User) GetAnyTypePropNullableOk() (*AnyType, bool)` + +GetAnyTypePropNullableOk returns a tuple with the AnyTypePropNullable field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetAnyTypePropNullable + +`func (o *User) SetAnyTypePropNullable(v AnyType)` + +SetAnyTypePropNullable sets AnyTypePropNullable field to given value. + +### HasAnyTypePropNullable + +`func (o *User) HasAnyTypePropNullable() bool` + +HasAnyTypePropNullable returns a boolean if a field has been set. + +### SetAnyTypePropNullableNil + +`func (o *User) SetAnyTypePropNullableNil(b bool)` + + SetAnyTypePropNullableNil sets the value for AnyTypePropNullable to be an explicit nil + +### UnsetAnyTypePropNullable +`func (o *User) UnsetAnyTypePropNullable()` + +UnsetAnyTypePropNullable ensures that no value is present for AnyTypePropNullable, not even an explicit nil [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/UserApi.md b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/UserApi.md index 43fccd38582a..bdcc5b481c92 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/UserApi.md +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/UserApi.md @@ -36,7 +36,7 @@ import ( ) func main() { - user := openapiclient.User{Id: int64(123), Username: "Username_example", FirstName: "FirstName_example", LastName: "LastName_example", Email: "Email_example", Password: "Password_example", Phone: "Phone_example", UserStatus: 123, ArbitraryObject: "TODO", ArbitraryNullableObject: "TODO", ArbitraryTypeValue: "TODO", ArbitraryNullableTypeValue: "TODO"} // User | Created user object + user := openapiclient.User{Id: int64(123), Username: "Username_example", FirstName: "FirstName_example", LastName: "LastName_example", Email: "Email_example", Password: "Password_example", Phone: "Phone_example", UserStatus: 123, ObjectWithNoDeclaredProps: "TODO", ObjectWithNoDeclaredPropsNullable: "TODO", AnyTypeProp: "TODO", AnyTypeExceptNullProp: 123, AnyTypePropNullable: "TODO"} // User | Created user object configuration := openapiclient.NewConfiguration() api_client := openapiclient.NewAPIClient(configuration) @@ -98,7 +98,7 @@ import ( ) func main() { - user := []User{openapiclient.User{Id: int64(123), Username: "Username_example", FirstName: "FirstName_example", LastName: "LastName_example", Email: "Email_example", Password: "Password_example", Phone: "Phone_example", UserStatus: 123, ArbitraryObject: "TODO", ArbitraryNullableObject: "TODO", ArbitraryTypeValue: "TODO", ArbitraryNullableTypeValue: "TODO"}} // []User | List of user object + user := []User{openapiclient.User{Id: int64(123), Username: "Username_example", FirstName: "FirstName_example", LastName: "LastName_example", Email: "Email_example", Password: "Password_example", Phone: "Phone_example", UserStatus: 123, ObjectWithNoDeclaredProps: "TODO", ObjectWithNoDeclaredPropsNullable: "TODO", AnyTypeProp: "TODO", AnyTypeExceptNullProp: 123, AnyTypePropNullable: "TODO"}} // []User | List of user object configuration := openapiclient.NewConfiguration() api_client := openapiclient.NewAPIClient(configuration) diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_user.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_user.go index ffa722e3bc24..da5283679c49 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_user.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_user.go @@ -25,13 +25,15 @@ type User struct { // User Status UserStatus *int32 `json:"userStatus,omitempty"` // test code generation for objects Value must be a map of strings to values. It cannot be the 'null' value. - ArbitraryObject *ObjectType `json:"arbitraryObject,omitempty"` + ObjectWithNoDeclaredProps *ObjectType `json:"objectWithNoDeclaredProps,omitempty"` // test code generation for nullable objects. Value must be a map of strings to values or the 'null' value. - ArbitraryNullableObject ObjectType `json:"arbitraryNullableObject,omitempty"` - // test code generation for any type Value can be any type - string, number, boolean, array or object. - ArbitraryTypeValue *AnyType `json:"arbitraryTypeValue,omitempty"` - // test code generation for any type Value can be any type - string, number, boolean, array, object or the 'null' value. - ArbitraryNullableTypeValue AnyType `json:"arbitraryNullableTypeValue,omitempty"` + ObjectWithNoDeclaredPropsNullable ObjectType `json:"objectWithNoDeclaredPropsNullable,omitempty"` + // test code generation for any type Here the 'type' attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. See https://github.com/OAI/OpenAPI-Specification/issues/1389 + AnyTypeProp *AnyType `json:"anyTypeProp,omitempty"` + // any type except 'null' Here the 'type' attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. + AnyTypeExceptNullProp *ObjectType `json:"anyTypeExceptNullProp,omitempty"` + // test code generation for any type Here the 'type' attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. The 'nullable' attribute does not change the allowed values. + AnyTypePropNullable AnyType `json:"anyTypePropNullable,omitempty"` } // NewUser instantiates a new User object @@ -307,134 +309,166 @@ func (o *User) SetUserStatus(v int32) { o.UserStatus = &v } -// GetArbitraryObject returns the ArbitraryObject field value if set, zero value otherwise. -func (o *User) GetArbitraryObject() ObjectType { - if o == nil || o.ArbitraryObject == nil { +// GetObjectWithNoDeclaredProps returns the ObjectWithNoDeclaredProps field value if set, zero value otherwise. +func (o *User) GetObjectWithNoDeclaredProps() ObjectType { + if o == nil || o.ObjectWithNoDeclaredProps == nil { var ret ObjectType return ret } - return *o.ArbitraryObject + return *o.ObjectWithNoDeclaredProps } -// GetArbitraryObjectOk returns a tuple with the ArbitraryObject field value if set, nil otherwise +// GetObjectWithNoDeclaredPropsOk returns a tuple with the ObjectWithNoDeclaredProps field value if set, nil otherwise // and a boolean to check if the value has been set. -func (o *User) GetArbitraryObjectOk() (*ObjectType, bool) { - if o == nil || o.ArbitraryObject == nil { +func (o *User) GetObjectWithNoDeclaredPropsOk() (*ObjectType, bool) { + if o == nil || o.ObjectWithNoDeclaredProps == nil { return nil, false } - return o.ArbitraryObject, true + return o.ObjectWithNoDeclaredProps, true } -// HasArbitraryObject returns a boolean if a field has been set. -func (o *User) HasArbitraryObject() bool { - if o != nil && o.ArbitraryObject != nil { +// HasObjectWithNoDeclaredProps returns a boolean if a field has been set. +func (o *User) HasObjectWithNoDeclaredProps() bool { + if o != nil && o.ObjectWithNoDeclaredProps != nil { return true } return false } -// SetArbitraryObject gets a reference to the given ObjectType and assigns it to the ArbitraryObject field. -func (o *User) SetArbitraryObject(v ObjectType) { - o.ArbitraryObject = &v +// SetObjectWithNoDeclaredProps gets a reference to the given ObjectType and assigns it to the ObjectWithNoDeclaredProps field. +func (o *User) SetObjectWithNoDeclaredProps(v ObjectType) { + o.ObjectWithNoDeclaredProps = &v } -// GetArbitraryNullableObject returns the ArbitraryNullableObject field value if set, zero value otherwise (both if not set or set to explicit null). -func (o *User) GetArbitraryNullableObject() ObjectType { +// GetObjectWithNoDeclaredPropsNullable returns the ObjectWithNoDeclaredPropsNullable field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *User) GetObjectWithNoDeclaredPropsNullable() ObjectType { if o == nil { var ret ObjectType return ret } - return o.ArbitraryNullableObject + return o.ObjectWithNoDeclaredPropsNullable } -// GetArbitraryNullableObjectOk returns a tuple with the ArbitraryNullableObject field value if set, nil otherwise +// GetObjectWithNoDeclaredPropsNullableOk returns a tuple with the ObjectWithNoDeclaredPropsNullable field value if set, nil otherwise // and a boolean to check if the value has been set. // NOTE: If the value is an explicit nil, `nil, true` will be returned -func (o *User) GetArbitraryNullableObjectOk() (*ObjectType, bool) { - if o == nil || o.ArbitraryNullableObject == nil { +func (o *User) GetObjectWithNoDeclaredPropsNullableOk() (*ObjectType, bool) { + if o == nil || o.ObjectWithNoDeclaredPropsNullable == nil { return nil, false } - return &o.ArbitraryNullableObject, true + return &o.ObjectWithNoDeclaredPropsNullable, true } -// HasArbitraryNullableObject returns a boolean if a field has been set. -func (o *User) HasArbitraryNullableObject() bool { - if o != nil && o.ArbitraryNullableObject != nil { +// HasObjectWithNoDeclaredPropsNullable returns a boolean if a field has been set. +func (o *User) HasObjectWithNoDeclaredPropsNullable() bool { + if o != nil && o.ObjectWithNoDeclaredPropsNullable != nil { return true } return false } -// SetArbitraryNullableObject gets a reference to the given ObjectType and assigns it to the ArbitraryNullableObject field. -func (o *User) SetArbitraryNullableObject(v ObjectType) { - o.ArbitraryNullableObject = v +// SetObjectWithNoDeclaredPropsNullable gets a reference to the given ObjectType and assigns it to the ObjectWithNoDeclaredPropsNullable field. +func (o *User) SetObjectWithNoDeclaredPropsNullable(v ObjectType) { + o.ObjectWithNoDeclaredPropsNullable = v } -// GetArbitraryTypeValue returns the ArbitraryTypeValue field value if set, zero value otherwise. -func (o *User) GetArbitraryTypeValue() AnyType { - if o == nil || o.ArbitraryTypeValue == nil { +// GetAnyTypeProp returns the AnyTypeProp field value if set, zero value otherwise. +func (o *User) GetAnyTypeProp() AnyType { + if o == nil || o.AnyTypeProp == nil { var ret AnyType return ret } - return *o.ArbitraryTypeValue + return *o.AnyTypeProp } -// GetArbitraryTypeValueOk returns a tuple with the ArbitraryTypeValue field value if set, nil otherwise +// GetAnyTypePropOk returns a tuple with the AnyTypeProp field value if set, nil otherwise // and a boolean to check if the value has been set. -func (o *User) GetArbitraryTypeValueOk() (*AnyType, bool) { - if o == nil || o.ArbitraryTypeValue == nil { +func (o *User) GetAnyTypePropOk() (*AnyType, bool) { + if o == nil || o.AnyTypeProp == nil { return nil, false } - return o.ArbitraryTypeValue, true + return o.AnyTypeProp, true } -// HasArbitraryTypeValue returns a boolean if a field has been set. -func (o *User) HasArbitraryTypeValue() bool { - if o != nil && o.ArbitraryTypeValue != nil { +// HasAnyTypeProp returns a boolean if a field has been set. +func (o *User) HasAnyTypeProp() bool { + if o != nil && o.AnyTypeProp != nil { return true } return false } -// SetArbitraryTypeValue gets a reference to the given AnyType and assigns it to the ArbitraryTypeValue field. -func (o *User) SetArbitraryTypeValue(v AnyType) { - o.ArbitraryTypeValue = &v +// SetAnyTypeProp gets a reference to the given AnyType and assigns it to the AnyTypeProp field. +func (o *User) SetAnyTypeProp(v AnyType) { + o.AnyTypeProp = &v } -// GetArbitraryNullableTypeValue returns the ArbitraryNullableTypeValue field value if set, zero value otherwise (both if not set or set to explicit null). -func (o *User) GetArbitraryNullableTypeValue() AnyType { +// GetAnyTypeExceptNullProp returns the AnyTypeExceptNullProp field value if set, zero value otherwise. +func (o *User) GetAnyTypeExceptNullProp() ObjectType { + if o == nil || o.AnyTypeExceptNullProp == nil { + var ret ObjectType + return ret + } + return *o.AnyTypeExceptNullProp +} + +// GetAnyTypeExceptNullPropOk returns a tuple with the AnyTypeExceptNullProp field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *User) GetAnyTypeExceptNullPropOk() (*ObjectType, bool) { + if o == nil || o.AnyTypeExceptNullProp == nil { + return nil, false + } + return o.AnyTypeExceptNullProp, true +} + +// HasAnyTypeExceptNullProp returns a boolean if a field has been set. +func (o *User) HasAnyTypeExceptNullProp() bool { + if o != nil && o.AnyTypeExceptNullProp != nil { + return true + } + + return false +} + +// SetAnyTypeExceptNullProp gets a reference to the given ObjectType and assigns it to the AnyTypeExceptNullProp field. +func (o *User) SetAnyTypeExceptNullProp(v ObjectType) { + o.AnyTypeExceptNullProp = &v +} + +// GetAnyTypePropNullable returns the AnyTypePropNullable field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *User) GetAnyTypePropNullable() AnyType { if o == nil { var ret AnyType return ret } - return o.ArbitraryNullableTypeValue + return o.AnyTypePropNullable } -// GetArbitraryNullableTypeValueOk returns a tuple with the ArbitraryNullableTypeValue field value if set, nil otherwise +// GetAnyTypePropNullableOk returns a tuple with the AnyTypePropNullable field value if set, nil otherwise // and a boolean to check if the value has been set. // NOTE: If the value is an explicit nil, `nil, true` will be returned -func (o *User) GetArbitraryNullableTypeValueOk() (*AnyType, bool) { - if o == nil || o.ArbitraryNullableTypeValue == nil { +func (o *User) GetAnyTypePropNullableOk() (*AnyType, bool) { + if o == nil || o.AnyTypePropNullable == nil { return nil, false } - return &o.ArbitraryNullableTypeValue, true + return &o.AnyTypePropNullable, true } -// HasArbitraryNullableTypeValue returns a boolean if a field has been set. -func (o *User) HasArbitraryNullableTypeValue() bool { - if o != nil && o.ArbitraryNullableTypeValue != nil { +// HasAnyTypePropNullable returns a boolean if a field has been set. +func (o *User) HasAnyTypePropNullable() bool { + if o != nil && o.AnyTypePropNullable != nil { return true } return false } -// SetArbitraryNullableTypeValue gets a reference to the given AnyType and assigns it to the ArbitraryNullableTypeValue field. -func (o *User) SetArbitraryNullableTypeValue(v AnyType) { - o.ArbitraryNullableTypeValue = v +// SetAnyTypePropNullable gets a reference to the given AnyType and assigns it to the AnyTypePropNullable field. +func (o *User) SetAnyTypePropNullable(v AnyType) { + o.AnyTypePropNullable = v } func (o User) MarshalJSON() ([]byte, error) { @@ -463,17 +497,20 @@ func (o User) MarshalJSON() ([]byte, error) { if o.UserStatus != nil { toSerialize["userStatus"] = o.UserStatus } - if o.ArbitraryObject != nil { - toSerialize["arbitraryObject"] = o.ArbitraryObject + if o.ObjectWithNoDeclaredProps != nil { + toSerialize["objectWithNoDeclaredProps"] = o.ObjectWithNoDeclaredProps + } + if o.ObjectWithNoDeclaredPropsNullable != nil { + toSerialize["objectWithNoDeclaredPropsNullable"] = o.ObjectWithNoDeclaredPropsNullable } - if o.ArbitraryNullableObject != nil { - toSerialize["arbitraryNullableObject"] = o.ArbitraryNullableObject + if o.AnyTypeProp != nil { + toSerialize["anyTypeProp"] = o.AnyTypeProp } - if o.ArbitraryTypeValue != nil { - toSerialize["arbitraryTypeValue"] = o.ArbitraryTypeValue + if o.AnyTypeExceptNullProp != nil { + toSerialize["anyTypeExceptNullProp"] = o.AnyTypeExceptNullProp } - if o.ArbitraryNullableTypeValue != nil { - toSerialize["arbitraryNullableTypeValue"] = o.ArbitraryNullableTypeValue + if o.AnyTypePropNullable != nil { + toSerialize["anyTypePropNullable"] = o.AnyTypePropNullable } return json.Marshal(toSerialize) } From 543d4060ca95186737018e95107adba5729df35b Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Mon, 4 May 2020 11:51:48 -0700 Subject: [PATCH 19/48] 'Any type' includes the null value, so 'isNullable' should be set to TRUE --- .../org/openapitools/codegen/DefaultCodegen.java | 15 ++++++++++++++- .../go-experimental/go-petstore/docs/User.md | 10 ++++++++++ .../go-experimental/go-petstore/model_user.go | 13 +++++++------ 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index 6394f1ace4cb..1f5e3a815c63 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -2163,7 +2163,14 @@ public CodegenModel fromModel(String name, Schema schema) { m.xmlNamespace = schema.getXml().getNamespace(); m.xmlName = schema.getXml().getName(); } - + if (ModelUtils.isAnyTypeSchema(schema)) { + // The 'null' value is allowed when the OAS schema is 'any type'. + // See https://github.com/OAI/OpenAPI-Specification/issues/1389 + if (Boolean.FALSE.equals(schema.getNullable())) { + LOGGER.error("Schema '{}' is any type, which includes the 'null' value. 'nullable' cannot be set to 'false'", name); + } + m.isNullable = true; + } if (ModelUtils.isArraySchema(schema)) { m.isArrayModel = true; m.arrayModelType = fromProperty(name, schema).complexType; @@ -2986,6 +2993,12 @@ public CodegenProperty fromProperty(String name, Schema p) { } else if (ModelUtils.isFreeFormObject(p)) { property.isFreeFormObject = true; } else if (ModelUtils.isAnyTypeSchema(p)) { + // The 'null' value is allowed when the OAS schema is 'any type'. + // See https://github.com/OAI/OpenAPI-Specification/issues/1389 + if (Boolean.FALSE.equals(p.getNullable())) { + LOGGER.error("Schema '{}' is any type, which includes the 'null' value. 'nullable' cannot be set to 'false'", p.getName()); + } + property.isNullable = true; property.isAnyType = true; } else if (ModelUtils.isArraySchema(p)) { // default to string if inner item is undefined diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/User.md b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/User.md index 86acd98001dd..6739ef07e07b 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/User.md +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/User.md @@ -322,6 +322,16 @@ SetAnyTypeProp sets AnyTypeProp field to given value. HasAnyTypeProp returns a boolean if a field has been set. +### SetAnyTypePropNil + +`func (o *User) SetAnyTypePropNil(b bool)` + + SetAnyTypePropNil sets the value for AnyTypeProp to be an explicit nil + +### UnsetAnyTypeProp +`func (o *User) UnsetAnyTypeProp()` + +UnsetAnyTypeProp ensures that no value is present for AnyTypeProp, not even an explicit nil ### GetAnyTypeExceptNullProp `func (o *User) GetAnyTypeExceptNullProp() ObjectType` diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_user.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_user.go index da5283679c49..07bf92d38d34 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_user.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_user.go @@ -29,7 +29,7 @@ type User struct { // test code generation for nullable objects. Value must be a map of strings to values or the 'null' value. ObjectWithNoDeclaredPropsNullable ObjectType `json:"objectWithNoDeclaredPropsNullable,omitempty"` // test code generation for any type Here the 'type' attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. See https://github.com/OAI/OpenAPI-Specification/issues/1389 - AnyTypeProp *AnyType `json:"anyTypeProp,omitempty"` + AnyTypeProp AnyType `json:"anyTypeProp,omitempty"` // any type except 'null' Here the 'type' attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. AnyTypeExceptNullProp *ObjectType `json:"anyTypeExceptNullProp,omitempty"` // test code generation for any type Here the 'type' attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. The 'nullable' attribute does not change the allowed values. @@ -374,22 +374,23 @@ func (o *User) SetObjectWithNoDeclaredPropsNullable(v ObjectType) { o.ObjectWithNoDeclaredPropsNullable = v } -// GetAnyTypeProp returns the AnyTypeProp field value if set, zero value otherwise. +// GetAnyTypeProp returns the AnyTypeProp field value if set, zero value otherwise (both if not set or set to explicit null). func (o *User) GetAnyTypeProp() AnyType { - if o == nil || o.AnyTypeProp == nil { + if o == nil { var ret AnyType return ret } - return *o.AnyTypeProp + return o.AnyTypeProp } // GetAnyTypePropOk returns a tuple with the AnyTypeProp field value if set, nil otherwise // and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned func (o *User) GetAnyTypePropOk() (*AnyType, bool) { if o == nil || o.AnyTypeProp == nil { return nil, false } - return o.AnyTypeProp, true + return &o.AnyTypeProp, true } // HasAnyTypeProp returns a boolean if a field has been set. @@ -403,7 +404,7 @@ func (o *User) HasAnyTypeProp() bool { // SetAnyTypeProp gets a reference to the given AnyType and assigns it to the AnyTypeProp field. func (o *User) SetAnyTypeProp(v AnyType) { - o.AnyTypeProp = &v + o.AnyTypeProp = v } // GetAnyTypeExceptNullProp returns the AnyTypeExceptNullProp field value if set, zero value otherwise. From 81093c7f8ba6f5a3e75708a78c06c584cf257b3d Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Mon, 4 May 2020 12:12:38 -0700 Subject: [PATCH 20/48] 'Any type' includes the null value, so 'isNullable' should be set to TRUE --- ...odels-for-testing-with-http-signature.yaml | 13 ++++--- .../go-petstore/api/openapi.yaml | 11 +----- .../go-petstore/docs/FakeApi.md | 2 +- .../go-experimental/go-petstore/docs/User.md | 26 ------------- .../go-petstore/docs/UserApi.md | 4 +- .../go-experimental/go-petstore/model_user.go | 37 ------------------- 6 files changed, 12 insertions(+), 81 deletions(-) diff --git a/modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml b/modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml index a3379d5e4650..3e779d042413 100644 --- a/modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml @@ -1264,12 +1264,13 @@ components: Here the 'type' attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. See https://github.com/OAI/OpenAPI-Specification/issues/1389 - anyTypeExceptNullProp: - description: any type except 'null' - Here the 'type' attribute is not specified, which means the value can be anything, - including the null value, string, number, boolean, array or object. - not: - type: 'null' + # TODO: this should be supported, currently there are some issues in the code generation. + #anyTypeExceptNullProp: + # description: any type except 'null' + # Here the 'type' attribute is not specified, which means the value can be anything, + # including the null value, string, number, boolean, array or object. + # not: + # type: 'null' anyTypePropNullable: description: test code generation for any type Here the 'type' attribute is not specified, which means the value can be anything, diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/api/openapi.yaml b/samples/openapi3/client/petstore/go-experimental/go-petstore/api/openapi.yaml index 762d0966ab93..9b3612e2dbf3 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/api/openapi.yaml +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/api/openapi.yaml @@ -1295,12 +1295,11 @@ components: name: Category User: example: + firstName: firstName lastName: lastName + password: password userStatus: 6 objectWithNoDeclaredPropsNullable: '{}' - anyTypeExceptNullProp: "" - firstName: firstName - password: password phone: phone objectWithNoDeclaredProps: '{}' id: 0 @@ -1342,12 +1341,6 @@ components: description: test code generation for any type Here the 'type' attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. See https://github.com/OAI/OpenAPI-Specification/issues/1389 - anyTypeExceptNullProp: - description: any type except 'null' Here the 'type' attribute is not specified, - which means the value can be anything, including the null value, string, - number, boolean, array or object. - not: - type: "null" anyTypePropNullable: description: test code generation for any type Here the 'type' attribute is not specified, which means the value can be anything, including the diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/FakeApi.md b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/FakeApi.md index ddc157ba045a..d449f064d4aa 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/FakeApi.md +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/FakeApi.md @@ -428,7 +428,7 @@ import ( func main() { query := "query_example" // string | - user := openapiclient.User{Id: int64(123), Username: "Username_example", FirstName: "FirstName_example", LastName: "LastName_example", Email: "Email_example", Password: "Password_example", Phone: "Phone_example", UserStatus: 123, ObjectWithNoDeclaredProps: "TODO", ObjectWithNoDeclaredPropsNullable: "TODO", AnyTypeProp: "TODO", AnyTypeExceptNullProp: 123, AnyTypePropNullable: "TODO"} // User | + user := openapiclient.User{Id: int64(123), Username: "Username_example", FirstName: "FirstName_example", LastName: "LastName_example", Email: "Email_example", Password: "Password_example", Phone: "Phone_example", UserStatus: 123, ObjectWithNoDeclaredProps: "TODO", ObjectWithNoDeclaredPropsNullable: "TODO", AnyTypeProp: "TODO", AnyTypePropNullable: "TODO"} // User | configuration := openapiclient.NewConfiguration() api_client := openapiclient.NewAPIClient(configuration) diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/User.md b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/User.md index 6739ef07e07b..ff06cfa1d78c 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/User.md +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/User.md @@ -15,7 +15,6 @@ Name | Type | Description | Notes **ObjectWithNoDeclaredProps** | Pointer to [**ObjectType**](.md) | test code generation for objects Value must be a map of strings to values. It cannot be the 'null' value. | [optional] **ObjectWithNoDeclaredPropsNullable** | Pointer to [**ObjectType**](.md) | test code generation for nullable objects. Value must be a map of strings to values or the 'null' value. | [optional] **AnyTypeProp** | Pointer to [**AnyType**](.md) | test code generation for any type Here the 'type' attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. See https://github.com/OAI/OpenAPI-Specification/issues/1389 | [optional] -**AnyTypeExceptNullProp** | Pointer to **ObjectType** | any type except 'null' Here the 'type' attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. | [optional] **AnyTypePropNullable** | Pointer to [**AnyType**](.md) | test code generation for any type Here the 'type' attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. The 'nullable' attribute does not change the allowed values. | [optional] ## Methods @@ -332,31 +331,6 @@ HasAnyTypeProp returns a boolean if a field has been set. `func (o *User) UnsetAnyTypeProp()` UnsetAnyTypeProp ensures that no value is present for AnyTypeProp, not even an explicit nil -### GetAnyTypeExceptNullProp - -`func (o *User) GetAnyTypeExceptNullProp() ObjectType` - -GetAnyTypeExceptNullProp returns the AnyTypeExceptNullProp field if non-nil, zero value otherwise. - -### GetAnyTypeExceptNullPropOk - -`func (o *User) GetAnyTypeExceptNullPropOk() (*ObjectType, bool)` - -GetAnyTypeExceptNullPropOk returns a tuple with the AnyTypeExceptNullProp field if it's non-nil, zero value otherwise -and a boolean to check if the value has been set. - -### SetAnyTypeExceptNullProp - -`func (o *User) SetAnyTypeExceptNullProp(v ObjectType)` - -SetAnyTypeExceptNullProp sets AnyTypeExceptNullProp field to given value. - -### HasAnyTypeExceptNullProp - -`func (o *User) HasAnyTypeExceptNullProp() bool` - -HasAnyTypeExceptNullProp returns a boolean if a field has been set. - ### GetAnyTypePropNullable `func (o *User) GetAnyTypePropNullable() AnyType` diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/UserApi.md b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/UserApi.md index bdcc5b481c92..b3aca49efb1f 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/UserApi.md +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/UserApi.md @@ -36,7 +36,7 @@ import ( ) func main() { - user := openapiclient.User{Id: int64(123), Username: "Username_example", FirstName: "FirstName_example", LastName: "LastName_example", Email: "Email_example", Password: "Password_example", Phone: "Phone_example", UserStatus: 123, ObjectWithNoDeclaredProps: "TODO", ObjectWithNoDeclaredPropsNullable: "TODO", AnyTypeProp: "TODO", AnyTypeExceptNullProp: 123, AnyTypePropNullable: "TODO"} // User | Created user object + user := openapiclient.User{Id: int64(123), Username: "Username_example", FirstName: "FirstName_example", LastName: "LastName_example", Email: "Email_example", Password: "Password_example", Phone: "Phone_example", UserStatus: 123, ObjectWithNoDeclaredProps: "TODO", ObjectWithNoDeclaredPropsNullable: "TODO", AnyTypeProp: "TODO", AnyTypePropNullable: "TODO"} // User | Created user object configuration := openapiclient.NewConfiguration() api_client := openapiclient.NewAPIClient(configuration) @@ -98,7 +98,7 @@ import ( ) func main() { - user := []User{openapiclient.User{Id: int64(123), Username: "Username_example", FirstName: "FirstName_example", LastName: "LastName_example", Email: "Email_example", Password: "Password_example", Phone: "Phone_example", UserStatus: 123, ObjectWithNoDeclaredProps: "TODO", ObjectWithNoDeclaredPropsNullable: "TODO", AnyTypeProp: "TODO", AnyTypeExceptNullProp: 123, AnyTypePropNullable: "TODO"}} // []User | List of user object + user := []User{openapiclient.User{Id: int64(123), Username: "Username_example", FirstName: "FirstName_example", LastName: "LastName_example", Email: "Email_example", Password: "Password_example", Phone: "Phone_example", UserStatus: 123, ObjectWithNoDeclaredProps: "TODO", ObjectWithNoDeclaredPropsNullable: "TODO", AnyTypeProp: "TODO", AnyTypePropNullable: "TODO"}} // []User | List of user object configuration := openapiclient.NewConfiguration() api_client := openapiclient.NewAPIClient(configuration) diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_user.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_user.go index 07bf92d38d34..53fa7d567428 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_user.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_user.go @@ -30,8 +30,6 @@ type User struct { ObjectWithNoDeclaredPropsNullable ObjectType `json:"objectWithNoDeclaredPropsNullable,omitempty"` // test code generation for any type Here the 'type' attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. See https://github.com/OAI/OpenAPI-Specification/issues/1389 AnyTypeProp AnyType `json:"anyTypeProp,omitempty"` - // any type except 'null' Here the 'type' attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. - AnyTypeExceptNullProp *ObjectType `json:"anyTypeExceptNullProp,omitempty"` // test code generation for any type Here the 'type' attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. The 'nullable' attribute does not change the allowed values. AnyTypePropNullable AnyType `json:"anyTypePropNullable,omitempty"` } @@ -407,38 +405,6 @@ func (o *User) SetAnyTypeProp(v AnyType) { o.AnyTypeProp = v } -// GetAnyTypeExceptNullProp returns the AnyTypeExceptNullProp field value if set, zero value otherwise. -func (o *User) GetAnyTypeExceptNullProp() ObjectType { - if o == nil || o.AnyTypeExceptNullProp == nil { - var ret ObjectType - return ret - } - return *o.AnyTypeExceptNullProp -} - -// GetAnyTypeExceptNullPropOk returns a tuple with the AnyTypeExceptNullProp field value if set, nil otherwise -// and a boolean to check if the value has been set. -func (o *User) GetAnyTypeExceptNullPropOk() (*ObjectType, bool) { - if o == nil || o.AnyTypeExceptNullProp == nil { - return nil, false - } - return o.AnyTypeExceptNullProp, true -} - -// HasAnyTypeExceptNullProp returns a boolean if a field has been set. -func (o *User) HasAnyTypeExceptNullProp() bool { - if o != nil && o.AnyTypeExceptNullProp != nil { - return true - } - - return false -} - -// SetAnyTypeExceptNullProp gets a reference to the given ObjectType and assigns it to the AnyTypeExceptNullProp field. -func (o *User) SetAnyTypeExceptNullProp(v ObjectType) { - o.AnyTypeExceptNullProp = &v -} - // GetAnyTypePropNullable returns the AnyTypePropNullable field value if set, zero value otherwise (both if not set or set to explicit null). func (o *User) GetAnyTypePropNullable() AnyType { if o == nil { @@ -507,9 +473,6 @@ func (o User) MarshalJSON() ([]byte, error) { if o.AnyTypeProp != nil { toSerialize["anyTypeProp"] = o.AnyTypeProp } - if o.AnyTypeExceptNullProp != nil { - toSerialize["anyTypeExceptNullProp"] = o.AnyTypeExceptNullProp - } if o.AnyTypePropNullable != nil { toSerialize["anyTypePropNullable"] = o.AnyTypePropNullable } From 9a54ea10b567557d9b4d02c211c44ec618969eba Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Mon, 4 May 2020 18:03:57 -0700 Subject: [PATCH 21/48] Handle AnyType and NullType --- .../openapitools/codegen/languages/AbstractGoCodegen.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java index 31c318f3b9ce..15a871b036f9 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java @@ -607,10 +607,10 @@ private void setExportParameterName(List codegenParameters) { @Override public void postProcessModelProperty(CodegenModel model, CodegenProperty property) { // The 'go-experimental/model.mustache' template conditionally generates accessor methods. - // For primitive types and custom types (e.g. interface{}, map[string]interface{}...), - // the generated code has a wrapper type and a Get() function to access the underlying type. - // For containers (e.g. Array, Map), the generated code returns the type directly. - if (property.isContainer || property.isFreeFormObject || property.isAnyType) { + // For containers (e.g. Array, Map), the generated code returns the type directly. + // In other cases, the generated code has a wrapper type and a Get() function to + // access the underlying type. + if (property.isContainer) { property.vendorExtensions.put("x-golang-is-container", true); } } From dc7a7e05b4d1890c36e40507d3edbce67e5c006b Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Mon, 4 May 2020 22:09:24 -0700 Subject: [PATCH 22/48] handle anytype for go-experimental --- .../GoClientExperimentalCodegen.java | 10 +- .../resources/go-experimental/model.mustache | 25 ++++ .../resources/go-experimental/utils.mustache | 16 +-- ...dPropertiesAndAdditionalPropertiesClass.md | 6 +- .../go-petstore/docs/NullableClass.md | 18 +-- .../go-experimental/go-petstore/docs/User.md | 24 ++-- ...perties_and_additional_properties_class.go | 14 +-- .../go-petstore/model_nullable_class.go | 30 ++--- .../go-experimental/go-petstore/model_user.go | 113 +++++++++++------- .../go-experimental/go-petstore/utils.go | 16 +-- 10 files changed, 165 insertions(+), 107 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoClientExperimentalCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoClientExperimentalCodegen.java index 0bea07e4dba7..2fc84f25dfd8 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoClientExperimentalCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoClientExperimentalCodegen.java @@ -177,9 +177,15 @@ public Map postProcessModels(Map objs) { } for (CodegenProperty param : model.vars) { + if (param.isAnyType) { + param.vendorExtensions.put("x-go-base-type", "interface{}"); + continue; + } else if (param.isFreeFormObject) { + param.vendorExtensions.put("x-go-base-type", "map[string]interface{}"); + continue; + } param.vendorExtensions.put("x-go-base-type", param.dataType); - if (!param.isNullable || param.isMapContainer || param.isListContainer || - param.isFreeFormObject || param.isAnyType) { + if (!param.isNullable || param.isMapContainer || param.isListContainer) { continue; } if (param.isDateTime) { diff --git a/modules/openapi-generator/src/main/resources/go-experimental/model.mustache b/modules/openapi-generator/src/main/resources/go-experimental/model.mustache index 848f145fbe75..3948469c5d25 100644 --- a/modules/openapi-generator/src/main/resources/go-experimental/model.mustache +++ b/modules/openapi-generator/src/main/resources/go-experimental/model.mustache @@ -129,7 +129,12 @@ func (o *{{classname}}) Get{{name}}() {{vendorExtensions.x-go-base-type}} { {{/vendorExtensions.x-golang-is-container}} {{/isNullable}} {{^isNullable}} +{{#isFreeFormObject}} + return o.{{name}}.Get() +{{/isFreeFormObject}} +{{^isFreeFormObject}} return o.{{name}} +{{/isFreeFormObject}} {{/isNullable}} } @@ -151,7 +156,12 @@ func (o *{{classname}}) Get{{name}}Ok() (*{{vendorExtensions.x-go-base-type}}, b {{/vendorExtensions.x-golang-is-container}} {{/isNullable}} {{^isNullable}} +{{#isFreeFormObject}} + return &o.{{name}}.Get(), true +{{/isFreeFormObject}} +{{^isFreeFormObject}} return &o.{{name}}, true +{{/isFreeFormObject}} {{/isNullable}} } @@ -187,7 +197,12 @@ func (o *{{classname}}) Get{{name}}() {{vendorExtensions.x-go-base-type}} { {{/vendorExtensions.x-golang-is-container}} {{/isNullable}} {{^isNullable}} +{{#isFreeFormObject}} + return *o.{{name}}.Get() +{{/isFreeFormObject}} +{{^isFreeFormObject}} return *o.{{name}} +{{/isFreeFormObject}} {{/isNullable}} } @@ -209,7 +224,12 @@ func (o *{{classname}}) Get{{name}}Ok() (*{{vendorExtensions.x-go-base-type}}, b {{/vendorExtensions.x-golang-is-container}} {{/isNullable}} {{^isNullable}} +{{#isFreeFormObject}} + return o.{{name}}.Get(), true +{{/isFreeFormObject}} +{{^isFreeFormObject}} return o.{{name}}, true +{{/isFreeFormObject}} {{/isNullable}} } @@ -233,7 +253,12 @@ func (o *{{classname}}) Set{{name}}(v {{vendorExtensions.x-go-base-type}}) { {{/vendorExtensions.x-golang-is-container}} {{/isNullable}} {{^isNullable}} +{{#isFreeFormObject}} + o.{{name}}.Set(&v) +{{/isFreeFormObject}} +{{^isFreeFormObject}} o.{{name}} = &v +{{/isFreeFormObject}} {{/isNullable}} } {{#isNullable}} diff --git a/modules/openapi-generator/src/main/resources/go-experimental/utils.mustache b/modules/openapi-generator/src/main/resources/go-experimental/utils.mustache index e65f1c4d0ed9..046d5c9574f1 100644 --- a/modules/openapi-generator/src/main/resources/go-experimental/utils.mustache +++ b/modules/openapi-generator/src/main/resources/go-experimental/utils.mustache @@ -73,19 +73,19 @@ func (v *NullType) UnmarshalJSON(src []byte) error { // AnyType is a type whose value can anything. type AnyType struct{ - value interface{} + value *interface{} isSet bool } -func NewAnyType(val interface{}) *AnyType { +func NewAnyType(val *interface{}) *AnyType { return &AnyType{value: val, isSet: true} } -func (v AnyType) Get() interface{} { +func (v AnyType) Get() *interface{} { return v.value } -func (v *AnyType) Set(val interface{}) { +func (v *AnyType) Set(val *interface{}) { v.value = val v.isSet = true } @@ -109,19 +109,19 @@ func (v *AnyType) UnmarshalJSON(src []byte) error { // ObjectType is a type whose value can be an object with undeclared properties. type ObjectType struct{ - value map[string]interface{} + value *map[string]interface{} isSet bool } -func NewObjectType(val map[string]interface{}) *ObjectType { +func NewObjectType(val *map[string]interface{}) *ObjectType { return &ObjectType{value: val, isSet: true} } -func (v ObjectType) Get() map[string]interface{} { +func (v ObjectType) Get() *map[string]interface{} { return v.value } -func (v *ObjectType) Set(val map[string]interface{}) { +func (v *ObjectType) Set(val *map[string]interface{}) { v.value = val v.isSet = true } diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/MixedPropertiesAndAdditionalPropertiesClass.md b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/MixedPropertiesAndAdditionalPropertiesClass.md index f726ffe63e13..5db7cf034089 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/MixedPropertiesAndAdditionalPropertiesClass.md +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/MixedPropertiesAndAdditionalPropertiesClass.md @@ -79,20 +79,20 @@ HasDateTime returns a boolean if a field has been set. ### GetMap -`func (o *MixedPropertiesAndAdditionalPropertiesClass) GetMap() map[string]Animal` +`func (o *MixedPropertiesAndAdditionalPropertiesClass) GetMap() map[string]interface{}` GetMap returns the Map field if non-nil, zero value otherwise. ### GetMapOk -`func (o *MixedPropertiesAndAdditionalPropertiesClass) GetMapOk() (*map[string]Animal, bool)` +`func (o *MixedPropertiesAndAdditionalPropertiesClass) GetMapOk() (*map[string]interface{}, bool)` GetMapOk returns a tuple with the Map field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetMap -`func (o *MixedPropertiesAndAdditionalPropertiesClass) SetMap(v map[string]Animal)` +`func (o *MixedPropertiesAndAdditionalPropertiesClass) SetMap(v map[string]interface{})` SetMap sets Map field to given value. diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/NullableClass.md b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/NullableClass.md index e81e45f2d40a..24f221592b06 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/NullableClass.md +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/NullableClass.md @@ -343,20 +343,20 @@ HasArrayItemsNullable returns a boolean if a field has been set. ### GetObjectNullableProp -`func (o *NullableClass) GetObjectNullableProp() map[string]ObjectType` +`func (o *NullableClass) GetObjectNullableProp() map[string]interface{}` GetObjectNullableProp returns the ObjectNullableProp field if non-nil, zero value otherwise. ### GetObjectNullablePropOk -`func (o *NullableClass) GetObjectNullablePropOk() (*map[string]ObjectType, bool)` +`func (o *NullableClass) GetObjectNullablePropOk() (*map[string]interface{}, bool)` GetObjectNullablePropOk returns a tuple with the ObjectNullableProp field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetObjectNullableProp -`func (o *NullableClass) SetObjectNullableProp(v map[string]ObjectType)` +`func (o *NullableClass) SetObjectNullableProp(v map[string]interface{})` SetObjectNullableProp sets ObjectNullableProp field to given value. @@ -378,20 +378,20 @@ HasObjectNullableProp returns a boolean if a field has been set. UnsetObjectNullableProp ensures that no value is present for ObjectNullableProp, not even an explicit nil ### GetObjectAndItemsNullableProp -`func (o *NullableClass) GetObjectAndItemsNullableProp() map[string]ObjectType` +`func (o *NullableClass) GetObjectAndItemsNullableProp() map[string]interface{}` GetObjectAndItemsNullableProp returns the ObjectAndItemsNullableProp field if non-nil, zero value otherwise. ### GetObjectAndItemsNullablePropOk -`func (o *NullableClass) GetObjectAndItemsNullablePropOk() (*map[string]ObjectType, bool)` +`func (o *NullableClass) GetObjectAndItemsNullablePropOk() (*map[string]interface{}, bool)` GetObjectAndItemsNullablePropOk returns a tuple with the ObjectAndItemsNullableProp field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetObjectAndItemsNullableProp -`func (o *NullableClass) SetObjectAndItemsNullableProp(v map[string]ObjectType)` +`func (o *NullableClass) SetObjectAndItemsNullableProp(v map[string]interface{})` SetObjectAndItemsNullableProp sets ObjectAndItemsNullableProp field to given value. @@ -413,20 +413,20 @@ HasObjectAndItemsNullableProp returns a boolean if a field has been set. UnsetObjectAndItemsNullableProp ensures that no value is present for ObjectAndItemsNullableProp, not even an explicit nil ### GetObjectItemsNullable -`func (o *NullableClass) GetObjectItemsNullable() map[string]ObjectType` +`func (o *NullableClass) GetObjectItemsNullable() map[string]interface{}` GetObjectItemsNullable returns the ObjectItemsNullable field if non-nil, zero value otherwise. ### GetObjectItemsNullableOk -`func (o *NullableClass) GetObjectItemsNullableOk() (*map[string]ObjectType, bool)` +`func (o *NullableClass) GetObjectItemsNullableOk() (*map[string]interface{}, bool)` GetObjectItemsNullableOk returns a tuple with the ObjectItemsNullable field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetObjectItemsNullable -`func (o *NullableClass) SetObjectItemsNullable(v map[string]ObjectType)` +`func (o *NullableClass) SetObjectItemsNullable(v map[string]interface{})` SetObjectItemsNullable sets ObjectItemsNullable field to given value. diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/User.md b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/User.md index ff06cfa1d78c..cb5481722eff 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/User.md +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/User.md @@ -238,20 +238,20 @@ HasUserStatus returns a boolean if a field has been set. ### GetObjectWithNoDeclaredProps -`func (o *User) GetObjectWithNoDeclaredProps() ObjectType` +`func (o *User) GetObjectWithNoDeclaredProps() map[string]interface{}` GetObjectWithNoDeclaredProps returns the ObjectWithNoDeclaredProps field if non-nil, zero value otherwise. ### GetObjectWithNoDeclaredPropsOk -`func (o *User) GetObjectWithNoDeclaredPropsOk() (*ObjectType, bool)` +`func (o *User) GetObjectWithNoDeclaredPropsOk() (*map[string]interface{}, bool)` GetObjectWithNoDeclaredPropsOk returns a tuple with the ObjectWithNoDeclaredProps field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetObjectWithNoDeclaredProps -`func (o *User) SetObjectWithNoDeclaredProps(v ObjectType)` +`func (o *User) SetObjectWithNoDeclaredProps(v map[string]interface{})` SetObjectWithNoDeclaredProps sets ObjectWithNoDeclaredProps field to given value. @@ -263,20 +263,20 @@ HasObjectWithNoDeclaredProps returns a boolean if a field has been set. ### GetObjectWithNoDeclaredPropsNullable -`func (o *User) GetObjectWithNoDeclaredPropsNullable() ObjectType` +`func (o *User) GetObjectWithNoDeclaredPropsNullable() map[string]interface{}` GetObjectWithNoDeclaredPropsNullable returns the ObjectWithNoDeclaredPropsNullable field if non-nil, zero value otherwise. ### GetObjectWithNoDeclaredPropsNullableOk -`func (o *User) GetObjectWithNoDeclaredPropsNullableOk() (*ObjectType, bool)` +`func (o *User) GetObjectWithNoDeclaredPropsNullableOk() (*map[string]interface{}, bool)` GetObjectWithNoDeclaredPropsNullableOk returns a tuple with the ObjectWithNoDeclaredPropsNullable field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetObjectWithNoDeclaredPropsNullable -`func (o *User) SetObjectWithNoDeclaredPropsNullable(v ObjectType)` +`func (o *User) SetObjectWithNoDeclaredPropsNullable(v map[string]interface{})` SetObjectWithNoDeclaredPropsNullable sets ObjectWithNoDeclaredPropsNullable field to given value. @@ -298,20 +298,20 @@ HasObjectWithNoDeclaredPropsNullable returns a boolean if a field has been set. UnsetObjectWithNoDeclaredPropsNullable ensures that no value is present for ObjectWithNoDeclaredPropsNullable, not even an explicit nil ### GetAnyTypeProp -`func (o *User) GetAnyTypeProp() AnyType` +`func (o *User) GetAnyTypeProp() interface{}` GetAnyTypeProp returns the AnyTypeProp field if non-nil, zero value otherwise. ### GetAnyTypePropOk -`func (o *User) GetAnyTypePropOk() (*AnyType, bool)` +`func (o *User) GetAnyTypePropOk() (*interface{}, bool)` GetAnyTypePropOk returns a tuple with the AnyTypeProp field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetAnyTypeProp -`func (o *User) SetAnyTypeProp(v AnyType)` +`func (o *User) SetAnyTypeProp(v interface{})` SetAnyTypeProp sets AnyTypeProp field to given value. @@ -333,20 +333,20 @@ HasAnyTypeProp returns a boolean if a field has been set. UnsetAnyTypeProp ensures that no value is present for AnyTypeProp, not even an explicit nil ### GetAnyTypePropNullable -`func (o *User) GetAnyTypePropNullable() AnyType` +`func (o *User) GetAnyTypePropNullable() interface{}` GetAnyTypePropNullable returns the AnyTypePropNullable field if non-nil, zero value otherwise. ### GetAnyTypePropNullableOk -`func (o *User) GetAnyTypePropNullableOk() (*AnyType, bool)` +`func (o *User) GetAnyTypePropNullableOk() (*interface{}, bool)` GetAnyTypePropNullableOk returns a tuple with the AnyTypePropNullable field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetAnyTypePropNullable -`func (o *User) SetAnyTypePropNullable(v AnyType)` +`func (o *User) SetAnyTypePropNullable(v interface{})` SetAnyTypePropNullable sets AnyTypePropNullable field to given value. diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_mixed_properties_and_additional_properties_class.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_mixed_properties_and_additional_properties_class.go index 355bcab85031..efa3264c3d51 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_mixed_properties_and_additional_properties_class.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_mixed_properties_and_additional_properties_class.go @@ -103,21 +103,21 @@ func (o *MixedPropertiesAndAdditionalPropertiesClass) SetDateTime(v time.Time) { } // GetMap returns the Map field value if set, zero value otherwise. -func (o *MixedPropertiesAndAdditionalPropertiesClass) GetMap() map[string]Animal { +func (o *MixedPropertiesAndAdditionalPropertiesClass) GetMap() map[string]interface{} { if o == nil || o.Map == nil { - var ret map[string]Animal + var ret map[string]interface{} return ret } - return *o.Map + return *o.Map.Get() } // GetMapOk returns a tuple with the Map field value if set, nil otherwise // and a boolean to check if the value has been set. -func (o *MixedPropertiesAndAdditionalPropertiesClass) GetMapOk() (*map[string]Animal, bool) { +func (o *MixedPropertiesAndAdditionalPropertiesClass) GetMapOk() (*map[string]interface{}, bool) { if o == nil || o.Map == nil { return nil, false } - return o.Map, true + return o.Map.Get(), true } // HasMap returns a boolean if a field has been set. @@ -130,8 +130,8 @@ func (o *MixedPropertiesAndAdditionalPropertiesClass) HasMap() bool { } // SetMap gets a reference to the given map[string]Animal and assigns it to the Map field. -func (o *MixedPropertiesAndAdditionalPropertiesClass) SetMap(v map[string]Animal) { - o.Map = &v +func (o *MixedPropertiesAndAdditionalPropertiesClass) SetMap(v map[string]interface{}) { + o.Map.Set(&v) } func (o MixedPropertiesAndAdditionalPropertiesClass) MarshalJSON() ([]byte, error) { diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_nullable_class.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_nullable_class.go index a465419c12d8..b6b1d947a122 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_nullable_class.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_nullable_class.go @@ -398,9 +398,9 @@ func (o *NullableClass) SetArrayItemsNullable(v []ObjectType) { } // GetObjectNullableProp returns the ObjectNullableProp field value if set, zero value otherwise (both if not set or set to explicit null). -func (o *NullableClass) GetObjectNullableProp() map[string]ObjectType { +func (o *NullableClass) GetObjectNullableProp() map[string]interface{} { if o == nil { - var ret map[string]ObjectType + var ret map[string]interface{} return ret } return o.ObjectNullableProp @@ -409,7 +409,7 @@ func (o *NullableClass) GetObjectNullableProp() map[string]ObjectType { // GetObjectNullablePropOk returns a tuple with the ObjectNullableProp field value if set, nil otherwise // and a boolean to check if the value has been set. // NOTE: If the value is an explicit nil, `nil, true` will be returned -func (o *NullableClass) GetObjectNullablePropOk() (*map[string]ObjectType, bool) { +func (o *NullableClass) GetObjectNullablePropOk() (*map[string]interface{}, bool) { if o == nil || o.ObjectNullableProp == nil { return nil, false } @@ -426,14 +426,14 @@ func (o *NullableClass) HasObjectNullableProp() bool { } // SetObjectNullableProp gets a reference to the given map[string]ObjectType and assigns it to the ObjectNullableProp field. -func (o *NullableClass) SetObjectNullableProp(v map[string]ObjectType) { +func (o *NullableClass) SetObjectNullableProp(v map[string]interface{}) { o.ObjectNullableProp = v } // GetObjectAndItemsNullableProp returns the ObjectAndItemsNullableProp field value if set, zero value otherwise (both if not set or set to explicit null). -func (o *NullableClass) GetObjectAndItemsNullableProp() map[string]ObjectType { +func (o *NullableClass) GetObjectAndItemsNullableProp() map[string]interface{} { if o == nil { - var ret map[string]ObjectType + var ret map[string]interface{} return ret } return o.ObjectAndItemsNullableProp @@ -442,7 +442,7 @@ func (o *NullableClass) GetObjectAndItemsNullableProp() map[string]ObjectType { // GetObjectAndItemsNullablePropOk returns a tuple with the ObjectAndItemsNullableProp field value if set, nil otherwise // and a boolean to check if the value has been set. // NOTE: If the value is an explicit nil, `nil, true` will be returned -func (o *NullableClass) GetObjectAndItemsNullablePropOk() (*map[string]ObjectType, bool) { +func (o *NullableClass) GetObjectAndItemsNullablePropOk() (*map[string]interface{}, bool) { if o == nil || o.ObjectAndItemsNullableProp == nil { return nil, false } @@ -459,26 +459,26 @@ func (o *NullableClass) HasObjectAndItemsNullableProp() bool { } // SetObjectAndItemsNullableProp gets a reference to the given map[string]ObjectType and assigns it to the ObjectAndItemsNullableProp field. -func (o *NullableClass) SetObjectAndItemsNullableProp(v map[string]ObjectType) { +func (o *NullableClass) SetObjectAndItemsNullableProp(v map[string]interface{}) { o.ObjectAndItemsNullableProp = v } // GetObjectItemsNullable returns the ObjectItemsNullable field value if set, zero value otherwise. -func (o *NullableClass) GetObjectItemsNullable() map[string]ObjectType { +func (o *NullableClass) GetObjectItemsNullable() map[string]interface{} { if o == nil || o.ObjectItemsNullable == nil { - var ret map[string]ObjectType + var ret map[string]interface{} return ret } - return *o.ObjectItemsNullable + return *o.ObjectItemsNullable.Get() } // GetObjectItemsNullableOk returns a tuple with the ObjectItemsNullable field value if set, nil otherwise // and a boolean to check if the value has been set. -func (o *NullableClass) GetObjectItemsNullableOk() (*map[string]ObjectType, bool) { +func (o *NullableClass) GetObjectItemsNullableOk() (*map[string]interface{}, bool) { if o == nil || o.ObjectItemsNullable == nil { return nil, false } - return o.ObjectItemsNullable, true + return o.ObjectItemsNullable.Get(), true } // HasObjectItemsNullable returns a boolean if a field has been set. @@ -491,8 +491,8 @@ func (o *NullableClass) HasObjectItemsNullable() bool { } // SetObjectItemsNullable gets a reference to the given map[string]ObjectType and assigns it to the ObjectItemsNullable field. -func (o *NullableClass) SetObjectItemsNullable(v map[string]ObjectType) { - o.ObjectItemsNullable = &v +func (o *NullableClass) SetObjectItemsNullable(v map[string]interface{}) { + o.ObjectItemsNullable.Set(&v) } func (o NullableClass) MarshalJSON() ([]byte, error) { diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_user.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_user.go index 53fa7d567428..352dcf15745c 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_user.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_user.go @@ -308,21 +308,21 @@ func (o *User) SetUserStatus(v int32) { } // GetObjectWithNoDeclaredProps returns the ObjectWithNoDeclaredProps field value if set, zero value otherwise. -func (o *User) GetObjectWithNoDeclaredProps() ObjectType { +func (o *User) GetObjectWithNoDeclaredProps() map[string]interface{} { if o == nil || o.ObjectWithNoDeclaredProps == nil { - var ret ObjectType + var ret map[string]interface{} return ret } - return *o.ObjectWithNoDeclaredProps + return *o.ObjectWithNoDeclaredProps.Get() } // GetObjectWithNoDeclaredPropsOk returns a tuple with the ObjectWithNoDeclaredProps field value if set, nil otherwise // and a boolean to check if the value has been set. -func (o *User) GetObjectWithNoDeclaredPropsOk() (*ObjectType, bool) { +func (o *User) GetObjectWithNoDeclaredPropsOk() (*map[string]interface{}, bool) { if o == nil || o.ObjectWithNoDeclaredProps == nil { return nil, false } - return o.ObjectWithNoDeclaredProps, true + return o.ObjectWithNoDeclaredProps.Get(), true } // HasObjectWithNoDeclaredProps returns a boolean if a field has been set. @@ -335,32 +335,32 @@ func (o *User) HasObjectWithNoDeclaredProps() bool { } // SetObjectWithNoDeclaredProps gets a reference to the given ObjectType and assigns it to the ObjectWithNoDeclaredProps field. -func (o *User) SetObjectWithNoDeclaredProps(v ObjectType) { - o.ObjectWithNoDeclaredProps = &v +func (o *User) SetObjectWithNoDeclaredProps(v map[string]interface{}) { + o.ObjectWithNoDeclaredProps.Set(&v) } // GetObjectWithNoDeclaredPropsNullable returns the ObjectWithNoDeclaredPropsNullable field value if set, zero value otherwise (both if not set or set to explicit null). -func (o *User) GetObjectWithNoDeclaredPropsNullable() ObjectType { - if o == nil { - var ret ObjectType +func (o *User) GetObjectWithNoDeclaredPropsNullable() map[string]interface{} { + if o == nil || o.ObjectWithNoDeclaredPropsNullable.Get() == nil { + var ret map[string]interface{} return ret } - return o.ObjectWithNoDeclaredPropsNullable + return *o.ObjectWithNoDeclaredPropsNullable.Get() } // GetObjectWithNoDeclaredPropsNullableOk returns a tuple with the ObjectWithNoDeclaredPropsNullable field value if set, nil otherwise // and a boolean to check if the value has been set. // NOTE: If the value is an explicit nil, `nil, true` will be returned -func (o *User) GetObjectWithNoDeclaredPropsNullableOk() (*ObjectType, bool) { - if o == nil || o.ObjectWithNoDeclaredPropsNullable == nil { +func (o *User) GetObjectWithNoDeclaredPropsNullableOk() (*map[string]interface{}, bool) { + if o == nil { return nil, false } - return &o.ObjectWithNoDeclaredPropsNullable, true + return o.ObjectWithNoDeclaredPropsNullable.Get(), o.ObjectWithNoDeclaredPropsNullable.IsSet() } // HasObjectWithNoDeclaredPropsNullable returns a boolean if a field has been set. func (o *User) HasObjectWithNoDeclaredPropsNullable() bool { - if o != nil && o.ObjectWithNoDeclaredPropsNullable != nil { + if o != nil && o.ObjectWithNoDeclaredPropsNullable.IsSet() { return true } @@ -368,32 +368,41 @@ func (o *User) HasObjectWithNoDeclaredPropsNullable() bool { } // SetObjectWithNoDeclaredPropsNullable gets a reference to the given ObjectType and assigns it to the ObjectWithNoDeclaredPropsNullable field. -func (o *User) SetObjectWithNoDeclaredPropsNullable(v ObjectType) { - o.ObjectWithNoDeclaredPropsNullable = v +func (o *User) SetObjectWithNoDeclaredPropsNullable(v map[string]interface{}) { + o.ObjectWithNoDeclaredPropsNullable.Set(&v) +} +// SetObjectWithNoDeclaredPropsNullableNil sets the value for ObjectWithNoDeclaredPropsNullable to be an explicit nil +func (o *User) SetObjectWithNoDeclaredPropsNullableNil() { + o.ObjectWithNoDeclaredPropsNullable.Set(nil) +} + +// UnsetObjectWithNoDeclaredPropsNullable ensures that no value is present for ObjectWithNoDeclaredPropsNullable, not even an explicit nil +func (o *User) UnsetObjectWithNoDeclaredPropsNullable() { + o.ObjectWithNoDeclaredPropsNullable.Unset() } // GetAnyTypeProp returns the AnyTypeProp field value if set, zero value otherwise (both if not set or set to explicit null). -func (o *User) GetAnyTypeProp() AnyType { - if o == nil { - var ret AnyType +func (o *User) GetAnyTypeProp() interface{} { + if o == nil || o.AnyTypeProp.Get() == nil { + var ret interface{} return ret } - return o.AnyTypeProp + return *o.AnyTypeProp.Get() } // GetAnyTypePropOk returns a tuple with the AnyTypeProp field value if set, nil otherwise // and a boolean to check if the value has been set. // NOTE: If the value is an explicit nil, `nil, true` will be returned -func (o *User) GetAnyTypePropOk() (*AnyType, bool) { - if o == nil || o.AnyTypeProp == nil { +func (o *User) GetAnyTypePropOk() (*interface{}, bool) { + if o == nil { return nil, false } - return &o.AnyTypeProp, true + return o.AnyTypeProp.Get(), o.AnyTypeProp.IsSet() } // HasAnyTypeProp returns a boolean if a field has been set. func (o *User) HasAnyTypeProp() bool { - if o != nil && o.AnyTypeProp != nil { + if o != nil && o.AnyTypeProp.IsSet() { return true } @@ -401,32 +410,41 @@ func (o *User) HasAnyTypeProp() bool { } // SetAnyTypeProp gets a reference to the given AnyType and assigns it to the AnyTypeProp field. -func (o *User) SetAnyTypeProp(v AnyType) { - o.AnyTypeProp = v +func (o *User) SetAnyTypeProp(v interface{}) { + o.AnyTypeProp.Set(&v) +} +// SetAnyTypePropNil sets the value for AnyTypeProp to be an explicit nil +func (o *User) SetAnyTypePropNil() { + o.AnyTypeProp.Set(nil) +} + +// UnsetAnyTypeProp ensures that no value is present for AnyTypeProp, not even an explicit nil +func (o *User) UnsetAnyTypeProp() { + o.AnyTypeProp.Unset() } // GetAnyTypePropNullable returns the AnyTypePropNullable field value if set, zero value otherwise (both if not set or set to explicit null). -func (o *User) GetAnyTypePropNullable() AnyType { - if o == nil { - var ret AnyType +func (o *User) GetAnyTypePropNullable() interface{} { + if o == nil || o.AnyTypePropNullable.Get() == nil { + var ret interface{} return ret } - return o.AnyTypePropNullable + return *o.AnyTypePropNullable.Get() } // GetAnyTypePropNullableOk returns a tuple with the AnyTypePropNullable field value if set, nil otherwise // and a boolean to check if the value has been set. // NOTE: If the value is an explicit nil, `nil, true` will be returned -func (o *User) GetAnyTypePropNullableOk() (*AnyType, bool) { - if o == nil || o.AnyTypePropNullable == nil { +func (o *User) GetAnyTypePropNullableOk() (*interface{}, bool) { + if o == nil { return nil, false } - return &o.AnyTypePropNullable, true + return o.AnyTypePropNullable.Get(), o.AnyTypePropNullable.IsSet() } // HasAnyTypePropNullable returns a boolean if a field has been set. func (o *User) HasAnyTypePropNullable() bool { - if o != nil && o.AnyTypePropNullable != nil { + if o != nil && o.AnyTypePropNullable.IsSet() { return true } @@ -434,8 +452,17 @@ func (o *User) HasAnyTypePropNullable() bool { } // SetAnyTypePropNullable gets a reference to the given AnyType and assigns it to the AnyTypePropNullable field. -func (o *User) SetAnyTypePropNullable(v AnyType) { - o.AnyTypePropNullable = v +func (o *User) SetAnyTypePropNullable(v interface{}) { + o.AnyTypePropNullable.Set(&v) +} +// SetAnyTypePropNullableNil sets the value for AnyTypePropNullable to be an explicit nil +func (o *User) SetAnyTypePropNullableNil() { + o.AnyTypePropNullable.Set(nil) +} + +// UnsetAnyTypePropNullable ensures that no value is present for AnyTypePropNullable, not even an explicit nil +func (o *User) UnsetAnyTypePropNullable() { + o.AnyTypePropNullable.Unset() } func (o User) MarshalJSON() ([]byte, error) { @@ -467,14 +494,14 @@ func (o User) MarshalJSON() ([]byte, error) { if o.ObjectWithNoDeclaredProps != nil { toSerialize["objectWithNoDeclaredProps"] = o.ObjectWithNoDeclaredProps } - if o.ObjectWithNoDeclaredPropsNullable != nil { - toSerialize["objectWithNoDeclaredPropsNullable"] = o.ObjectWithNoDeclaredPropsNullable + if o.ObjectWithNoDeclaredPropsNullable.IsSet() { + toSerialize["objectWithNoDeclaredPropsNullable"] = o.ObjectWithNoDeclaredPropsNullable.Get() } - if o.AnyTypeProp != nil { - toSerialize["anyTypeProp"] = o.AnyTypeProp + if o.AnyTypeProp.IsSet() { + toSerialize["anyTypeProp"] = o.AnyTypeProp.Get() } - if o.AnyTypePropNullable != nil { - toSerialize["anyTypePropNullable"] = o.AnyTypePropNullable + if o.AnyTypePropNullable.IsSet() { + toSerialize["anyTypePropNullable"] = o.AnyTypePropNullable.Get() } return json.Marshal(toSerialize) } diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/utils.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/utils.go index 7679b630ed84..d82d433b8b41 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/utils.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/utils.go @@ -81,19 +81,19 @@ func (v *NullType) UnmarshalJSON(src []byte) error { // AnyType is a type whose value can anything. type AnyType struct{ - value interface{} + value *interface{} isSet bool } -func NewAnyType(val interface{}) *AnyType { +func NewAnyType(val *interface{}) *AnyType { return &AnyType{value: val, isSet: true} } -func (v AnyType) Get() interface{} { +func (v AnyType) Get() *interface{} { return v.value } -func (v *AnyType) Set(val interface{}) { +func (v *AnyType) Set(val *interface{}) { v.value = val v.isSet = true } @@ -117,19 +117,19 @@ func (v *AnyType) UnmarshalJSON(src []byte) error { // ObjectType is a type whose value can be an object with undeclared properties. type ObjectType struct{ - value map[string]interface{} + value *map[string]interface{} isSet bool } -func NewObjectType(val map[string]interface{}) *ObjectType { +func NewObjectType(val *map[string]interface{}) *ObjectType { return &ObjectType{value: val, isSet: true} } -func (v ObjectType) Get() map[string]interface{} { +func (v ObjectType) Get() *map[string]interface{} { return v.value } -func (v *ObjectType) Set(val map[string]interface{}) { +func (v *ObjectType) Set(val *map[string]interface{}) { v.value = val v.isSet = true } From 03ec9149e16c117e841d565276e589b3f0ab109c Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Tue, 5 May 2020 08:53:19 -0700 Subject: [PATCH 23/48] Log warning instead of error --- .../src/main/java/org/openapitools/codegen/DefaultCodegen.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index 1f5e3a815c63..1d85b75eab47 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -2996,7 +2996,7 @@ public CodegenProperty fromProperty(String name, Schema p) { // The 'null' value is allowed when the OAS schema is 'any type'. // See https://github.com/OAI/OpenAPI-Specification/issues/1389 if (Boolean.FALSE.equals(p.getNullable())) { - LOGGER.error("Schema '{}' is any type, which includes the 'null' value. 'nullable' cannot be set to 'false'", p.getName()); + LOGGER.warn("Schema '{}' is any type, which includes the 'null' value. 'nullable' cannot be set to 'false'", p.getName()); } property.isNullable = true; property.isAnyType = true; From bdf3653778a78076c75eda000c079aceffab5306 Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Tue, 5 May 2020 09:00:36 -0700 Subject: [PATCH 24/48] anyOf/oneOf --- .../python/python-experimental/model_utils.mustache | 7 ++++--- .../python-experimental/petstore_api/model_utils.py | 7 ++++--- .../python-experimental/petstore_api/model_utils.py | 7 ++++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache b/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache index 686173802c22..70728c8b8f21 100644 --- a/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache +++ b/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache @@ -64,6 +64,10 @@ class OpenApiModel(object): # this function uses the discriminator to # pick a new schema/class to instantiate because a discriminator # propertyName value was passed in + oneof_anyof_classes = cls._composed_schemas.get('oneOf', ()) + + cls._composed_schemas.get('anyOf', ()) + if oneof_anyof_classes and none_type in oneof_anyof_classes and args[0] is None: + return None visited_composed_classes = kwargs.get('_visited_composed_classes', ()) if ( @@ -75,9 +79,6 @@ class OpenApiModel(object): # want to instantiate it this time return super(OpenApiModel, cls).__new__(cls) - oneof_anyof_classes = [] - oneof_anyof_classes.extend(cls._composed_schemas.get('oneOf', ())) - oneof_anyof_classes.extend(cls._composed_schemas.get('anyOf', ())) new_cls = cls.get_discriminator_class(kwargs) if new_cls is None: disc_prop_name_py = list(cls.discriminator.keys())[0] diff --git a/samples/client/petstore/python-experimental/petstore_api/model_utils.py b/samples/client/petstore/python-experimental/petstore_api/model_utils.py index ee328e57a311..7874c5d3de9b 100644 --- a/samples/client/petstore/python-experimental/petstore_api/model_utils.py +++ b/samples/client/petstore/python-experimental/petstore_api/model_utils.py @@ -134,6 +134,10 @@ def __new__(cls, *args, **kwargs): # this function uses the discriminator to # pick a new schema/class to instantiate because a discriminator # propertyName value was passed in + oneof_anyof_classes = cls._composed_schemas.get('oneOf', ()) + + cls._composed_schemas.get('anyOf', ()) + if oneof_anyof_classes and none_type in oneof_anyof_classes and args[0] is None: + return None visited_composed_classes = kwargs.get('_visited_composed_classes', ()) if ( @@ -145,9 +149,6 @@ def __new__(cls, *args, **kwargs): # want to instantiate it this time return super(OpenApiModel, cls).__new__(cls) - oneof_anyof_classes = [] - oneof_anyof_classes.extend(cls._composed_schemas.get('oneOf', ())) - oneof_anyof_classes.extend(cls._composed_schemas.get('anyOf', ())) new_cls = cls.get_discriminator_class(kwargs) if new_cls is None: disc_prop_name_py = list(cls.discriminator.keys())[0] diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py index ee328e57a311..7874c5d3de9b 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py @@ -134,6 +134,10 @@ def __new__(cls, *args, **kwargs): # this function uses the discriminator to # pick a new schema/class to instantiate because a discriminator # propertyName value was passed in + oneof_anyof_classes = cls._composed_schemas.get('oneOf', ()) + + cls._composed_schemas.get('anyOf', ()) + if oneof_anyof_classes and none_type in oneof_anyof_classes and args[0] is None: + return None visited_composed_classes = kwargs.get('_visited_composed_classes', ()) if ( @@ -145,9 +149,6 @@ def __new__(cls, *args, **kwargs): # want to instantiate it this time return super(OpenApiModel, cls).__new__(cls) - oneof_anyof_classes = [] - oneof_anyof_classes.extend(cls._composed_schemas.get('oneOf', ())) - oneof_anyof_classes.extend(cls._composed_schemas.get('anyOf', ())) new_cls = cls.get_discriminator_class(kwargs) if new_cls is None: disc_prop_name_py = list(cls.discriminator.keys())[0] From 9dbae45a54f8018b5c51e95485dd983c9b4edcd8 Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Tue, 5 May 2020 09:57:14 -0700 Subject: [PATCH 25/48] Change x-golang-is-container extension to x-golang-has-wrapper --- .../codegen/languages/AbstractGoCodegen.java | 11 +- .../resources/go-experimental/model.mustache | 118 +++++++++--------- 2 files changed, 65 insertions(+), 64 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java index 15a871b036f9..18cf002a6d7f 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java @@ -607,11 +607,12 @@ private void setExportParameterName(List codegenParameters) { @Override public void postProcessModelProperty(CodegenModel model, CodegenProperty property) { // The 'go-experimental/model.mustache' template conditionally generates accessor methods. - // For containers (e.g. Array, Map), the generated code returns the type directly. - // In other cases, the generated code has a wrapper type and a Get() function to - // access the underlying type. - if (property.isContainer) { - property.vendorExtensions.put("x-golang-is-container", true); + // For containers (e.g. Array, Map) and non-nullable primitive types, the generated code + // returns the type directly. + // In other cases (nullable primitive types, free-form objects...), the generated code has + // a wrapper type and a Get() function to access the underlying type. + if ((property.isNullable && !property.isContainer) || property.isFreeFormObject) { + property.vendorExtensions.put("x-golang-has-wrapper", true); } } diff --git a/modules/openapi-generator/src/main/resources/go-experimental/model.mustache b/modules/openapi-generator/src/main/resources/go-experimental/model.mustache index 3948469c5d25..76cbb8ef562c 100644 --- a/modules/openapi-generator/src/main/resources/go-experimental/model.mustache +++ b/modules/openapi-generator/src/main/resources/go-experimental/model.mustache @@ -69,16 +69,16 @@ func New{{classname}}({{#vars}}{{#required}}{{nameInCamelCase}} {{dataType}}, {{ {{/required}} {{^required}} {{#defaultValue}} -{{^vendorExtensions.x-golang-is-container}} {{#isNullable}} +{{#vendorExtensions.x-golang-has-wrapper}} var {{nameInCamelCase}} {{{datatypeWithEnum}}} = {{{.}}} this.{{name}} = *New{{{dataType}}}(&{{nameInCamelCase}}) +{{/vendorExtensions.x-golang-has-wrapper}} {{/isNullable}} {{^isNullable}} var {{nameInCamelCase}} {{{dataType}}} = {{{.}}} this.{{name}} = &{{nameInCamelCase}} {{/isNullable}} -{{/vendorExtensions.x-golang-is-container}} {{/defaultValue}} {{/required}} {{/vars}} @@ -92,17 +92,17 @@ func New{{classname}}WithDefaults() *{{classname}} { this := {{classname}}{} {{#vars}} {{#defaultValue}} -{{^vendorExtensions.x-golang-is-container}} {{#isNullable}} +{{#vendorExtensions.x-golang-has-wrapper}} {{!we use datatypeWithEnum here, since it will represent the non-nullable name of the datatype, e.g. int64 for NullableInt64}} var {{nameInCamelCase}} {{{datatypeWithEnum}}} = {{{.}}} this.{{name}} = *New{{{dataType}}}(&{{nameInCamelCase}}) +{{/vendorExtensions.x-golang-has-wrapper}} {{/isNullable}} {{^isNullable}} var {{nameInCamelCase}} {{{dataType}}} = {{{.}}} this.{{name}} = {{^required}}&{{/required}}{{nameInCamelCase}} {{/isNullable}} -{{/vendorExtensions.x-golang-is-container}} {{/defaultValue}} {{/vars}} return &this @@ -115,26 +115,26 @@ func New{{classname}}WithDefaults() *{{classname}} { // If the value is explicit nil, the zero value for {{vendorExtensions.x-go-base-type}} will be returned {{/isNullable}} func (o *{{classname}}) Get{{name}}() {{vendorExtensions.x-go-base-type}} { - if o == nil {{#isNullable}}{{^vendorExtensions.x-golang-is-container}}|| o.{{name}}.Get() == nil{{/vendorExtensions.x-golang-is-container}}{{/isNullable}} { + if o == nil {{#isNullable}}{{#vendorExtensions.x-golang-has-wrapper}}|| o.{{name}}.Get() == nil{{/vendorExtensions.x-golang-has-wrapper}}{{/isNullable}} { var ret {{vendorExtensions.x-go-base-type}} return ret } {{#isNullable}} -{{#vendorExtensions.x-golang-is-container}} +{{^vendorExtensions.x-golang-has-wrapper}} return o.{{name}} -{{/vendorExtensions.x-golang-is-container}} -{{^vendorExtensions.x-golang-is-container}} +{{/vendorExtensions.x-golang-has-wrapper}} +{{#vendorExtensions.x-golang-has-wrapper}} return *o.{{name}}.Get() -{{/vendorExtensions.x-golang-is-container}} +{{/vendorExtensions.x-golang-has-wrapper}} {{/isNullable}} {{^isNullable}} -{{#isFreeFormObject}} +{{#vendorExtensions.x-golang-has-wrapper}} return o.{{name}}.Get() -{{/isFreeFormObject}} -{{^isFreeFormObject}} +{{/vendorExtensions.x-golang-has-wrapper}} +{{^vendorExtensions.x-golang-has-wrapper}} return o.{{name}} -{{/isFreeFormObject}} +{{/vendorExtensions.x-golang-has-wrapper}} {{/isNullable}} } @@ -144,36 +144,36 @@ func (o *{{classname}}) Get{{name}}() {{vendorExtensions.x-go-base-type}} { // NOTE: If the value is an explicit nil, `nil, true` will be returned {{/isNullable}} func (o *{{classname}}) Get{{name}}Ok() (*{{vendorExtensions.x-go-base-type}}, bool) { - if o == nil {{#isNullable}}{{#vendorExtensions.x-golang-is-container}}|| o.{{name}} == nil{{/vendorExtensions.x-golang-is-container}}{{/isNullable}} { + if o == nil {{#isNullable}}{{^vendorExtensions.x-golang-has-wrapper}}|| o.{{name}} == nil{{/vendorExtensions.x-golang-has-wrapper}}{{/isNullable}} { return nil, false } {{#isNullable}} -{{#vendorExtensions.x-golang-is-container}} +{{^vendorExtensions.x-golang-has-wrapper}} return &o.{{name}}, true -{{/vendorExtensions.x-golang-is-container}} -{{^vendorExtensions.x-golang-is-container}} +{{/vendorExtensions.x-golang-has-wrapper}} +{{#vendorExtensions.x-golang-has-wrapper}} return o.{{name}}.Get(), o.{{name}}.IsSet() -{{/vendorExtensions.x-golang-is-container}} +{{/vendorExtensions.x-golang-has-wrapper}} {{/isNullable}} {{^isNullable}} -{{#isFreeFormObject}} +{{#vendorExtensions.x-golang-has-wrapper}} return &o.{{name}}.Get(), true -{{/isFreeFormObject}} -{{^isFreeFormObject}} +{{/vendorExtensions.x-golang-has-wrapper}} +{{^vendorExtensions.x-golang-has-wrapper}} return &o.{{name}}, true -{{/isFreeFormObject}} +{{/vendorExtensions.x-golang-has-wrapper}} {{/isNullable}} } // Set{{name}} sets field value func (o *{{classname}}) Set{{name}}(v {{vendorExtensions.x-go-base-type}}) { {{#isNullable}} -{{#vendorExtensions.x-golang-is-container}} +{{^vendorExtensions.x-golang-has-wrapper}} o.{{name}} = v -{{/vendorExtensions.x-golang-is-container}} -{{^vendorExtensions.x-golang-is-container}} +{{/vendorExtensions.x-golang-has-wrapper}} +{{#vendorExtensions.x-golang-has-wrapper}} o.{{name}}.Set(&v) -{{/vendorExtensions.x-golang-is-container}} +{{/vendorExtensions.x-golang-has-wrapper}} {{/isNullable}} {{^isNullable}} o.{{name}} = v @@ -184,25 +184,25 @@ func (o *{{classname}}) Set{{name}}(v {{vendorExtensions.x-go-base-type}}) { {{^required}} // Get{{name}} returns the {{name}} field value if set, zero value otherwise{{#isNullable}} (both if not set or set to explicit null){{/isNullable}}. func (o *{{classname}}) Get{{name}}() {{vendorExtensions.x-go-base-type}} { - if o == nil {{^isNullable}}|| o.{{name}} == nil{{/isNullable}}{{#isNullable}}{{^vendorExtensions.x-golang-is-container}}|| o.{{name}}.Get() == nil{{/vendorExtensions.x-golang-is-container}}{{/isNullable}} { + if o == nil {{^isNullable}}|| o.{{name}} == nil{{/isNullable}}{{#isNullable}}{{#vendorExtensions.x-golang-has-wrapper}}|| o.{{name}}.Get() == nil{{/vendorExtensions.x-golang-has-wrapper}}{{/isNullable}} { var ret {{vendorExtensions.x-go-base-type}} return ret } {{#isNullable}} -{{#vendorExtensions.x-golang-is-container}} +{{^vendorExtensions.x-golang-has-wrapper}} return o.{{name}} -{{/vendorExtensions.x-golang-is-container}} -{{^vendorExtensions.x-golang-is-container}} +{{/vendorExtensions.x-golang-has-wrapper}} +{{#vendorExtensions.x-golang-has-wrapper}} return *o.{{name}}.Get() -{{/vendorExtensions.x-golang-is-container}} +{{/vendorExtensions.x-golang-has-wrapper}} {{/isNullable}} {{^isNullable}} -{{#isFreeFormObject}} +{{#vendorExtensions.x-golang-has-wrapper}} return *o.{{name}}.Get() -{{/isFreeFormObject}} -{{^isFreeFormObject}} +{{/vendorExtensions.x-golang-has-wrapper}} +{{^vendorExtensions.x-golang-has-wrapper}} return *o.{{name}} -{{/isFreeFormObject}} +{{/vendorExtensions.x-golang-has-wrapper}} {{/isNullable}} } @@ -212,30 +212,30 @@ func (o *{{classname}}) Get{{name}}() {{vendorExtensions.x-go-base-type}} { // NOTE: If the value is an explicit nil, `nil, true` will be returned {{/isNullable}} func (o *{{classname}}) Get{{name}}Ok() (*{{vendorExtensions.x-go-base-type}}, bool) { - if o == nil {{^isNullable}}|| o.{{name}} == nil{{/isNullable}}{{#isNullable}}{{#vendorExtensions.x-golang-is-container}}|| o.{{name}} == nil{{/vendorExtensions.x-golang-is-container}}{{/isNullable}} { + if o == nil {{^isNullable}}|| o.{{name}} == nil{{/isNullable}}{{#isNullable}}{{^vendorExtensions.x-golang-has-wrapper}}|| o.{{name}} == nil{{/vendorExtensions.x-golang-has-wrapper}}{{/isNullable}} { return nil, false } {{#isNullable}} -{{#vendorExtensions.x-golang-is-container}} +{{^vendorExtensions.x-golang-has-wrapper}} return &o.{{name}}, true -{{/vendorExtensions.x-golang-is-container}} -{{^vendorExtensions.x-golang-is-container}} +{{/vendorExtensions.x-golang-has-wrapper}} +{{#vendorExtensions.x-golang-has-wrapper}} return o.{{name}}.Get(), o.{{name}}.IsSet() -{{/vendorExtensions.x-golang-is-container}} +{{/vendorExtensions.x-golang-has-wrapper}} {{/isNullable}} {{^isNullable}} -{{#isFreeFormObject}} +{{#vendorExtensions.x-golang-has-wrapper}} return o.{{name}}.Get(), true -{{/isFreeFormObject}} -{{^isFreeFormObject}} +{{/vendorExtensions.x-golang-has-wrapper}} +{{^vendorExtensions.x-golang-has-wrapper}} return o.{{name}}, true -{{/isFreeFormObject}} +{{/vendorExtensions.x-golang-has-wrapper}} {{/isNullable}} } // Has{{name}} returns a boolean if a field has been set. func (o *{{classname}}) Has{{name}}() bool { - if o != nil && {{^isNullable}}o.{{name}} != nil{{/isNullable}}{{#isNullable}}{{#vendorExtensions.x-golang-is-container}}o.{{name}} != nil{{/vendorExtensions.x-golang-is-container}}{{^vendorExtensions.x-golang-is-container}}o.{{name}}.IsSet(){{/vendorExtensions.x-golang-is-container}}{{/isNullable}} { + if o != nil && {{^isNullable}}o.{{name}} != nil{{/isNullable}}{{#isNullable}}{{^vendorExtensions.x-golang-has-wrapper}}o.{{name}} != nil{{/vendorExtensions.x-golang-has-wrapper}}{{#vendorExtensions.x-golang-has-wrapper}}o.{{name}}.IsSet(){{/vendorExtensions.x-golang-has-wrapper}}{{/isNullable}} { return true } @@ -245,24 +245,24 @@ func (o *{{classname}}) Has{{name}}() bool { // Set{{name}} gets a reference to the given {{dataType}} and assigns it to the {{name}} field. func (o *{{classname}}) Set{{name}}(v {{vendorExtensions.x-go-base-type}}) { {{#isNullable}} -{{#vendorExtensions.x-golang-is-container}} +{{^vendorExtensions.x-golang-has-wrapper}} o.{{name}} = v -{{/vendorExtensions.x-golang-is-container}} -{{^vendorExtensions.x-golang-is-container}} +{{/vendorExtensions.x-golang-has-wrapper}} +{{#vendorExtensions.x-golang-has-wrapper}} o.{{name}}.Set(&v) -{{/vendorExtensions.x-golang-is-container}} +{{/vendorExtensions.x-golang-has-wrapper}} {{/isNullable}} {{^isNullable}} -{{#isFreeFormObject}} +{{#vendorExtensions.x-golang-has-wrapper}} o.{{name}}.Set(&v) -{{/isFreeFormObject}} -{{^isFreeFormObject}} +{{/vendorExtensions.x-golang-has-wrapper}} +{{^vendorExtensions.x-golang-has-wrapper}} o.{{name}} = &v -{{/isFreeFormObject}} +{{/vendorExtensions.x-golang-has-wrapper}} {{/isNullable}} } {{#isNullable}} -{{^vendorExtensions.x-golang-is-container}} +{{#vendorExtensions.x-golang-has-wrapper}} // Set{{name}}Nil sets the value for {{name}} to be an explicit nil func (o *{{classname}}) Set{{name}}Nil() { o.{{name}}.Set(nil) @@ -272,7 +272,7 @@ func (o *{{classname}}) Set{{name}}Nil() { func (o *{{classname}}) Unset{{name}}() { o.{{name}}.Unset() } -{{/vendorExtensions.x-golang-is-container}} +{{/vendorExtensions.x-golang-has-wrapper}} {{/isNullable}} {{/required}} @@ -294,17 +294,17 @@ func (o {{classname}}) MarshalJSON() ([]byte, error) { {{#vars}} {{! if argument is nullable, only serialize it if it is set}} {{#isNullable}} - {{#vendorExtensions.x-golang-is-container}} + {{^vendorExtensions.x-golang-has-wrapper}} {{! support for container fields is not ideal at this point because of lack of Nullable* types}} if o.{{name}} != nil { toSerialize["{{baseName}}"] = o.{{name}} } - {{/vendorExtensions.x-golang-is-container}} - {{^vendorExtensions.x-golang-is-container}} + {{/vendorExtensions.x-golang-has-wrapper}} + {{#vendorExtensions.x-golang-has-wrapper}} if {{#required}}true{{/required}}{{^required}}o.{{name}}.IsSet(){{/required}} { toSerialize["{{baseName}}"] = o.{{name}}.Get() } - {{/vendorExtensions.x-golang-is-container}} + {{/vendorExtensions.x-golang-has-wrapper}} {{/isNullable}} {{! if argument is not nullable, don't set it if it is nil}} {{^isNullable}} From e1417ecd5e5880b253a817a96ea54eba55c2b3c3 Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Tue, 5 May 2020 10:25:21 -0700 Subject: [PATCH 26/48] Add code comments --- .../src/main/resources/go-experimental/utils.mustache | 8 ++++++-- .../client/petstore/go-experimental/go-petstore/utils.go | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/go-experimental/utils.mustache b/modules/openapi-generator/src/main/resources/go-experimental/utils.mustache index 046d5c9574f1..a2b033a80046 100644 --- a/modules/openapi-generator/src/main/resources/go-experimental/utils.mustache +++ b/modules/openapi-generator/src/main/resources/go-experimental/utils.mustache @@ -71,7 +71,9 @@ func (v *NullType) UnmarshalJSON(src []byte) error { return errors.New("Cannot unmarshal value into 'null' type") } -// AnyType is a type whose value can anything. +// AnyType is a type whose value can any valid OpenAPI type. +// The value may be the null value, a string, integer, number, boolean, array +// or object. type AnyType struct{ value *interface{} isSet bool @@ -107,12 +109,14 @@ func (v *AnyType) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } -// ObjectType is a type whose value can be an object with undeclared properties. +// ObjectType is a type whose value can be any OpenAPI object with undeclared properties. type ObjectType struct{ value *map[string]interface{} isSet bool } +// NewObjectType creates and returns an object with the specified map +// of undeclared properties. func NewObjectType(val *map[string]interface{}) *ObjectType { return &ObjectType{value: val, isSet: true} } diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/utils.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/utils.go index d82d433b8b41..6c470ffcd2ad 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/utils.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/utils.go @@ -79,7 +79,9 @@ func (v *NullType) UnmarshalJSON(src []byte) error { return errors.New("Cannot unmarshal value into 'null' type") } -// AnyType is a type whose value can anything. +// AnyType is a type whose value can any valid OpenAPI type. +// The value may be the null value, a string, integer, number, boolean, array +// or object. type AnyType struct{ value *interface{} isSet bool @@ -115,12 +117,14 @@ func (v *AnyType) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } -// ObjectType is a type whose value can be an object with undeclared properties. +// ObjectType is a type whose value can be any OpenAPI object with undeclared properties. type ObjectType struct{ value *map[string]interface{} isSet bool } +// NewObjectType creates and returns an object with the specified map +// of undeclared properties. func NewObjectType(val *map[string]interface{}) *ObjectType { return &ObjectType{value: val, isSet: true} } From 480ecbefdbcd0838ec3faac22fb841750aa863f4 Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Tue, 5 May 2020 10:26:36 -0700 Subject: [PATCH 27/48] Handle Object and any type --- .../docs/AdditionalPropertiesClass.md | 18 +++++++++--------- ...edPropertiesAndAdditionalPropertiesClass.md | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/samples/client/petstore/go-experimental/go-petstore/docs/AdditionalPropertiesClass.md b/samples/client/petstore/go-experimental/go-petstore/docs/AdditionalPropertiesClass.md index 25607757d82f..a8d460c4abae 100644 --- a/samples/client/petstore/go-experimental/go-petstore/docs/AdditionalPropertiesClass.md +++ b/samples/client/petstore/go-experimental/go-petstore/docs/AdditionalPropertiesClass.md @@ -237,20 +237,20 @@ HasMapMapAnytype returns a boolean if a field has been set. ### GetAnytype1 -`func (o *AdditionalPropertiesClass) GetAnytype1() ObjectType` +`func (o *AdditionalPropertiesClass) GetAnytype1() map[string]interface{}` GetAnytype1 returns the Anytype1 field if non-nil, zero value otherwise. ### GetAnytype1Ok -`func (o *AdditionalPropertiesClass) GetAnytype1Ok() (*ObjectType, bool)` +`func (o *AdditionalPropertiesClass) GetAnytype1Ok() (*map[string]interface{}, bool)` GetAnytype1Ok returns a tuple with the Anytype1 field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetAnytype1 -`func (o *AdditionalPropertiesClass) SetAnytype1(v ObjectType)` +`func (o *AdditionalPropertiesClass) SetAnytype1(v map[string]interface{})` SetAnytype1 sets Anytype1 field to given value. @@ -262,20 +262,20 @@ HasAnytype1 returns a boolean if a field has been set. ### GetAnytype2 -`func (o *AdditionalPropertiesClass) GetAnytype2() ObjectType` +`func (o *AdditionalPropertiesClass) GetAnytype2() map[string]interface{}` GetAnytype2 returns the Anytype2 field if non-nil, zero value otherwise. ### GetAnytype2Ok -`func (o *AdditionalPropertiesClass) GetAnytype2Ok() (*ObjectType, bool)` +`func (o *AdditionalPropertiesClass) GetAnytype2Ok() (*map[string]interface{}, bool)` GetAnytype2Ok returns a tuple with the Anytype2 field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetAnytype2 -`func (o *AdditionalPropertiesClass) SetAnytype2(v ObjectType)` +`func (o *AdditionalPropertiesClass) SetAnytype2(v map[string]interface{})` SetAnytype2 sets Anytype2 field to given value. @@ -287,20 +287,20 @@ HasAnytype2 returns a boolean if a field has been set. ### GetAnytype3 -`func (o *AdditionalPropertiesClass) GetAnytype3() ObjectType` +`func (o *AdditionalPropertiesClass) GetAnytype3() map[string]interface{}` GetAnytype3 returns the Anytype3 field if non-nil, zero value otherwise. ### GetAnytype3Ok -`func (o *AdditionalPropertiesClass) GetAnytype3Ok() (*ObjectType, bool)` +`func (o *AdditionalPropertiesClass) GetAnytype3Ok() (*map[string]interface{}, bool)` GetAnytype3Ok returns a tuple with the Anytype3 field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetAnytype3 -`func (o *AdditionalPropertiesClass) SetAnytype3(v ObjectType)` +`func (o *AdditionalPropertiesClass) SetAnytype3(v map[string]interface{})` SetAnytype3 sets Anytype3 field to given value. diff --git a/samples/client/petstore/go-experimental/go-petstore/docs/MixedPropertiesAndAdditionalPropertiesClass.md b/samples/client/petstore/go-experimental/go-petstore/docs/MixedPropertiesAndAdditionalPropertiesClass.md index f726ffe63e13..5db7cf034089 100644 --- a/samples/client/petstore/go-experimental/go-petstore/docs/MixedPropertiesAndAdditionalPropertiesClass.md +++ b/samples/client/petstore/go-experimental/go-petstore/docs/MixedPropertiesAndAdditionalPropertiesClass.md @@ -79,20 +79,20 @@ HasDateTime returns a boolean if a field has been set. ### GetMap -`func (o *MixedPropertiesAndAdditionalPropertiesClass) GetMap() map[string]Animal` +`func (o *MixedPropertiesAndAdditionalPropertiesClass) GetMap() map[string]interface{}` GetMap returns the Map field if non-nil, zero value otherwise. ### GetMapOk -`func (o *MixedPropertiesAndAdditionalPropertiesClass) GetMapOk() (*map[string]Animal, bool)` +`func (o *MixedPropertiesAndAdditionalPropertiesClass) GetMapOk() (*map[string]interface{}, bool)` GetMapOk returns a tuple with the Map field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetMap -`func (o *MixedPropertiesAndAdditionalPropertiesClass) SetMap(v map[string]Animal)` +`func (o *MixedPropertiesAndAdditionalPropertiesClass) SetMap(v map[string]interface{})` SetMap sets Map field to given value. From a58f121343c1a50a559691fcf1a52559b0ed8866 Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Tue, 5 May 2020 10:27:41 -0700 Subject: [PATCH 28/48] Handle Object and any type --- .../model_additional_properties_class.go | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_class.go b/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_class.go index 72a6df95c099..eff3aa3e1780 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_class.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_class.go @@ -302,21 +302,21 @@ func (o *AdditionalPropertiesClass) SetMapMapAnytype(v map[string]map[string]Obj } // GetAnytype1 returns the Anytype1 field value if set, zero value otherwise. -func (o *AdditionalPropertiesClass) GetAnytype1() ObjectType { +func (o *AdditionalPropertiesClass) GetAnytype1() map[string]interface{} { if o == nil || o.Anytype1 == nil { - var ret ObjectType + var ret map[string]interface{} return ret } - return *o.Anytype1 + return *o.Anytype1.Get() } // GetAnytype1Ok returns a tuple with the Anytype1 field value if set, nil otherwise // and a boolean to check if the value has been set. -func (o *AdditionalPropertiesClass) GetAnytype1Ok() (*ObjectType, bool) { +func (o *AdditionalPropertiesClass) GetAnytype1Ok() (*map[string]interface{}, bool) { if o == nil || o.Anytype1 == nil { return nil, false } - return o.Anytype1, true + return o.Anytype1.Get(), true } // HasAnytype1 returns a boolean if a field has been set. @@ -329,26 +329,26 @@ func (o *AdditionalPropertiesClass) HasAnytype1() bool { } // SetAnytype1 gets a reference to the given ObjectType and assigns it to the Anytype1 field. -func (o *AdditionalPropertiesClass) SetAnytype1(v ObjectType) { - o.Anytype1 = &v +func (o *AdditionalPropertiesClass) SetAnytype1(v map[string]interface{}) { + o.Anytype1.Set(&v) } // GetAnytype2 returns the Anytype2 field value if set, zero value otherwise. -func (o *AdditionalPropertiesClass) GetAnytype2() ObjectType { +func (o *AdditionalPropertiesClass) GetAnytype2() map[string]interface{} { if o == nil || o.Anytype2 == nil { - var ret ObjectType + var ret map[string]interface{} return ret } - return *o.Anytype2 + return *o.Anytype2.Get() } // GetAnytype2Ok returns a tuple with the Anytype2 field value if set, nil otherwise // and a boolean to check if the value has been set. -func (o *AdditionalPropertiesClass) GetAnytype2Ok() (*ObjectType, bool) { +func (o *AdditionalPropertiesClass) GetAnytype2Ok() (*map[string]interface{}, bool) { if o == nil || o.Anytype2 == nil { return nil, false } - return o.Anytype2, true + return o.Anytype2.Get(), true } // HasAnytype2 returns a boolean if a field has been set. @@ -361,26 +361,26 @@ func (o *AdditionalPropertiesClass) HasAnytype2() bool { } // SetAnytype2 gets a reference to the given ObjectType and assigns it to the Anytype2 field. -func (o *AdditionalPropertiesClass) SetAnytype2(v ObjectType) { - o.Anytype2 = &v +func (o *AdditionalPropertiesClass) SetAnytype2(v map[string]interface{}) { + o.Anytype2.Set(&v) } // GetAnytype3 returns the Anytype3 field value if set, zero value otherwise. -func (o *AdditionalPropertiesClass) GetAnytype3() ObjectType { +func (o *AdditionalPropertiesClass) GetAnytype3() map[string]interface{} { if o == nil || o.Anytype3 == nil { - var ret ObjectType + var ret map[string]interface{} return ret } - return *o.Anytype3 + return *o.Anytype3.Get() } // GetAnytype3Ok returns a tuple with the Anytype3 field value if set, nil otherwise // and a boolean to check if the value has been set. -func (o *AdditionalPropertiesClass) GetAnytype3Ok() (*ObjectType, bool) { +func (o *AdditionalPropertiesClass) GetAnytype3Ok() (*map[string]interface{}, bool) { if o == nil || o.Anytype3 == nil { return nil, false } - return o.Anytype3, true + return o.Anytype3.Get(), true } // HasAnytype3 returns a boolean if a field has been set. @@ -393,8 +393,8 @@ func (o *AdditionalPropertiesClass) HasAnytype3() bool { } // SetAnytype3 gets a reference to the given ObjectType and assigns it to the Anytype3 field. -func (o *AdditionalPropertiesClass) SetAnytype3(v ObjectType) { - o.Anytype3 = &v +func (o *AdditionalPropertiesClass) SetAnytype3(v map[string]interface{}) { + o.Anytype3.Set(&v) } func (o AdditionalPropertiesClass) MarshalJSON() ([]byte, error) { From 01ff36e8937cb811389030d4aef8a425a851046b Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Tue, 5 May 2020 10:28:58 -0700 Subject: [PATCH 29/48] Handle object and any type --- .../go-experimental/go-petstore/utils.go | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/samples/client/petstore/go-experimental/go-petstore/utils.go b/samples/client/petstore/go-experimental/go-petstore/utils.go index 7679b630ed84..6c470ffcd2ad 100644 --- a/samples/client/petstore/go-experimental/go-petstore/utils.go +++ b/samples/client/petstore/go-experimental/go-petstore/utils.go @@ -79,21 +79,23 @@ func (v *NullType) UnmarshalJSON(src []byte) error { return errors.New("Cannot unmarshal value into 'null' type") } -// AnyType is a type whose value can anything. +// AnyType is a type whose value can any valid OpenAPI type. +// The value may be the null value, a string, integer, number, boolean, array +// or object. type AnyType struct{ - value interface{} + value *interface{} isSet bool } -func NewAnyType(val interface{}) *AnyType { +func NewAnyType(val *interface{}) *AnyType { return &AnyType{value: val, isSet: true} } -func (v AnyType) Get() interface{} { +func (v AnyType) Get() *interface{} { return v.value } -func (v *AnyType) Set(val interface{}) { +func (v *AnyType) Set(val *interface{}) { v.value = val v.isSet = true } @@ -115,21 +117,23 @@ func (v *AnyType) UnmarshalJSON(src []byte) error { return json.Unmarshal(src, &v.value) } -// ObjectType is a type whose value can be an object with undeclared properties. +// ObjectType is a type whose value can be any OpenAPI object with undeclared properties. type ObjectType struct{ - value map[string]interface{} + value *map[string]interface{} isSet bool } -func NewObjectType(val map[string]interface{}) *ObjectType { +// NewObjectType creates and returns an object with the specified map +// of undeclared properties. +func NewObjectType(val *map[string]interface{}) *ObjectType { return &ObjectType{value: val, isSet: true} } -func (v ObjectType) Get() map[string]interface{} { +func (v ObjectType) Get() *map[string]interface{} { return v.value } -func (v *ObjectType) Set(val map[string]interface{}) { +func (v *ObjectType) Set(val *map[string]interface{}) { v.value = val v.isSet = true } From ec97db3363beb36b5157ffec0d366fd3b7811478 Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Wed, 6 May 2020 06:32:54 -0700 Subject: [PATCH 30/48] add code comments --- .../main/java/org/openapitools/codegen/CodegenProperty.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenProperty.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenProperty.java index bc1101c015e9..41c22ca86f02 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenProperty.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenProperty.java @@ -134,7 +134,9 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti public boolean isUri; public boolean isEmail; /** - * The type is a free-form object, i.e. it is a map of string to values with no declared properties + * The type is a free-form object, i.e. it is a map of string to values with no declared properties. + * A OAS free-form schema may include the 'additionalProperties' attribute, which puts a constraint + * on the type of the undeclared properties. */ public boolean isFreeFormObject; /** From 431356c557cdb3de46817189f56b347df1e38727 Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Wed, 6 May 2020 09:37:02 -0700 Subject: [PATCH 31/48] handle additional properties --- .../docs/MixedPropertiesAndAdditionalPropertiesClass.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/client/petstore/go-experimental/go-petstore/docs/MixedPropertiesAndAdditionalPropertiesClass.md b/samples/client/petstore/go-experimental/go-petstore/docs/MixedPropertiesAndAdditionalPropertiesClass.md index 5db7cf034089..f726ffe63e13 100644 --- a/samples/client/petstore/go-experimental/go-petstore/docs/MixedPropertiesAndAdditionalPropertiesClass.md +++ b/samples/client/petstore/go-experimental/go-petstore/docs/MixedPropertiesAndAdditionalPropertiesClass.md @@ -79,20 +79,20 @@ HasDateTime returns a boolean if a field has been set. ### GetMap -`func (o *MixedPropertiesAndAdditionalPropertiesClass) GetMap() map[string]interface{}` +`func (o *MixedPropertiesAndAdditionalPropertiesClass) GetMap() map[string]Animal` GetMap returns the Map field if non-nil, zero value otherwise. ### GetMapOk -`func (o *MixedPropertiesAndAdditionalPropertiesClass) GetMapOk() (*map[string]interface{}, bool)` +`func (o *MixedPropertiesAndAdditionalPropertiesClass) GetMapOk() (*map[string]Animal, bool)` GetMapOk returns a tuple with the Map field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetMap -`func (o *MixedPropertiesAndAdditionalPropertiesClass) SetMap(v map[string]interface{})` +`func (o *MixedPropertiesAndAdditionalPropertiesClass) SetMap(v map[string]Animal)` SetMap sets Map field to given value. From 93752ff6e82e7b0d938a20c5fadbf87360edba36 Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Wed, 6 May 2020 09:37:28 -0700 Subject: [PATCH 32/48] handle additional properties --- .../docs/MixedPropertiesAndAdditionalPropertiesClass.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/MixedPropertiesAndAdditionalPropertiesClass.md b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/MixedPropertiesAndAdditionalPropertiesClass.md index 5db7cf034089..f726ffe63e13 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/MixedPropertiesAndAdditionalPropertiesClass.md +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/MixedPropertiesAndAdditionalPropertiesClass.md @@ -79,20 +79,20 @@ HasDateTime returns a boolean if a field has been set. ### GetMap -`func (o *MixedPropertiesAndAdditionalPropertiesClass) GetMap() map[string]interface{}` +`func (o *MixedPropertiesAndAdditionalPropertiesClass) GetMap() map[string]Animal` GetMap returns the Map field if non-nil, zero value otherwise. ### GetMapOk -`func (o *MixedPropertiesAndAdditionalPropertiesClass) GetMapOk() (*map[string]interface{}, bool)` +`func (o *MixedPropertiesAndAdditionalPropertiesClass) GetMapOk() (*map[string]Animal, bool)` GetMapOk returns a tuple with the Map field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetMap -`func (o *MixedPropertiesAndAdditionalPropertiesClass) SetMap(v map[string]interface{})` +`func (o *MixedPropertiesAndAdditionalPropertiesClass) SetMap(v map[string]Animal)` SetMap sets Map field to given value. From 261dbcdb33bc98df86b803f5e96d2167c75fa01e Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Wed, 6 May 2020 09:38:25 -0700 Subject: [PATCH 33/48] handle additional properties --- ...d_properties_and_additional_properties_class.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_mixed_properties_and_additional_properties_class.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_mixed_properties_and_additional_properties_class.go index efa3264c3d51..355bcab85031 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_mixed_properties_and_additional_properties_class.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_mixed_properties_and_additional_properties_class.go @@ -103,21 +103,21 @@ func (o *MixedPropertiesAndAdditionalPropertiesClass) SetDateTime(v time.Time) { } // GetMap returns the Map field value if set, zero value otherwise. -func (o *MixedPropertiesAndAdditionalPropertiesClass) GetMap() map[string]interface{} { +func (o *MixedPropertiesAndAdditionalPropertiesClass) GetMap() map[string]Animal { if o == nil || o.Map == nil { - var ret map[string]interface{} + var ret map[string]Animal return ret } - return *o.Map.Get() + return *o.Map } // GetMapOk returns a tuple with the Map field value if set, nil otherwise // and a boolean to check if the value has been set. -func (o *MixedPropertiesAndAdditionalPropertiesClass) GetMapOk() (*map[string]interface{}, bool) { +func (o *MixedPropertiesAndAdditionalPropertiesClass) GetMapOk() (*map[string]Animal, bool) { if o == nil || o.Map == nil { return nil, false } - return o.Map.Get(), true + return o.Map, true } // HasMap returns a boolean if a field has been set. @@ -130,8 +130,8 @@ func (o *MixedPropertiesAndAdditionalPropertiesClass) HasMap() bool { } // SetMap gets a reference to the given map[string]Animal and assigns it to the Map field. -func (o *MixedPropertiesAndAdditionalPropertiesClass) SetMap(v map[string]interface{}) { - o.Map.Set(&v) +func (o *MixedPropertiesAndAdditionalPropertiesClass) SetMap(v map[string]Animal) { + o.Map = &v } func (o MixedPropertiesAndAdditionalPropertiesClass) MarshalJSON() ([]byte, error) { From aa6b6dfcec737e2c03fe2a0c3cc17db894b50c4d Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Wed, 6 May 2020 14:35:53 -0700 Subject: [PATCH 34/48] handle anytype and objecttype for go-exerimental --- .../openapitools/codegen/CodegenProperty.java | 3 ++ .../codegen/languages/AbstractGoCodegen.java | 51 +++++++++++++++++-- .../GoClientExperimentalCodegen.java | 26 ++++++++-- .../go-petstore/docs/NullableClass.md | 18 +++---- .../go-experimental/go-petstore/go.mod | 4 +- .../go-petstore/model_nullable_class.go | 30 +++++------ 6 files changed, 98 insertions(+), 34 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenProperty.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenProperty.java index 41c22ca86f02..6ec7490bfc47 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenProperty.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenProperty.java @@ -155,6 +155,9 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti public boolean isDiscriminator; public List _enum; public Map allowableValues; + // If 'additionalProperties' is not set, items is null. + // If 'additionalProperties' is set to a type or refers to a type, 'items' provides the type information for + // the undeclared properties. public CodegenProperty items; public CodegenProperty mostInnerItems; public Map vendorExtensions = new HashMap(); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java index 18cf002a6d7f..38e6419238cd 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java @@ -604,14 +604,57 @@ private void setExportParameterName(List codegenParameters) { } } + /** + * OAS type mapping to golang implementation: + * + * AnyType interface{} Any type, e.g. null, string, integer, number, boolean, map, array. + * ObjectType map[string]interface{} Free-form object with no constraint on additional properties. + * map[string]Animal map[string]Animal Free-form object. The value of undeclared properties must be 'Animal'. + * map[string]ObjectType map[string]map[string]interface{} Free-form object. The value of undeclared properties must be an object (map). + * map[string][]interface{} Free-form object. The value of undeclared properties must be an array. + * + */ @Override public void postProcessModelProperty(CodegenModel model, CodegenProperty property) { - // The 'go-experimental/model.mustache' template conditionally generates accessor methods. - // For containers (e.g. Array, Map) and non-nullable primitive types, the generated code - // returns the type directly. + // The 'go-experimental/model.mustache' template generates accessor methods. + // For containers (e.g. Array, Map) and non-nullable primitive types, the go struct field + // is the underlying type, e.g. *int32, *string, *bool... // In other cases (nullable primitive types, free-form objects...), the generated code has // a wrapper type and a Get() function to access the underlying type. - if ((property.isNullable && !property.isContainer) || property.isFreeFormObject) { + boolean hasWrapper = false; + if (property.isAnyType) { + // The wrapper type is the 'AnyType' struct and the wrapped type is 'interface{}'. + hasWrapper = true; + } else if (property.isFreeFormObject && !property.isNullable) { // && + // Undeclared properties use case. + // The undeclared properties are implemented using a go map. + // The map key is always a string. + // The map value is interface{} when there are no constraints, but the + // 'additionalProperties' attribute may require a specific type. + if (property.items == null) { + // The 'additionalProperties' attribute is not set, so it is a free-form object + // with no constraint on the type of undeclared properties. + // The wrapper type is 'ObjectType'. + // The wrapped type is 'map[string]interface{}'. + hasWrapper = true; + } else if (property.items.isFreeFormObject && !property.items.isNullable) { + // The 'additionalProperties' attribute is set, and the value of the undeclared + // properties must be a free-form object. Hence it's a map of map. + // The wrapper type is map[string]ObjectType. + // The wrapped type is 'map[string]map[string]interface{}'. + hasWrapper = true; + } else { + // The 'additionalProperties' attribute is set, and the value of the undeclared + // properties is not free-form. For example, if the undeclared properties must + // be of type 'Animal', then: + // The wrapper type is map[string]Animal. + // The wrapped type is 'map[string]Animal'. + } + } else if (property.isNullable && !property.isContainer) { + // Primitive types. + hasWrapper = true; + } + if (hasWrapper) { property.vendorExtensions.put("x-golang-has-wrapper", true); } } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoClientExperimentalCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoClientExperimentalCodegen.java index 2fc84f25dfd8..69e013eb74a2 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoClientExperimentalCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoClientExperimentalCodegen.java @@ -177,17 +177,37 @@ public Map postProcessModels(Map objs) { } for (CodegenProperty param : model.vars) { + // Two golang types are used in the generated code: the type of the + // struct fields and the types of the getter and setter methods. + // The struct fields may use a wrapper type (such as 'NullableBool'), + // whereas the getter method returns the unwrapped type (e.g. 'bool'). + // param.dataType is the golang type of the generated struct field. + // "x-go-base-type" is the type in the setter and getter functions. + param.vendorExtensions.put("x-go-base-type", param.dataType); + if (!param.vendorExtensions.containsKey("x-golang-has-wrapper")) { + continue; + } if (param.isAnyType) { param.vendorExtensions.put("x-go-base-type", "interface{}"); continue; } else if (param.isFreeFormObject) { - param.vendorExtensions.put("x-go-base-type", "map[string]interface{}"); - continue; + switch (param.dataType) { + case "ObjectType": + param.vendorExtensions.put("x-go-base-type", "map[string]interface{}"); + continue; + case "[]ObjectType": + param.vendorExtensions.put("x-go-base-type", "map[string][]interface{}"); + continue; + case "map[string]ObjectType": + param.vendorExtensions.put("x-go-base-type", "map[string]map[string]interface{}"); + continue; + } } - param.vendorExtensions.put("x-go-base-type", param.dataType); + /* if (!param.isNullable || param.isMapContainer || param.isListContainer) { continue; } + */ if (param.isDateTime) { // Note this could have been done by adding the following line in processOpts(), // however, we only want to represent the DateTime object as NullableTime if diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/NullableClass.md b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/NullableClass.md index 24f221592b06..e81e45f2d40a 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/NullableClass.md +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/NullableClass.md @@ -343,20 +343,20 @@ HasArrayItemsNullable returns a boolean if a field has been set. ### GetObjectNullableProp -`func (o *NullableClass) GetObjectNullableProp() map[string]interface{}` +`func (o *NullableClass) GetObjectNullableProp() map[string]ObjectType` GetObjectNullableProp returns the ObjectNullableProp field if non-nil, zero value otherwise. ### GetObjectNullablePropOk -`func (o *NullableClass) GetObjectNullablePropOk() (*map[string]interface{}, bool)` +`func (o *NullableClass) GetObjectNullablePropOk() (*map[string]ObjectType, bool)` GetObjectNullablePropOk returns a tuple with the ObjectNullableProp field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetObjectNullableProp -`func (o *NullableClass) SetObjectNullableProp(v map[string]interface{})` +`func (o *NullableClass) SetObjectNullableProp(v map[string]ObjectType)` SetObjectNullableProp sets ObjectNullableProp field to given value. @@ -378,20 +378,20 @@ HasObjectNullableProp returns a boolean if a field has been set. UnsetObjectNullableProp ensures that no value is present for ObjectNullableProp, not even an explicit nil ### GetObjectAndItemsNullableProp -`func (o *NullableClass) GetObjectAndItemsNullableProp() map[string]interface{}` +`func (o *NullableClass) GetObjectAndItemsNullableProp() map[string]ObjectType` GetObjectAndItemsNullableProp returns the ObjectAndItemsNullableProp field if non-nil, zero value otherwise. ### GetObjectAndItemsNullablePropOk -`func (o *NullableClass) GetObjectAndItemsNullablePropOk() (*map[string]interface{}, bool)` +`func (o *NullableClass) GetObjectAndItemsNullablePropOk() (*map[string]ObjectType, bool)` GetObjectAndItemsNullablePropOk returns a tuple with the ObjectAndItemsNullableProp field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetObjectAndItemsNullableProp -`func (o *NullableClass) SetObjectAndItemsNullableProp(v map[string]interface{})` +`func (o *NullableClass) SetObjectAndItemsNullableProp(v map[string]ObjectType)` SetObjectAndItemsNullableProp sets ObjectAndItemsNullableProp field to given value. @@ -413,20 +413,20 @@ HasObjectAndItemsNullableProp returns a boolean if a field has been set. UnsetObjectAndItemsNullableProp ensures that no value is present for ObjectAndItemsNullableProp, not even an explicit nil ### GetObjectItemsNullable -`func (o *NullableClass) GetObjectItemsNullable() map[string]interface{}` +`func (o *NullableClass) GetObjectItemsNullable() map[string]ObjectType` GetObjectItemsNullable returns the ObjectItemsNullable field if non-nil, zero value otherwise. ### GetObjectItemsNullableOk -`func (o *NullableClass) GetObjectItemsNullableOk() (*map[string]interface{}, bool)` +`func (o *NullableClass) GetObjectItemsNullableOk() (*map[string]ObjectType, bool)` GetObjectItemsNullableOk returns a tuple with the ObjectItemsNullable field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetObjectItemsNullable -`func (o *NullableClass) SetObjectItemsNullable(v map[string]interface{})` +`func (o *NullableClass) SetObjectItemsNullable(v map[string]ObjectType)` SetObjectItemsNullable sets ObjectItemsNullable field to given value. diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/go.mod b/samples/openapi3/client/petstore/go-experimental/go-petstore/go.mod index f9811556cc5a..89d18393f73e 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/go.mod +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/go.mod @@ -2,6 +2,4 @@ module github.com/GIT_USER_ID/GIT_REPO_ID go 1.13 -require ( - golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 -) +require golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_nullable_class.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_nullable_class.go index b6b1d947a122..a465419c12d8 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_nullable_class.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_nullable_class.go @@ -398,9 +398,9 @@ func (o *NullableClass) SetArrayItemsNullable(v []ObjectType) { } // GetObjectNullableProp returns the ObjectNullableProp field value if set, zero value otherwise (both if not set or set to explicit null). -func (o *NullableClass) GetObjectNullableProp() map[string]interface{} { +func (o *NullableClass) GetObjectNullableProp() map[string]ObjectType { if o == nil { - var ret map[string]interface{} + var ret map[string]ObjectType return ret } return o.ObjectNullableProp @@ -409,7 +409,7 @@ func (o *NullableClass) GetObjectNullableProp() map[string]interface{} { // GetObjectNullablePropOk returns a tuple with the ObjectNullableProp field value if set, nil otherwise // and a boolean to check if the value has been set. // NOTE: If the value is an explicit nil, `nil, true` will be returned -func (o *NullableClass) GetObjectNullablePropOk() (*map[string]interface{}, bool) { +func (o *NullableClass) GetObjectNullablePropOk() (*map[string]ObjectType, bool) { if o == nil || o.ObjectNullableProp == nil { return nil, false } @@ -426,14 +426,14 @@ func (o *NullableClass) HasObjectNullableProp() bool { } // SetObjectNullableProp gets a reference to the given map[string]ObjectType and assigns it to the ObjectNullableProp field. -func (o *NullableClass) SetObjectNullableProp(v map[string]interface{}) { +func (o *NullableClass) SetObjectNullableProp(v map[string]ObjectType) { o.ObjectNullableProp = v } // GetObjectAndItemsNullableProp returns the ObjectAndItemsNullableProp field value if set, zero value otherwise (both if not set or set to explicit null). -func (o *NullableClass) GetObjectAndItemsNullableProp() map[string]interface{} { +func (o *NullableClass) GetObjectAndItemsNullableProp() map[string]ObjectType { if o == nil { - var ret map[string]interface{} + var ret map[string]ObjectType return ret } return o.ObjectAndItemsNullableProp @@ -442,7 +442,7 @@ func (o *NullableClass) GetObjectAndItemsNullableProp() map[string]interface{} { // GetObjectAndItemsNullablePropOk returns a tuple with the ObjectAndItemsNullableProp field value if set, nil otherwise // and a boolean to check if the value has been set. // NOTE: If the value is an explicit nil, `nil, true` will be returned -func (o *NullableClass) GetObjectAndItemsNullablePropOk() (*map[string]interface{}, bool) { +func (o *NullableClass) GetObjectAndItemsNullablePropOk() (*map[string]ObjectType, bool) { if o == nil || o.ObjectAndItemsNullableProp == nil { return nil, false } @@ -459,26 +459,26 @@ func (o *NullableClass) HasObjectAndItemsNullableProp() bool { } // SetObjectAndItemsNullableProp gets a reference to the given map[string]ObjectType and assigns it to the ObjectAndItemsNullableProp field. -func (o *NullableClass) SetObjectAndItemsNullableProp(v map[string]interface{}) { +func (o *NullableClass) SetObjectAndItemsNullableProp(v map[string]ObjectType) { o.ObjectAndItemsNullableProp = v } // GetObjectItemsNullable returns the ObjectItemsNullable field value if set, zero value otherwise. -func (o *NullableClass) GetObjectItemsNullable() map[string]interface{} { +func (o *NullableClass) GetObjectItemsNullable() map[string]ObjectType { if o == nil || o.ObjectItemsNullable == nil { - var ret map[string]interface{} + var ret map[string]ObjectType return ret } - return *o.ObjectItemsNullable.Get() + return *o.ObjectItemsNullable } // GetObjectItemsNullableOk returns a tuple with the ObjectItemsNullable field value if set, nil otherwise // and a boolean to check if the value has been set. -func (o *NullableClass) GetObjectItemsNullableOk() (*map[string]interface{}, bool) { +func (o *NullableClass) GetObjectItemsNullableOk() (*map[string]ObjectType, bool) { if o == nil || o.ObjectItemsNullable == nil { return nil, false } - return o.ObjectItemsNullable.Get(), true + return o.ObjectItemsNullable, true } // HasObjectItemsNullable returns a boolean if a field has been set. @@ -491,8 +491,8 @@ func (o *NullableClass) HasObjectItemsNullable() bool { } // SetObjectItemsNullable gets a reference to the given map[string]ObjectType and assigns it to the ObjectItemsNullable field. -func (o *NullableClass) SetObjectItemsNullable(v map[string]interface{}) { - o.ObjectItemsNullable.Set(&v) +func (o *NullableClass) SetObjectItemsNullable(v map[string]ObjectType) { + o.ObjectItemsNullable = &v } func (o NullableClass) MarshalJSON() ([]byte, error) { From 90c0c9ed7a47eee28f05bc079c600bcee7e03af5 Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Thu, 7 May 2020 12:23:56 -0700 Subject: [PATCH 35/48] Move golang changes to a separate branch --- .../codegen/languages/AbstractGoCodegen.java | 74 +++---------------- .../GoClientExperimentalCodegen.java | 30 +------- 2 files changed, 14 insertions(+), 90 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java index 38e6419238cd..bedd7ed652a8 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java @@ -92,8 +92,8 @@ public AbstractGoCodegen() { "complex128", "rune", "byte", - "ObjectType", - "AnyType" + "map[string]interface{}", + "interface{}" ) ); @@ -128,15 +128,9 @@ public AbstractGoCodegen() { // map[string]interface{}, whereas an arbitrary type is implemented // in golang as interface{}. // See issue #5387 for more details. - typeMapping.put("object", "ObjectType"); - // A schema that does not specify the 'type' attribute. The value - // can be anything. - typeMapping.put("AnyType", "AnyType"); - // Below is the entry to map the JSON 'null' type to golang. - // Note there is no built-in 'null' type in golang, and it's not possible - // to declare a variable whose only possible value is 'nil'. - // For example `a := nil` is not a valid go statement. - typeMapping.put("null", "NullType"); + typeMapping.put("object", "map[string]interface{}"); + typeMapping.put("interface{}", "interface{}"); + typeMapping.put("AnyType", "interface{}"); numberTypes = new HashSet( Arrays.asList( @@ -397,7 +391,7 @@ public String getSchemaType(Schema p) { type = openAPIType; } else if ("object".equals(openAPIType) && ModelUtils.isAnyTypeSchema(p)) { // Arbitrary type. Note this is not the same thing as free-form object. - type = "AnyType"; + type = "interface{}"; } else if (typeMapping.containsKey(openAPIType)) { type = typeMapping.get(openAPIType); if (languageSpecificPrimitives.contains(type)) @@ -604,58 +598,14 @@ private void setExportParameterName(List codegenParameters) { } } - /** - * OAS type mapping to golang implementation: - * - * AnyType interface{} Any type, e.g. null, string, integer, number, boolean, map, array. - * ObjectType map[string]interface{} Free-form object with no constraint on additional properties. - * map[string]Animal map[string]Animal Free-form object. The value of undeclared properties must be 'Animal'. - * map[string]ObjectType map[string]map[string]interface{} Free-form object. The value of undeclared properties must be an object (map). - * map[string][]interface{} Free-form object. The value of undeclared properties must be an array. - * - */ @Override public void postProcessModelProperty(CodegenModel model, CodegenProperty property) { - // The 'go-experimental/model.mustache' template generates accessor methods. - // For containers (e.g. Array, Map) and non-nullable primitive types, the go struct field - // is the underlying type, e.g. *int32, *string, *bool... - // In other cases (nullable primitive types, free-form objects...), the generated code has - // a wrapper type and a Get() function to access the underlying type. - boolean hasWrapper = false; - if (property.isAnyType) { - // The wrapper type is the 'AnyType' struct and the wrapped type is 'interface{}'. - hasWrapper = true; - } else if (property.isFreeFormObject && !property.isNullable) { // && - // Undeclared properties use case. - // The undeclared properties are implemented using a go map. - // The map key is always a string. - // The map value is interface{} when there are no constraints, but the - // 'additionalProperties' attribute may require a specific type. - if (property.items == null) { - // The 'additionalProperties' attribute is not set, so it is a free-form object - // with no constraint on the type of undeclared properties. - // The wrapper type is 'ObjectType'. - // The wrapped type is 'map[string]interface{}'. - hasWrapper = true; - } else if (property.items.isFreeFormObject && !property.items.isNullable) { - // The 'additionalProperties' attribute is set, and the value of the undeclared - // properties must be a free-form object. Hence it's a map of map. - // The wrapper type is map[string]ObjectType. - // The wrapped type is 'map[string]map[string]interface{}'. - hasWrapper = true; - } else { - // The 'additionalProperties' attribute is set, and the value of the undeclared - // properties is not free-form. For example, if the undeclared properties must - // be of type 'Animal', then: - // The wrapper type is map[string]Animal. - // The wrapped type is 'map[string]Animal'. - } - } else if (property.isNullable && !property.isContainer) { - // Primitive types. - hasWrapper = true; - } - if (hasWrapper) { - property.vendorExtensions.put("x-golang-has-wrapper", true); + // The 'go-experimental/model.mustache' template conditionally generates accessor methods. + // For primitive types and custom types (e.g. interface{}, map[string]interface{}...), + // the generated code has a wrapper type and a Get() function to access the underlying type. + // For containers (e.g. Array, Map), the generated code returns the type directly. + if (property.isContainer || property.isFreeFormObject || property.isAnyType) { + property.vendorExtensions.put("x-golang-is-container", true); } } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoClientExperimentalCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoClientExperimentalCodegen.java index 69e013eb74a2..0bea07e4dba7 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoClientExperimentalCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoClientExperimentalCodegen.java @@ -177,37 +177,11 @@ public Map postProcessModels(Map objs) { } for (CodegenProperty param : model.vars) { - // Two golang types are used in the generated code: the type of the - // struct fields and the types of the getter and setter methods. - // The struct fields may use a wrapper type (such as 'NullableBool'), - // whereas the getter method returns the unwrapped type (e.g. 'bool'). - // param.dataType is the golang type of the generated struct field. - // "x-go-base-type" is the type in the setter and getter functions. param.vendorExtensions.put("x-go-base-type", param.dataType); - if (!param.vendorExtensions.containsKey("x-golang-has-wrapper")) { + if (!param.isNullable || param.isMapContainer || param.isListContainer || + param.isFreeFormObject || param.isAnyType) { continue; } - if (param.isAnyType) { - param.vendorExtensions.put("x-go-base-type", "interface{}"); - continue; - } else if (param.isFreeFormObject) { - switch (param.dataType) { - case "ObjectType": - param.vendorExtensions.put("x-go-base-type", "map[string]interface{}"); - continue; - case "[]ObjectType": - param.vendorExtensions.put("x-go-base-type", "map[string][]interface{}"); - continue; - case "map[string]ObjectType": - param.vendorExtensions.put("x-go-base-type", "map[string]map[string]interface{}"); - continue; - } - } - /* - if (!param.isNullable || param.isMapContainer || param.isListContainer) { - continue; - } - */ if (param.isDateTime) { // Note this could have been done by adding the following line in processOpts(), // however, we only want to represent the DateTime object as NullableTime if From f56c812a50a51bd14890a8e9ded1ada615548af0 Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Thu, 7 May 2020 12:27:08 -0700 Subject: [PATCH 36/48] Move golang changes to a separate branch --- .../resources/go-experimental/model.mustache | 104 ++++++---------- .../resources/go-experimental/utils.mustache | 117 ------------------ 2 files changed, 39 insertions(+), 182 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/go-experimental/model.mustache b/modules/openapi-generator/src/main/resources/go-experimental/model.mustache index 76cbb8ef562c..91a0d12b3149 100644 --- a/modules/openapi-generator/src/main/resources/go-experimental/model.mustache +++ b/modules/openapi-generator/src/main/resources/go-experimental/model.mustache @@ -69,16 +69,16 @@ func New{{classname}}({{#vars}}{{#required}}{{nameInCamelCase}} {{dataType}}, {{ {{/required}} {{^required}} {{#defaultValue}} +{{^vendorExtensions.x-golang-is-container}} {{#isNullable}} -{{#vendorExtensions.x-golang-has-wrapper}} var {{nameInCamelCase}} {{{datatypeWithEnum}}} = {{{.}}} this.{{name}} = *New{{{dataType}}}(&{{nameInCamelCase}}) -{{/vendorExtensions.x-golang-has-wrapper}} {{/isNullable}} {{^isNullable}} var {{nameInCamelCase}} {{{dataType}}} = {{{.}}} this.{{name}} = &{{nameInCamelCase}} {{/isNullable}} +{{/vendorExtensions.x-golang-is-container}} {{/defaultValue}} {{/required}} {{/vars}} @@ -92,17 +92,17 @@ func New{{classname}}WithDefaults() *{{classname}} { this := {{classname}}{} {{#vars}} {{#defaultValue}} +{{^vendorExtensions.x-golang-is-container}} {{#isNullable}} -{{#vendorExtensions.x-golang-has-wrapper}} {{!we use datatypeWithEnum here, since it will represent the non-nullable name of the datatype, e.g. int64 for NullableInt64}} var {{nameInCamelCase}} {{{datatypeWithEnum}}} = {{{.}}} this.{{name}} = *New{{{dataType}}}(&{{nameInCamelCase}}) -{{/vendorExtensions.x-golang-has-wrapper}} {{/isNullable}} {{^isNullable}} var {{nameInCamelCase}} {{{dataType}}} = {{{.}}} this.{{name}} = {{^required}}&{{/required}}{{nameInCamelCase}} {{/isNullable}} +{{/vendorExtensions.x-golang-is-container}} {{/defaultValue}} {{/vars}} return &this @@ -115,26 +115,21 @@ func New{{classname}}WithDefaults() *{{classname}} { // If the value is explicit nil, the zero value for {{vendorExtensions.x-go-base-type}} will be returned {{/isNullable}} func (o *{{classname}}) Get{{name}}() {{vendorExtensions.x-go-base-type}} { - if o == nil {{#isNullable}}{{#vendorExtensions.x-golang-has-wrapper}}|| o.{{name}}.Get() == nil{{/vendorExtensions.x-golang-has-wrapper}}{{/isNullable}} { + if o == nil {{#isNullable}}{{^vendorExtensions.x-golang-is-container}}|| o.{{name}}.Get() == nil{{/vendorExtensions.x-golang-is-container}}{{/isNullable}} { var ret {{vendorExtensions.x-go-base-type}} return ret } {{#isNullable}} -{{^vendorExtensions.x-golang-has-wrapper}} +{{#vendorExtensions.x-golang-is-container}} return o.{{name}} -{{/vendorExtensions.x-golang-has-wrapper}} -{{#vendorExtensions.x-golang-has-wrapper}} +{{/vendorExtensions.x-golang-is-container}} +{{^vendorExtensions.x-golang-is-container}} return *o.{{name}}.Get() -{{/vendorExtensions.x-golang-has-wrapper}} +{{/vendorExtensions.x-golang-is-container}} {{/isNullable}} {{^isNullable}} -{{#vendorExtensions.x-golang-has-wrapper}} - return o.{{name}}.Get() -{{/vendorExtensions.x-golang-has-wrapper}} -{{^vendorExtensions.x-golang-has-wrapper}} return o.{{name}} -{{/vendorExtensions.x-golang-has-wrapper}} {{/isNullable}} } @@ -144,36 +139,31 @@ func (o *{{classname}}) Get{{name}}() {{vendorExtensions.x-go-base-type}} { // NOTE: If the value is an explicit nil, `nil, true` will be returned {{/isNullable}} func (o *{{classname}}) Get{{name}}Ok() (*{{vendorExtensions.x-go-base-type}}, bool) { - if o == nil {{#isNullable}}{{^vendorExtensions.x-golang-has-wrapper}}|| o.{{name}} == nil{{/vendorExtensions.x-golang-has-wrapper}}{{/isNullable}} { + if o == nil {{#isNullable}}{{#vendorExtensions.x-golang-is-container}}|| o.{{name}} == nil{{/vendorExtensions.x-golang-is-container}}{{/isNullable}} { return nil, false } {{#isNullable}} -{{^vendorExtensions.x-golang-has-wrapper}} +{{#vendorExtensions.x-golang-is-container}} return &o.{{name}}, true -{{/vendorExtensions.x-golang-has-wrapper}} -{{#vendorExtensions.x-golang-has-wrapper}} +{{/vendorExtensions.x-golang-is-container}} +{{^vendorExtensions.x-golang-is-container}} return o.{{name}}.Get(), o.{{name}}.IsSet() -{{/vendorExtensions.x-golang-has-wrapper}} +{{/vendorExtensions.x-golang-is-container}} {{/isNullable}} {{^isNullable}} -{{#vendorExtensions.x-golang-has-wrapper}} - return &o.{{name}}.Get(), true -{{/vendorExtensions.x-golang-has-wrapper}} -{{^vendorExtensions.x-golang-has-wrapper}} return &o.{{name}}, true -{{/vendorExtensions.x-golang-has-wrapper}} {{/isNullable}} } // Set{{name}} sets field value func (o *{{classname}}) Set{{name}}(v {{vendorExtensions.x-go-base-type}}) { {{#isNullable}} -{{^vendorExtensions.x-golang-has-wrapper}} +{{#vendorExtensions.x-golang-is-container}} o.{{name}} = v -{{/vendorExtensions.x-golang-has-wrapper}} -{{#vendorExtensions.x-golang-has-wrapper}} +{{/vendorExtensions.x-golang-is-container}} +{{^vendorExtensions.x-golang-is-container}} o.{{name}}.Set(&v) -{{/vendorExtensions.x-golang-has-wrapper}} +{{/vendorExtensions.x-golang-is-container}} {{/isNullable}} {{^isNullable}} o.{{name}} = v @@ -184,25 +174,20 @@ func (o *{{classname}}) Set{{name}}(v {{vendorExtensions.x-go-base-type}}) { {{^required}} // Get{{name}} returns the {{name}} field value if set, zero value otherwise{{#isNullable}} (both if not set or set to explicit null){{/isNullable}}. func (o *{{classname}}) Get{{name}}() {{vendorExtensions.x-go-base-type}} { - if o == nil {{^isNullable}}|| o.{{name}} == nil{{/isNullable}}{{#isNullable}}{{#vendorExtensions.x-golang-has-wrapper}}|| o.{{name}}.Get() == nil{{/vendorExtensions.x-golang-has-wrapper}}{{/isNullable}} { + if o == nil {{^isNullable}}|| o.{{name}} == nil{{/isNullable}}{{#isNullable}}{{^vendorExtensions.x-golang-is-container}}|| o.{{name}}.Get() == nil{{/vendorExtensions.x-golang-is-container}}{{/isNullable}} { var ret {{vendorExtensions.x-go-base-type}} return ret } {{#isNullable}} -{{^vendorExtensions.x-golang-has-wrapper}} +{{#vendorExtensions.x-golang-is-container}} return o.{{name}} -{{/vendorExtensions.x-golang-has-wrapper}} -{{#vendorExtensions.x-golang-has-wrapper}} +{{/vendorExtensions.x-golang-is-container}} +{{^vendorExtensions.x-golang-is-container}} return *o.{{name}}.Get() -{{/vendorExtensions.x-golang-has-wrapper}} +{{/vendorExtensions.x-golang-is-container}} {{/isNullable}} {{^isNullable}} -{{#vendorExtensions.x-golang-has-wrapper}} - return *o.{{name}}.Get() -{{/vendorExtensions.x-golang-has-wrapper}} -{{^vendorExtensions.x-golang-has-wrapper}} return *o.{{name}} -{{/vendorExtensions.x-golang-has-wrapper}} {{/isNullable}} } @@ -212,30 +197,25 @@ func (o *{{classname}}) Get{{name}}() {{vendorExtensions.x-go-base-type}} { // NOTE: If the value is an explicit nil, `nil, true` will be returned {{/isNullable}} func (o *{{classname}}) Get{{name}}Ok() (*{{vendorExtensions.x-go-base-type}}, bool) { - if o == nil {{^isNullable}}|| o.{{name}} == nil{{/isNullable}}{{#isNullable}}{{^vendorExtensions.x-golang-has-wrapper}}|| o.{{name}} == nil{{/vendorExtensions.x-golang-has-wrapper}}{{/isNullable}} { + if o == nil {{^isNullable}}|| o.{{name}} == nil{{/isNullable}}{{#isNullable}}{{#vendorExtensions.x-golang-is-container}}|| o.{{name}} == nil{{/vendorExtensions.x-golang-is-container}}{{/isNullable}} { return nil, false } {{#isNullable}} -{{^vendorExtensions.x-golang-has-wrapper}} +{{#vendorExtensions.x-golang-is-container}} return &o.{{name}}, true -{{/vendorExtensions.x-golang-has-wrapper}} -{{#vendorExtensions.x-golang-has-wrapper}} +{{/vendorExtensions.x-golang-is-container}} +{{^vendorExtensions.x-golang-is-container}} return o.{{name}}.Get(), o.{{name}}.IsSet() -{{/vendorExtensions.x-golang-has-wrapper}} +{{/vendorExtensions.x-golang-is-container}} {{/isNullable}} {{^isNullable}} -{{#vendorExtensions.x-golang-has-wrapper}} - return o.{{name}}.Get(), true -{{/vendorExtensions.x-golang-has-wrapper}} -{{^vendorExtensions.x-golang-has-wrapper}} return o.{{name}}, true -{{/vendorExtensions.x-golang-has-wrapper}} {{/isNullable}} } // Has{{name}} returns a boolean if a field has been set. func (o *{{classname}}) Has{{name}}() bool { - if o != nil && {{^isNullable}}o.{{name}} != nil{{/isNullable}}{{#isNullable}}{{^vendorExtensions.x-golang-has-wrapper}}o.{{name}} != nil{{/vendorExtensions.x-golang-has-wrapper}}{{#vendorExtensions.x-golang-has-wrapper}}o.{{name}}.IsSet(){{/vendorExtensions.x-golang-has-wrapper}}{{/isNullable}} { + if o != nil && {{^isNullable}}o.{{name}} != nil{{/isNullable}}{{#isNullable}}{{#vendorExtensions.x-golang-is-container}}o.{{name}} != nil{{/vendorExtensions.x-golang-is-container}}{{^vendorExtensions.x-golang-is-container}}o.{{name}}.IsSet(){{/vendorExtensions.x-golang-is-container}}{{/isNullable}} { return true } @@ -245,24 +225,19 @@ func (o *{{classname}}) Has{{name}}() bool { // Set{{name}} gets a reference to the given {{dataType}} and assigns it to the {{name}} field. func (o *{{classname}}) Set{{name}}(v {{vendorExtensions.x-go-base-type}}) { {{#isNullable}} -{{^vendorExtensions.x-golang-has-wrapper}} +{{#vendorExtensions.x-golang-is-container}} o.{{name}} = v -{{/vendorExtensions.x-golang-has-wrapper}} -{{#vendorExtensions.x-golang-has-wrapper}} +{{/vendorExtensions.x-golang-is-container}} +{{^vendorExtensions.x-golang-is-container}} o.{{name}}.Set(&v) -{{/vendorExtensions.x-golang-has-wrapper}} +{{/vendorExtensions.x-golang-is-container}} {{/isNullable}} {{^isNullable}} -{{#vendorExtensions.x-golang-has-wrapper}} - o.{{name}}.Set(&v) -{{/vendorExtensions.x-golang-has-wrapper}} -{{^vendorExtensions.x-golang-has-wrapper}} o.{{name}} = &v -{{/vendorExtensions.x-golang-has-wrapper}} {{/isNullable}} } {{#isNullable}} -{{#vendorExtensions.x-golang-has-wrapper}} +{{^vendorExtensions.x-golang-is-container}} // Set{{name}}Nil sets the value for {{name}} to be an explicit nil func (o *{{classname}}) Set{{name}}Nil() { o.{{name}}.Set(nil) @@ -272,7 +247,7 @@ func (o *{{classname}}) Set{{name}}Nil() { func (o *{{classname}}) Unset{{name}}() { o.{{name}}.Unset() } -{{/vendorExtensions.x-golang-has-wrapper}} +{{/vendorExtensions.x-golang-is-container}} {{/isNullable}} {{/required}} @@ -294,17 +269,17 @@ func (o {{classname}}) MarshalJSON() ([]byte, error) { {{#vars}} {{! if argument is nullable, only serialize it if it is set}} {{#isNullable}} - {{^vendorExtensions.x-golang-has-wrapper}} + {{#vendorExtensions.x-golang-is-container}} {{! support for container fields is not ideal at this point because of lack of Nullable* types}} if o.{{name}} != nil { toSerialize["{{baseName}}"] = o.{{name}} } - {{/vendorExtensions.x-golang-has-wrapper}} - {{#vendorExtensions.x-golang-has-wrapper}} + {{/vendorExtensions.x-golang-is-container}} + {{^vendorExtensions.x-golang-is-container}} if {{#required}}true{{/required}}{{^required}}o.{{name}}.IsSet(){{/required}} { toSerialize["{{baseName}}"] = o.{{name}}.Get() } - {{/vendorExtensions.x-golang-has-wrapper}} + {{/vendorExtensions.x-golang-is-container}} {{/isNullable}} {{! if argument is not nullable, don't set it if it is nil}} {{^isNullable}} @@ -351,7 +326,6 @@ func (s *{{classname}}) UnmarshalJSON(src []byte) error { {{/discriminator}} {{^discriminator}} {{#oneOf}} - {{! TODO: validate the payload against the JSON schema. Relying on golang JSON unmarshaling is not sufficient to determine the payload validates against the schema}} var unmarshaled{{{.}}} *{{{.}}} = &{{{.}}}{} err = json.Unmarshal(src, unmarshaled{{{.}}}) if err == nil { diff --git a/modules/openapi-generator/src/main/resources/go-experimental/utils.mustache b/modules/openapi-generator/src/main/resources/go-experimental/utils.mustache index a2b033a80046..89e00e0267be 100644 --- a/modules/openapi-generator/src/main/resources/go-experimental/utils.mustache +++ b/modules/openapi-generator/src/main/resources/go-experimental/utils.mustache @@ -2,9 +2,7 @@ package {{packageName}} import ( - "bytes" "encoding/json" - "errors" "time" ) @@ -32,121 +30,6 @@ func PtrString(v string) *string { return &v } // PtrTime is helper routine that returns a pointer to given Time value. func PtrTime(v time.Time) *time.Time { return &v } -var nullLiteral []byte = []byte("null") - -// NullType is a type whose only value can be the JSON 'null' value. -type NullType struct{ - isSet bool -} - -func NewNullType() *NullType { - return nil -} - -func (v NullType) Get() interface{} { - return nil -} - -func (v *NullType) Set() { - v.isSet = true -} - -func (v NullType) IsSet() bool { - return v.isSet -} - -func (v *NullType) Unset() { - v.isSet = false -} - -func (v NullType) MarshalJSON() ([]byte, error) { - return nullLiteral, nil -} - -func (v *NullType) UnmarshalJSON(src []byte) error { - if bytes.Equal(bytes.TrimSpace(nullLiteral), src) { - v.isSet = true - return nil - } - return errors.New("Cannot unmarshal value into 'null' type") -} - -// AnyType is a type whose value can any valid OpenAPI type. -// The value may be the null value, a string, integer, number, boolean, array -// or object. -type AnyType struct{ - value *interface{} - isSet bool -} - -func NewAnyType(val *interface{}) *AnyType { - return &AnyType{value: val, isSet: true} -} - -func (v AnyType) Get() *interface{} { - return v.value -} - -func (v *AnyType) Set(val *interface{}) { - v.value = val - v.isSet = true -} - -func (v AnyType) IsSet() bool { - return v.isSet -} - -func (v *AnyType) Unset() { - v.isSet = false -} - -func (v AnyType) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *AnyType) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -// ObjectType is a type whose value can be any OpenAPI object with undeclared properties. -type ObjectType struct{ - value *map[string]interface{} - isSet bool -} - -// NewObjectType creates and returns an object with the specified map -// of undeclared properties. -func NewObjectType(val *map[string]interface{}) *ObjectType { - return &ObjectType{value: val, isSet: true} -} - -func (v ObjectType) Get() *map[string]interface{} { - return v.value -} - -func (v *ObjectType) Set(val *map[string]interface{}) { - v.value = val - v.isSet = true -} - -func (v ObjectType) IsSet() bool { - return v.isSet -} - -func (v *ObjectType) Unset() { - v.isSet = false -} - -func (v ObjectType) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *ObjectType) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - type NullableBool struct { value *bool isSet bool From b159356fb73060a0dcef2336a05020dfb165599e Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Thu, 7 May 2020 12:34:36 -0700 Subject: [PATCH 37/48] Better names for the OAS document test properties --- ...odels-for-testing-with-http-signature.yaml | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml b/modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml index 784e47d60b2d..036f78b0a744 100644 --- a/modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml @@ -1250,22 +1250,32 @@ components: type: integer format: int32 description: User Status - arbitraryObject: + objectWithNoDeclaredProps: type: object description: test code generation for objects Value must be a map of strings to values. It cannot be the 'null' value. - arbitraryNullableObject: + objectWithNoDeclaredPropsNullable: type: object description: test code generation for nullable objects. Value must be a map of strings to values or the 'null' value. nullable: true - arbitraryTypeValue: + anyTypeProp: description: test code generation for any type - Value can be any type - string, number, boolean, array or object. - arbitraryNullableTypeValue: + Here the 'type' attribute is not specified, which means the value can be anything, + including the null value, string, number, boolean, array or object. + See https://github.com/OAI/OpenAPI-Specification/issues/1389 + # TODO: this should be supported, currently there are some issues in the code generation. + #anyTypeExceptNullProp: + # description: any type except 'null' + # Here the 'type' attribute is not specified, which means the value can be anything, + # including the null value, string, number, boolean, array or object. + # not: + # type: 'null' + anyTypePropNullable: description: test code generation for any type - Value can be any type - string, number, boolean, array, object or - the 'null' value. + Here the 'type' attribute is not specified, which means the value can be anything, + including the null value, string, number, boolean, array or object. + The 'nullable' attribute does not change the allowed values. nullable: true xml: name: User From ef5149ef2b19c5dff503bafdc7bf81cc73450a47 Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Thu, 7 May 2020 12:35:53 -0700 Subject: [PATCH 38/48] Move golang changes to a separate branch --- ...odels-for-testing-with-http-signature.yaml | 25 ++++++------------- 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml b/modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml index 3e779d042413..74598c6ce709 100644 --- a/modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml @@ -1250,32 +1250,22 @@ components: type: integer format: int32 description: User Status - objectWithNoDeclaredProps: + arbitraryObject: type: object description: test code generation for objects Value must be a map of strings to values. It cannot be the 'null' value. - objectWithNoDeclaredPropsNullable: + arbitraryNullableObject: type: object description: test code generation for nullable objects. Value must be a map of strings to values or the 'null' value. nullable: true - anyTypeProp: + arbitraryTypeValue: description: test code generation for any type - Here the 'type' attribute is not specified, which means the value can be anything, - including the null value, string, number, boolean, array or object. - See https://github.com/OAI/OpenAPI-Specification/issues/1389 - # TODO: this should be supported, currently there are some issues in the code generation. - #anyTypeExceptNullProp: - # description: any type except 'null' - # Here the 'type' attribute is not specified, which means the value can be anything, - # including the null value, string, number, boolean, array or object. - # not: - # type: 'null' - anyTypePropNullable: + Value can be any type - string, number, boolean, array or object. + arbitraryNullableTypeValue: description: test code generation for any type - Here the 'type' attribute is not specified, which means the value can be anything, - including the null value, string, number, boolean, array or object. - The 'nullable' attribute does not change the allowed values. + Value can be any type - string, number, boolean, array, object or + the 'null' value. nullable: true xml: name: User @@ -1865,7 +1855,6 @@ components: - $ref: '#/components/schemas/banana' fruitReq: oneOf: - - type: 'null' - $ref: '#/components/schemas/appleReq' - $ref: '#/components/schemas/bananaReq' appleReq: From 84162bea7c8e7c0ab7e6e5d6e74aefb8859ede98 Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Thu, 7 May 2020 12:39:21 -0700 Subject: [PATCH 39/48] Run samples scripts --- .../docs/AdditionalPropertiesClass.md | 22 +-- .../model_additional_properties_class.go | 54 +++--- .../go-experimental/go-petstore/utils.go | 117 ------------ .../go-petstore/api/openapi.yaml | 28 ++- .../go-petstore/docs/FakeApi.md | 2 +- .../go-petstore/docs/NullableClass.md | 48 ++--- .../go-experimental/go-petstore/docs/User.md | 140 +++++++-------- .../go-petstore/docs/UserApi.md | 4 +- .../go-experimental/go-petstore/go.mod | 4 +- .../go-petstore/model_fruit_req.go | 6 - .../go-petstore/model_nullable_class.go | 72 ++++---- .../go-experimental/go-petstore/model_user.go | 167 ++++++++---------- .../go-experimental/go-petstore/utils.go | 117 ------------ 13 files changed, 256 insertions(+), 525 deletions(-) diff --git a/samples/client/petstore/go-experimental/go-petstore/docs/AdditionalPropertiesClass.md b/samples/client/petstore/go-experimental/go-petstore/docs/AdditionalPropertiesClass.md index a8d460c4abae..2f6d0c688fc9 100644 --- a/samples/client/petstore/go-experimental/go-petstore/docs/AdditionalPropertiesClass.md +++ b/samples/client/petstore/go-experimental/go-petstore/docs/AdditionalPropertiesClass.md @@ -9,12 +9,12 @@ Name | Type | Description | Notes **MapInteger** | Pointer to **map[string]int32** | | [optional] **MapBoolean** | Pointer to **map[string]bool** | | [optional] **MapArrayInteger** | Pointer to [**map[string][]int32**](array.md) | | [optional] -**MapArrayAnytype** | Pointer to [**map[string][]ObjectType**](array.md) | | [optional] +**MapArrayAnytype** | Pointer to [**map[string][]map[string]interface{}**](array.md) | | [optional] **MapMapString** | Pointer to [**map[string]map[string]string**](map.md) | | [optional] -**MapMapAnytype** | Pointer to [**map[string]map[string]ObjectType**](map.md) | | [optional] -**Anytype1** | Pointer to [**ObjectType**](.md) | | [optional] -**Anytype2** | Pointer to [**ObjectType**](.md) | | [optional] -**Anytype3** | Pointer to [**ObjectType**](.md) | | [optional] +**MapMapAnytype** | Pointer to [**map[string]map[string]map[string]interface{}**](map.md) | | [optional] +**Anytype1** | Pointer to [**map[string]interface{}**](.md) | | [optional] +**Anytype2** | Pointer to [**map[string]interface{}**](.md) | | [optional] +**Anytype3** | Pointer to [**map[string]interface{}**](.md) | | [optional] ## Methods @@ -162,20 +162,20 @@ HasMapArrayInteger returns a boolean if a field has been set. ### GetMapArrayAnytype -`func (o *AdditionalPropertiesClass) GetMapArrayAnytype() map[string][]ObjectType` +`func (o *AdditionalPropertiesClass) GetMapArrayAnytype() map[string][]map[string]interface{}` GetMapArrayAnytype returns the MapArrayAnytype field if non-nil, zero value otherwise. ### GetMapArrayAnytypeOk -`func (o *AdditionalPropertiesClass) GetMapArrayAnytypeOk() (*map[string][]ObjectType, bool)` +`func (o *AdditionalPropertiesClass) GetMapArrayAnytypeOk() (*map[string][]map[string]interface{}, bool)` GetMapArrayAnytypeOk returns a tuple with the MapArrayAnytype field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetMapArrayAnytype -`func (o *AdditionalPropertiesClass) SetMapArrayAnytype(v map[string][]ObjectType)` +`func (o *AdditionalPropertiesClass) SetMapArrayAnytype(v map[string][]map[string]interface{})` SetMapArrayAnytype sets MapArrayAnytype field to given value. @@ -212,20 +212,20 @@ HasMapMapString returns a boolean if a field has been set. ### GetMapMapAnytype -`func (o *AdditionalPropertiesClass) GetMapMapAnytype() map[string]map[string]ObjectType` +`func (o *AdditionalPropertiesClass) GetMapMapAnytype() map[string]map[string]map[string]interface{}` GetMapMapAnytype returns the MapMapAnytype field if non-nil, zero value otherwise. ### GetMapMapAnytypeOk -`func (o *AdditionalPropertiesClass) GetMapMapAnytypeOk() (*map[string]map[string]ObjectType, bool)` +`func (o *AdditionalPropertiesClass) GetMapMapAnytypeOk() (*map[string]map[string]map[string]interface{}, bool)` GetMapMapAnytypeOk returns a tuple with the MapMapAnytype field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetMapMapAnytype -`func (o *AdditionalPropertiesClass) SetMapMapAnytype(v map[string]map[string]ObjectType)` +`func (o *AdditionalPropertiesClass) SetMapMapAnytype(v map[string]map[string]map[string]interface{})` SetMapMapAnytype sets MapMapAnytype field to given value. diff --git a/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_class.go b/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_class.go index eff3aa3e1780..9505c3e7e6d6 100644 --- a/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_class.go +++ b/samples/client/petstore/go-experimental/go-petstore/model_additional_properties_class.go @@ -20,12 +20,12 @@ type AdditionalPropertiesClass struct { MapInteger *map[string]int32 `json:"map_integer,omitempty"` MapBoolean *map[string]bool `json:"map_boolean,omitempty"` MapArrayInteger *map[string][]int32 `json:"map_array_integer,omitempty"` - MapArrayAnytype *map[string][]ObjectType `json:"map_array_anytype,omitempty"` + MapArrayAnytype *map[string][]map[string]interface{} `json:"map_array_anytype,omitempty"` MapMapString *map[string]map[string]string `json:"map_map_string,omitempty"` - MapMapAnytype *map[string]map[string]ObjectType `json:"map_map_anytype,omitempty"` - Anytype1 *ObjectType `json:"anytype_1,omitempty"` - Anytype2 *ObjectType `json:"anytype_2,omitempty"` - Anytype3 *ObjectType `json:"anytype_3,omitempty"` + MapMapAnytype *map[string]map[string]map[string]interface{} `json:"map_map_anytype,omitempty"` + Anytype1 *map[string]interface{} `json:"anytype_1,omitempty"` + Anytype2 *map[string]interface{} `json:"anytype_2,omitempty"` + Anytype3 *map[string]interface{} `json:"anytype_3,omitempty"` } // NewAdditionalPropertiesClass instantiates a new AdditionalPropertiesClass object @@ -206,9 +206,9 @@ func (o *AdditionalPropertiesClass) SetMapArrayInteger(v map[string][]int32) { } // GetMapArrayAnytype returns the MapArrayAnytype field value if set, zero value otherwise. -func (o *AdditionalPropertiesClass) GetMapArrayAnytype() map[string][]ObjectType { +func (o *AdditionalPropertiesClass) GetMapArrayAnytype() map[string][]map[string]interface{} { if o == nil || o.MapArrayAnytype == nil { - var ret map[string][]ObjectType + var ret map[string][]map[string]interface{} return ret } return *o.MapArrayAnytype @@ -216,7 +216,7 @@ func (o *AdditionalPropertiesClass) GetMapArrayAnytype() map[string][]ObjectType // GetMapArrayAnytypeOk returns a tuple with the MapArrayAnytype field value if set, nil otherwise // and a boolean to check if the value has been set. -func (o *AdditionalPropertiesClass) GetMapArrayAnytypeOk() (*map[string][]ObjectType, bool) { +func (o *AdditionalPropertiesClass) GetMapArrayAnytypeOk() (*map[string][]map[string]interface{}, bool) { if o == nil || o.MapArrayAnytype == nil { return nil, false } @@ -232,8 +232,8 @@ func (o *AdditionalPropertiesClass) HasMapArrayAnytype() bool { return false } -// SetMapArrayAnytype gets a reference to the given map[string][]ObjectType and assigns it to the MapArrayAnytype field. -func (o *AdditionalPropertiesClass) SetMapArrayAnytype(v map[string][]ObjectType) { +// SetMapArrayAnytype gets a reference to the given map[string][]map[string]interface{} and assigns it to the MapArrayAnytype field. +func (o *AdditionalPropertiesClass) SetMapArrayAnytype(v map[string][]map[string]interface{}) { o.MapArrayAnytype = &v } @@ -270,9 +270,9 @@ func (o *AdditionalPropertiesClass) SetMapMapString(v map[string]map[string]stri } // GetMapMapAnytype returns the MapMapAnytype field value if set, zero value otherwise. -func (o *AdditionalPropertiesClass) GetMapMapAnytype() map[string]map[string]ObjectType { +func (o *AdditionalPropertiesClass) GetMapMapAnytype() map[string]map[string]map[string]interface{} { if o == nil || o.MapMapAnytype == nil { - var ret map[string]map[string]ObjectType + var ret map[string]map[string]map[string]interface{} return ret } return *o.MapMapAnytype @@ -280,7 +280,7 @@ func (o *AdditionalPropertiesClass) GetMapMapAnytype() map[string]map[string]Obj // GetMapMapAnytypeOk returns a tuple with the MapMapAnytype field value if set, nil otherwise // and a boolean to check if the value has been set. -func (o *AdditionalPropertiesClass) GetMapMapAnytypeOk() (*map[string]map[string]ObjectType, bool) { +func (o *AdditionalPropertiesClass) GetMapMapAnytypeOk() (*map[string]map[string]map[string]interface{}, bool) { if o == nil || o.MapMapAnytype == nil { return nil, false } @@ -296,8 +296,8 @@ func (o *AdditionalPropertiesClass) HasMapMapAnytype() bool { return false } -// SetMapMapAnytype gets a reference to the given map[string]map[string]ObjectType and assigns it to the MapMapAnytype field. -func (o *AdditionalPropertiesClass) SetMapMapAnytype(v map[string]map[string]ObjectType) { +// SetMapMapAnytype gets a reference to the given map[string]map[string]map[string]interface{} and assigns it to the MapMapAnytype field. +func (o *AdditionalPropertiesClass) SetMapMapAnytype(v map[string]map[string]map[string]interface{}) { o.MapMapAnytype = &v } @@ -307,7 +307,7 @@ func (o *AdditionalPropertiesClass) GetAnytype1() map[string]interface{} { var ret map[string]interface{} return ret } - return *o.Anytype1.Get() + return *o.Anytype1 } // GetAnytype1Ok returns a tuple with the Anytype1 field value if set, nil otherwise @@ -316,7 +316,7 @@ func (o *AdditionalPropertiesClass) GetAnytype1Ok() (*map[string]interface{}, bo if o == nil || o.Anytype1 == nil { return nil, false } - return o.Anytype1.Get(), true + return o.Anytype1, true } // HasAnytype1 returns a boolean if a field has been set. @@ -328,9 +328,9 @@ func (o *AdditionalPropertiesClass) HasAnytype1() bool { return false } -// SetAnytype1 gets a reference to the given ObjectType and assigns it to the Anytype1 field. +// SetAnytype1 gets a reference to the given map[string]interface{} and assigns it to the Anytype1 field. func (o *AdditionalPropertiesClass) SetAnytype1(v map[string]interface{}) { - o.Anytype1.Set(&v) + o.Anytype1 = &v } // GetAnytype2 returns the Anytype2 field value if set, zero value otherwise. @@ -339,7 +339,7 @@ func (o *AdditionalPropertiesClass) GetAnytype2() map[string]interface{} { var ret map[string]interface{} return ret } - return *o.Anytype2.Get() + return *o.Anytype2 } // GetAnytype2Ok returns a tuple with the Anytype2 field value if set, nil otherwise @@ -348,7 +348,7 @@ func (o *AdditionalPropertiesClass) GetAnytype2Ok() (*map[string]interface{}, bo if o == nil || o.Anytype2 == nil { return nil, false } - return o.Anytype2.Get(), true + return o.Anytype2, true } // HasAnytype2 returns a boolean if a field has been set. @@ -360,9 +360,9 @@ func (o *AdditionalPropertiesClass) HasAnytype2() bool { return false } -// SetAnytype2 gets a reference to the given ObjectType and assigns it to the Anytype2 field. +// SetAnytype2 gets a reference to the given map[string]interface{} and assigns it to the Anytype2 field. func (o *AdditionalPropertiesClass) SetAnytype2(v map[string]interface{}) { - o.Anytype2.Set(&v) + o.Anytype2 = &v } // GetAnytype3 returns the Anytype3 field value if set, zero value otherwise. @@ -371,7 +371,7 @@ func (o *AdditionalPropertiesClass) GetAnytype3() map[string]interface{} { var ret map[string]interface{} return ret } - return *o.Anytype3.Get() + return *o.Anytype3 } // GetAnytype3Ok returns a tuple with the Anytype3 field value if set, nil otherwise @@ -380,7 +380,7 @@ func (o *AdditionalPropertiesClass) GetAnytype3Ok() (*map[string]interface{}, bo if o == nil || o.Anytype3 == nil { return nil, false } - return o.Anytype3.Get(), true + return o.Anytype3, true } // HasAnytype3 returns a boolean if a field has been set. @@ -392,9 +392,9 @@ func (o *AdditionalPropertiesClass) HasAnytype3() bool { return false } -// SetAnytype3 gets a reference to the given ObjectType and assigns it to the Anytype3 field. +// SetAnytype3 gets a reference to the given map[string]interface{} and assigns it to the Anytype3 field. func (o *AdditionalPropertiesClass) SetAnytype3(v map[string]interface{}) { - o.Anytype3.Set(&v) + o.Anytype3 = &v } func (o AdditionalPropertiesClass) MarshalJSON() ([]byte, error) { diff --git a/samples/client/petstore/go-experimental/go-petstore/utils.go b/samples/client/petstore/go-experimental/go-petstore/utils.go index 6c470ffcd2ad..9fb7a1847cd3 100644 --- a/samples/client/petstore/go-experimental/go-petstore/utils.go +++ b/samples/client/petstore/go-experimental/go-petstore/utils.go @@ -10,9 +10,7 @@ package petstore import ( - "bytes" "encoding/json" - "errors" "time" ) @@ -40,121 +38,6 @@ func PtrString(v string) *string { return &v } // PtrTime is helper routine that returns a pointer to given Time value. func PtrTime(v time.Time) *time.Time { return &v } -var nullLiteral []byte = []byte("null") - -// NullType is a type whose only value can be the JSON 'null' value. -type NullType struct{ - isSet bool -} - -func NewNullType() *NullType { - return nil -} - -func (v NullType) Get() interface{} { - return nil -} - -func (v *NullType) Set() { - v.isSet = true -} - -func (v NullType) IsSet() bool { - return v.isSet -} - -func (v *NullType) Unset() { - v.isSet = false -} - -func (v NullType) MarshalJSON() ([]byte, error) { - return nullLiteral, nil -} - -func (v *NullType) UnmarshalJSON(src []byte) error { - if bytes.Equal(bytes.TrimSpace(nullLiteral), src) { - v.isSet = true - return nil - } - return errors.New("Cannot unmarshal value into 'null' type") -} - -// AnyType is a type whose value can any valid OpenAPI type. -// The value may be the null value, a string, integer, number, boolean, array -// or object. -type AnyType struct{ - value *interface{} - isSet bool -} - -func NewAnyType(val *interface{}) *AnyType { - return &AnyType{value: val, isSet: true} -} - -func (v AnyType) Get() *interface{} { - return v.value -} - -func (v *AnyType) Set(val *interface{}) { - v.value = val - v.isSet = true -} - -func (v AnyType) IsSet() bool { - return v.isSet -} - -func (v *AnyType) Unset() { - v.isSet = false -} - -func (v AnyType) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *AnyType) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -// ObjectType is a type whose value can be any OpenAPI object with undeclared properties. -type ObjectType struct{ - value *map[string]interface{} - isSet bool -} - -// NewObjectType creates and returns an object with the specified map -// of undeclared properties. -func NewObjectType(val *map[string]interface{}) *ObjectType { - return &ObjectType{value: val, isSet: true} -} - -func (v ObjectType) Get() *map[string]interface{} { - return v.value -} - -func (v *ObjectType) Set(val *map[string]interface{}) { - v.value = val - v.isSet = true -} - -func (v ObjectType) IsSet() bool { - return v.isSet -} - -func (v *ObjectType) Unset() { - v.isSet = false -} - -func (v ObjectType) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *ObjectType) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - type NullableBool struct { value *bool isSet bool diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/api/openapi.yaml b/samples/openapi3/client/petstore/go-experimental/go-petstore/api/openapi.yaml index 9b3612e2dbf3..8f1a907787d2 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/api/openapi.yaml +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/api/openapi.yaml @@ -1299,13 +1299,13 @@ components: lastName: lastName password: password userStatus: 6 - objectWithNoDeclaredPropsNullable: '{}' + arbitraryTypeValue: "" + arbitraryNullableTypeValue: "" phone: phone - objectWithNoDeclaredProps: '{}' id: 0 - anyTypePropNullable: "" + arbitraryObject: '{}' email: email - anyTypeProp: "" + arbitraryNullableObject: '{}' username: username properties: id: @@ -1328,24 +1328,21 @@ components: description: User Status format: int32 type: integer - objectWithNoDeclaredProps: + arbitraryObject: description: test code generation for objects Value must be a map of strings to values. It cannot be the 'null' value. type: object - objectWithNoDeclaredPropsNullable: + arbitraryNullableObject: description: test code generation for nullable objects. Value must be a map of strings to values or the 'null' value. nullable: true type: object - anyTypeProp: - description: test code generation for any type Here the 'type' attribute - is not specified, which means the value can be anything, including the - null value, string, number, boolean, array or object. See https://github.com/OAI/OpenAPI-Specification/issues/1389 - anyTypePropNullable: - description: test code generation for any type Here the 'type' attribute - is not specified, which means the value can be anything, including the - null value, string, number, boolean, array or object. The 'nullable' attribute - does not change the allowed values. + arbitraryTypeValue: + description: test code generation for any type Value can be any type - string, + number, boolean, array or object. + arbitraryNullableTypeValue: + description: test code generation for any type Value can be any type - string, + number, boolean, array, object or the 'null' value. nullable: true type: object xml: @@ -1976,7 +1973,6 @@ components: type: string fruitReq: oneOf: - - type: "null" - $ref: '#/components/schemas/appleReq' - $ref: '#/components/schemas/bananaReq' x-one-of-name: FruitReq diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/FakeApi.md b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/FakeApi.md index d449f064d4aa..ba556cb8ea45 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/FakeApi.md +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/FakeApi.md @@ -428,7 +428,7 @@ import ( func main() { query := "query_example" // string | - user := openapiclient.User{Id: int64(123), Username: "Username_example", FirstName: "FirstName_example", LastName: "LastName_example", Email: "Email_example", Password: "Password_example", Phone: "Phone_example", UserStatus: 123, ObjectWithNoDeclaredProps: "TODO", ObjectWithNoDeclaredPropsNullable: "TODO", AnyTypeProp: "TODO", AnyTypePropNullable: "TODO"} // User | + user := openapiclient.User{Id: int64(123), Username: "Username_example", FirstName: "FirstName_example", LastName: "LastName_example", Email: "Email_example", Password: "Password_example", Phone: "Phone_example", UserStatus: 123, ArbitraryObject: "TODO", ArbitraryNullableObject: "TODO", ArbitraryTypeValue: "TODO", ArbitraryNullableTypeValue: "TODO"} // User | configuration := openapiclient.NewConfiguration() api_client := openapiclient.NewAPIClient(configuration) diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/NullableClass.md b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/NullableClass.md index e81e45f2d40a..e24e64475153 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/NullableClass.md +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/NullableClass.md @@ -10,12 +10,12 @@ Name | Type | Description | Notes **StringProp** | Pointer to **NullableString** | | [optional] **DateProp** | Pointer to **NullableString** | | [optional] **DatetimeProp** | Pointer to [**NullableTime**](time.Time.md) | | [optional] -**ArrayNullableProp** | Pointer to **[]ObjectType** | | [optional] -**ArrayAndItemsNullableProp** | Pointer to **[]ObjectType** | | [optional] -**ArrayItemsNullable** | Pointer to **[]ObjectType** | | [optional] -**ObjectNullableProp** | Pointer to **map[string]ObjectType** | | [optional] -**ObjectAndItemsNullableProp** | Pointer to **map[string]ObjectType** | | [optional] -**ObjectItemsNullable** | Pointer to **map[string]ObjectType** | | [optional] +**ArrayNullableProp** | Pointer to **[]map[string]interface{}** | | [optional] +**ArrayAndItemsNullableProp** | Pointer to **[]map[string]interface{}** | | [optional] +**ArrayItemsNullable** | Pointer to **[]map[string]interface{}** | | [optional] +**ObjectNullableProp** | Pointer to **map[string]map[string]interface{}** | | [optional] +**ObjectAndItemsNullableProp** | Pointer to **map[string]map[string]interface{}** | | [optional] +**ObjectItemsNullable** | Pointer to **map[string]map[string]interface{}** | | [optional] ## Methods @@ -248,20 +248,20 @@ HasDatetimeProp returns a boolean if a field has been set. UnsetDatetimeProp ensures that no value is present for DatetimeProp, not even an explicit nil ### GetArrayNullableProp -`func (o *NullableClass) GetArrayNullableProp() []ObjectType` +`func (o *NullableClass) GetArrayNullableProp() []map[string]interface{}` GetArrayNullableProp returns the ArrayNullableProp field if non-nil, zero value otherwise. ### GetArrayNullablePropOk -`func (o *NullableClass) GetArrayNullablePropOk() (*[]ObjectType, bool)` +`func (o *NullableClass) GetArrayNullablePropOk() (*[]map[string]interface{}, bool)` GetArrayNullablePropOk returns a tuple with the ArrayNullableProp field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetArrayNullableProp -`func (o *NullableClass) SetArrayNullableProp(v []ObjectType)` +`func (o *NullableClass) SetArrayNullableProp(v []map[string]interface{})` SetArrayNullableProp sets ArrayNullableProp field to given value. @@ -283,20 +283,20 @@ HasArrayNullableProp returns a boolean if a field has been set. UnsetArrayNullableProp ensures that no value is present for ArrayNullableProp, not even an explicit nil ### GetArrayAndItemsNullableProp -`func (o *NullableClass) GetArrayAndItemsNullableProp() []ObjectType` +`func (o *NullableClass) GetArrayAndItemsNullableProp() []map[string]interface{}` GetArrayAndItemsNullableProp returns the ArrayAndItemsNullableProp field if non-nil, zero value otherwise. ### GetArrayAndItemsNullablePropOk -`func (o *NullableClass) GetArrayAndItemsNullablePropOk() (*[]ObjectType, bool)` +`func (o *NullableClass) GetArrayAndItemsNullablePropOk() (*[]map[string]interface{}, bool)` GetArrayAndItemsNullablePropOk returns a tuple with the ArrayAndItemsNullableProp field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetArrayAndItemsNullableProp -`func (o *NullableClass) SetArrayAndItemsNullableProp(v []ObjectType)` +`func (o *NullableClass) SetArrayAndItemsNullableProp(v []map[string]interface{})` SetArrayAndItemsNullableProp sets ArrayAndItemsNullableProp field to given value. @@ -318,20 +318,20 @@ HasArrayAndItemsNullableProp returns a boolean if a field has been set. UnsetArrayAndItemsNullableProp ensures that no value is present for ArrayAndItemsNullableProp, not even an explicit nil ### GetArrayItemsNullable -`func (o *NullableClass) GetArrayItemsNullable() []ObjectType` +`func (o *NullableClass) GetArrayItemsNullable() []map[string]interface{}` GetArrayItemsNullable returns the ArrayItemsNullable field if non-nil, zero value otherwise. ### GetArrayItemsNullableOk -`func (o *NullableClass) GetArrayItemsNullableOk() (*[]ObjectType, bool)` +`func (o *NullableClass) GetArrayItemsNullableOk() (*[]map[string]interface{}, bool)` GetArrayItemsNullableOk returns a tuple with the ArrayItemsNullable field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetArrayItemsNullable -`func (o *NullableClass) SetArrayItemsNullable(v []ObjectType)` +`func (o *NullableClass) SetArrayItemsNullable(v []map[string]interface{})` SetArrayItemsNullable sets ArrayItemsNullable field to given value. @@ -343,20 +343,20 @@ HasArrayItemsNullable returns a boolean if a field has been set. ### GetObjectNullableProp -`func (o *NullableClass) GetObjectNullableProp() map[string]ObjectType` +`func (o *NullableClass) GetObjectNullableProp() map[string]map[string]interface{}` GetObjectNullableProp returns the ObjectNullableProp field if non-nil, zero value otherwise. ### GetObjectNullablePropOk -`func (o *NullableClass) GetObjectNullablePropOk() (*map[string]ObjectType, bool)` +`func (o *NullableClass) GetObjectNullablePropOk() (*map[string]map[string]interface{}, bool)` GetObjectNullablePropOk returns a tuple with the ObjectNullableProp field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetObjectNullableProp -`func (o *NullableClass) SetObjectNullableProp(v map[string]ObjectType)` +`func (o *NullableClass) SetObjectNullableProp(v map[string]map[string]interface{})` SetObjectNullableProp sets ObjectNullableProp field to given value. @@ -378,20 +378,20 @@ HasObjectNullableProp returns a boolean if a field has been set. UnsetObjectNullableProp ensures that no value is present for ObjectNullableProp, not even an explicit nil ### GetObjectAndItemsNullableProp -`func (o *NullableClass) GetObjectAndItemsNullableProp() map[string]ObjectType` +`func (o *NullableClass) GetObjectAndItemsNullableProp() map[string]map[string]interface{}` GetObjectAndItemsNullableProp returns the ObjectAndItemsNullableProp field if non-nil, zero value otherwise. ### GetObjectAndItemsNullablePropOk -`func (o *NullableClass) GetObjectAndItemsNullablePropOk() (*map[string]ObjectType, bool)` +`func (o *NullableClass) GetObjectAndItemsNullablePropOk() (*map[string]map[string]interface{}, bool)` GetObjectAndItemsNullablePropOk returns a tuple with the ObjectAndItemsNullableProp field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetObjectAndItemsNullableProp -`func (o *NullableClass) SetObjectAndItemsNullableProp(v map[string]ObjectType)` +`func (o *NullableClass) SetObjectAndItemsNullableProp(v map[string]map[string]interface{})` SetObjectAndItemsNullableProp sets ObjectAndItemsNullableProp field to given value. @@ -413,20 +413,20 @@ HasObjectAndItemsNullableProp returns a boolean if a field has been set. UnsetObjectAndItemsNullableProp ensures that no value is present for ObjectAndItemsNullableProp, not even an explicit nil ### GetObjectItemsNullable -`func (o *NullableClass) GetObjectItemsNullable() map[string]ObjectType` +`func (o *NullableClass) GetObjectItemsNullable() map[string]map[string]interface{}` GetObjectItemsNullable returns the ObjectItemsNullable field if non-nil, zero value otherwise. ### GetObjectItemsNullableOk -`func (o *NullableClass) GetObjectItemsNullableOk() (*map[string]ObjectType, bool)` +`func (o *NullableClass) GetObjectItemsNullableOk() (*map[string]map[string]interface{}, bool)` GetObjectItemsNullableOk returns a tuple with the ObjectItemsNullable field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetObjectItemsNullable -`func (o *NullableClass) SetObjectItemsNullable(v map[string]ObjectType)` +`func (o *NullableClass) SetObjectItemsNullable(v map[string]map[string]interface{})` SetObjectItemsNullable sets ObjectItemsNullable field to given value. diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/User.md b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/User.md index cb5481722eff..3f838110ceef 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/User.md +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/User.md @@ -12,10 +12,10 @@ Name | Type | Description | Notes **Password** | Pointer to **string** | | [optional] **Phone** | Pointer to **string** | | [optional] **UserStatus** | Pointer to **int32** | User Status | [optional] -**ObjectWithNoDeclaredProps** | Pointer to [**ObjectType**](.md) | test code generation for objects Value must be a map of strings to values. It cannot be the 'null' value. | [optional] -**ObjectWithNoDeclaredPropsNullable** | Pointer to [**ObjectType**](.md) | test code generation for nullable objects. Value must be a map of strings to values or the 'null' value. | [optional] -**AnyTypeProp** | Pointer to [**AnyType**](.md) | test code generation for any type Here the 'type' attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. See https://github.com/OAI/OpenAPI-Specification/issues/1389 | [optional] -**AnyTypePropNullable** | Pointer to [**AnyType**](.md) | test code generation for any type Here the 'type' attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. The 'nullable' attribute does not change the allowed values. | [optional] +**ArbitraryObject** | Pointer to [**map[string]interface{}**](.md) | test code generation for objects Value must be a map of strings to values. It cannot be the 'null' value. | [optional] +**ArbitraryNullableObject** | Pointer to [**map[string]interface{}**](.md) | test code generation for nullable objects. Value must be a map of strings to values or the 'null' value. | [optional] +**ArbitraryTypeValue** | Pointer to [**interface{}**](.md) | test code generation for any type Value can be any type - string, number, boolean, array or object. | [optional] +**ArbitraryNullableTypeValue** | Pointer to [**interface{}**](.md) | test code generation for any type Value can be any type - string, number, boolean, array, object or the 'null' value. | [optional] ## Methods @@ -236,136 +236,136 @@ SetUserStatus sets UserStatus field to given value. HasUserStatus returns a boolean if a field has been set. -### GetObjectWithNoDeclaredProps +### GetArbitraryObject -`func (o *User) GetObjectWithNoDeclaredProps() map[string]interface{}` +`func (o *User) GetArbitraryObject() map[string]interface{}` -GetObjectWithNoDeclaredProps returns the ObjectWithNoDeclaredProps field if non-nil, zero value otherwise. +GetArbitraryObject returns the ArbitraryObject field if non-nil, zero value otherwise. -### GetObjectWithNoDeclaredPropsOk +### GetArbitraryObjectOk -`func (o *User) GetObjectWithNoDeclaredPropsOk() (*map[string]interface{}, bool)` +`func (o *User) GetArbitraryObjectOk() (*map[string]interface{}, bool)` -GetObjectWithNoDeclaredPropsOk returns a tuple with the ObjectWithNoDeclaredProps field if it's non-nil, zero value otherwise +GetArbitraryObjectOk returns a tuple with the ArbitraryObject field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. -### SetObjectWithNoDeclaredProps +### SetArbitraryObject -`func (o *User) SetObjectWithNoDeclaredProps(v map[string]interface{})` +`func (o *User) SetArbitraryObject(v map[string]interface{})` -SetObjectWithNoDeclaredProps sets ObjectWithNoDeclaredProps field to given value. +SetArbitraryObject sets ArbitraryObject field to given value. -### HasObjectWithNoDeclaredProps +### HasArbitraryObject -`func (o *User) HasObjectWithNoDeclaredProps() bool` +`func (o *User) HasArbitraryObject() bool` -HasObjectWithNoDeclaredProps returns a boolean if a field has been set. +HasArbitraryObject returns a boolean if a field has been set. -### GetObjectWithNoDeclaredPropsNullable +### GetArbitraryNullableObject -`func (o *User) GetObjectWithNoDeclaredPropsNullable() map[string]interface{}` +`func (o *User) GetArbitraryNullableObject() map[string]interface{}` -GetObjectWithNoDeclaredPropsNullable returns the ObjectWithNoDeclaredPropsNullable field if non-nil, zero value otherwise. +GetArbitraryNullableObject returns the ArbitraryNullableObject field if non-nil, zero value otherwise. -### GetObjectWithNoDeclaredPropsNullableOk +### GetArbitraryNullableObjectOk -`func (o *User) GetObjectWithNoDeclaredPropsNullableOk() (*map[string]interface{}, bool)` +`func (o *User) GetArbitraryNullableObjectOk() (*map[string]interface{}, bool)` -GetObjectWithNoDeclaredPropsNullableOk returns a tuple with the ObjectWithNoDeclaredPropsNullable field if it's non-nil, zero value otherwise +GetArbitraryNullableObjectOk returns a tuple with the ArbitraryNullableObject field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. -### SetObjectWithNoDeclaredPropsNullable +### SetArbitraryNullableObject -`func (o *User) SetObjectWithNoDeclaredPropsNullable(v map[string]interface{})` +`func (o *User) SetArbitraryNullableObject(v map[string]interface{})` -SetObjectWithNoDeclaredPropsNullable sets ObjectWithNoDeclaredPropsNullable field to given value. +SetArbitraryNullableObject sets ArbitraryNullableObject field to given value. -### HasObjectWithNoDeclaredPropsNullable +### HasArbitraryNullableObject -`func (o *User) HasObjectWithNoDeclaredPropsNullable() bool` +`func (o *User) HasArbitraryNullableObject() bool` -HasObjectWithNoDeclaredPropsNullable returns a boolean if a field has been set. +HasArbitraryNullableObject returns a boolean if a field has been set. -### SetObjectWithNoDeclaredPropsNullableNil +### SetArbitraryNullableObjectNil -`func (o *User) SetObjectWithNoDeclaredPropsNullableNil(b bool)` +`func (o *User) SetArbitraryNullableObjectNil(b bool)` - SetObjectWithNoDeclaredPropsNullableNil sets the value for ObjectWithNoDeclaredPropsNullable to be an explicit nil + SetArbitraryNullableObjectNil sets the value for ArbitraryNullableObject to be an explicit nil -### UnsetObjectWithNoDeclaredPropsNullable -`func (o *User) UnsetObjectWithNoDeclaredPropsNullable()` +### UnsetArbitraryNullableObject +`func (o *User) UnsetArbitraryNullableObject()` -UnsetObjectWithNoDeclaredPropsNullable ensures that no value is present for ObjectWithNoDeclaredPropsNullable, not even an explicit nil -### GetAnyTypeProp +UnsetArbitraryNullableObject ensures that no value is present for ArbitraryNullableObject, not even an explicit nil +### GetArbitraryTypeValue -`func (o *User) GetAnyTypeProp() interface{}` +`func (o *User) GetArbitraryTypeValue() interface{}` -GetAnyTypeProp returns the AnyTypeProp field if non-nil, zero value otherwise. +GetArbitraryTypeValue returns the ArbitraryTypeValue field if non-nil, zero value otherwise. -### GetAnyTypePropOk +### GetArbitraryTypeValueOk -`func (o *User) GetAnyTypePropOk() (*interface{}, bool)` +`func (o *User) GetArbitraryTypeValueOk() (*interface{}, bool)` -GetAnyTypePropOk returns a tuple with the AnyTypeProp field if it's non-nil, zero value otherwise +GetArbitraryTypeValueOk returns a tuple with the ArbitraryTypeValue field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. -### SetAnyTypeProp +### SetArbitraryTypeValue -`func (o *User) SetAnyTypeProp(v interface{})` +`func (o *User) SetArbitraryTypeValue(v interface{})` -SetAnyTypeProp sets AnyTypeProp field to given value. +SetArbitraryTypeValue sets ArbitraryTypeValue field to given value. -### HasAnyTypeProp +### HasArbitraryTypeValue -`func (o *User) HasAnyTypeProp() bool` +`func (o *User) HasArbitraryTypeValue() bool` -HasAnyTypeProp returns a boolean if a field has been set. +HasArbitraryTypeValue returns a boolean if a field has been set. -### SetAnyTypePropNil +### SetArbitraryTypeValueNil -`func (o *User) SetAnyTypePropNil(b bool)` +`func (o *User) SetArbitraryTypeValueNil(b bool)` - SetAnyTypePropNil sets the value for AnyTypeProp to be an explicit nil + SetArbitraryTypeValueNil sets the value for ArbitraryTypeValue to be an explicit nil -### UnsetAnyTypeProp -`func (o *User) UnsetAnyTypeProp()` +### UnsetArbitraryTypeValue +`func (o *User) UnsetArbitraryTypeValue()` -UnsetAnyTypeProp ensures that no value is present for AnyTypeProp, not even an explicit nil -### GetAnyTypePropNullable +UnsetArbitraryTypeValue ensures that no value is present for ArbitraryTypeValue, not even an explicit nil +### GetArbitraryNullableTypeValue -`func (o *User) GetAnyTypePropNullable() interface{}` +`func (o *User) GetArbitraryNullableTypeValue() interface{}` -GetAnyTypePropNullable returns the AnyTypePropNullable field if non-nil, zero value otherwise. +GetArbitraryNullableTypeValue returns the ArbitraryNullableTypeValue field if non-nil, zero value otherwise. -### GetAnyTypePropNullableOk +### GetArbitraryNullableTypeValueOk -`func (o *User) GetAnyTypePropNullableOk() (*interface{}, bool)` +`func (o *User) GetArbitraryNullableTypeValueOk() (*interface{}, bool)` -GetAnyTypePropNullableOk returns a tuple with the AnyTypePropNullable field if it's non-nil, zero value otherwise +GetArbitraryNullableTypeValueOk returns a tuple with the ArbitraryNullableTypeValue field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. -### SetAnyTypePropNullable +### SetArbitraryNullableTypeValue -`func (o *User) SetAnyTypePropNullable(v interface{})` +`func (o *User) SetArbitraryNullableTypeValue(v interface{})` -SetAnyTypePropNullable sets AnyTypePropNullable field to given value. +SetArbitraryNullableTypeValue sets ArbitraryNullableTypeValue field to given value. -### HasAnyTypePropNullable +### HasArbitraryNullableTypeValue -`func (o *User) HasAnyTypePropNullable() bool` +`func (o *User) HasArbitraryNullableTypeValue() bool` -HasAnyTypePropNullable returns a boolean if a field has been set. +HasArbitraryNullableTypeValue returns a boolean if a field has been set. -### SetAnyTypePropNullableNil +### SetArbitraryNullableTypeValueNil -`func (o *User) SetAnyTypePropNullableNil(b bool)` +`func (o *User) SetArbitraryNullableTypeValueNil(b bool)` - SetAnyTypePropNullableNil sets the value for AnyTypePropNullable to be an explicit nil + SetArbitraryNullableTypeValueNil sets the value for ArbitraryNullableTypeValue to be an explicit nil -### UnsetAnyTypePropNullable -`func (o *User) UnsetAnyTypePropNullable()` +### UnsetArbitraryNullableTypeValue +`func (o *User) UnsetArbitraryNullableTypeValue()` -UnsetAnyTypePropNullable ensures that no value is present for AnyTypePropNullable, not even an explicit nil +UnsetArbitraryNullableTypeValue ensures that no value is present for ArbitraryNullableTypeValue, not even an explicit nil [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/UserApi.md b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/UserApi.md index b3aca49efb1f..43fccd38582a 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/UserApi.md +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/docs/UserApi.md @@ -36,7 +36,7 @@ import ( ) func main() { - user := openapiclient.User{Id: int64(123), Username: "Username_example", FirstName: "FirstName_example", LastName: "LastName_example", Email: "Email_example", Password: "Password_example", Phone: "Phone_example", UserStatus: 123, ObjectWithNoDeclaredProps: "TODO", ObjectWithNoDeclaredPropsNullable: "TODO", AnyTypeProp: "TODO", AnyTypePropNullable: "TODO"} // User | Created user object + user := openapiclient.User{Id: int64(123), Username: "Username_example", FirstName: "FirstName_example", LastName: "LastName_example", Email: "Email_example", Password: "Password_example", Phone: "Phone_example", UserStatus: 123, ArbitraryObject: "TODO", ArbitraryNullableObject: "TODO", ArbitraryTypeValue: "TODO", ArbitraryNullableTypeValue: "TODO"} // User | Created user object configuration := openapiclient.NewConfiguration() api_client := openapiclient.NewAPIClient(configuration) @@ -98,7 +98,7 @@ import ( ) func main() { - user := []User{openapiclient.User{Id: int64(123), Username: "Username_example", FirstName: "FirstName_example", LastName: "LastName_example", Email: "Email_example", Password: "Password_example", Phone: "Phone_example", UserStatus: 123, ObjectWithNoDeclaredProps: "TODO", ObjectWithNoDeclaredPropsNullable: "TODO", AnyTypeProp: "TODO", AnyTypePropNullable: "TODO"}} // []User | List of user object + user := []User{openapiclient.User{Id: int64(123), Username: "Username_example", FirstName: "FirstName_example", LastName: "LastName_example", Email: "Email_example", Password: "Password_example", Phone: "Phone_example", UserStatus: 123, ArbitraryObject: "TODO", ArbitraryNullableObject: "TODO", ArbitraryTypeValue: "TODO", ArbitraryNullableTypeValue: "TODO"}} // []User | List of user object configuration := openapiclient.NewConfiguration() api_client := openapiclient.NewAPIClient(configuration) diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/go.mod b/samples/openapi3/client/petstore/go-experimental/go-petstore/go.mod index 89d18393f73e..f9811556cc5a 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/go.mod +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/go.mod @@ -2,4 +2,6 @@ module github.com/GIT_USER_ID/GIT_REPO_ID go 1.13 -require golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 +require ( + golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 +) diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_fruit_req.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_fruit_req.go index 3fdfbcf76008..86320b7c9b8e 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_fruit_req.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_fruit_req.go @@ -37,12 +37,6 @@ func (s *FruitReq) UnmarshalJSON(src []byte) error { s.FruitReqInterface = unmarshaledBananaReq return nil } - var unmarshaledNullType *NullType = &NullType{} - err = json.Unmarshal(src, unmarshaledNullType) - if err == nil { - s.FruitReqInterface = unmarshaledNullType - return nil - } return fmt.Errorf("No oneOf model could be deserialized from payload: %s", string(src)) } type NullableFruitReq struct { diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_nullable_class.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_nullable_class.go index a465419c12d8..c9d8facc2a84 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_nullable_class.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_nullable_class.go @@ -22,12 +22,12 @@ type NullableClass struct { StringProp NullableString `json:"string_prop,omitempty"` DateProp NullableString `json:"date_prop,omitempty"` DatetimeProp NullableTime `json:"datetime_prop,omitempty"` - ArrayNullableProp []ObjectType `json:"array_nullable_prop,omitempty"` - ArrayAndItemsNullableProp []ObjectType `json:"array_and_items_nullable_prop,omitempty"` - ArrayItemsNullable *[]ObjectType `json:"array_items_nullable,omitempty"` - ObjectNullableProp map[string]ObjectType `json:"object_nullable_prop,omitempty"` - ObjectAndItemsNullableProp map[string]ObjectType `json:"object_and_items_nullable_prop,omitempty"` - ObjectItemsNullable *map[string]ObjectType `json:"object_items_nullable,omitempty"` + ArrayNullableProp []map[string]interface{} `json:"array_nullable_prop,omitempty"` + ArrayAndItemsNullableProp []map[string]interface{} `json:"array_and_items_nullable_prop,omitempty"` + ArrayItemsNullable *[]map[string]interface{} `json:"array_items_nullable,omitempty"` + ObjectNullableProp map[string]map[string]interface{} `json:"object_nullable_prop,omitempty"` + ObjectAndItemsNullableProp map[string]map[string]interface{} `json:"object_and_items_nullable_prop,omitempty"` + ObjectItemsNullable *map[string]map[string]interface{} `json:"object_items_nullable,omitempty"` } // NewNullableClass instantiates a new NullableClass object @@ -300,9 +300,9 @@ func (o *NullableClass) UnsetDatetimeProp() { } // GetArrayNullableProp returns the ArrayNullableProp field value if set, zero value otherwise (both if not set or set to explicit null). -func (o *NullableClass) GetArrayNullableProp() []ObjectType { +func (o *NullableClass) GetArrayNullableProp() []map[string]interface{} { if o == nil { - var ret []ObjectType + var ret []map[string]interface{} return ret } return o.ArrayNullableProp @@ -311,7 +311,7 @@ func (o *NullableClass) GetArrayNullableProp() []ObjectType { // GetArrayNullablePropOk returns a tuple with the ArrayNullableProp field value if set, nil otherwise // and a boolean to check if the value has been set. // NOTE: If the value is an explicit nil, `nil, true` will be returned -func (o *NullableClass) GetArrayNullablePropOk() (*[]ObjectType, bool) { +func (o *NullableClass) GetArrayNullablePropOk() (*[]map[string]interface{}, bool) { if o == nil || o.ArrayNullableProp == nil { return nil, false } @@ -327,15 +327,15 @@ func (o *NullableClass) HasArrayNullableProp() bool { return false } -// SetArrayNullableProp gets a reference to the given []ObjectType and assigns it to the ArrayNullableProp field. -func (o *NullableClass) SetArrayNullableProp(v []ObjectType) { +// SetArrayNullableProp gets a reference to the given []map[string]interface{} and assigns it to the ArrayNullableProp field. +func (o *NullableClass) SetArrayNullableProp(v []map[string]interface{}) { o.ArrayNullableProp = v } // GetArrayAndItemsNullableProp returns the ArrayAndItemsNullableProp field value if set, zero value otherwise (both if not set or set to explicit null). -func (o *NullableClass) GetArrayAndItemsNullableProp() []ObjectType { +func (o *NullableClass) GetArrayAndItemsNullableProp() []map[string]interface{} { if o == nil { - var ret []ObjectType + var ret []map[string]interface{} return ret } return o.ArrayAndItemsNullableProp @@ -344,7 +344,7 @@ func (o *NullableClass) GetArrayAndItemsNullableProp() []ObjectType { // GetArrayAndItemsNullablePropOk returns a tuple with the ArrayAndItemsNullableProp field value if set, nil otherwise // and a boolean to check if the value has been set. // NOTE: If the value is an explicit nil, `nil, true` will be returned -func (o *NullableClass) GetArrayAndItemsNullablePropOk() (*[]ObjectType, bool) { +func (o *NullableClass) GetArrayAndItemsNullablePropOk() (*[]map[string]interface{}, bool) { if o == nil || o.ArrayAndItemsNullableProp == nil { return nil, false } @@ -360,15 +360,15 @@ func (o *NullableClass) HasArrayAndItemsNullableProp() bool { return false } -// SetArrayAndItemsNullableProp gets a reference to the given []ObjectType and assigns it to the ArrayAndItemsNullableProp field. -func (o *NullableClass) SetArrayAndItemsNullableProp(v []ObjectType) { +// SetArrayAndItemsNullableProp gets a reference to the given []map[string]interface{} and assigns it to the ArrayAndItemsNullableProp field. +func (o *NullableClass) SetArrayAndItemsNullableProp(v []map[string]interface{}) { o.ArrayAndItemsNullableProp = v } // GetArrayItemsNullable returns the ArrayItemsNullable field value if set, zero value otherwise. -func (o *NullableClass) GetArrayItemsNullable() []ObjectType { +func (o *NullableClass) GetArrayItemsNullable() []map[string]interface{} { if o == nil || o.ArrayItemsNullable == nil { - var ret []ObjectType + var ret []map[string]interface{} return ret } return *o.ArrayItemsNullable @@ -376,7 +376,7 @@ func (o *NullableClass) GetArrayItemsNullable() []ObjectType { // GetArrayItemsNullableOk returns a tuple with the ArrayItemsNullable field value if set, nil otherwise // and a boolean to check if the value has been set. -func (o *NullableClass) GetArrayItemsNullableOk() (*[]ObjectType, bool) { +func (o *NullableClass) GetArrayItemsNullableOk() (*[]map[string]interface{}, bool) { if o == nil || o.ArrayItemsNullable == nil { return nil, false } @@ -392,15 +392,15 @@ func (o *NullableClass) HasArrayItemsNullable() bool { return false } -// SetArrayItemsNullable gets a reference to the given []ObjectType and assigns it to the ArrayItemsNullable field. -func (o *NullableClass) SetArrayItemsNullable(v []ObjectType) { +// SetArrayItemsNullable gets a reference to the given []map[string]interface{} and assigns it to the ArrayItemsNullable field. +func (o *NullableClass) SetArrayItemsNullable(v []map[string]interface{}) { o.ArrayItemsNullable = &v } // GetObjectNullableProp returns the ObjectNullableProp field value if set, zero value otherwise (both if not set or set to explicit null). -func (o *NullableClass) GetObjectNullableProp() map[string]ObjectType { +func (o *NullableClass) GetObjectNullableProp() map[string]map[string]interface{} { if o == nil { - var ret map[string]ObjectType + var ret map[string]map[string]interface{} return ret } return o.ObjectNullableProp @@ -409,7 +409,7 @@ func (o *NullableClass) GetObjectNullableProp() map[string]ObjectType { // GetObjectNullablePropOk returns a tuple with the ObjectNullableProp field value if set, nil otherwise // and a boolean to check if the value has been set. // NOTE: If the value is an explicit nil, `nil, true` will be returned -func (o *NullableClass) GetObjectNullablePropOk() (*map[string]ObjectType, bool) { +func (o *NullableClass) GetObjectNullablePropOk() (*map[string]map[string]interface{}, bool) { if o == nil || o.ObjectNullableProp == nil { return nil, false } @@ -425,15 +425,15 @@ func (o *NullableClass) HasObjectNullableProp() bool { return false } -// SetObjectNullableProp gets a reference to the given map[string]ObjectType and assigns it to the ObjectNullableProp field. -func (o *NullableClass) SetObjectNullableProp(v map[string]ObjectType) { +// SetObjectNullableProp gets a reference to the given map[string]map[string]interface{} and assigns it to the ObjectNullableProp field. +func (o *NullableClass) SetObjectNullableProp(v map[string]map[string]interface{}) { o.ObjectNullableProp = v } // GetObjectAndItemsNullableProp returns the ObjectAndItemsNullableProp field value if set, zero value otherwise (both if not set or set to explicit null). -func (o *NullableClass) GetObjectAndItemsNullableProp() map[string]ObjectType { +func (o *NullableClass) GetObjectAndItemsNullableProp() map[string]map[string]interface{} { if o == nil { - var ret map[string]ObjectType + var ret map[string]map[string]interface{} return ret } return o.ObjectAndItemsNullableProp @@ -442,7 +442,7 @@ func (o *NullableClass) GetObjectAndItemsNullableProp() map[string]ObjectType { // GetObjectAndItemsNullablePropOk returns a tuple with the ObjectAndItemsNullableProp field value if set, nil otherwise // and a boolean to check if the value has been set. // NOTE: If the value is an explicit nil, `nil, true` will be returned -func (o *NullableClass) GetObjectAndItemsNullablePropOk() (*map[string]ObjectType, bool) { +func (o *NullableClass) GetObjectAndItemsNullablePropOk() (*map[string]map[string]interface{}, bool) { if o == nil || o.ObjectAndItemsNullableProp == nil { return nil, false } @@ -458,15 +458,15 @@ func (o *NullableClass) HasObjectAndItemsNullableProp() bool { return false } -// SetObjectAndItemsNullableProp gets a reference to the given map[string]ObjectType and assigns it to the ObjectAndItemsNullableProp field. -func (o *NullableClass) SetObjectAndItemsNullableProp(v map[string]ObjectType) { +// SetObjectAndItemsNullableProp gets a reference to the given map[string]map[string]interface{} and assigns it to the ObjectAndItemsNullableProp field. +func (o *NullableClass) SetObjectAndItemsNullableProp(v map[string]map[string]interface{}) { o.ObjectAndItemsNullableProp = v } // GetObjectItemsNullable returns the ObjectItemsNullable field value if set, zero value otherwise. -func (o *NullableClass) GetObjectItemsNullable() map[string]ObjectType { +func (o *NullableClass) GetObjectItemsNullable() map[string]map[string]interface{} { if o == nil || o.ObjectItemsNullable == nil { - var ret map[string]ObjectType + var ret map[string]map[string]interface{} return ret } return *o.ObjectItemsNullable @@ -474,7 +474,7 @@ func (o *NullableClass) GetObjectItemsNullable() map[string]ObjectType { // GetObjectItemsNullableOk returns a tuple with the ObjectItemsNullable field value if set, nil otherwise // and a boolean to check if the value has been set. -func (o *NullableClass) GetObjectItemsNullableOk() (*map[string]ObjectType, bool) { +func (o *NullableClass) GetObjectItemsNullableOk() (*map[string]map[string]interface{}, bool) { if o == nil || o.ObjectItemsNullable == nil { return nil, false } @@ -490,8 +490,8 @@ func (o *NullableClass) HasObjectItemsNullable() bool { return false } -// SetObjectItemsNullable gets a reference to the given map[string]ObjectType and assigns it to the ObjectItemsNullable field. -func (o *NullableClass) SetObjectItemsNullable(v map[string]ObjectType) { +// SetObjectItemsNullable gets a reference to the given map[string]map[string]interface{} and assigns it to the ObjectItemsNullable field. +func (o *NullableClass) SetObjectItemsNullable(v map[string]map[string]interface{}) { o.ObjectItemsNullable = &v } diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_user.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_user.go index 352dcf15745c..6310038b817d 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/model_user.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/model_user.go @@ -25,13 +25,13 @@ type User struct { // User Status UserStatus *int32 `json:"userStatus,omitempty"` // test code generation for objects Value must be a map of strings to values. It cannot be the 'null' value. - ObjectWithNoDeclaredProps *ObjectType `json:"objectWithNoDeclaredProps,omitempty"` + ArbitraryObject *map[string]interface{} `json:"arbitraryObject,omitempty"` // test code generation for nullable objects. Value must be a map of strings to values or the 'null' value. - ObjectWithNoDeclaredPropsNullable ObjectType `json:"objectWithNoDeclaredPropsNullable,omitempty"` - // test code generation for any type Here the 'type' attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. See https://github.com/OAI/OpenAPI-Specification/issues/1389 - AnyTypeProp AnyType `json:"anyTypeProp,omitempty"` - // test code generation for any type Here the 'type' attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. The 'nullable' attribute does not change the allowed values. - AnyTypePropNullable AnyType `json:"anyTypePropNullable,omitempty"` + ArbitraryNullableObject map[string]interface{} `json:"arbitraryNullableObject,omitempty"` + // test code generation for any type Value can be any type - string, number, boolean, array or object. + ArbitraryTypeValue interface{} `json:"arbitraryTypeValue,omitempty"` + // test code generation for any type Value can be any type - string, number, boolean, array, object or the 'null' value. + ArbitraryNullableTypeValue interface{} `json:"arbitraryNullableTypeValue,omitempty"` } // NewUser instantiates a new User object @@ -307,162 +307,135 @@ func (o *User) SetUserStatus(v int32) { o.UserStatus = &v } -// GetObjectWithNoDeclaredProps returns the ObjectWithNoDeclaredProps field value if set, zero value otherwise. -func (o *User) GetObjectWithNoDeclaredProps() map[string]interface{} { - if o == nil || o.ObjectWithNoDeclaredProps == nil { +// GetArbitraryObject returns the ArbitraryObject field value if set, zero value otherwise. +func (o *User) GetArbitraryObject() map[string]interface{} { + if o == nil || o.ArbitraryObject == nil { var ret map[string]interface{} return ret } - return *o.ObjectWithNoDeclaredProps.Get() + return *o.ArbitraryObject } -// GetObjectWithNoDeclaredPropsOk returns a tuple with the ObjectWithNoDeclaredProps field value if set, nil otherwise +// GetArbitraryObjectOk returns a tuple with the ArbitraryObject field value if set, nil otherwise // and a boolean to check if the value has been set. -func (o *User) GetObjectWithNoDeclaredPropsOk() (*map[string]interface{}, bool) { - if o == nil || o.ObjectWithNoDeclaredProps == nil { +func (o *User) GetArbitraryObjectOk() (*map[string]interface{}, bool) { + if o == nil || o.ArbitraryObject == nil { return nil, false } - return o.ObjectWithNoDeclaredProps.Get(), true + return o.ArbitraryObject, true } -// HasObjectWithNoDeclaredProps returns a boolean if a field has been set. -func (o *User) HasObjectWithNoDeclaredProps() bool { - if o != nil && o.ObjectWithNoDeclaredProps != nil { +// HasArbitraryObject returns a boolean if a field has been set. +func (o *User) HasArbitraryObject() bool { + if o != nil && o.ArbitraryObject != nil { return true } return false } -// SetObjectWithNoDeclaredProps gets a reference to the given ObjectType and assigns it to the ObjectWithNoDeclaredProps field. -func (o *User) SetObjectWithNoDeclaredProps(v map[string]interface{}) { - o.ObjectWithNoDeclaredProps.Set(&v) +// SetArbitraryObject gets a reference to the given map[string]interface{} and assigns it to the ArbitraryObject field. +func (o *User) SetArbitraryObject(v map[string]interface{}) { + o.ArbitraryObject = &v } -// GetObjectWithNoDeclaredPropsNullable returns the ObjectWithNoDeclaredPropsNullable field value if set, zero value otherwise (both if not set or set to explicit null). -func (o *User) GetObjectWithNoDeclaredPropsNullable() map[string]interface{} { - if o == nil || o.ObjectWithNoDeclaredPropsNullable.Get() == nil { +// GetArbitraryNullableObject returns the ArbitraryNullableObject field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *User) GetArbitraryNullableObject() map[string]interface{} { + if o == nil { var ret map[string]interface{} return ret } - return *o.ObjectWithNoDeclaredPropsNullable.Get() + return o.ArbitraryNullableObject } -// GetObjectWithNoDeclaredPropsNullableOk returns a tuple with the ObjectWithNoDeclaredPropsNullable field value if set, nil otherwise +// GetArbitraryNullableObjectOk returns a tuple with the ArbitraryNullableObject field value if set, nil otherwise // and a boolean to check if the value has been set. // NOTE: If the value is an explicit nil, `nil, true` will be returned -func (o *User) GetObjectWithNoDeclaredPropsNullableOk() (*map[string]interface{}, bool) { - if o == nil { +func (o *User) GetArbitraryNullableObjectOk() (*map[string]interface{}, bool) { + if o == nil || o.ArbitraryNullableObject == nil { return nil, false } - return o.ObjectWithNoDeclaredPropsNullable.Get(), o.ObjectWithNoDeclaredPropsNullable.IsSet() + return &o.ArbitraryNullableObject, true } -// HasObjectWithNoDeclaredPropsNullable returns a boolean if a field has been set. -func (o *User) HasObjectWithNoDeclaredPropsNullable() bool { - if o != nil && o.ObjectWithNoDeclaredPropsNullable.IsSet() { +// HasArbitraryNullableObject returns a boolean if a field has been set. +func (o *User) HasArbitraryNullableObject() bool { + if o != nil && o.ArbitraryNullableObject != nil { return true } return false } -// SetObjectWithNoDeclaredPropsNullable gets a reference to the given ObjectType and assigns it to the ObjectWithNoDeclaredPropsNullable field. -func (o *User) SetObjectWithNoDeclaredPropsNullable(v map[string]interface{}) { - o.ObjectWithNoDeclaredPropsNullable.Set(&v) -} -// SetObjectWithNoDeclaredPropsNullableNil sets the value for ObjectWithNoDeclaredPropsNullable to be an explicit nil -func (o *User) SetObjectWithNoDeclaredPropsNullableNil() { - o.ObjectWithNoDeclaredPropsNullable.Set(nil) -} - -// UnsetObjectWithNoDeclaredPropsNullable ensures that no value is present for ObjectWithNoDeclaredPropsNullable, not even an explicit nil -func (o *User) UnsetObjectWithNoDeclaredPropsNullable() { - o.ObjectWithNoDeclaredPropsNullable.Unset() +// SetArbitraryNullableObject gets a reference to the given map[string]interface{} and assigns it to the ArbitraryNullableObject field. +func (o *User) SetArbitraryNullableObject(v map[string]interface{}) { + o.ArbitraryNullableObject = v } -// GetAnyTypeProp returns the AnyTypeProp field value if set, zero value otherwise (both if not set or set to explicit null). -func (o *User) GetAnyTypeProp() interface{} { - if o == nil || o.AnyTypeProp.Get() == nil { +// GetArbitraryTypeValue returns the ArbitraryTypeValue field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *User) GetArbitraryTypeValue() interface{} { + if o == nil { var ret interface{} return ret } - return *o.AnyTypeProp.Get() + return o.ArbitraryTypeValue } -// GetAnyTypePropOk returns a tuple with the AnyTypeProp field value if set, nil otherwise +// GetArbitraryTypeValueOk returns a tuple with the ArbitraryTypeValue field value if set, nil otherwise // and a boolean to check if the value has been set. // NOTE: If the value is an explicit nil, `nil, true` will be returned -func (o *User) GetAnyTypePropOk() (*interface{}, bool) { - if o == nil { +func (o *User) GetArbitraryTypeValueOk() (*interface{}, bool) { + if o == nil || o.ArbitraryTypeValue == nil { return nil, false } - return o.AnyTypeProp.Get(), o.AnyTypeProp.IsSet() + return &o.ArbitraryTypeValue, true } -// HasAnyTypeProp returns a boolean if a field has been set. -func (o *User) HasAnyTypeProp() bool { - if o != nil && o.AnyTypeProp.IsSet() { +// HasArbitraryTypeValue returns a boolean if a field has been set. +func (o *User) HasArbitraryTypeValue() bool { + if o != nil && o.ArbitraryTypeValue != nil { return true } return false } -// SetAnyTypeProp gets a reference to the given AnyType and assigns it to the AnyTypeProp field. -func (o *User) SetAnyTypeProp(v interface{}) { - o.AnyTypeProp.Set(&v) -} -// SetAnyTypePropNil sets the value for AnyTypeProp to be an explicit nil -func (o *User) SetAnyTypePropNil() { - o.AnyTypeProp.Set(nil) +// SetArbitraryTypeValue gets a reference to the given interface{} and assigns it to the ArbitraryTypeValue field. +func (o *User) SetArbitraryTypeValue(v interface{}) { + o.ArbitraryTypeValue = v } -// UnsetAnyTypeProp ensures that no value is present for AnyTypeProp, not even an explicit nil -func (o *User) UnsetAnyTypeProp() { - o.AnyTypeProp.Unset() -} - -// GetAnyTypePropNullable returns the AnyTypePropNullable field value if set, zero value otherwise (both if not set or set to explicit null). -func (o *User) GetAnyTypePropNullable() interface{} { - if o == nil || o.AnyTypePropNullable.Get() == nil { +// GetArbitraryNullableTypeValue returns the ArbitraryNullableTypeValue field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *User) GetArbitraryNullableTypeValue() interface{} { + if o == nil { var ret interface{} return ret } - return *o.AnyTypePropNullable.Get() + return o.ArbitraryNullableTypeValue } -// GetAnyTypePropNullableOk returns a tuple with the AnyTypePropNullable field value if set, nil otherwise +// GetArbitraryNullableTypeValueOk returns a tuple with the ArbitraryNullableTypeValue field value if set, nil otherwise // and a boolean to check if the value has been set. // NOTE: If the value is an explicit nil, `nil, true` will be returned -func (o *User) GetAnyTypePropNullableOk() (*interface{}, bool) { - if o == nil { +func (o *User) GetArbitraryNullableTypeValueOk() (*interface{}, bool) { + if o == nil || o.ArbitraryNullableTypeValue == nil { return nil, false } - return o.AnyTypePropNullable.Get(), o.AnyTypePropNullable.IsSet() + return &o.ArbitraryNullableTypeValue, true } -// HasAnyTypePropNullable returns a boolean if a field has been set. -func (o *User) HasAnyTypePropNullable() bool { - if o != nil && o.AnyTypePropNullable.IsSet() { +// HasArbitraryNullableTypeValue returns a boolean if a field has been set. +func (o *User) HasArbitraryNullableTypeValue() bool { + if o != nil && o.ArbitraryNullableTypeValue != nil { return true } return false } -// SetAnyTypePropNullable gets a reference to the given AnyType and assigns it to the AnyTypePropNullable field. -func (o *User) SetAnyTypePropNullable(v interface{}) { - o.AnyTypePropNullable.Set(&v) -} -// SetAnyTypePropNullableNil sets the value for AnyTypePropNullable to be an explicit nil -func (o *User) SetAnyTypePropNullableNil() { - o.AnyTypePropNullable.Set(nil) -} - -// UnsetAnyTypePropNullable ensures that no value is present for AnyTypePropNullable, not even an explicit nil -func (o *User) UnsetAnyTypePropNullable() { - o.AnyTypePropNullable.Unset() +// SetArbitraryNullableTypeValue gets a reference to the given interface{} and assigns it to the ArbitraryNullableTypeValue field. +func (o *User) SetArbitraryNullableTypeValue(v interface{}) { + o.ArbitraryNullableTypeValue = v } func (o User) MarshalJSON() ([]byte, error) { @@ -491,17 +464,17 @@ func (o User) MarshalJSON() ([]byte, error) { if o.UserStatus != nil { toSerialize["userStatus"] = o.UserStatus } - if o.ObjectWithNoDeclaredProps != nil { - toSerialize["objectWithNoDeclaredProps"] = o.ObjectWithNoDeclaredProps + if o.ArbitraryObject != nil { + toSerialize["arbitraryObject"] = o.ArbitraryObject } - if o.ObjectWithNoDeclaredPropsNullable.IsSet() { - toSerialize["objectWithNoDeclaredPropsNullable"] = o.ObjectWithNoDeclaredPropsNullable.Get() + if o.ArbitraryNullableObject != nil { + toSerialize["arbitraryNullableObject"] = o.ArbitraryNullableObject } - if o.AnyTypeProp.IsSet() { - toSerialize["anyTypeProp"] = o.AnyTypeProp.Get() + if o.ArbitraryTypeValue != nil { + toSerialize["arbitraryTypeValue"] = o.ArbitraryTypeValue } - if o.AnyTypePropNullable.IsSet() { - toSerialize["anyTypePropNullable"] = o.AnyTypePropNullable.Get() + if o.ArbitraryNullableTypeValue != nil { + toSerialize["arbitraryNullableTypeValue"] = o.ArbitraryNullableTypeValue } return json.Marshal(toSerialize) } diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/utils.go b/samples/openapi3/client/petstore/go-experimental/go-petstore/utils.go index 6c470ffcd2ad..9fb7a1847cd3 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/utils.go +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/utils.go @@ -10,9 +10,7 @@ package petstore import ( - "bytes" "encoding/json" - "errors" "time" ) @@ -40,121 +38,6 @@ func PtrString(v string) *string { return &v } // PtrTime is helper routine that returns a pointer to given Time value. func PtrTime(v time.Time) *time.Time { return &v } -var nullLiteral []byte = []byte("null") - -// NullType is a type whose only value can be the JSON 'null' value. -type NullType struct{ - isSet bool -} - -func NewNullType() *NullType { - return nil -} - -func (v NullType) Get() interface{} { - return nil -} - -func (v *NullType) Set() { - v.isSet = true -} - -func (v NullType) IsSet() bool { - return v.isSet -} - -func (v *NullType) Unset() { - v.isSet = false -} - -func (v NullType) MarshalJSON() ([]byte, error) { - return nullLiteral, nil -} - -func (v *NullType) UnmarshalJSON(src []byte) error { - if bytes.Equal(bytes.TrimSpace(nullLiteral), src) { - v.isSet = true - return nil - } - return errors.New("Cannot unmarshal value into 'null' type") -} - -// AnyType is a type whose value can any valid OpenAPI type. -// The value may be the null value, a string, integer, number, boolean, array -// or object. -type AnyType struct{ - value *interface{} - isSet bool -} - -func NewAnyType(val *interface{}) *AnyType { - return &AnyType{value: val, isSet: true} -} - -func (v AnyType) Get() *interface{} { - return v.value -} - -func (v *AnyType) Set(val *interface{}) { - v.value = val - v.isSet = true -} - -func (v AnyType) IsSet() bool { - return v.isSet -} - -func (v *AnyType) Unset() { - v.isSet = false -} - -func (v AnyType) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *AnyType) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - -// ObjectType is a type whose value can be any OpenAPI object with undeclared properties. -type ObjectType struct{ - value *map[string]interface{} - isSet bool -} - -// NewObjectType creates and returns an object with the specified map -// of undeclared properties. -func NewObjectType(val *map[string]interface{}) *ObjectType { - return &ObjectType{value: val, isSet: true} -} - -func (v ObjectType) Get() *map[string]interface{} { - return v.value -} - -func (v *ObjectType) Set(val *map[string]interface{}) { - v.value = val - v.isSet = true -} - -func (v ObjectType) IsSet() bool { - return v.isSet -} - -func (v *ObjectType) Unset() { - v.isSet = false -} - -func (v ObjectType) MarshalJSON() ([]byte, error) { - return json.Marshal(v.value) -} - -func (v *ObjectType) UnmarshalJSON(src []byte) error { - v.isSet = true - return json.Unmarshal(src, &v.value) -} - type NullableBool struct { value *bool isSet bool From ee786cb6797518ff624384f49d99c2fa6a9208f7 Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Thu, 7 May 2020 12:45:47 -0700 Subject: [PATCH 40/48] Run samples scripts --- .../go/go-petstore/docs/AdditionalPropertiesClass.md | 10 +++++----- .../go-petstore/model_additional_properties_class.go | 10 +++++----- .../petstore/go/go-petstore/docs/NullableClass.md | 12 ++++++------ .../petstore/go/go-petstore/model_nullable_class.go | 12 ++++++------ 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/samples/client/petstore/go/go-petstore/docs/AdditionalPropertiesClass.md b/samples/client/petstore/go/go-petstore/docs/AdditionalPropertiesClass.md index e193ede86dc0..877a5d45a316 100644 --- a/samples/client/petstore/go/go-petstore/docs/AdditionalPropertiesClass.md +++ b/samples/client/petstore/go/go-petstore/docs/AdditionalPropertiesClass.md @@ -9,12 +9,12 @@ Name | Type | Description | Notes **MapInteger** | **map[string]int32** | | [optional] **MapBoolean** | **map[string]bool** | | [optional] **MapArrayInteger** | [**map[string][]int32**](array.md) | | [optional] -**MapArrayAnytype** | [**map[string][]ObjectType**](array.md) | | [optional] +**MapArrayAnytype** | [**map[string][]map[string]interface{}**](array.md) | | [optional] **MapMapString** | [**map[string]map[string]string**](map.md) | | [optional] -**MapMapAnytype** | [**map[string]map[string]ObjectType**](map.md) | | [optional] -**Anytype1** | [**ObjectType**](.md) | | [optional] -**Anytype2** | [**ObjectType**](.md) | | [optional] -**Anytype3** | [**ObjectType**](.md) | | [optional] +**MapMapAnytype** | [**map[string]map[string]map[string]interface{}**](map.md) | | [optional] +**Anytype1** | [**map[string]interface{}**](.md) | | [optional] +**Anytype2** | [**map[string]interface{}**](.md) | | [optional] +**Anytype3** | [**map[string]interface{}**](.md) | | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/go/go-petstore/model_additional_properties_class.go b/samples/client/petstore/go/go-petstore/model_additional_properties_class.go index ea4dcdfff22e..00ca7fb44061 100644 --- a/samples/client/petstore/go/go-petstore/model_additional_properties_class.go +++ b/samples/client/petstore/go/go-petstore/model_additional_properties_class.go @@ -15,10 +15,10 @@ type AdditionalPropertiesClass struct { MapInteger map[string]int32 `json:"map_integer,omitempty"` MapBoolean map[string]bool `json:"map_boolean,omitempty"` MapArrayInteger map[string][]int32 `json:"map_array_integer,omitempty"` - MapArrayAnytype map[string][]ObjectType `json:"map_array_anytype,omitempty"` + MapArrayAnytype map[string][]map[string]interface{} `json:"map_array_anytype,omitempty"` MapMapString map[string]map[string]string `json:"map_map_string,omitempty"` - MapMapAnytype map[string]map[string]ObjectType `json:"map_map_anytype,omitempty"` - Anytype1 ObjectType `json:"anytype_1,omitempty"` - Anytype2 ObjectType `json:"anytype_2,omitempty"` - Anytype3 ObjectType `json:"anytype_3,omitempty"` + MapMapAnytype map[string]map[string]map[string]interface{} `json:"map_map_anytype,omitempty"` + Anytype1 map[string]interface{} `json:"anytype_1,omitempty"` + Anytype2 map[string]interface{} `json:"anytype_2,omitempty"` + Anytype3 map[string]interface{} `json:"anytype_3,omitempty"` } diff --git a/samples/openapi3/client/petstore/go/go-petstore/docs/NullableClass.md b/samples/openapi3/client/petstore/go/go-petstore/docs/NullableClass.md index 1628c3c91c73..a5758169c98d 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/docs/NullableClass.md +++ b/samples/openapi3/client/petstore/go/go-petstore/docs/NullableClass.md @@ -10,12 +10,12 @@ Name | Type | Description | Notes **StringProp** | Pointer to **string** | | [optional] **DateProp** | Pointer to **string** | | [optional] **DatetimeProp** | Pointer to [**time.Time**](time.Time.md) | | [optional] -**ArrayNullableProp** | Pointer to **[]ObjectType** | | [optional] -**ArrayAndItemsNullableProp** | Pointer to **[]ObjectType** | | [optional] -**ArrayItemsNullable** | **[]ObjectType** | | [optional] -**ObjectNullableProp** | Pointer to **map[string]ObjectType** | | [optional] -**ObjectAndItemsNullableProp** | Pointer to **map[string]ObjectType** | | [optional] -**ObjectItemsNullable** | **map[string]ObjectType** | | [optional] +**ArrayNullableProp** | Pointer to **[]map[string]interface{}** | | [optional] +**ArrayAndItemsNullableProp** | Pointer to **[]map[string]interface{}** | | [optional] +**ArrayItemsNullable** | **[]map[string]interface{}** | | [optional] +**ObjectNullableProp** | Pointer to **map[string]map[string]interface{}** | | [optional] +**ObjectAndItemsNullableProp** | Pointer to **map[string]map[string]interface{}** | | [optional] +**ObjectItemsNullable** | **map[string]map[string]interface{}** | | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_nullable_class.go b/samples/openapi3/client/petstore/go/go-petstore/model_nullable_class.go index 86155d24b797..952129120f9a 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_nullable_class.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_nullable_class.go @@ -19,10 +19,10 @@ type NullableClass struct { StringProp *string `json:"string_prop,omitempty"` DateProp *string `json:"date_prop,omitempty"` DatetimeProp *time.Time `json:"datetime_prop,omitempty"` - ArrayNullableProp *[]ObjectType `json:"array_nullable_prop,omitempty"` - ArrayAndItemsNullableProp *[]ObjectType `json:"array_and_items_nullable_prop,omitempty"` - ArrayItemsNullable []ObjectType `json:"array_items_nullable,omitempty"` - ObjectNullableProp *map[string]ObjectType `json:"object_nullable_prop,omitempty"` - ObjectAndItemsNullableProp *map[string]ObjectType `json:"object_and_items_nullable_prop,omitempty"` - ObjectItemsNullable map[string]ObjectType `json:"object_items_nullable,omitempty"` + ArrayNullableProp *[]map[string]interface{} `json:"array_nullable_prop,omitempty"` + ArrayAndItemsNullableProp *[]map[string]interface{} `json:"array_and_items_nullable_prop,omitempty"` + ArrayItemsNullable []map[string]interface{} `json:"array_items_nullable,omitempty"` + ObjectNullableProp *map[string]map[string]interface{} `json:"object_nullable_prop,omitempty"` + ObjectAndItemsNullableProp *map[string]map[string]interface{} `json:"object_and_items_nullable_prop,omitempty"` + ObjectItemsNullable map[string]map[string]interface{} `json:"object_items_nullable,omitempty"` } From 82cb0e91d3758bc510ca893640eef73d513da796 Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Thu, 7 May 2020 18:31:52 -0700 Subject: [PATCH 41/48] fix unit test issues --- .../python-experimental/model_utils.mustache | 27 ++++++++++++++++--- .../petstore_api/model_utils.py | 27 ++++++++++++++++--- .../petstore/python-experimental/docs/User.md | 8 +++--- .../petstore_api/model_utils.py | 27 ++++++++++++++++--- .../petstore_api/models/user.py | 24 ++++++++--------- .../tests/test_deserialization.py | 7 +++-- 6 files changed, 93 insertions(+), 27 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache b/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache index 70728c8b8f21..c7118043d89c 100644 --- a/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache +++ b/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache @@ -64,9 +64,10 @@ class OpenApiModel(object): # this function uses the discriminator to # pick a new schema/class to instantiate because a discriminator # propertyName value was passed in - oneof_anyof_classes = cls._composed_schemas.get('oneOf', ()) + - cls._composed_schemas.get('anyOf', ()) - if oneof_anyof_classes and none_type in oneof_anyof_classes and args[0] is None: + oneof_anyof_classes = (cls._composed_schemas.get('oneOf', ()) + + cls._composed_schemas.get('anyOf', ())) + if oneof_anyof_classes and none_type in oneof_anyof_classes and \ + len(args) == 1 and args[0] is None: return None visited_composed_classes = kwargs.get('_visited_composed_classes', ()) @@ -1042,6 +1043,16 @@ def get_oneof_instance(self, model_args, constant_args): # Iterate over each oneOf schema and determine if the input data # matches the oneOf schemas. for oneof_class in self._composed_schemas['oneOf']: + # The composed oneOf schema allows the 'null' type and the input data + # is the null value. This is a OAS >= 3.1 feature. + if oneof_class is none_type: + if model_args is None: + return model_args + else: + # Skip to the next oneOf. + # Only the null value matches the null type. + continue + # transform js keys from input data to python keys in fixed_model_args fixed_model_args = change_keys_js_to_python( model_args, oneof_class) @@ -1101,6 +1112,16 @@ def get_anyof_instances(self, model_args, constant_args): return anyof_instances for anyof_class in self._composed_schemas['anyOf']: + # The composed oneOf schema allows the 'null' type and the input data + # is the null value. This is a OAS >= 3.1 feature. + if anyof_class is none_type: + if model_args is None: + return model_args + else: + # Skip to the next oneOf. + # Only the null value matches the null type. + continue + # transform js keys to python keys in fixed_model_args fixed_model_args = change_keys_js_to_python(model_args, anyof_class) diff --git a/samples/client/petstore/python-experimental/petstore_api/model_utils.py b/samples/client/petstore/python-experimental/petstore_api/model_utils.py index 7874c5d3de9b..122d3fadaf2c 100644 --- a/samples/client/petstore/python-experimental/petstore_api/model_utils.py +++ b/samples/client/petstore/python-experimental/petstore_api/model_utils.py @@ -134,9 +134,10 @@ def __new__(cls, *args, **kwargs): # this function uses the discriminator to # pick a new schema/class to instantiate because a discriminator # propertyName value was passed in - oneof_anyof_classes = cls._composed_schemas.get('oneOf', ()) + - cls._composed_schemas.get('anyOf', ()) - if oneof_anyof_classes and none_type in oneof_anyof_classes and args[0] is None: + oneof_anyof_classes = (cls._composed_schemas.get('oneOf', ()) + + cls._composed_schemas.get('anyOf', ())) + if oneof_anyof_classes and none_type in oneof_anyof_classes and \ + len(args) == 1 and args[0] is None: return None visited_composed_classes = kwargs.get('_visited_composed_classes', ()) @@ -1303,6 +1304,16 @@ def get_oneof_instance(self, model_args, constant_args): # Iterate over each oneOf schema and determine if the input data # matches the oneOf schemas. for oneof_class in self._composed_schemas['oneOf']: + # The composed oneOf schema allows the 'null' type and the input data + # is the null value. This is a OAS >= 3.1 feature. + if oneof_class is none_type: + if model_args is None: + return model_args + else: + # Skip to the next oneOf. + # Only the null value matches the null type. + continue + # transform js keys from input data to python keys in fixed_model_args fixed_model_args = change_keys_js_to_python( model_args, oneof_class) @@ -1362,6 +1373,16 @@ def get_anyof_instances(self, model_args, constant_args): return anyof_instances for anyof_class in self._composed_schemas['anyOf']: + # The composed oneOf schema allows the 'null' type and the input data + # is the null value. This is a OAS >= 3.1 feature. + if anyof_class is none_type: + if model_args is None: + return model_args + else: + # Skip to the next oneOf. + # Only the null value matches the null type. + continue + # transform js keys to python keys in fixed_model_args fixed_model_args = change_keys_js_to_python(model_args, anyof_class) diff --git a/samples/openapi3/client/petstore/python-experimental/docs/User.md b/samples/openapi3/client/petstore/python-experimental/docs/User.md index 3e15df53f8fa..e0591f2fb222 100644 --- a/samples/openapi3/client/petstore/python-experimental/docs/User.md +++ b/samples/openapi3/client/petstore/python-experimental/docs/User.md @@ -11,10 +11,10 @@ Name | Type | Description | Notes **password** | **str** | | [optional] **phone** | **str** | | [optional] **user_status** | **int** | User Status | [optional] -**arbitrary_object** | **bool, date, datetime, dict, float, int, list, str** | test code generation for objects Value must be a map of strings to values. It cannot be the 'null' value. | [optional] -**arbitrary_nullable_object** | **bool, date, datetime, dict, float, int, list, str, none_type** | test code generation for nullable objects. Value must be a map of strings to values or the 'null' value. | [optional] -**arbitrary_type_value** | **object** | test code generation for any type Value can be any type - string, number, boolean, array or object. | [optional] -**arbitrary_nullable_type_value** | **object, none_type** | test code generation for any type Value can be any type - string, number, boolean, array, object or the 'null' value. | [optional] +**object_with_no_declared_props** | **bool, date, datetime, dict, float, int, list, str** | test code generation for objects Value must be a map of strings to values. It cannot be the 'null' value. | [optional] +**object_with_no_declared_props_nullable** | **bool, date, datetime, dict, float, int, list, str, none_type** | test code generation for nullable objects. Value must be a map of strings to values or the 'null' value. | [optional] +**any_type_prop** | **object** | test code generation for any type Here the 'type' attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. See https://github.com/OAI/OpenAPI-Specification/issues/1389 | [optional] +**any_type_prop_nullable** | **object, none_type** | test code generation for any type Here the 'type' attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. The 'nullable' attribute does not change the allowed values. | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py index 7874c5d3de9b..122d3fadaf2c 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py @@ -134,9 +134,10 @@ def __new__(cls, *args, **kwargs): # this function uses the discriminator to # pick a new schema/class to instantiate because a discriminator # propertyName value was passed in - oneof_anyof_classes = cls._composed_schemas.get('oneOf', ()) + - cls._composed_schemas.get('anyOf', ()) - if oneof_anyof_classes and none_type in oneof_anyof_classes and args[0] is None: + oneof_anyof_classes = (cls._composed_schemas.get('oneOf', ()) + + cls._composed_schemas.get('anyOf', ())) + if oneof_anyof_classes and none_type in oneof_anyof_classes and \ + len(args) == 1 and args[0] is None: return None visited_composed_classes = kwargs.get('_visited_composed_classes', ()) @@ -1303,6 +1304,16 @@ def get_oneof_instance(self, model_args, constant_args): # Iterate over each oneOf schema and determine if the input data # matches the oneOf schemas. for oneof_class in self._composed_schemas['oneOf']: + # The composed oneOf schema allows the 'null' type and the input data + # is the null value. This is a OAS >= 3.1 feature. + if oneof_class is none_type: + if model_args is None: + return model_args + else: + # Skip to the next oneOf. + # Only the null value matches the null type. + continue + # transform js keys from input data to python keys in fixed_model_args fixed_model_args = change_keys_js_to_python( model_args, oneof_class) @@ -1362,6 +1373,16 @@ def get_anyof_instances(self, model_args, constant_args): return anyof_instances for anyof_class in self._composed_schemas['anyOf']: + # The composed oneOf schema allows the 'null' type and the input data + # is the null value. This is a OAS >= 3.1 feature. + if anyof_class is none_type: + if model_args is None: + return model_args + else: + # Skip to the next oneOf. + # Only the null value matches the null type. + continue + # transform js keys to python keys in fixed_model_args fixed_model_args = change_keys_js_to_python(model_args, anyof_class) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/user.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/user.py index 7a571040a2fa..a88a46b49a67 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/user.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/user.py @@ -85,10 +85,10 @@ def openapi_types(): 'password': (str,), # noqa: E501 'phone': (str,), # noqa: E501 'user_status': (int,), # noqa: E501 - 'arbitrary_object': (bool, date, datetime, dict, float, int, list, str,), # noqa: E501 - 'arbitrary_nullable_object': (bool, date, datetime, dict, float, int, list, str, none_type,), # noqa: E501 - 'arbitrary_type_value': (object,), # noqa: E501 - 'arbitrary_nullable_type_value': (object, none_type,), # noqa: E501 + 'object_with_no_declared_props': (bool, date, datetime, dict, float, int, list, str,), # noqa: E501 + 'object_with_no_declared_props_nullable': (bool, date, datetime, dict, float, int, list, str, none_type,), # noqa: E501 + 'any_type_prop': (object,), # noqa: E501 + 'any_type_prop_nullable': (object, none_type,), # noqa: E501 } @cached_property @@ -104,10 +104,10 @@ def discriminator(): 'password': 'password', # noqa: E501 'phone': 'phone', # noqa: E501 'user_status': 'userStatus', # noqa: E501 - 'arbitrary_object': 'arbitraryObject', # noqa: E501 - 'arbitrary_nullable_object': 'arbitraryNullableObject', # noqa: E501 - 'arbitrary_type_value': 'arbitraryTypeValue', # noqa: E501 - 'arbitrary_nullable_type_value': 'arbitraryNullableTypeValue', # noqa: E501 + 'object_with_no_declared_props': 'objectWithNoDeclaredProps', # noqa: E501 + 'object_with_no_declared_props_nullable': 'objectWithNoDeclaredPropsNullable', # noqa: E501 + 'any_type_prop': 'anyTypeProp', # noqa: E501 + 'any_type_prop_nullable': 'anyTypePropNullable', # noqa: E501 } _composed_schemas = {} @@ -162,10 +162,10 @@ def __init__(self, _check_type=True, _from_server=False, _path_to_item=(), _conf password (str): [optional] # noqa: E501 phone (str): [optional] # noqa: E501 user_status (int): User Status. [optional] # noqa: E501 - arbitrary_object (bool, date, datetime, dict, float, int, list, str): test code generation for objects Value must be a map of strings to values. It cannot be the 'null' value.. [optional] # noqa: E501 - arbitrary_nullable_object (bool, date, datetime, dict, float, int, list, str, none_type): test code generation for nullable objects. Value must be a map of strings to values or the 'null' value.. [optional] # noqa: E501 - arbitrary_type_value (object): test code generation for any type Value can be any type - string, number, boolean, array or object.. [optional] # noqa: E501 - arbitrary_nullable_type_value (object, none_type): test code generation for any type Value can be any type - string, number, boolean, array, object or the 'null' value.. [optional] # noqa: E501 + object_with_no_declared_props (bool, date, datetime, dict, float, int, list, str): test code generation for objects Value must be a map of strings to values. It cannot be the 'null' value.. [optional] # noqa: E501 + object_with_no_declared_props_nullable (bool, date, datetime, dict, float, int, list, str, none_type): test code generation for nullable objects. Value must be a map of strings to values or the 'null' value.. [optional] # noqa: E501 + any_type_prop (object): test code generation for any type Here the 'type' attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. See https://github.com/OAI/OpenAPI-Specification/issues/1389. [optional] # noqa: E501 + any_type_prop_nullable (object, none_type): test code generation for any type Here the 'type' attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. The 'nullable' attribute does not change the allowed values.. [optional] # noqa: E501 """ self._data_store = {} diff --git a/samples/openapi3/client/petstore/python-experimental/tests/test_deserialization.py b/samples/openapi3/client/petstore/python-experimental/tests/test_deserialization.py index 6ee87a7e6612..944349054243 100644 --- a/samples/openapi3/client/petstore/python-experimental/tests/test_deserialization.py +++ b/samples/openapi3/client/petstore/python-experimental/tests/test_deserialization.py @@ -127,9 +127,9 @@ def test_deserialize_mammal(self): self.assertEqual(deserialized.type, zebra_type) self.assertEqual(deserialized.class_name, class_name) - def test_deserialize_fruit(self): + def test_deserialize_fruit_null_value(self): """ - deserialize fruit + deserialize fruit with null value. fruitReq is a oneOf composed schema model with discriminator, including 'null' type. """ @@ -138,3 +138,6 @@ def test_deserialize_fruit(self): response = MockResponse(data=json.dumps(data)) deserialized = self.deserialize(response, (petstore_api.FruitReq, type(None)), True) self.assertEqual(type(deserialized), type(None)) + + inst = petstore_api.FruitReq(None) + self.assertIsNone(inst) From 2c5c1cf3b7566990a388ac13266a1eea86c40e81 Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Thu, 7 May 2020 18:53:50 -0700 Subject: [PATCH 42/48] Handle none type --- .../python-experimental/model_utils.mustache | 18 ++++++------------ .../petstore_api/model_utils.py | 18 ++++++------------ .../petstore_api/model_utils.py | 18 ++++++------------ 3 files changed, 18 insertions(+), 36 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache b/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache index c7118043d89c..4eddc80def49 100644 --- a/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache +++ b/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache @@ -1046,12 +1046,9 @@ def get_oneof_instance(self, model_args, constant_args): # The composed oneOf schema allows the 'null' type and the input data # is the null value. This is a OAS >= 3.1 feature. if oneof_class is none_type: - if model_args is None: - return model_args - else: - # Skip to the next oneOf. - # Only the null value matches the null type. - continue + # skip none_types because we are deserializing dict data. + # none_type deserialization is handled in the __new__ method + continue # transform js keys from input data to python keys in fixed_model_args fixed_model_args = change_keys_js_to_python( @@ -1115,12 +1112,9 @@ def get_anyof_instances(self, model_args, constant_args): # The composed oneOf schema allows the 'null' type and the input data # is the null value. This is a OAS >= 3.1 feature. if anyof_class is none_type: - if model_args is None: - return model_args - else: - # Skip to the next oneOf. - # Only the null value matches the null type. - continue + # skip none_types because we are deserializing dict data. + # none_type deserialization is handled in the __new__ method + continue # transform js keys to python keys in fixed_model_args fixed_model_args = change_keys_js_to_python(model_args, anyof_class) diff --git a/samples/client/petstore/python-experimental/petstore_api/model_utils.py b/samples/client/petstore/python-experimental/petstore_api/model_utils.py index 122d3fadaf2c..f29f2437a7ee 100644 --- a/samples/client/petstore/python-experimental/petstore_api/model_utils.py +++ b/samples/client/petstore/python-experimental/petstore_api/model_utils.py @@ -1307,12 +1307,9 @@ def get_oneof_instance(self, model_args, constant_args): # The composed oneOf schema allows the 'null' type and the input data # is the null value. This is a OAS >= 3.1 feature. if oneof_class is none_type: - if model_args is None: - return model_args - else: - # Skip to the next oneOf. - # Only the null value matches the null type. - continue + # skip none_types because we are deserializing dict data. + # none_type deserialization is handled in the __new__ method + continue # transform js keys from input data to python keys in fixed_model_args fixed_model_args = change_keys_js_to_python( @@ -1376,12 +1373,9 @@ def get_anyof_instances(self, model_args, constant_args): # The composed oneOf schema allows the 'null' type and the input data # is the null value. This is a OAS >= 3.1 feature. if anyof_class is none_type: - if model_args is None: - return model_args - else: - # Skip to the next oneOf. - # Only the null value matches the null type. - continue + # skip none_types because we are deserializing dict data. + # none_type deserialization is handled in the __new__ method + continue # transform js keys to python keys in fixed_model_args fixed_model_args = change_keys_js_to_python(model_args, anyof_class) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py index 122d3fadaf2c..f29f2437a7ee 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py @@ -1307,12 +1307,9 @@ def get_oneof_instance(self, model_args, constant_args): # The composed oneOf schema allows the 'null' type and the input data # is the null value. This is a OAS >= 3.1 feature. if oneof_class is none_type: - if model_args is None: - return model_args - else: - # Skip to the next oneOf. - # Only the null value matches the null type. - continue + # skip none_types because we are deserializing dict data. + # none_type deserialization is handled in the __new__ method + continue # transform js keys from input data to python keys in fixed_model_args fixed_model_args = change_keys_js_to_python( @@ -1376,12 +1373,9 @@ def get_anyof_instances(self, model_args, constant_args): # The composed oneOf schema allows the 'null' type and the input data # is the null value. This is a OAS >= 3.1 feature. if anyof_class is none_type: - if model_args is None: - return model_args - else: - # Skip to the next oneOf. - # Only the null value matches the null type. - continue + # skip none_types because we are deserializing dict data. + # none_type deserialization is handled in the __new__ method + continue # transform js keys to python keys in fixed_model_args fixed_model_args = change_keys_js_to_python(model_args, anyof_class) From f275dc92a15675738fecef4f34c999e1bfd58dca Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Fri, 8 May 2020 12:32:12 -0700 Subject: [PATCH 43/48] Fix index out of range exception --- .../python/python-experimental/model_utils.mustache | 10 ++++++++-- .../python-experimental/petstore_api/model_utils.py | 10 ++++++++-- .../python-experimental/petstore_api/model_utils.py | 10 ++++++++-- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache b/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache index 4eddc80def49..c8ba4d582e1b 100644 --- a/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache +++ b/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache @@ -64,10 +64,16 @@ class OpenApiModel(object): # this function uses the discriminator to # pick a new schema/class to instantiate because a discriminator # propertyName value was passed in - oneof_anyof_classes = (cls._composed_schemas.get('oneOf', ()) + - cls._composed_schemas.get('anyOf', ())) + + # Build a list containing all oneOf and anyOf descendants. + oneof_anyof_classes = None + if cls._composed_schemas is not None: + oneof_anyof_classes = (cls._composed_schemas.get('oneOf', ()) + + cls._composed_schemas.get('anyOf', ())) if oneof_anyof_classes and none_type in oneof_anyof_classes and \ len(args) == 1 and args[0] is None: + # The input data is the 'null' value AND one of the oneOf/anyOf children + # is the 'null' type (which is introduced in OAS schema >= 3.1). return None visited_composed_classes = kwargs.get('_visited_composed_classes', ()) diff --git a/samples/client/petstore/python-experimental/petstore_api/model_utils.py b/samples/client/petstore/python-experimental/petstore_api/model_utils.py index f29f2437a7ee..ce2ea3aeb580 100644 --- a/samples/client/petstore/python-experimental/petstore_api/model_utils.py +++ b/samples/client/petstore/python-experimental/petstore_api/model_utils.py @@ -134,10 +134,16 @@ def __new__(cls, *args, **kwargs): # this function uses the discriminator to # pick a new schema/class to instantiate because a discriminator # propertyName value was passed in - oneof_anyof_classes = (cls._composed_schemas.get('oneOf', ()) + - cls._composed_schemas.get('anyOf', ())) + + # Build a list containing all oneOf and anyOf descendants. + oneof_anyof_classes = None + if cls._composed_schemas is not None: + oneof_anyof_classes = (cls._composed_schemas.get('oneOf', ()) + + cls._composed_schemas.get('anyOf', ())) if oneof_anyof_classes and none_type in oneof_anyof_classes and \ len(args) == 1 and args[0] is None: + # The input data is the 'null' value AND one of the oneOf/anyOf children + # is the 'null' type (which is introduced in OAS schema >= 3.1). return None visited_composed_classes = kwargs.get('_visited_composed_classes', ()) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py index f29f2437a7ee..ce2ea3aeb580 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py @@ -134,10 +134,16 @@ def __new__(cls, *args, **kwargs): # this function uses the discriminator to # pick a new schema/class to instantiate because a discriminator # propertyName value was passed in - oneof_anyof_classes = (cls._composed_schemas.get('oneOf', ()) + - cls._composed_schemas.get('anyOf', ())) + + # Build a list containing all oneOf and anyOf descendants. + oneof_anyof_classes = None + if cls._composed_schemas is not None: + oneof_anyof_classes = (cls._composed_schemas.get('oneOf', ()) + + cls._composed_schemas.get('anyOf', ())) if oneof_anyof_classes and none_type in oneof_anyof_classes and \ len(args) == 1 and args[0] is None: + # The input data is the 'null' value AND one of the oneOf/anyOf children + # is the 'null' type (which is introduced in OAS schema >= 3.1). return None visited_composed_classes = kwargs.get('_visited_composed_classes', ()) From 93cc8c8053d4d817274547187434c4be2f8ce535 Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Fri, 8 May 2020 12:38:17 -0700 Subject: [PATCH 44/48] fix formatting issues --- .../resources/python/python-experimental/model_utils.mustache | 4 ++-- .../petstore/python-experimental/petstore_api/model_utils.py | 4 ++-- .../petstore/python-experimental/petstore_api/model_utils.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache b/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache index c8ba4d582e1b..c684cba83b39 100644 --- a/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache +++ b/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache @@ -70,8 +70,8 @@ class OpenApiModel(object): if cls._composed_schemas is not None: oneof_anyof_classes = (cls._composed_schemas.get('oneOf', ()) + cls._composed_schemas.get('anyOf', ())) - if oneof_anyof_classes and none_type in oneof_anyof_classes and \ - len(args) == 1 and args[0] is None: + if (oneof_anyof_classes and none_type in oneof_anyof_classes and + len(args) == 1 and args[0] is None): # The input data is the 'null' value AND one of the oneOf/anyOf children # is the 'null' type (which is introduced in OAS schema >= 3.1). return None diff --git a/samples/client/petstore/python-experimental/petstore_api/model_utils.py b/samples/client/petstore/python-experimental/petstore_api/model_utils.py index ce2ea3aeb580..95d3ea920ad8 100644 --- a/samples/client/petstore/python-experimental/petstore_api/model_utils.py +++ b/samples/client/petstore/python-experimental/petstore_api/model_utils.py @@ -140,8 +140,8 @@ def __new__(cls, *args, **kwargs): if cls._composed_schemas is not None: oneof_anyof_classes = (cls._composed_schemas.get('oneOf', ()) + cls._composed_schemas.get('anyOf', ())) - if oneof_anyof_classes and none_type in oneof_anyof_classes and \ - len(args) == 1 and args[0] is None: + if (oneof_anyof_classes and none_type in oneof_anyof_classes and + len(args) == 1 and args[0] is None): # The input data is the 'null' value AND one of the oneOf/anyOf children # is the 'null' type (which is introduced in OAS schema >= 3.1). return None diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py index ce2ea3aeb580..95d3ea920ad8 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py @@ -140,8 +140,8 @@ def __new__(cls, *args, **kwargs): if cls._composed_schemas is not None: oneof_anyof_classes = (cls._composed_schemas.get('oneOf', ()) + cls._composed_schemas.get('anyOf', ())) - if oneof_anyof_classes and none_type in oneof_anyof_classes and \ - len(args) == 1 and args[0] is None: + if (oneof_anyof_classes and none_type in oneof_anyof_classes and + len(args) == 1 and args[0] is None): # The input data is the 'null' value AND one of the oneOf/anyOf children # is the 'null' type (which is introduced in OAS schema >= 3.1). return None From 69396481c6d94787ac94955b0a9fe0a366b3d648 Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Fri, 8 May 2020 13:40:04 -0700 Subject: [PATCH 45/48] fix formatting issues --- .../resources/python/python-experimental/model_utils.mustache | 2 +- .../petstore/python-experimental/petstore_api/model_utils.py | 2 +- .../petstore/python-experimental/petstore_api/model_utils.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache b/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache index c684cba83b39..1cf04a144a0f 100644 --- a/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache +++ b/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache @@ -69,7 +69,7 @@ class OpenApiModel(object): oneof_anyof_classes = None if cls._composed_schemas is not None: oneof_anyof_classes = (cls._composed_schemas.get('oneOf', ()) + - cls._composed_schemas.get('anyOf', ())) + cls._composed_schemas.get('anyOf', ())) if (oneof_anyof_classes and none_type in oneof_anyof_classes and len(args) == 1 and args[0] is None): # The input data is the 'null' value AND one of the oneOf/anyOf children diff --git a/samples/client/petstore/python-experimental/petstore_api/model_utils.py b/samples/client/petstore/python-experimental/petstore_api/model_utils.py index 95d3ea920ad8..686f8da05109 100644 --- a/samples/client/petstore/python-experimental/petstore_api/model_utils.py +++ b/samples/client/petstore/python-experimental/petstore_api/model_utils.py @@ -139,7 +139,7 @@ def __new__(cls, *args, **kwargs): oneof_anyof_classes = None if cls._composed_schemas is not None: oneof_anyof_classes = (cls._composed_schemas.get('oneOf', ()) + - cls._composed_schemas.get('anyOf', ())) + cls._composed_schemas.get('anyOf', ())) if (oneof_anyof_classes and none_type in oneof_anyof_classes and len(args) == 1 and args[0] is None): # The input data is the 'null' value AND one of the oneOf/anyOf children diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py index 95d3ea920ad8..686f8da05109 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py @@ -139,7 +139,7 @@ def __new__(cls, *args, **kwargs): oneof_anyof_classes = None if cls._composed_schemas is not None: oneof_anyof_classes = (cls._composed_schemas.get('oneOf', ()) + - cls._composed_schemas.get('anyOf', ())) + cls._composed_schemas.get('anyOf', ())) if (oneof_anyof_classes and none_type in oneof_anyof_classes and len(args) == 1 and args[0] is None): # The input data is the 'null' value AND one of the oneOf/anyOf children From 8bdca05fa36a0811d01c9e1c3c8b86847fcd2b76 Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Fri, 8 May 2020 14:43:51 -0700 Subject: [PATCH 46/48] fix formatting issues. Finally figured out how to check formatting in local workspace --- .../resources/python/python-experimental/model_utils.mustache | 3 ++- .../petstore/python-experimental/petstore_api/model_utils.py | 3 ++- .../petstore/python-experimental/petstore_api/model_utils.py | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache b/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache index 1cf04a144a0f..7d25bc13f6dc 100644 --- a/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache +++ b/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache @@ -68,7 +68,8 @@ class OpenApiModel(object): # Build a list containing all oneOf and anyOf descendants. oneof_anyof_classes = None if cls._composed_schemas is not None: - oneof_anyof_classes = (cls._composed_schemas.get('oneOf', ()) + + oneof_anyof_classes = ( + cls._composed_schemas.get('oneOf', ()) + cls._composed_schemas.get('anyOf', ())) if (oneof_anyof_classes and none_type in oneof_anyof_classes and len(args) == 1 and args[0] is None): diff --git a/samples/client/petstore/python-experimental/petstore_api/model_utils.py b/samples/client/petstore/python-experimental/petstore_api/model_utils.py index 686f8da05109..7718d1372740 100644 --- a/samples/client/petstore/python-experimental/petstore_api/model_utils.py +++ b/samples/client/petstore/python-experimental/petstore_api/model_utils.py @@ -138,7 +138,8 @@ def __new__(cls, *args, **kwargs): # Build a list containing all oneOf and anyOf descendants. oneof_anyof_classes = None if cls._composed_schemas is not None: - oneof_anyof_classes = (cls._composed_schemas.get('oneOf', ()) + + oneof_anyof_classes = ( + cls._composed_schemas.get('oneOf', ()) + cls._composed_schemas.get('anyOf', ())) if (oneof_anyof_classes and none_type in oneof_anyof_classes and len(args) == 1 and args[0] is None): diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py index 686f8da05109..7718d1372740 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py @@ -138,7 +138,8 @@ def __new__(cls, *args, **kwargs): # Build a list containing all oneOf and anyOf descendants. oneof_anyof_classes = None if cls._composed_schemas is not None: - oneof_anyof_classes = (cls._composed_schemas.get('oneOf', ()) + + oneof_anyof_classes = ( + cls._composed_schemas.get('oneOf', ()) + cls._composed_schemas.get('anyOf', ())) if (oneof_anyof_classes and none_type in oneof_anyof_classes and len(args) == 1 and args[0] is None): From 4c0134444b8d81e908c9e4d366b32f1e2864b7ad Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Fri, 8 May 2020 15:48:34 -0700 Subject: [PATCH 47/48] fix formatting issues --- .../resources/python/python-experimental/model_utils.mustache | 4 ++-- .../petstore/python-experimental/petstore_api/model_utils.py | 4 ++-- .../petstore/python-experimental/petstore_api/model_utils.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache b/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache index 7d25bc13f6dc..49a83a2a358a 100644 --- a/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache +++ b/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache @@ -1055,7 +1055,7 @@ def get_oneof_instance(self, model_args, constant_args): if oneof_class is none_type: # skip none_types because we are deserializing dict data. # none_type deserialization is handled in the __new__ method - continue + continue # transform js keys from input data to python keys in fixed_model_args fixed_model_args = change_keys_js_to_python( @@ -1121,7 +1121,7 @@ def get_anyof_instances(self, model_args, constant_args): if anyof_class is none_type: # skip none_types because we are deserializing dict data. # none_type deserialization is handled in the __new__ method - continue + continue # transform js keys to python keys in fixed_model_args fixed_model_args = change_keys_js_to_python(model_args, anyof_class) diff --git a/samples/client/petstore/python-experimental/petstore_api/model_utils.py b/samples/client/petstore/python-experimental/petstore_api/model_utils.py index 7718d1372740..b8a026ef575a 100644 --- a/samples/client/petstore/python-experimental/petstore_api/model_utils.py +++ b/samples/client/petstore/python-experimental/petstore_api/model_utils.py @@ -1316,7 +1316,7 @@ def get_oneof_instance(self, model_args, constant_args): if oneof_class is none_type: # skip none_types because we are deserializing dict data. # none_type deserialization is handled in the __new__ method - continue + continue # transform js keys from input data to python keys in fixed_model_args fixed_model_args = change_keys_js_to_python( @@ -1382,7 +1382,7 @@ def get_anyof_instances(self, model_args, constant_args): if anyof_class is none_type: # skip none_types because we are deserializing dict data. # none_type deserialization is handled in the __new__ method - continue + continue # transform js keys to python keys in fixed_model_args fixed_model_args = change_keys_js_to_python(model_args, anyof_class) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py index 7718d1372740..b8a026ef575a 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py @@ -1316,7 +1316,7 @@ def get_oneof_instance(self, model_args, constant_args): if oneof_class is none_type: # skip none_types because we are deserializing dict data. # none_type deserialization is handled in the __new__ method - continue + continue # transform js keys from input data to python keys in fixed_model_args fixed_model_args = change_keys_js_to_python( @@ -1382,7 +1382,7 @@ def get_anyof_instances(self, model_args, constant_args): if anyof_class is none_type: # skip none_types because we are deserializing dict data. # none_type deserialization is handled in the __new__ method - continue + continue # transform js keys to python keys in fixed_model_args fixed_model_args = change_keys_js_to_python(model_args, anyof_class) From 5e48c724f2ddf5fb14b8a4772c53f67199c300a4 Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Tue, 12 May 2020 11:20:34 -0700 Subject: [PATCH 48/48] run samples scripts --- .../client/petstore/python-experimental/docs/User.md | 4 ++-- .../python-experimental/petstore_api/models/user.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/samples/openapi3/client/petstore/python-experimental/docs/User.md b/samples/openapi3/client/petstore/python-experimental/docs/User.md index e0591f2fb222..2d9e43b532c2 100644 --- a/samples/openapi3/client/petstore/python-experimental/docs/User.md +++ b/samples/openapi3/client/petstore/python-experimental/docs/User.md @@ -13,8 +13,8 @@ Name | Type | Description | Notes **user_status** | **int** | User Status | [optional] **object_with_no_declared_props** | **bool, date, datetime, dict, float, int, list, str** | test code generation for objects Value must be a map of strings to values. It cannot be the 'null' value. | [optional] **object_with_no_declared_props_nullable** | **bool, date, datetime, dict, float, int, list, str, none_type** | test code generation for nullable objects. Value must be a map of strings to values or the 'null' value. | [optional] -**any_type_prop** | **object** | test code generation for any type Here the 'type' attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. See https://github.com/OAI/OpenAPI-Specification/issues/1389 | [optional] -**any_type_prop_nullable** | **object, none_type** | test code generation for any type Here the 'type' attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. The 'nullable' attribute does not change the allowed values. | [optional] +**any_type_prop** | **bool, date, datetime, dict, float, int, list, str, none_type** | test code generation for any type Here the 'type' attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. See https://github.com/OAI/OpenAPI-Specification/issues/1389 | [optional] +**any_type_prop_nullable** | **bool, date, datetime, dict, float, int, list, str, none_type** | test code generation for any type Here the 'type' attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. The 'nullable' attribute does not change the allowed values. | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/user.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/user.py index a88a46b49a67..b8d64ff38c3a 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/user.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/user.py @@ -87,8 +87,8 @@ def openapi_types(): 'user_status': (int,), # noqa: E501 'object_with_no_declared_props': (bool, date, datetime, dict, float, int, list, str,), # noqa: E501 'object_with_no_declared_props_nullable': (bool, date, datetime, dict, float, int, list, str, none_type,), # noqa: E501 - 'any_type_prop': (object,), # noqa: E501 - 'any_type_prop_nullable': (object, none_type,), # noqa: E501 + 'any_type_prop': (bool, date, datetime, dict, float, int, list, str, none_type,), # noqa: E501 + 'any_type_prop_nullable': (bool, date, datetime, dict, float, int, list, str, none_type,), # noqa: E501 } @cached_property @@ -164,8 +164,8 @@ def __init__(self, _check_type=True, _from_server=False, _path_to_item=(), _conf user_status (int): User Status. [optional] # noqa: E501 object_with_no_declared_props (bool, date, datetime, dict, float, int, list, str): test code generation for objects Value must be a map of strings to values. It cannot be the 'null' value.. [optional] # noqa: E501 object_with_no_declared_props_nullable (bool, date, datetime, dict, float, int, list, str, none_type): test code generation for nullable objects. Value must be a map of strings to values or the 'null' value.. [optional] # noqa: E501 - any_type_prop (object): test code generation for any type Here the 'type' attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. See https://github.com/OAI/OpenAPI-Specification/issues/1389. [optional] # noqa: E501 - any_type_prop_nullable (object, none_type): test code generation for any type Here the 'type' attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. The 'nullable' attribute does not change the allowed values.. [optional] # noqa: E501 + any_type_prop (bool, date, datetime, dict, float, int, list, str, none_type): test code generation for any type Here the 'type' attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. See https://github.com/OAI/OpenAPI-Specification/issues/1389. [optional] # noqa: E501 + any_type_prop_nullable (bool, date, datetime, dict, float, int, list, str, none_type): test code generation for any type Here the 'type' attribute is not specified, which means the value can be anything, including the null value, string, number, boolean, array or object. The 'nullable' attribute does not change the allowed values.. [optional] # noqa: E501 """ self._data_store = {}