From 4487042f0d4ef1f4686950f0c1ddac6fe6d44f98 Mon Sep 17 00:00:00 2001 From: Vittorio Parrella <93098480+parvit@users.noreply.github.com> Date: Sun, 20 Nov 2022 02:09:33 -0500 Subject: [PATCH] Issue 11401 - report correctly the parameters with the deep object specification (#13909) * issue #11401 - Go client generator doesn't support deepObject in query * samples generation * fix generation * fix generation * generated samples # Conflicts: # samples/client/petstore/go/go-petstore/model_200_response.go # samples/client/petstore/go/go-petstore/model_additional_properties_any_type.go # samples/client/petstore/go/go-petstore/model_client.go * Fixed unit tests * revert to http connection for tests * fix model_simple generation * Fix parameter encoding issue * simplified routine * fix test url * adapted for latest master, necessary generation * samples generation * sync with new master, regenerate samples * added api client test --- .../src/main/resources/go/api.mustache | 22 +- .../src/main/resources/go/client.mustache | 121 +++++++++-- .../main/resources/go/model_simple.mustache | 47 +++-- .../src/main/resources/go/utils.mustache | 4 + ...odels-for-testing-with-http-signature.yaml | 25 ++- .../petstore/go/go-petstore/api_fake.go | 72 +++---- .../client/petstore/go/go-petstore/api_pet.go | 24 +-- .../petstore/go/go-petstore/api_store.go | 4 +- .../petstore/go/go-petstore/api_user.go | 10 +- .../client/petstore/go/go-petstore/client.go | 121 +++++++++-- .../go/go-petstore/model_200_response.go | 13 +- .../model_additional_properties_any_type.go | 13 +- .../model_additional_properties_array.go | 13 +- .../model_additional_properties_boolean.go | 13 +- .../model_additional_properties_class.go | 13 +- .../model_additional_properties_integer.go | 13 +- .../model_additional_properties_number.go | 13 +- .../model_additional_properties_object.go | 13 +- .../model_additional_properties_string.go | 13 +- .../petstore/go/go-petstore/model_animal.go | 17 +- .../go/go-petstore/model_api_response.go | 13 +- .../model_array_of_array_of_number_only.go | 13 +- .../go-petstore/model_array_of_number_only.go | 13 +- .../go/go-petstore/model_array_test_.go | 13 +- .../petstore/go/go-petstore/model_big_cat.go | 17 +- .../go/go-petstore/model_big_cat_all_of.go | 13 +- .../go/go-petstore/model_capitalization.go | 13 +- .../petstore/go/go-petstore/model_cat.go | 17 +- .../go/go-petstore/model_cat_all_of.go | 13 +- .../petstore/go/go-petstore/model_category.go | 17 +- .../go/go-petstore/model_class_model.go | 13 +- .../petstore/go/go-petstore/model_client.go | 13 +- .../petstore/go/go-petstore/model_dog.go | 17 +- .../go/go-petstore/model_dog_all_of.go | 13 +- .../go/go-petstore/model_enum_arrays.go | 13 +- .../go/go-petstore/model_enum_test_.go | 17 +- .../petstore/go/go-petstore/model_file.go | 13 +- .../model_file_schema_test_class.go | 13 +- .../go/go-petstore/model_format_test_.go | 29 +-- .../go-petstore/model_has_only_read_only.go | 13 +- .../petstore/go/go-petstore/model_list.go | 13 +- .../go/go-petstore/model_map_test_.go | 13 +- ...perties_and_additional_properties_class.go | 13 +- .../petstore/go/go-petstore/model_name.go | 17 +- .../go/go-petstore/model_number_only.go | 13 +- .../petstore/go/go-petstore/model_order.go | 13 +- .../go/go-petstore/model_outer_composite.go | 13 +- .../petstore/go/go-petstore/model_pet.go | 21 +- .../go/go-petstore/model_read_only_first.go | 13 +- .../petstore/go/go-petstore/model_return.go | 13 +- .../go-petstore/model_special_model_name.go | 13 +- .../petstore/go/go-petstore/model_tag.go | 13 +- .../go-petstore/model_type_holder_default.go | 31 +-- .../go-petstore/model_type_holder_example.go | 35 ++- .../petstore/go/go-petstore/model_user.go | 13 +- .../petstore/go/go-petstore/model_xml_item.go | 13 +- .../client/petstore/go/go-petstore/utils.go | 4 + samples/client/petstore/go/pet_api_test.go | 2 +- samples/client/petstore/go/store_api_test.go | 2 +- .../x-auth-id-alias/go-experimental/client.go | 121 +++++++++-- .../x-auth-id-alias/go-experimental/utils.go | 4 + .../client/petstore/go/fake_api_test.go | 52 +++++ .../client/petstore/go/go-petstore/README.md | 1 + .../petstore/go/go-petstore/api/openapi.yaml | 25 ++- .../petstore/go/go-petstore/api_fake.go | 199 ++++++++++++++---- .../client/petstore/go/go-petstore/api_pet.go | 24 +-- .../petstore/go/go-petstore/api_store.go | 4 +- .../petstore/go/go-petstore/api_user.go | 10 +- .../client/petstore/go/go-petstore/client.go | 121 +++++++++-- .../petstore/go/go-petstore/docs/FakeApi.md | 67 +++++- .../go/go-petstore/model_200_response.go | 13 +- .../model__foo_get_default_response.go | 13 +- .../go-petstore/model__special_model_name_.go | 13 +- .../model_additional_properties_class.go | 13 +- .../petstore/go/go-petstore/model_animal.go | 17 +- .../go/go-petstore/model_api_response.go | 13 +- .../petstore/go/go-petstore/model_apple.go | 13 +- .../go/go-petstore/model_apple_req.go | 17 +- .../model_array_of_array_of_number_only.go | 13 +- .../go-petstore/model_array_of_number_only.go | 13 +- .../go/go-petstore/model_array_test_.go | 13 +- .../petstore/go/go-petstore/model_banana.go | 13 +- .../go/go-petstore/model_banana_req.go | 17 +- .../go/go-petstore/model_capitalization.go | 13 +- .../petstore/go/go-petstore/model_cat.go | 17 +- .../go/go-petstore/model_cat_all_of.go | 13 +- .../petstore/go/go-petstore/model_category.go | 17 +- .../go/go-petstore/model_class_model.go | 13 +- .../petstore/go/go-petstore/model_client.go | 13 +- .../petstore/go/go-petstore/model_dog.go | 17 +- .../go/go-petstore/model_dog_all_of.go | 13 +- .../model_duplicated_prop_child.go | 17 +- .../model_duplicated_prop_child_all_of.go | 13 +- .../model_duplicated_prop_parent.go | 17 +- .../go/go-petstore/model_enum_arrays.go | 13 +- .../go/go-petstore/model_enum_test_.go | 17 +- .../petstore/go/go-petstore/model_file.go | 13 +- .../model_file_schema_test_class.go | 13 +- .../petstore/go/go-petstore/model_foo.go | 13 +- .../go/go-petstore/model_format_test_.go | 29 +-- .../go-petstore/model_has_only_read_only.go | 13 +- .../go-petstore/model_health_check_result.go | 13 +- .../petstore/go/go-petstore/model_list.go | 13 +- .../go/go-petstore/model_map_of_file_test_.go | 13 +- .../go/go-petstore/model_map_test_.go | 13 +- ...perties_and_additional_properties_class.go | 13 +- .../petstore/go/go-petstore/model_name.go | 17 +- .../go/go-petstore/model_nullable_all_of.go | 13 +- .../model_nullable_all_of_child.go | 13 +- .../go/go-petstore/model_nullable_class.go | 13 +- .../go/go-petstore/model_number_only.go | 13 +- .../model_one_of_primitive_type_child.go | 13 +- .../petstore/go/go-petstore/model_order.go | 13 +- .../go/go-petstore/model_outer_composite.go | 13 +- .../petstore/go/go-petstore/model_pet.go | 21 +- .../go/go-petstore/model_read_only_first.go | 13 +- .../model_read_only_with_default.go | 13 +- .../petstore/go/go-petstore/model_return.go | 13 +- .../petstore/go/go-petstore/model_tag.go | 13 +- .../petstore/go/go-petstore/model_user.go | 13 +- .../petstore/go/go-petstore/model_whale.go | 17 +- .../petstore/go/go-petstore/model_zebra.go | 17 +- .../client/petstore/go/go-petstore/utils.go | 4 + .../client/petstore/go/pet_api_test.go | 20 ++ 124 files changed, 2103 insertions(+), 445 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/go/api.mustache b/modules/openapi-generator/src/main/resources/go/api.mustache index 44fbbcf4f955..c7840ffe566a 100644 --- a/modules/openapi-generator/src/main/resources/go/api.mustache +++ b/modules/openapi-generator/src/main/resources/go/api.mustache @@ -124,7 +124,7 @@ func (a *{{{classname}}}Service) {{nickname}}Execute(r {{#structPrefix}}{{&class } localVarPath := localBasePath + "{{{path}}}"{{#pathParams}} - localVarPath = strings.Replace(localVarPath, "{"+"{{baseName}}"+"}", url.PathEscape(parameterToString(r.{{paramName}}, "{{collectionFormat}}")), -1){{/pathParams}} + localVarPath = strings.Replace(localVarPath, "{"+"{{baseName}}"+"}", url.PathEscape(parameterValueToString(r.{{paramName}}, "{{paramName}}")), -1){{/pathParams}} localVarHeaderParams := make(map[string]string) localVarQueryParams := url.Values{} @@ -189,15 +189,15 @@ func (a *{{{classname}}}Service) {{nickname}}Execute(r {{#structPrefix}}{{&class if reflect.TypeOf(t).Kind() == reflect.Slice { s := reflect.ValueOf(t) for i := 0; i < s.Len(); i++ { - localVarQueryParams.Add("{{baseName}}", parameterToString(s.Index(i), "{{collectionFormat}}")) + parameterAddToQuery(localVarQueryParams, "{{baseName}}", s.Index(i), "{{collectionFormat}}") } } else { - localVarQueryParams.Add("{{baseName}}", parameterToString(t, "{{collectionFormat}}")) + parameterAddToQuery(localVarQueryParams, "{{baseName}}", t, "{{collectionFormat}}") } } {{/isCollectionFormatMulti}} {{^isCollectionFormatMulti}} - localVarQueryParams.Add("{{baseName}}", parameterToString(*r.{{paramName}}, "{{collectionFormat}}")) + parameterAddToQuery(localVarQueryParams, "{{baseName}}", r.{{paramName}}, "{{collectionFormat}}") {{/isCollectionFormatMulti}} {{/required}} {{^required}} @@ -207,14 +207,14 @@ func (a *{{{classname}}}Service) {{nickname}}Execute(r {{#structPrefix}}{{&class if reflect.TypeOf(t).Kind() == reflect.Slice { s := reflect.ValueOf(t) for i := 0; i < s.Len(); i++ { - localVarQueryParams.Add("{{baseName}}", parameterToString(s.Index(i), "{{collectionFormat}}")) + parameterAddToQuery(localVarQueryParams, "{{baseName}}", s.Index(i), "{{collectionFormat}}") } } else { - localVarQueryParams.Add("{{baseName}}", parameterToString(t, "{{collectionFormat}}")) + parameterAddToQuery(localVarQueryParams, "{{baseName}}", t, "{{collectionFormat}}") } {{/isCollectionFormatMulti}} {{^isCollectionFormatMulti}} - localVarQueryParams.Add("{{baseName}}", parameterToString(*r.{{paramName}}, "{{collectionFormat}}")) + parameterAddToQuery(localVarQueryParams, "{{baseName}}", r.{{paramName}}, "{{collectionFormat}}") {{/isCollectionFormatMulti}} } {{/required}} @@ -242,11 +242,11 @@ func (a *{{{classname}}}Service) {{nickname}}Execute(r {{#structPrefix}}{{&class } {{#headerParams}} {{#required}} - localVarHeaderParams["{{baseName}}"] = parameterToString(*r.{{paramName}}, "{{collectionFormat}}") + parameterAddToQuery(localVarQueryParams, "{{baseName}}", r.{{paramName}}, "{{collectionFormat}}") {{/required}} {{^required}} if r.{{paramName}} != nil { - localVarHeaderParams["{{baseName}}"] = parameterToString(*r.{{paramName}}, "{{collectionFormat}}") + parameterAddToQuery(localVarQueryParams, "{{baseName}}", r.{{paramName}}, "{{collectionFormat}}") } {{/required}} {{/headerParams}} @@ -277,7 +277,7 @@ func (a *{{{classname}}}Service) {{nickname}}Execute(r {{#structPrefix}}{{&class {{/isFile}} {{^isFile}} {{#required}} - localVarFormParams.Add("{{baseName}}", parameterToString(*r.{{paramName}}, "{{collectionFormat}}")) + parameterAddToQuery(localVarFormParams, "{{baseName}}", r.{{paramName}}, "{{collectionFormat}}") {{/required}} {{^required}} {{#isModel}} @@ -291,7 +291,7 @@ func (a *{{{classname}}}Service) {{nickname}}Execute(r {{#structPrefix}}{{&class {{/isModel}} {{^isModel}} if r.{{paramName}} != nil { - localVarFormParams.Add("{{baseName}}", parameterToString(*r.{{paramName}}, "{{collectionFormat}}")) + parameterAddToQuery(localVarFormParams, "{{baseName}}", r.{{paramName}}, "{{collectionFormat}}") } {{/isModel}} {{/required}} diff --git a/modules/openapi-generator/src/main/resources/go/client.mustache b/modules/openapi-generator/src/main/resources/go/client.mustache index dd5ea6ce226c..616772c88915 100644 --- a/modules/openapi-generator/src/main/resources/go/client.mustache +++ b/modules/openapi-generator/src/main/resources/go/client.mustache @@ -34,6 +34,8 @@ import ( var ( jsonCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:vnd\.[^;]+\+)?json)`) xmlCheck = regexp.MustCompile(`(?i:(?:application|text)/xml)`) + queryParamSplit = regexp.MustCompile(`(^|&)([^&]+)`) + queryDescape = strings.NewReplacer( "%5B", "[", "%5D", "]" ) ) // APIClient manages communication with the {{appName}} API v{{version}} @@ -132,28 +134,101 @@ func typeCheckParameter(obj interface{}, expected string, name string) error { return nil } -// parameterToString convert interface{} parameters to string, using a delimiter if format is provided. -func parameterToString(obj interface{}, collectionFormat string) string { - var delimiter string - - switch collectionFormat { - case "pipes": - delimiter = "|" - case "ssv": - delimiter = " " - case "tsv": - delimiter = "\t" - case "csv": - delimiter = "," - } +func parameterValueToString( obj interface{}, key string ) string { + if reflect.TypeOf(obj).Kind() != reflect.Ptr { + return fmt.Sprintf("%v", obj) + } + var param,ok = obj.(MappedNullable) + if !ok { + return "" + } + dataMap,err := param.ToMap() + if err != nil { + return "" + } + return fmt.Sprintf("%v", dataMap[key]) +} - if reflect.TypeOf(obj).Kind() == reflect.Slice { - return strings.Trim(strings.Replace(fmt.Sprint(obj), " ", delimiter, -1), "[]") - } else if t, ok := obj.(time.Time); ok { - return t.Format(time.RFC3339) - } +// parameterAddToQuery adds the provided object to the url query supporting deep object syntax +func parameterAddToQuery(queryParams interface{}, keyPrefix string, obj interface{}, collectionType string) { + var v = reflect.ValueOf(obj) + var value = "" + if v == reflect.ValueOf(nil) { + value = "null" + } else { + switch v.Kind() { + case reflect.Invalid: + value = "invalid" + + case reflect.Struct: + if t,ok := obj.(MappedNullable); ok { + dataMap,err := t.ToMap() + if err != nil { + return + } + parameterAddToQuery(queryParams, keyPrefix, dataMap, collectionType) + return + } + if t, ok := obj.(time.Time); ok { + parameterAddToQuery(queryParams, keyPrefix, t.Format(time.RFC3339), collectionType) + return + } + value = v.Type().String() + " value" + case reflect.Slice: + var indValue = reflect.ValueOf(obj) + if indValue == reflect.ValueOf(nil) { + return + } + var lenIndValue = indValue.Len() + for i:=0;i= 300 { + newErr := &GenericOpenAPIError{ + body: localVarBody, + error: localVarHTTPResponse.Status, + } + return localVarHTTPResponse, newErr + } + + return localVarHTTPResponse, nil +} + +type ApiTestQueryDeepObjectRequest struct { + ctx context.Context + ApiService FakeApi + testPet *Pet + inputOptions *Category +} + +func (r ApiTestQueryDeepObjectRequest) TestPet(testPet Pet) ApiTestQueryDeepObjectRequest { + r.testPet = &testPet + return r +} + +func (r ApiTestQueryDeepObjectRequest) InputOptions(inputOptions Category) ApiTestQueryDeepObjectRequest { + r.inputOptions = &inputOptions + return r +} + +func (r ApiTestQueryDeepObjectRequest) Execute() (*http.Response, error) { + return r.ApiService.TestQueryDeepObjectExecute(r) +} + +/* +TestQueryDeepObject Method for TestQueryDeepObject + + @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + @return ApiTestQueryDeepObjectRequest +*/ +func (a *FakeApiService) TestQueryDeepObject(ctx context.Context) ApiTestQueryDeepObjectRequest { + return ApiTestQueryDeepObjectRequest{ + ApiService: a, + ctx: ctx, + } +} + +// Execute executes the request +func (a *FakeApiService) TestQueryDeepObjectExecute(r ApiTestQueryDeepObjectRequest) (*http.Response, error) { + var ( + localVarHTTPMethod = http.MethodGet + localVarPostBody interface{} + formFiles []formFile + ) + + localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "FakeApiService.TestQueryDeepObject") + if err != nil { + return nil, &GenericOpenAPIError{error: err.Error()} + } + + localVarPath := localBasePath + "/fake/deep_object_test" + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := url.Values{} + localVarFormParams := url.Values{} + + if r.testPet != nil { + parameterAddToQuery(localVarQueryParams, "test_pet", r.testPet, "") + } + if r.inputOptions != nil { + parameterAddToQuery(localVarQueryParams, "inputOptions", r.inputOptions, "") + } + // to determine the Content-Type header + localVarHTTPContentTypes := []string{} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) if err != nil { return nil, err @@ -1978,24 +2093,24 @@ func (a *FakeApiService) TestQueryParameterCollectionFormatExecute(r ApiTestQuer if reflect.TypeOf(t).Kind() == reflect.Slice { s := reflect.ValueOf(t) for i := 0; i < s.Len(); i++ { - localVarQueryParams.Add("pipe", parameterToString(s.Index(i), "multi")) + parameterAddToQuery(localVarQueryParams, "pipe", s.Index(i), "multi") } } else { - localVarQueryParams.Add("pipe", parameterToString(t, "multi")) + parameterAddToQuery(localVarQueryParams, "pipe", t, "multi") } } - localVarQueryParams.Add("ioutil", parameterToString(*r.ioutil, "csv")) - localVarQueryParams.Add("http", parameterToString(*r.http, "ssv")) - localVarQueryParams.Add("url", parameterToString(*r.url, "csv")) + parameterAddToQuery(localVarQueryParams, "ioutil", r.ioutil, "csv") + parameterAddToQuery(localVarQueryParams, "http", r.http, "ssv") + parameterAddToQuery(localVarQueryParams, "url", r.url, "csv") { t := *r.context if reflect.TypeOf(t).Kind() == reflect.Slice { s := reflect.ValueOf(t) for i := 0; i < s.Len(); i++ { - localVarQueryParams.Add("context", parameterToString(s.Index(i), "multi")) + parameterAddToQuery(localVarQueryParams, "context", s.Index(i), "multi") } } else { - localVarQueryParams.Add("context", parameterToString(t, "multi")) + parameterAddToQuery(localVarQueryParams, "context", t, "multi") } } // to determine the Content-Type header @@ -2111,10 +2226,10 @@ func (a *FakeApiService) TestUniqueItemsHeaderAndQueryParameterCollectionFormatE if reflect.TypeOf(t).Kind() == reflect.Slice { s := reflect.ValueOf(t) for i := 0; i < s.Len(); i++ { - localVarQueryParams.Add("queryUnique", parameterToString(s.Index(i), "multi")) + parameterAddToQuery(localVarQueryParams, "queryUnique", s.Index(i), "multi") } } else { - localVarQueryParams.Add("queryUnique", parameterToString(t, "multi")) + parameterAddToQuery(localVarQueryParams, "queryUnique", t, "multi") } } // to determine the Content-Type header @@ -2134,7 +2249,7 @@ func (a *FakeApiService) TestUniqueItemsHeaderAndQueryParameterCollectionFormatE if localVarHTTPHeaderAccept != "" { localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept } - localVarHeaderParams["headerUnique"] = parameterToString(*r.headerUnique, "csv") + parameterAddToQuery(localVarQueryParams, "headerUnique", r.headerUnique, "csv") req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) if err != nil { return localVarReturnValue, nil, err diff --git a/samples/openapi3/client/petstore/go/go-petstore/api_pet.go b/samples/openapi3/client/petstore/go/go-petstore/api_pet.go index 1d50da9d7b19..3d780fd17208 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/api_pet.go +++ b/samples/openapi3/client/petstore/go/go-petstore/api_pet.go @@ -304,7 +304,7 @@ func (a *PetApiService) DeletePetExecute(r ApiDeletePetRequest) (*http.Response, } localVarPath := localBasePath + "/pet/{petId}" - localVarPath = strings.Replace(localVarPath, "{"+"petId"+"}", url.PathEscape(parameterToString(r.petId, "")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"petId"+"}", url.PathEscape(parameterValueToString(r.petId, "petId")), -1) localVarHeaderParams := make(map[string]string) localVarQueryParams := url.Values{} @@ -328,7 +328,7 @@ func (a *PetApiService) DeletePetExecute(r ApiDeletePetRequest) (*http.Response, localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept } if r.apiKey != nil { - localVarHeaderParams["api_key"] = parameterToString(*r.apiKey, "") + parameterAddToQuery(localVarQueryParams, "api_key", r.apiKey, "") } req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) if err != nil { @@ -414,7 +414,7 @@ func (a *PetApiService) FindPetsByStatusExecute(r ApiFindPetsByStatusRequest) ([ return localVarReturnValue, nil, reportError("status is required and must be specified") } - localVarQueryParams.Add("status", parameterToString(*r.status, "csv")) + parameterAddToQuery(localVarQueryParams, "status", r.status, "csv") // to determine the Content-Type header localVarHTTPContentTypes := []string{} @@ -527,7 +527,7 @@ func (a *PetApiService) FindPetsByTagsExecute(r ApiFindPetsByTagsRequest) ([]Pet return localVarReturnValue, nil, reportError("tags is required and must be specified") } - localVarQueryParams.Add("tags", parameterToString(*r.tags, "csv")) + parameterAddToQuery(localVarQueryParams, "tags", r.tags, "csv") // to determine the Content-Type header localVarHTTPContentTypes := []string{} @@ -625,7 +625,7 @@ func (a *PetApiService) GetPetByIdExecute(r ApiGetPetByIdRequest) (*Pet, *http.R } localVarPath := localBasePath + "/pet/{petId}" - localVarPath = strings.Replace(localVarPath, "{"+"petId"+"}", url.PathEscape(parameterToString(r.petId, "")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"petId"+"}", url.PathEscape(parameterValueToString(r.petId, "petId")), -1) localVarHeaderParams := make(map[string]string) localVarQueryParams := url.Values{} @@ -854,7 +854,7 @@ func (a *PetApiService) UpdatePetWithFormExecute(r ApiUpdatePetWithFormRequest) } localVarPath := localBasePath + "/pet/{petId}" - localVarPath = strings.Replace(localVarPath, "{"+"petId"+"}", url.PathEscape(parameterToString(r.petId, "")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"petId"+"}", url.PathEscape(parameterValueToString(r.petId, "petId")), -1) localVarHeaderParams := make(map[string]string) localVarQueryParams := url.Values{} @@ -878,10 +878,10 @@ func (a *PetApiService) UpdatePetWithFormExecute(r ApiUpdatePetWithFormRequest) localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept } if r.name != nil { - localVarFormParams.Add("name", parameterToString(*r.name, "")) + parameterAddToQuery(localVarFormParams, "name", r.name, "") } if r.status != nil { - localVarFormParams.Add("status", parameterToString(*r.status, "")) + parameterAddToQuery(localVarFormParams, "status", r.status, "") } req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) if err != nil { @@ -968,7 +968,7 @@ func (a *PetApiService) UploadFileExecute(r ApiUploadFileRequest) (*ApiResponse, } localVarPath := localBasePath + "/pet/{petId}/uploadImage" - localVarPath = strings.Replace(localVarPath, "{"+"petId"+"}", url.PathEscape(parameterToString(r.petId, "")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"petId"+"}", url.PathEscape(parameterValueToString(r.petId, "petId")), -1) localVarHeaderParams := make(map[string]string) localVarQueryParams := url.Values{} @@ -992,7 +992,7 @@ func (a *PetApiService) UploadFileExecute(r ApiUploadFileRequest) (*ApiResponse, localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept } if r.additionalMetadata != nil { - localVarFormParams.Add("additionalMetadata", parameterToString(*r.additionalMetadata, "")) + parameterAddToQuery(localVarFormParams, "additionalMetadata", r.additionalMetadata, "") } var fileLocalVarFormFileName string var fileLocalVarFileName string @@ -1105,7 +1105,7 @@ func (a *PetApiService) UploadFileWithRequiredFileExecute(r ApiUploadFileWithReq } localVarPath := localBasePath + "/fake/{petId}/uploadImageWithRequiredFile" - localVarPath = strings.Replace(localVarPath, "{"+"petId"+"}", url.PathEscape(parameterToString(r.petId, "")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"petId"+"}", url.PathEscape(parameterValueToString(r.petId, "petId")), -1) localVarHeaderParams := make(map[string]string) localVarQueryParams := url.Values{} @@ -1132,7 +1132,7 @@ func (a *PetApiService) UploadFileWithRequiredFileExecute(r ApiUploadFileWithReq localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept } if r.additionalMetadata != nil { - localVarFormParams.Add("additionalMetadata", parameterToString(*r.additionalMetadata, "")) + parameterAddToQuery(localVarFormParams, "additionalMetadata", r.additionalMetadata, "") } var requiredFileLocalVarFormFileName string var requiredFileLocalVarFileName string diff --git a/samples/openapi3/client/petstore/go/go-petstore/api_store.go b/samples/openapi3/client/petstore/go/go-petstore/api_store.go index 87abefe63618..030c089402f6 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/api_store.go +++ b/samples/openapi3/client/petstore/go/go-petstore/api_store.go @@ -124,7 +124,7 @@ func (a *StoreApiService) DeleteOrderExecute(r ApiDeleteOrderRequest) (*http.Res } localVarPath := localBasePath + "/store/order/{order_id}" - localVarPath = strings.Replace(localVarPath, "{"+"order_id"+"}", url.PathEscape(parameterToString(r.orderId, "")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"order_id"+"}", url.PathEscape(parameterValueToString(r.orderId, "orderId")), -1) localVarHeaderParams := make(map[string]string) localVarQueryParams := url.Values{} @@ -331,7 +331,7 @@ func (a *StoreApiService) GetOrderByIdExecute(r ApiGetOrderByIdRequest) (*Order, } localVarPath := localBasePath + "/store/order/{order_id}" - localVarPath = strings.Replace(localVarPath, "{"+"order_id"+"}", url.PathEscape(parameterToString(r.orderId, "")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"order_id"+"}", url.PathEscape(parameterValueToString(r.orderId, "orderId")), -1) localVarHeaderParams := make(map[string]string) localVarQueryParams := url.Values{} diff --git a/samples/openapi3/client/petstore/go/go-petstore/api_user.go b/samples/openapi3/client/petstore/go/go-petstore/api_user.go index 0ac28a9deefc..c4bb61f81f85 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/api_user.go +++ b/samples/openapi3/client/petstore/go/go-petstore/api_user.go @@ -476,7 +476,7 @@ func (a *UserApiService) DeleteUserExecute(r ApiDeleteUserRequest) (*http.Respon } localVarPath := localBasePath + "/user/{username}" - localVarPath = strings.Replace(localVarPath, "{"+"username"+"}", url.PathEscape(parameterToString(r.username, "")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"username"+"}", url.PathEscape(parameterValueToString(r.username, "username")), -1) localVarHeaderParams := make(map[string]string) localVarQueryParams := url.Values{} @@ -570,7 +570,7 @@ func (a *UserApiService) GetUserByNameExecute(r ApiGetUserByNameRequest) (*User, } localVarPath := localBasePath + "/user/{username}" - localVarPath = strings.Replace(localVarPath, "{"+"username"+"}", url.PathEscape(parameterToString(r.username, "")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"username"+"}", url.PathEscape(parameterValueToString(r.username, "username")), -1) localVarHeaderParams := make(map[string]string) localVarQueryParams := url.Values{} @@ -695,8 +695,8 @@ func (a *UserApiService) LoginUserExecute(r ApiLoginUserRequest) (string, *http. return localVarReturnValue, nil, reportError("password is required and must be specified") } - localVarQueryParams.Add("username", parameterToString(*r.username, "")) - localVarQueryParams.Add("password", parameterToString(*r.password, "")) + parameterAddToQuery(localVarQueryParams, "username", r.username, "") + parameterAddToQuery(localVarQueryParams, "password", r.password, "") // to determine the Content-Type header localVarHTTPContentTypes := []string{} @@ -887,7 +887,7 @@ func (a *UserApiService) UpdateUserExecute(r ApiUpdateUserRequest) (*http.Respon } localVarPath := localBasePath + "/user/{username}" - localVarPath = strings.Replace(localVarPath, "{"+"username"+"}", url.PathEscape(parameterToString(r.username, "")), -1) + localVarPath = strings.Replace(localVarPath, "{"+"username"+"}", url.PathEscape(parameterValueToString(r.username, "username")), -1) localVarHeaderParams := make(map[string]string) localVarQueryParams := url.Values{} diff --git a/samples/openapi3/client/petstore/go/go-petstore/client.go b/samples/openapi3/client/petstore/go/go-petstore/client.go index 0bb67d159cca..fa1714c97fb2 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/client.go +++ b/samples/openapi3/client/petstore/go/go-petstore/client.go @@ -39,6 +39,8 @@ import ( var ( jsonCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:vnd\.[^;]+\+)?json)`) xmlCheck = regexp.MustCompile(`(?i:(?:application|text)/xml)`) + queryParamSplit = regexp.MustCompile(`(^|&)([^&]+)`) + queryDescape = strings.NewReplacer( "%5B", "[", "%5D", "]" ) ) // APIClient manages communication with the OpenAPI Petstore API v1.0.0 @@ -143,28 +145,101 @@ func typeCheckParameter(obj interface{}, expected string, name string) error { return nil } -// parameterToString convert interface{} parameters to string, using a delimiter if format is provided. -func parameterToString(obj interface{}, collectionFormat string) string { - var delimiter string - - switch collectionFormat { - case "pipes": - delimiter = "|" - case "ssv": - delimiter = " " - case "tsv": - delimiter = "\t" - case "csv": - delimiter = "," - } +func parameterValueToString( obj interface{}, key string ) string { + if reflect.TypeOf(obj).Kind() != reflect.Ptr { + return fmt.Sprintf("%v", obj) + } + var param,ok = obj.(MappedNullable) + if !ok { + return "" + } + dataMap,err := param.ToMap() + if err != nil { + return "" + } + return fmt.Sprintf("%v", dataMap[key]) +} - if reflect.TypeOf(obj).Kind() == reflect.Slice { - return strings.Trim(strings.Replace(fmt.Sprint(obj), " ", delimiter, -1), "[]") - } else if t, ok := obj.(time.Time); ok { - return t.Format(time.RFC3339) - } +// parameterAddToQuery adds the provided object to the url query supporting deep object syntax +func parameterAddToQuery(queryParams interface{}, keyPrefix string, obj interface{}, collectionType string) { + var v = reflect.ValueOf(obj) + var value = "" + if v == reflect.ValueOf(nil) { + value = "null" + } else { + switch v.Kind() { + case reflect.Invalid: + value = "invalid" + + case reflect.Struct: + if t,ok := obj.(MappedNullable); ok { + dataMap,err := t.ToMap() + if err != nil { + return + } + parameterAddToQuery(queryParams, keyPrefix, dataMap, collectionType) + return + } + if t, ok := obj.(time.Time); ok { + parameterAddToQuery(queryParams, keyPrefix, t.Format(time.RFC3339), collectionType) + return + } + value = v.Type().String() + " value" + case reflect.Slice: + var indValue = reflect.ValueOf(obj) + if indValue == reflect.ValueOf(nil) { + return + } + var lenIndValue = indValue.Len() + for i:=0;i TestQueryDeepObject(ctx).TestPet(testPet).InputOptions(inputOptions).Execute() + + + +### Example + +```go +package main + +import ( + "context" + "fmt" + "os" + openapiclient "./openapi" +) + +func main() { + testPet := map[string][]openapiclient.Pet{"key": map[string]interface{}{ ... }} // Pet | (optional) + inputOptions := map[string][]openapiclient.Category{"key": map[string]interface{}{ ... }} // Category | (optional) + + configuration := openapiclient.NewConfiguration() + apiClient := openapiclient.NewAPIClient(configuration) + resp, r, err := apiClient.FakeApi.TestQueryDeepObject(context.Background()).TestPet(testPet).InputOptions(inputOptions).Execute() + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `FakeApi.TestQueryDeepObject``: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } +} +``` + +### Path Parameters + + + +### Other Parameters + +Other parameters are passed through a pointer to a apiTestQueryDeepObjectRequest struct via the builder pattern + + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **testPet** | [**Pet**](Pet.md) | | + **inputOptions** | [**Category**](Category.md) | | + +### Return type + + (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: Not defined + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) +[[Back to Model list]](../README.md#documentation-for-models) +[[Back to README]](../README.md) + + ## TestQueryParameterCollectionFormat > TestQueryParameterCollectionFormat(ctx).Pipe(pipe).Ioutil(ioutil).Http(http).Url(url).Context(context).Execute() diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_200_response.go b/samples/openapi3/client/petstore/go/go-petstore/model_200_response.go index ed63ac8c99cd..46b818ed7943 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_200_response.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_200_response.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the Model200Response type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Model200Response{} + // Model200Response Model for testing model name starting with number type Model200Response struct { Name *int32 `json:"name,omitempty"` @@ -105,6 +108,14 @@ func (o *Model200Response) SetClass(v string) { } func (o Model200Response) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Model200Response) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if !isNil(o.Name) { toSerialize["name"] = o.Name @@ -117,7 +128,7 @@ func (o Model200Response) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *Model200Response) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model__foo_get_default_response.go b/samples/openapi3/client/petstore/go/go-petstore/model__foo_get_default_response.go index 433706818b1e..07626faeb067 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model__foo_get_default_response.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model__foo_get_default_response.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the FooGetDefaultResponse type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &FooGetDefaultResponse{} + // FooGetDefaultResponse struct for FooGetDefaultResponse type FooGetDefaultResponse struct { String *Foo `json:"string,omitempty"` @@ -72,6 +75,14 @@ func (o *FooGetDefaultResponse) SetString(v Foo) { } func (o FooGetDefaultResponse) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o FooGetDefaultResponse) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if !isNil(o.String) { toSerialize["string"] = o.String @@ -81,7 +92,7 @@ func (o FooGetDefaultResponse) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *FooGetDefaultResponse) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model__special_model_name_.go b/samples/openapi3/client/petstore/go/go-petstore/model__special_model_name_.go index a1f792ad6e30..eebad4330992 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model__special_model_name_.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model__special_model_name_.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the SpecialModelName type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &SpecialModelName{} + // SpecialModelName struct for SpecialModelName type SpecialModelName struct { SpecialPropertyName *int64 `json:"$special[property.name],omitempty"` @@ -72,6 +75,14 @@ func (o *SpecialModelName) SetSpecialPropertyName(v int64) { } func (o SpecialModelName) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o SpecialModelName) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if !isNil(o.SpecialPropertyName) { toSerialize["$special[property.name]"] = o.SpecialPropertyName @@ -81,7 +92,7 @@ func (o SpecialModelName) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *SpecialModelName) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_additional_properties_class.go b/samples/openapi3/client/petstore/go/go-petstore/model_additional_properties_class.go index 639a5a16b1b8..b2580f17a8dc 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_additional_properties_class.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_additional_properties_class.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the AdditionalPropertiesClass type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &AdditionalPropertiesClass{} + // AdditionalPropertiesClass struct for AdditionalPropertiesClass type AdditionalPropertiesClass struct { MapProperty *map[string]string `json:"map_property,omitempty"` @@ -105,6 +108,14 @@ func (o *AdditionalPropertiesClass) SetMapOfMapProperty(v map[string]map[string] } func (o AdditionalPropertiesClass) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o AdditionalPropertiesClass) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if !isNil(o.MapProperty) { toSerialize["map_property"] = o.MapProperty @@ -117,7 +128,7 @@ func (o AdditionalPropertiesClass) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *AdditionalPropertiesClass) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_animal.go b/samples/openapi3/client/petstore/go/go-petstore/model_animal.go index 20913dc1d711..a550cb4223a9 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_animal.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_animal.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the Animal type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Animal{} + // Animal struct for Animal type Animal struct { ClassName string `json:"className"` @@ -102,10 +105,16 @@ func (o *Animal) SetColor(v string) { } func (o Animal) MarshalJSON() ([]byte, error) { - toSerialize := map[string]interface{}{} - if true { - toSerialize["className"] = o.ClassName + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err } + return json.Marshal(toSerialize) +} + +func (o Animal) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["className"] = o.ClassName if !isNil(o.Color) { toSerialize["color"] = o.Color } @@ -114,7 +123,7 @@ func (o Animal) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *Animal) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_api_response.go b/samples/openapi3/client/petstore/go/go-petstore/model_api_response.go index 01cd35ae94b9..363721d3f091 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_api_response.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_api_response.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the ApiResponse type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &ApiResponse{} + // ApiResponse struct for ApiResponse type ApiResponse struct { Code *int32 `json:"code,omitempty"` @@ -138,6 +141,14 @@ func (o *ApiResponse) SetMessage(v string) { } func (o ApiResponse) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o ApiResponse) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if !isNil(o.Code) { toSerialize["code"] = o.Code @@ -153,7 +164,7 @@ func (o ApiResponse) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *ApiResponse) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_apple.go b/samples/openapi3/client/petstore/go/go-petstore/model_apple.go index c51835b85cf4..4e5bbfea741b 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_apple.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_apple.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the Apple type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Apple{} + // Apple struct for Apple type Apple struct { Cultivar *string `json:"cultivar,omitempty"` @@ -72,6 +75,14 @@ func (o *Apple) SetCultivar(v string) { } func (o Apple) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Apple) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if !isNil(o.Cultivar) { toSerialize["cultivar"] = o.Cultivar @@ -81,7 +92,7 @@ func (o Apple) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *Apple) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_apple_req.go b/samples/openapi3/client/petstore/go/go-petstore/model_apple_req.go index e49e22930808..0ceff9a111c8 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_apple_req.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_apple_req.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the AppleReq type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &AppleReq{} + // AppleReq struct for AppleReq type AppleReq struct { Cultivar string `json:"cultivar"` @@ -98,10 +101,16 @@ func (o *AppleReq) SetMealy(v bool) { } func (o AppleReq) MarshalJSON() ([]byte, error) { - toSerialize := map[string]interface{}{} - if true { - toSerialize["cultivar"] = o.Cultivar + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err } + return json.Marshal(toSerialize) +} + +func (o AppleReq) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["cultivar"] = o.Cultivar if !isNil(o.Mealy) { toSerialize["mealy"] = o.Mealy } @@ -110,7 +119,7 @@ func (o AppleReq) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *AppleReq) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_array_of_array_of_number_only.go b/samples/openapi3/client/petstore/go/go-petstore/model_array_of_array_of_number_only.go index 8e009522d2a1..4356c9e21979 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_array_of_array_of_number_only.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_array_of_array_of_number_only.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the ArrayOfArrayOfNumberOnly type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &ArrayOfArrayOfNumberOnly{} + // ArrayOfArrayOfNumberOnly struct for ArrayOfArrayOfNumberOnly type ArrayOfArrayOfNumberOnly struct { ArrayArrayNumber [][]float32 `json:"ArrayArrayNumber,omitempty"` @@ -72,6 +75,14 @@ func (o *ArrayOfArrayOfNumberOnly) SetArrayArrayNumber(v [][]float32) { } func (o ArrayOfArrayOfNumberOnly) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o ArrayOfArrayOfNumberOnly) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if !isNil(o.ArrayArrayNumber) { toSerialize["ArrayArrayNumber"] = o.ArrayArrayNumber @@ -81,7 +92,7 @@ func (o ArrayOfArrayOfNumberOnly) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *ArrayOfArrayOfNumberOnly) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_array_of_number_only.go b/samples/openapi3/client/petstore/go/go-petstore/model_array_of_number_only.go index 91d631d47162..ce3d568ab552 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_array_of_number_only.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_array_of_number_only.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the ArrayOfNumberOnly type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &ArrayOfNumberOnly{} + // ArrayOfNumberOnly struct for ArrayOfNumberOnly type ArrayOfNumberOnly struct { ArrayNumber []float32 `json:"ArrayNumber,omitempty"` @@ -72,6 +75,14 @@ func (o *ArrayOfNumberOnly) SetArrayNumber(v []float32) { } func (o ArrayOfNumberOnly) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o ArrayOfNumberOnly) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if !isNil(o.ArrayNumber) { toSerialize["ArrayNumber"] = o.ArrayNumber @@ -81,7 +92,7 @@ func (o ArrayOfNumberOnly) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *ArrayOfNumberOnly) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_array_test_.go b/samples/openapi3/client/petstore/go/go-petstore/model_array_test_.go index a90f27b0b46e..76d4ea444c96 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_array_test_.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_array_test_.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the ArrayTest type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &ArrayTest{} + // ArrayTest struct for ArrayTest type ArrayTest struct { ArrayOfString []string `json:"array_of_string,omitempty"` @@ -138,6 +141,14 @@ func (o *ArrayTest) SetArrayArrayOfModel(v [][]ReadOnlyFirst) { } func (o ArrayTest) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o ArrayTest) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if !isNil(o.ArrayOfString) { toSerialize["array_of_string"] = o.ArrayOfString @@ -153,7 +164,7 @@ func (o ArrayTest) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *ArrayTest) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_banana.go b/samples/openapi3/client/petstore/go/go-petstore/model_banana.go index 71a7c89275df..0a60a46712a2 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_banana.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_banana.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the Banana type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Banana{} + // Banana struct for Banana type Banana struct { LengthCm *float32 `json:"lengthCm,omitempty"` @@ -72,6 +75,14 @@ func (o *Banana) SetLengthCm(v float32) { } func (o Banana) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Banana) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if !isNil(o.LengthCm) { toSerialize["lengthCm"] = o.LengthCm @@ -81,7 +92,7 @@ func (o Banana) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *Banana) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_banana_req.go b/samples/openapi3/client/petstore/go/go-petstore/model_banana_req.go index 92b660dd30f7..79948f5f7fe1 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_banana_req.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_banana_req.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the BananaReq type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &BananaReq{} + // BananaReq struct for BananaReq type BananaReq struct { LengthCm float32 `json:"lengthCm"` @@ -98,10 +101,16 @@ func (o *BananaReq) SetSweet(v bool) { } func (o BananaReq) MarshalJSON() ([]byte, error) { - toSerialize := map[string]interface{}{} - if true { - toSerialize["lengthCm"] = o.LengthCm + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err } + return json.Marshal(toSerialize) +} + +func (o BananaReq) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["lengthCm"] = o.LengthCm if !isNil(o.Sweet) { toSerialize["sweet"] = o.Sweet } @@ -110,7 +119,7 @@ func (o BananaReq) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *BananaReq) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_capitalization.go b/samples/openapi3/client/petstore/go/go-petstore/model_capitalization.go index 575bf95b16d1..7cbea641aa56 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_capitalization.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_capitalization.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the Capitalization type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Capitalization{} + // Capitalization struct for Capitalization type Capitalization struct { SmallCamel *string `json:"smallCamel,omitempty"` @@ -238,6 +241,14 @@ func (o *Capitalization) SetATT_NAME(v string) { } func (o Capitalization) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Capitalization) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if !isNil(o.SmallCamel) { toSerialize["smallCamel"] = o.SmallCamel @@ -262,7 +273,7 @@ func (o Capitalization) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *Capitalization) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_cat.go b/samples/openapi3/client/petstore/go/go-petstore/model_cat.go index 17d259a5b5c7..45cbe81b14ce 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_cat.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_cat.go @@ -16,6 +16,9 @@ import ( "strings" ) +// checks if the Cat type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Cat{} + // Cat struct for Cat type Cat struct { Animal @@ -78,14 +81,22 @@ func (o *Cat) SetDeclawed(v bool) { } func (o Cat) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Cat) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} serializedAnimal, errAnimal := json.Marshal(o.Animal) if errAnimal != nil { - return []byte{}, errAnimal + return map[string]interface{}{}, errAnimal } errAnimal = json.Unmarshal([]byte(serializedAnimal), &toSerialize) if errAnimal != nil { - return []byte{}, errAnimal + return map[string]interface{}{}, errAnimal } if !isNil(o.Declawed) { toSerialize["declawed"] = o.Declawed @@ -95,7 +106,7 @@ func (o Cat) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *Cat) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_cat_all_of.go b/samples/openapi3/client/petstore/go/go-petstore/model_cat_all_of.go index 8c14cd39c761..b4d614021beb 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_cat_all_of.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_cat_all_of.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the CatAllOf type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &CatAllOf{} + // CatAllOf struct for CatAllOf type CatAllOf struct { Declawed *bool `json:"declawed,omitempty"` @@ -72,6 +75,14 @@ func (o *CatAllOf) SetDeclawed(v bool) { } func (o CatAllOf) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o CatAllOf) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if !isNil(o.Declawed) { toSerialize["declawed"] = o.Declawed @@ -81,7 +92,7 @@ func (o CatAllOf) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *CatAllOf) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_category.go b/samples/openapi3/client/petstore/go/go-petstore/model_category.go index 5900a618b9c2..edc91739855c 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_category.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_category.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the Category type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Category{} + // Category struct for Category type Category struct { Id *int64 `json:"id,omitempty"` @@ -100,19 +103,25 @@ func (o *Category) SetName(v string) { } func (o Category) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Category) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if !isNil(o.Id) { toSerialize["id"] = o.Id } - if true { - toSerialize["name"] = o.Name - } + toSerialize["name"] = o.Name for key, value := range o.AdditionalProperties { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *Category) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_class_model.go b/samples/openapi3/client/petstore/go/go-petstore/model_class_model.go index 6df4c3bf5408..c9e9015127a4 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_class_model.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_class_model.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the ClassModel type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &ClassModel{} + // ClassModel Model for testing model with \"_class\" property type ClassModel struct { Class *string `json:"_class,omitempty"` @@ -72,6 +75,14 @@ func (o *ClassModel) SetClass(v string) { } func (o ClassModel) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o ClassModel) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if !isNil(o.Class) { toSerialize["_class"] = o.Class @@ -81,7 +92,7 @@ func (o ClassModel) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *ClassModel) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_client.go b/samples/openapi3/client/petstore/go/go-petstore/model_client.go index e1fd5c611eb2..e50f1f84cf36 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_client.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_client.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the Client type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Client{} + // Client struct for Client type Client struct { Client *string `json:"client,omitempty"` @@ -72,6 +75,14 @@ func (o *Client) SetClient(v string) { } func (o Client) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Client) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if !isNil(o.Client) { toSerialize["client"] = o.Client @@ -81,7 +92,7 @@ func (o Client) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *Client) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_dog.go b/samples/openapi3/client/petstore/go/go-petstore/model_dog.go index db57aeb67f81..ac8ab0e79281 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_dog.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_dog.go @@ -16,6 +16,9 @@ import ( "strings" ) +// checks if the Dog type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Dog{} + // Dog struct for Dog type Dog struct { Animal @@ -78,14 +81,22 @@ func (o *Dog) SetBreed(v string) { } func (o Dog) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Dog) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} serializedAnimal, errAnimal := json.Marshal(o.Animal) if errAnimal != nil { - return []byte{}, errAnimal + return map[string]interface{}{}, errAnimal } errAnimal = json.Unmarshal([]byte(serializedAnimal), &toSerialize) if errAnimal != nil { - return []byte{}, errAnimal + return map[string]interface{}{}, errAnimal } if !isNil(o.Breed) { toSerialize["breed"] = o.Breed @@ -95,7 +106,7 @@ func (o Dog) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *Dog) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_dog_all_of.go b/samples/openapi3/client/petstore/go/go-petstore/model_dog_all_of.go index 75d154134f19..75b73bf9391d 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_dog_all_of.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_dog_all_of.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the DogAllOf type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &DogAllOf{} + // DogAllOf struct for DogAllOf type DogAllOf struct { Breed *string `json:"breed,omitempty"` @@ -72,6 +75,14 @@ func (o *DogAllOf) SetBreed(v string) { } func (o DogAllOf) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o DogAllOf) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if !isNil(o.Breed) { toSerialize["breed"] = o.Breed @@ -81,7 +92,7 @@ func (o DogAllOf) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *DogAllOf) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_duplicated_prop_child.go b/samples/openapi3/client/petstore/go/go-petstore/model_duplicated_prop_child.go index b6cb68e2dcaf..277f565a5db9 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_duplicated_prop_child.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_duplicated_prop_child.go @@ -16,6 +16,9 @@ import ( "strings" ) +// checks if the DuplicatedPropChild type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &DuplicatedPropChild{} + // DuplicatedPropChild struct for DuplicatedPropChild type DuplicatedPropChild struct { DuplicatedPropParent @@ -76,14 +79,22 @@ func (o *DuplicatedPropChild) SetDupProp(v string) { } func (o DuplicatedPropChild) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o DuplicatedPropChild) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} serializedDuplicatedPropParent, errDuplicatedPropParent := json.Marshal(o.DuplicatedPropParent) if errDuplicatedPropParent != nil { - return []byte{}, errDuplicatedPropParent + return map[string]interface{}{}, errDuplicatedPropParent } errDuplicatedPropParent = json.Unmarshal([]byte(serializedDuplicatedPropParent), &toSerialize) if errDuplicatedPropParent != nil { - return []byte{}, errDuplicatedPropParent + return map[string]interface{}{}, errDuplicatedPropParent } if !isNil(o.DupProp) { toSerialize["dup-prop"] = o.DupProp @@ -93,7 +104,7 @@ func (o DuplicatedPropChild) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *DuplicatedPropChild) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_duplicated_prop_child_all_of.go b/samples/openapi3/client/petstore/go/go-petstore/model_duplicated_prop_child_all_of.go index 9daabcd98127..c907167df1bb 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_duplicated_prop_child_all_of.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_duplicated_prop_child_all_of.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the DuplicatedPropChildAllOf type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &DuplicatedPropChildAllOf{} + // DuplicatedPropChildAllOf struct for DuplicatedPropChildAllOf type DuplicatedPropChildAllOf struct { // A discriminator value @@ -73,6 +76,14 @@ func (o *DuplicatedPropChildAllOf) SetDupProp(v string) { } func (o DuplicatedPropChildAllOf) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o DuplicatedPropChildAllOf) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if !isNil(o.DupProp) { toSerialize["dup-prop"] = o.DupProp @@ -82,7 +93,7 @@ func (o DuplicatedPropChildAllOf) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *DuplicatedPropChildAllOf) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_duplicated_prop_parent.go b/samples/openapi3/client/petstore/go/go-petstore/model_duplicated_prop_parent.go index 59f7f32eb7ae..1c8ed0909f66 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_duplicated_prop_parent.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_duplicated_prop_parent.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the DuplicatedPropParent type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &DuplicatedPropParent{} + // DuplicatedPropParent parent model with duplicated property type DuplicatedPropParent struct { // A discriminator value @@ -66,16 +69,22 @@ func (o *DuplicatedPropParent) SetDupProp(v string) { } func (o DuplicatedPropParent) MarshalJSON() ([]byte, error) { - toSerialize := map[string]interface{}{} - if true { - toSerialize["dup-prop"] = o.DupProp + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err } + return json.Marshal(toSerialize) +} + +func (o DuplicatedPropParent) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["dup-prop"] = o.DupProp for key, value := range o.AdditionalProperties { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *DuplicatedPropParent) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_enum_arrays.go b/samples/openapi3/client/petstore/go/go-petstore/model_enum_arrays.go index 14dc856c7de6..abbae9a9a241 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_enum_arrays.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_enum_arrays.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the EnumArrays type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &EnumArrays{} + // EnumArrays struct for EnumArrays type EnumArrays struct { JustSymbol *string `json:"just_symbol,omitempty"` @@ -105,6 +108,14 @@ func (o *EnumArrays) SetArrayEnum(v []string) { } func (o EnumArrays) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o EnumArrays) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if !isNil(o.JustSymbol) { toSerialize["just_symbol"] = o.JustSymbol @@ -117,7 +128,7 @@ func (o EnumArrays) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *EnumArrays) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_enum_test_.go b/samples/openapi3/client/petstore/go/go-petstore/model_enum_test_.go index fb07b82d2f5d..42941367b36b 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_enum_test_.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_enum_test_.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the EnumTest type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &EnumTest{} + // EnumTest struct for EnumTest type EnumTest struct { EnumString *string `json:"enum_string,omitempty"` @@ -314,13 +317,19 @@ func (o *EnumTest) SetOuterEnumIntegerDefaultValue(v OuterEnumIntegerDefaultValu } func (o EnumTest) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o EnumTest) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if !isNil(o.EnumString) { toSerialize["enum_string"] = o.EnumString } - if true { - toSerialize["enum_string_required"] = o.EnumStringRequired - } + toSerialize["enum_string_required"] = o.EnumStringRequired if !isNil(o.EnumInteger) { toSerialize["enum_integer"] = o.EnumInteger } @@ -344,7 +353,7 @@ func (o EnumTest) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *EnumTest) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_file.go b/samples/openapi3/client/petstore/go/go-petstore/model_file.go index 4d0f66a4a749..5d838b657ad5 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_file.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_file.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the File type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &File{} + // File Must be named `File` for test. type File struct { // Test capitalization @@ -73,6 +76,14 @@ func (o *File) SetSourceURI(v string) { } func (o File) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o File) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if !isNil(o.SourceURI) { toSerialize["sourceURI"] = o.SourceURI @@ -82,7 +93,7 @@ func (o File) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *File) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_file_schema_test_class.go b/samples/openapi3/client/petstore/go/go-petstore/model_file_schema_test_class.go index 67a8ff9b2eeb..6d587918ea1d 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_file_schema_test_class.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_file_schema_test_class.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the FileSchemaTestClass type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &FileSchemaTestClass{} + // FileSchemaTestClass struct for FileSchemaTestClass type FileSchemaTestClass struct { File *File `json:"file,omitempty"` @@ -105,6 +108,14 @@ func (o *FileSchemaTestClass) SetFiles(v []File) { } func (o FileSchemaTestClass) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o FileSchemaTestClass) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if !isNil(o.File) { toSerialize["file"] = o.File @@ -117,7 +128,7 @@ func (o FileSchemaTestClass) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *FileSchemaTestClass) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_foo.go b/samples/openapi3/client/petstore/go/go-petstore/model_foo.go index b4665327a639..a529b9b86c5c 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_foo.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_foo.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the Foo type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Foo{} + // Foo struct for Foo type Foo struct { Bar *string `json:"bar,omitempty"` @@ -76,6 +79,14 @@ func (o *Foo) SetBar(v string) { } func (o Foo) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Foo) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if !isNil(o.Bar) { toSerialize["bar"] = o.Bar @@ -85,7 +96,7 @@ func (o Foo) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *Foo) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_format_test_.go b/samples/openapi3/client/petstore/go/go-petstore/model_format_test_.go index 3bbcbca74959..fe95d07ffaf3 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_format_test_.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_format_test_.go @@ -16,6 +16,9 @@ import ( "time" ) +// checks if the FormatTest type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &FormatTest{} + // FormatTest struct for FormatTest type FormatTest struct { Integer *int32 `json:"integer,omitempty"` @@ -510,6 +513,14 @@ func (o *FormatTest) SetPatternWithDigitsAndDelimiter(v string) { } func (o FormatTest) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o FormatTest) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if !isNil(o.Integer) { toSerialize["integer"] = o.Integer @@ -520,9 +531,7 @@ func (o FormatTest) MarshalJSON() ([]byte, error) { if !isNil(o.Int64) { toSerialize["int64"] = o.Int64 } - if true { - toSerialize["number"] = o.Number - } + toSerialize["number"] = o.Number if !isNil(o.Float) { toSerialize["float"] = o.Float } @@ -532,24 +541,18 @@ func (o FormatTest) MarshalJSON() ([]byte, error) { if !isNil(o.String) { toSerialize["string"] = o.String } - if true { - toSerialize["byte"] = o.Byte - } + toSerialize["byte"] = o.Byte if !isNil(o.Binary) { toSerialize["binary"] = o.Binary } - if true { - toSerialize["date"] = o.Date - } + toSerialize["date"] = o.Date if !isNil(o.DateTime) { toSerialize["dateTime"] = o.DateTime } if !isNil(o.Uuid) { toSerialize["uuid"] = o.Uuid } - if true { - toSerialize["password"] = o.Password - } + toSerialize["password"] = o.Password if !isNil(o.PatternWithDigits) { toSerialize["pattern_with_digits"] = o.PatternWithDigits } @@ -561,7 +564,7 @@ func (o FormatTest) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *FormatTest) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_has_only_read_only.go b/samples/openapi3/client/petstore/go/go-petstore/model_has_only_read_only.go index 1472cc900592..37446bd9cce1 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_has_only_read_only.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_has_only_read_only.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the HasOnlyReadOnly type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &HasOnlyReadOnly{} + // HasOnlyReadOnly struct for HasOnlyReadOnly type HasOnlyReadOnly struct { Bar *string `json:"bar,omitempty"` @@ -105,6 +108,14 @@ func (o *HasOnlyReadOnly) SetFoo(v string) { } func (o HasOnlyReadOnly) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o HasOnlyReadOnly) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if !isNil(o.Bar) { toSerialize["bar"] = o.Bar @@ -117,7 +128,7 @@ func (o HasOnlyReadOnly) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *HasOnlyReadOnly) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_health_check_result.go b/samples/openapi3/client/petstore/go/go-petstore/model_health_check_result.go index c38d5f97d47b..4338603ff867 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_health_check_result.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_health_check_result.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the HealthCheckResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &HealthCheckResult{} + // HealthCheckResult Just a string to inform instance is up and running. Make it nullable in hope to get it as pointer in generated model. type HealthCheckResult struct { NullableMessage NullableString `json:"NullableMessage,omitempty"` @@ -82,6 +85,14 @@ func (o *HealthCheckResult) UnsetNullableMessage() { } func (o HealthCheckResult) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o HealthCheckResult) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if o.NullableMessage.IsSet() { toSerialize["NullableMessage"] = o.NullableMessage.Get() @@ -91,7 +102,7 @@ func (o HealthCheckResult) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *HealthCheckResult) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_list.go b/samples/openapi3/client/petstore/go/go-petstore/model_list.go index c5c9ecb2efd7..0be0312e32e2 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_list.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_list.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the List type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &List{} + // List struct for List type List struct { Var123List *string `json:"123-list,omitempty"` @@ -72,6 +75,14 @@ func (o *List) SetVar123List(v string) { } func (o List) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o List) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if !isNil(o.Var123List) { toSerialize["123-list"] = o.Var123List @@ -81,7 +92,7 @@ func (o List) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *List) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_map_of_file_test_.go b/samples/openapi3/client/petstore/go/go-petstore/model_map_of_file_test_.go index fab6400f3343..a96502e08477 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_map_of_file_test_.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_map_of_file_test_.go @@ -15,6 +15,9 @@ import ( "os" ) +// checks if the MapOfFileTest type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &MapOfFileTest{} + // MapOfFileTest test map of file in a property type MapOfFileTest struct { // a property to test map of file @@ -74,6 +77,14 @@ func (o *MapOfFileTest) SetPropTest(v map[string]*os.File) { } func (o MapOfFileTest) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o MapOfFileTest) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if !isNil(o.PropTest) { toSerialize["prop_test"] = o.PropTest @@ -83,7 +94,7 @@ func (o MapOfFileTest) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *MapOfFileTest) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_map_test_.go b/samples/openapi3/client/petstore/go/go-petstore/model_map_test_.go index 6d983de7315c..2f8a6f6371d1 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_map_test_.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_map_test_.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the MapTest type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &MapTest{} + // MapTest struct for MapTest type MapTest struct { MapMapOfString *map[string]map[string]string `json:"map_map_of_string,omitempty"` @@ -171,6 +174,14 @@ func (o *MapTest) SetIndirectMap(v map[string]bool) { } func (o MapTest) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o MapTest) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if !isNil(o.MapMapOfString) { toSerialize["map_map_of_string"] = o.MapMapOfString @@ -189,7 +200,7 @@ func (o MapTest) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *MapTest) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_mixed_properties_and_additional_properties_class.go b/samples/openapi3/client/petstore/go/go-petstore/model_mixed_properties_and_additional_properties_class.go index 932ba1768a09..5034ef2bc92a 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_mixed_properties_and_additional_properties_class.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_mixed_properties_and_additional_properties_class.go @@ -15,6 +15,9 @@ import ( "time" ) +// checks if the MixedPropertiesAndAdditionalPropertiesClass type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &MixedPropertiesAndAdditionalPropertiesClass{} + // MixedPropertiesAndAdditionalPropertiesClass struct for MixedPropertiesAndAdditionalPropertiesClass type MixedPropertiesAndAdditionalPropertiesClass struct { Uuid *string `json:"uuid,omitempty"` @@ -139,6 +142,14 @@ func (o *MixedPropertiesAndAdditionalPropertiesClass) SetMap(v map[string]Animal } func (o MixedPropertiesAndAdditionalPropertiesClass) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o MixedPropertiesAndAdditionalPropertiesClass) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if !isNil(o.Uuid) { toSerialize["uuid"] = o.Uuid @@ -154,7 +165,7 @@ func (o MixedPropertiesAndAdditionalPropertiesClass) MarshalJSON() ([]byte, erro toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *MixedPropertiesAndAdditionalPropertiesClass) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_name.go b/samples/openapi3/client/petstore/go/go-petstore/model_name.go index 167e669b2f42..22012a7d2cdb 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_name.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_name.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the Name type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Name{} + // Name Model for testing model name same as property name type Name struct { Name int32 `json:"name"` @@ -164,10 +167,16 @@ func (o *Name) SetVar123Number(v int32) { } func (o Name) MarshalJSON() ([]byte, error) { - toSerialize := map[string]interface{}{} - if true { - toSerialize["name"] = o.Name + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err } + return json.Marshal(toSerialize) +} + +func (o Name) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["name"] = o.Name if !isNil(o.SnakeCase) { toSerialize["snake_case"] = o.SnakeCase } @@ -182,7 +191,7 @@ func (o Name) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *Name) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_nullable_all_of.go b/samples/openapi3/client/petstore/go/go-petstore/model_nullable_all_of.go index 47f8019b4438..b773106a35eb 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_nullable_all_of.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_nullable_all_of.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the NullableAllOf type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &NullableAllOf{} + // NullableAllOf struct for NullableAllOf type NullableAllOf struct { Child NullableNullableAllOfChild `json:"child,omitempty"` @@ -82,6 +85,14 @@ func (o *NullableAllOf) UnsetChild() { } func (o NullableAllOf) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o NullableAllOf) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if o.Child.IsSet() { toSerialize["child"] = o.Child.Get() @@ -91,7 +102,7 @@ func (o NullableAllOf) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *NullableAllOf) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_nullable_all_of_child.go b/samples/openapi3/client/petstore/go/go-petstore/model_nullable_all_of_child.go index 31fa0dc39986..777c1cba4764 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_nullable_all_of_child.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_nullable_all_of_child.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the NullableAllOfChild type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &NullableAllOfChild{} + // NullableAllOfChild struct for NullableAllOfChild type NullableAllOfChild struct { Name *string `json:"name,omitempty"` @@ -72,6 +75,14 @@ func (o *NullableAllOfChild) SetName(v string) { } func (o NullableAllOfChild) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o NullableAllOfChild) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if !isNil(o.Name) { toSerialize["name"] = o.Name @@ -81,7 +92,7 @@ func (o NullableAllOfChild) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *NullableAllOfChild) UnmarshalJSON(bytes []byte) (err error) { 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 9eceb1aab4fe..3f55258256f7 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 @@ -15,6 +15,9 @@ import ( "time" ) +// checks if the NullableClass type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &NullableClass{} + // NullableClass struct for NullableClass type NullableClass struct { IntegerProp NullableInt32 `json:"integer_prop,omitempty"` @@ -501,6 +504,14 @@ func (o *NullableClass) SetObjectItemsNullable(v map[string]map[string]interface } func (o NullableClass) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o NullableClass) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if o.IntegerProp.IsSet() { toSerialize["integer_prop"] = o.IntegerProp.Get() @@ -538,7 +549,7 @@ func (o NullableClass) MarshalJSON() ([]byte, error) { if !isNil(o.ObjectItemsNullable) { toSerialize["object_items_nullable"] = o.ObjectItemsNullable } - return json.Marshal(toSerialize) + return toSerialize, nil } type NullableNullableClass struct { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_number_only.go b/samples/openapi3/client/petstore/go/go-petstore/model_number_only.go index 355f03eca4e4..7b98f85d8b78 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_number_only.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_number_only.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the NumberOnly type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &NumberOnly{} + // NumberOnly struct for NumberOnly type NumberOnly struct { JustNumber *float32 `json:"JustNumber,omitempty"` @@ -72,6 +75,14 @@ func (o *NumberOnly) SetJustNumber(v float32) { } func (o NumberOnly) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o NumberOnly) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if !isNil(o.JustNumber) { toSerialize["JustNumber"] = o.JustNumber @@ -81,7 +92,7 @@ func (o NumberOnly) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *NumberOnly) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_one_of_primitive_type_child.go b/samples/openapi3/client/petstore/go/go-petstore/model_one_of_primitive_type_child.go index 75da3eaeb4f7..f52fa72517f7 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_one_of_primitive_type_child.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_one_of_primitive_type_child.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the OneOfPrimitiveTypeChild type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &OneOfPrimitiveTypeChild{} + // OneOfPrimitiveTypeChild struct for OneOfPrimitiveTypeChild type OneOfPrimitiveTypeChild struct { Name *string `json:"name,omitempty"` @@ -72,6 +75,14 @@ func (o *OneOfPrimitiveTypeChild) SetName(v string) { } func (o OneOfPrimitiveTypeChild) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o OneOfPrimitiveTypeChild) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if !isNil(o.Name) { toSerialize["name"] = o.Name @@ -81,7 +92,7 @@ func (o OneOfPrimitiveTypeChild) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *OneOfPrimitiveTypeChild) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_order.go b/samples/openapi3/client/petstore/go/go-petstore/model_order.go index ab12f8725f08..45af84e4070c 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_order.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_order.go @@ -15,6 +15,9 @@ import ( "time" ) +// checks if the Order type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Order{} + // Order struct for Order type Order struct { Id *int64 `json:"id,omitempty"` @@ -243,6 +246,14 @@ func (o *Order) SetComplete(v bool) { } func (o Order) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Order) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if !isNil(o.Id) { toSerialize["id"] = o.Id @@ -267,7 +278,7 @@ func (o Order) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *Order) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_outer_composite.go b/samples/openapi3/client/petstore/go/go-petstore/model_outer_composite.go index 1e84b4df2f74..210cacc27105 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_outer_composite.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_outer_composite.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the OuterComposite type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &OuterComposite{} + // OuterComposite struct for OuterComposite type OuterComposite struct { MyNumber *float32 `json:"my_number,omitempty"` @@ -138,6 +141,14 @@ func (o *OuterComposite) SetMyBoolean(v bool) { } func (o OuterComposite) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o OuterComposite) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if !isNil(o.MyNumber) { toSerialize["my_number"] = o.MyNumber @@ -153,7 +164,7 @@ func (o OuterComposite) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *OuterComposite) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_pet.go b/samples/openapi3/client/petstore/go/go-petstore/model_pet.go index 3171045e49e1..008200fcb557 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_pet.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_pet.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the Pet type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Pet{} + // Pet struct for Pet type Pet struct { Id *int64 `json:"id,omitempty"` @@ -228,6 +231,14 @@ func (o *Pet) SetStatus(v string) { } func (o Pet) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Pet) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if !isNil(o.Id) { toSerialize["id"] = o.Id @@ -235,12 +246,8 @@ func (o Pet) MarshalJSON() ([]byte, error) { if !isNil(o.Category) { toSerialize["category"] = o.Category } - if true { - toSerialize["name"] = o.Name - } - if true { - toSerialize["photoUrls"] = o.PhotoUrls - } + toSerialize["name"] = o.Name + toSerialize["photoUrls"] = o.PhotoUrls if !isNil(o.Tags) { toSerialize["tags"] = o.Tags } @@ -252,7 +259,7 @@ func (o Pet) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *Pet) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_read_only_first.go b/samples/openapi3/client/petstore/go/go-petstore/model_read_only_first.go index 535f09e68dfe..56546056ecb3 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_read_only_first.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_read_only_first.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the ReadOnlyFirst type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &ReadOnlyFirst{} + // ReadOnlyFirst struct for ReadOnlyFirst type ReadOnlyFirst struct { Bar *string `json:"bar,omitempty"` @@ -105,6 +108,14 @@ func (o *ReadOnlyFirst) SetBaz(v string) { } func (o ReadOnlyFirst) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o ReadOnlyFirst) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if !isNil(o.Bar) { toSerialize["bar"] = o.Bar @@ -117,7 +128,7 @@ func (o ReadOnlyFirst) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *ReadOnlyFirst) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_read_only_with_default.go b/samples/openapi3/client/petstore/go/go-petstore/model_read_only_with_default.go index 66e40d42778b..3c754c02a15f 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_read_only_with_default.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_read_only_with_default.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the ReadOnlyWithDefault type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &ReadOnlyWithDefault{} + // ReadOnlyWithDefault struct for ReadOnlyWithDefault type ReadOnlyWithDefault struct { Prop1 *string `json:"prop1,omitempty"` @@ -282,6 +285,14 @@ func (o *ReadOnlyWithDefault) SetIntProp2(v float32) { } func (o ReadOnlyWithDefault) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o ReadOnlyWithDefault) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if !isNil(o.Prop1) { toSerialize["prop1"] = o.Prop1 @@ -309,7 +320,7 @@ func (o ReadOnlyWithDefault) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *ReadOnlyWithDefault) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_return.go b/samples/openapi3/client/petstore/go/go-petstore/model_return.go index dd4ef5496662..77cda0af9e40 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_return.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_return.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the Return type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Return{} + // Return Model for testing reserved words type Return struct { Return *int32 `json:"return,omitempty"` @@ -72,6 +75,14 @@ func (o *Return) SetReturn(v int32) { } func (o Return) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Return) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if !isNil(o.Return) { toSerialize["return"] = o.Return @@ -81,7 +92,7 @@ func (o Return) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *Return) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_tag.go b/samples/openapi3/client/petstore/go/go-petstore/model_tag.go index f6a0cf69f813..57fe9198929f 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_tag.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_tag.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the Tag type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Tag{} + // Tag struct for Tag type Tag struct { Id *int64 `json:"id,omitempty"` @@ -105,6 +108,14 @@ func (o *Tag) SetName(v string) { } func (o Tag) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Tag) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if !isNil(o.Id) { toSerialize["id"] = o.Id @@ -117,7 +128,7 @@ func (o Tag) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *Tag) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_user.go b/samples/openapi3/client/petstore/go/go-petstore/model_user.go index be7e90053227..389420e8e5ca 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_user.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_user.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the User type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &User{} + // User struct for User type User struct { Id *int64 `json:"id,omitempty"` @@ -443,6 +446,14 @@ func (o *User) SetArbitraryNullableTypeValue(v interface{}) { } func (o User) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o User) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if !isNil(o.Id) { toSerialize["id"] = o.Id @@ -485,7 +496,7 @@ func (o User) MarshalJSON() ([]byte, error) { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *User) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_whale.go b/samples/openapi3/client/petstore/go/go-petstore/model_whale.go index 8da3060406a2..f90923f10463 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_whale.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_whale.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the Whale type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Whale{} + // Whale struct for Whale type Whale struct { HasBaleen *bool `json:"hasBaleen,omitempty"` @@ -131,6 +134,14 @@ func (o *Whale) SetClassName(v string) { } func (o Whale) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Whale) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if !isNil(o.HasBaleen) { toSerialize["hasBaleen"] = o.HasBaleen @@ -138,15 +149,13 @@ func (o Whale) MarshalJSON() ([]byte, error) { if !isNil(o.HasTeeth) { toSerialize["hasTeeth"] = o.HasTeeth } - if true { - toSerialize["className"] = o.ClassName - } + toSerialize["className"] = o.ClassName for key, value := range o.AdditionalProperties { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *Whale) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/model_zebra.go b/samples/openapi3/client/petstore/go/go-petstore/model_zebra.go index 70a1ee363c61..76106e1eb546 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/model_zebra.go +++ b/samples/openapi3/client/petstore/go/go-petstore/model_zebra.go @@ -14,6 +14,9 @@ import ( "encoding/json" ) +// checks if the Zebra type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &Zebra{} + // Zebra struct for Zebra type Zebra struct { Type *string `json:"type,omitempty"` @@ -98,19 +101,25 @@ func (o *Zebra) SetClassName(v string) { } func (o Zebra) MarshalJSON() ([]byte, error) { + toSerialize,err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o Zebra) ToMap() (map[string]interface{}, error) { toSerialize := map[string]interface{}{} if !isNil(o.Type) { toSerialize["type"] = o.Type } - if true { - toSerialize["className"] = o.ClassName - } + toSerialize["className"] = o.ClassName for key, value := range o.AdditionalProperties { toSerialize[key] = value } - return json.Marshal(toSerialize) + return toSerialize, nil } func (o *Zebra) UnmarshalJSON(bytes []byte) (err error) { diff --git a/samples/openapi3/client/petstore/go/go-petstore/utils.go b/samples/openapi3/client/petstore/go/go-petstore/utils.go index f55144e1b47c..9e3eb715da43 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/utils.go +++ b/samples/openapi3/client/petstore/go/go-petstore/utils.go @@ -341,3 +341,7 @@ func isNil(i interface{}) bool { } return false } + +type MappedNullable interface { + ToMap() (map[string]interface{}, error) +} diff --git a/samples/openapi3/client/petstore/go/pet_api_test.go b/samples/openapi3/client/petstore/go/pet_api_test.go index f92873d5d12a..49896698b60a 100644 --- a/samples/openapi3/client/petstore/go/pet_api_test.go +++ b/samples/openapi3/client/petstore/go/pet_api_test.go @@ -184,6 +184,26 @@ func TestDeletePet(t *testing.T) { } } +// test deep object query parameter and verify via tcpdump +func TestDeepObjectQuery(t *testing.T) { + newPet := sw.Pet{ + Id: sw.PtrInt64(12830), Name: "gopher", + PhotoUrls: []string{"http://1.com", "http://2.com"}, Status: sw.PtrString("pending"), + Tags: []sw.Tag{{Id: sw.PtrInt64(1), Name: sw.PtrString("tag2")}}, + } + + newCategory := sw.Category{Id: sw.PtrInt64(12830), Name: "cat"} + configuration := sw.NewConfiguration() + apiClient := sw.NewAPIClient(configuration) + r, err := apiClient.FakeApi.TestQueryDeepObject(context.Background()).TestPet(newPet).InputOptions(newCategory).Execute() + if err != nil { + // for sure this will fail as the endpoint is fake + } + if r.StatusCode != 200 { + t.Log(r) + } +} + /* // Test we can concurrently create, retrieve, update, and delete. func TestConcurrency(t *testing.T) {