diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index aef49fd28e5..e0936c09b22 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -739,6 +739,16 @@ public class DefaultCodegen implements CodegenConfig { return name; } + /** + * Return the parameter name of array of model + * + * @param name name of the array model + * @return the sanitized parameter name + */ + public String toArrayModelParamName(String name) { + return toParamName(name); + } + /** * Return the Enum name (e.g. StatusEnum given 'status') * @@ -4232,7 +4242,7 @@ public class DefaultCodegen implements CodegenConfig { innerCp = innerCp.items; } codegenParameter.baseName = mostInnerItem.complexType; - codegenParameter.paramName = toParamName(mostInnerItem.complexType); + codegenParameter.paramName = toArrayModelParamName(mostInnerItem.complexType); codegenParameter.items = codegenProperty.items; codegenParameter.dataType = getTypeDeclaration(arraySchema); codegenParameter.baseType = getSchemaType(arraySchema); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ErlangClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ErlangClientCodegen.java index 1cb413dda00..323e81d6c71 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ErlangClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ErlangClientCodegen.java @@ -51,11 +51,11 @@ public class ErlangClientCodegen extends DefaultCodegen implements CodegenConfig setReservedWordsLowerCase( Arrays.asList( - "after","and","andalso","band","begin","bnot","bor","bsl","bsr","bxor","case", - "catch","cond","div","end","fun","if","let","not","of","or","orelse","receive", - "rem","try","when","xor" - ) - ); + "after", "and", "andalso", "band", "begin", "bnot", "bor", "bsl", "bsr", "bxor", "case", + "catch", "cond", "div", "end", "fun", "if", "let", "not", "of", "or", "orelse", "receive", + "rem", "try", "when", "xor" + ) + ); instantiationTypes.clear(); @@ -109,12 +109,11 @@ public class ErlangClientCodegen extends DefaultCodegen implements CodegenConfig public String getSchemaType(Schema p) { String schemaType = super.getSchemaType(p); String type = null; - if(typeMapping.containsKey(schemaType)) { + if (typeMapping.containsKey(schemaType)) { type = typeMapping.get(schemaType); - if(languageSpecificPrimitives.contains(type)) + if (languageSpecificPrimitives.contains(type)) return (type); - } - else + } else type = getTypeDeclaration(toModelName(snakeCase(schemaType))); return type; } @@ -125,15 +124,13 @@ public class ErlangClientCodegen extends DefaultCodegen implements CodegenConfig if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) { setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME)); - } - else { + } else { setPackageName("swagger"); } if (additionalProperties.containsKey(CodegenConstants.PACKAGE_VERSION)) { setPackageVersion((String) additionalProperties.get(CodegenConstants.PACKAGE_VERSION)); - } - else { + } else { setPackageVersion("1.0.0"); } @@ -157,7 +154,7 @@ public class ErlangClientCodegen extends DefaultCodegen implements CodegenConfig modelPackage = packageName; apiPackage = packageName; - supportingFiles.add(new SupportingFile("rebar.config.mustache","", "rebar.config")); + supportingFiles.add(new SupportingFile("rebar.config.mustache", "", "rebar.config")); supportingFiles.add(new SupportingFile("app.src.mustache", "", "src" + File.separator + this.packageName + ".app.src")); supportingFiles.add(new SupportingFile("utils.mustache", "", "src" + File.separator + this.packageName + "_utils.erl")); supportingFiles.add(new SupportingFile("README.mustache", "", "README.md")); @@ -177,8 +174,7 @@ public class ErlangClientCodegen extends DefaultCodegen implements CodegenConfig } @Override - public String escapeReservedWord(String name) - { + public String escapeReservedWord(String name) { // Can't start with an underscore, as our fields need to start with an // UppercaseLetter so that Go treats them as public/visible. @@ -190,7 +186,7 @@ public class ErlangClientCodegen extends DefaultCodegen implements CodegenConfig // - X_Name // ... or maybe a suffix? // - Name_ ... think this will work. - if(this.reservedWordsMappings().containsKey(name)) { + if (this.reservedWordsMappings().containsKey(name)) { return this.reservedWordsMappings().get(name); } return camelize(name) + '_'; @@ -222,6 +218,20 @@ public class ErlangClientCodegen extends DefaultCodegen implements CodegenConfig return camelize(toVarName(name)); } + @Override + public String toArrayModelParamName(String name) { + if (name == null) { + LOGGER.warn("parameter name for array model is null. Default to 'array_model'."); + name = "array_model"; + } + + if (name.indexOf(":") > 0) { + name = name.substring(0, name.indexOf(":")) + "_array"; + } + + return toParamName(name); + } + @Override public String toModelName(String name) { return this.packageName + "_" + underscore(name.replaceAll("-", "_").replaceAll("\\.", "_")); @@ -383,8 +393,8 @@ public class ErlangClientCodegen extends DefaultCodegen implements CodegenConfig this.produces = o.produces; this.bodyParam = o.bodyParam; this.allParams = o.allParams; - this.arityRequired = Integer.toString(lengthRequired(o.allParams)+1); - this.arityOptional = Integer.toString(lengthRequired(o.allParams)+2); + this.arityRequired = Integer.toString(lengthRequired(o.allParams) + 1); + this.arityOptional = Integer.toString(lengthRequired(o.allParams) + 2); this.bodyParams = o.bodyParams; this.pathParams = o.pathParams; this.queryParams = o.queryParams; diff --git a/samples/client/petstore/erlang-client/.swagger-codegen/VERSION b/samples/client/petstore/erlang-client/.swagger-codegen/VERSION index cc6612c36e0..096bf47efe3 100644 --- a/samples/client/petstore/erlang-client/.swagger-codegen/VERSION +++ b/samples/client/petstore/erlang-client/.swagger-codegen/VERSION @@ -1 +1 @@ -2.3.0 \ No newline at end of file +3.0.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/erlang-client/src/petstore_pet_api.erl b/samples/client/petstore/erlang-client/src/petstore_pet_api.erl index 88e9829da62..bbb664f66bd 100644 --- a/samples/client/petstore/erlang-client/src/petstore_pet_api.erl +++ b/samples/client/petstore/erlang-client/src/petstore_pet_api.erl @@ -12,12 +12,13 @@ -define(BASE_URL, "/v2"). %% @doc Add a new pet to the store +%% -spec add_pet(ctx:ctx(), petstore_pet:petstore_pet()) -> {ok, [], petstore_utils:response_info()} | {ok, hackney:client_ref()} | {error, term(), petstore_utils:response_info()}. -add_pet(Ctx, Body) -> - add_pet(Ctx, Body, #{}). +add_pet(Ctx, PetstorePet) -> + add_pet(Ctx, PetstorePet, #{}). -spec add_pet(ctx:ctx(), petstore_pet:petstore_pet(), maps:map()) -> {ok, [], petstore_utils:response_info()} | {ok, hackney:client_ref()} | {error, term(), petstore_utils:response_info()}. -add_pet(Ctx, Body, Optional) -> +add_pet(Ctx, PetstorePet, Optional) -> _OptionalParams = maps:get(params, Optional, #{}), Cfg = maps:get(cfg, Optional, application:get_env(kuberl, config, #{})), @@ -25,13 +26,14 @@ add_pet(Ctx, Body, Optional) -> Path = ["/pet"], QS = [], Headers = [], - Body1 = Body, + Body1 = PetstorePet, ContentTypeHeader = petstore_utils:select_header_content_type([<<"application/json">>, <<"application/xml">>]), Opts = maps:get(hackney_opts, Optional, []), petstore_utils:request(Ctx, Method, [?BASE_URL, Path], QS, ContentTypeHeader++Headers, Body1, Opts, Cfg). %% @doc Deletes a pet +%% -spec delete_pet(ctx:ctx(), integer()) -> {ok, [], petstore_utils:response_info()} | {ok, hackney:client_ref()} | {error, term(), petstore_utils:response_info()}. delete_pet(Ctx, PetId) -> delete_pet(Ctx, PetId, #{}). @@ -115,12 +117,13 @@ get_pet_by_id(Ctx, PetId, Optional) -> petstore_utils:request(Ctx, Method, [?BASE_URL, Path], QS, ContentTypeHeader++Headers, Body1, Opts, Cfg). %% @doc Update an existing pet +%% -spec update_pet(ctx:ctx(), petstore_pet:petstore_pet()) -> {ok, [], petstore_utils:response_info()} | {ok, hackney:client_ref()} | {error, term(), petstore_utils:response_info()}. -update_pet(Ctx, Body) -> - update_pet(Ctx, Body, #{}). +update_pet(Ctx, PetstorePet) -> + update_pet(Ctx, PetstorePet, #{}). -spec update_pet(ctx:ctx(), petstore_pet:petstore_pet(), maps:map()) -> {ok, [], petstore_utils:response_info()} | {ok, hackney:client_ref()} | {error, term(), petstore_utils:response_info()}. -update_pet(Ctx, Body, Optional) -> +update_pet(Ctx, PetstorePet, Optional) -> _OptionalParams = maps:get(params, Optional, #{}), Cfg = maps:get(cfg, Optional, application:get_env(kuberl, config, #{})), @@ -128,13 +131,14 @@ update_pet(Ctx, Body, Optional) -> Path = ["/pet"], QS = [], Headers = [], - Body1 = Body, + Body1 = PetstorePet, ContentTypeHeader = petstore_utils:select_header_content_type([<<"application/json">>, <<"application/xml">>]), Opts = maps:get(hackney_opts, Optional, []), petstore_utils:request(Ctx, Method, [?BASE_URL, Path], QS, ContentTypeHeader++Headers, Body1, Opts, Cfg). %% @doc Updates a pet in the store with form data +%% -spec update_pet_with_form(ctx:ctx(), integer()) -> {ok, [], petstore_utils:response_info()} | {ok, hackney:client_ref()} | {error, term(), petstore_utils:response_info()}. update_pet_with_form(Ctx, PetId) -> update_pet_with_form(Ctx, PetId, #{}). @@ -155,6 +159,7 @@ update_pet_with_form(Ctx, PetId, Optional) -> petstore_utils:request(Ctx, Method, [?BASE_URL, Path], QS, ContentTypeHeader++Headers, Body1, Opts, Cfg). %% @doc uploads an image +%% -spec upload_file(ctx:ctx(), integer()) -> {ok, petstore_api_response:petstore_api_response(), petstore_utils:response_info()} | {ok, hackney:client_ref()} | {error, term(), petstore_utils:response_info()}. upload_file(Ctx, PetId) -> upload_file(Ctx, PetId, #{}). diff --git a/samples/client/petstore/erlang-client/src/petstore_store_api.erl b/samples/client/petstore/erlang-client/src/petstore_store_api.erl index edb764f1d94..178cd0a2cb2 100644 --- a/samples/client/petstore/erlang-client/src/petstore_store_api.erl +++ b/samples/client/petstore/erlang-client/src/petstore_store_api.erl @@ -71,12 +71,13 @@ get_order_by_id(Ctx, OrderId, Optional) -> petstore_utils:request(Ctx, Method, [?BASE_URL, Path], QS, ContentTypeHeader++Headers, Body1, Opts, Cfg). %% @doc Place an order for a pet +%% -spec place_order(ctx:ctx(), petstore_order:petstore_order()) -> {ok, petstore_order:petstore_order(), petstore_utils:response_info()} | {ok, hackney:client_ref()} | {error, term(), petstore_utils:response_info()}. -place_order(Ctx, Body) -> - place_order(Ctx, Body, #{}). +place_order(Ctx, PetstoreOrder) -> + place_order(Ctx, PetstoreOrder, #{}). -spec place_order(ctx:ctx(), petstore_order:petstore_order(), maps:map()) -> {ok, petstore_order:petstore_order(), petstore_utils:response_info()} | {ok, hackney:client_ref()} | {error, term(), petstore_utils:response_info()}. -place_order(Ctx, Body, Optional) -> +place_order(Ctx, PetstoreOrder, Optional) -> _OptionalParams = maps:get(params, Optional, #{}), Cfg = maps:get(cfg, Optional, application:get_env(kuberl, config, #{})), @@ -84,7 +85,7 @@ place_order(Ctx, Body, Optional) -> Path = ["/store/order"], QS = [], Headers = [], - Body1 = Body, + Body1 = PetstoreOrder, ContentTypeHeader = petstore_utils:select_header_content_type([]), Opts = maps:get(hackney_opts, Optional, []), diff --git a/samples/client/petstore/erlang-client/src/petstore_user_api.erl b/samples/client/petstore/erlang-client/src/petstore_user_api.erl index d6b95213fbf..b1f07026be8 100644 --- a/samples/client/petstore/erlang-client/src/petstore_user_api.erl +++ b/samples/client/petstore/erlang-client/src/petstore_user_api.erl @@ -14,11 +14,11 @@ %% @doc Create user %% This can only be done by the logged in user. -spec create_user(ctx:ctx(), petstore_user:petstore_user()) -> {ok, [], petstore_utils:response_info()} | {ok, hackney:client_ref()} | {error, term(), petstore_utils:response_info()}. -create_user(Ctx, Body) -> - create_user(Ctx, Body, #{}). +create_user(Ctx, PetstoreUser) -> + create_user(Ctx, PetstoreUser, #{}). -spec create_user(ctx:ctx(), petstore_user:petstore_user(), maps:map()) -> {ok, [], petstore_utils:response_info()} | {ok, hackney:client_ref()} | {error, term(), petstore_utils:response_info()}. -create_user(Ctx, Body, Optional) -> +create_user(Ctx, PetstoreUser, Optional) -> _OptionalParams = maps:get(params, Optional, #{}), Cfg = maps:get(cfg, Optional, application:get_env(kuberl, config, #{})), @@ -26,19 +26,20 @@ create_user(Ctx, Body, Optional) -> Path = ["/user"], QS = [], Headers = [], - Body1 = Body, + Body1 = PetstoreUser, ContentTypeHeader = petstore_utils:select_header_content_type([]), Opts = maps:get(hackney_opts, Optional, []), petstore_utils:request(Ctx, Method, [?BASE_URL, Path], QS, ContentTypeHeader++Headers, Body1, Opts, Cfg). %% @doc Creates list of users with given input array +%% -spec create_users_with_array_input(ctx:ctx(), list()) -> {ok, [], petstore_utils:response_info()} | {ok, hackney:client_ref()} | {error, term(), petstore_utils:response_info()}. -create_users_with_array_input(Ctx, Body) -> - create_users_with_array_input(Ctx, Body, #{}). +create_users_with_array_input(Ctx, PetstoreUserArray) -> + create_users_with_array_input(Ctx, PetstoreUserArray, #{}). -spec create_users_with_array_input(ctx:ctx(), list(), maps:map()) -> {ok, [], petstore_utils:response_info()} | {ok, hackney:client_ref()} | {error, term(), petstore_utils:response_info()}. -create_users_with_array_input(Ctx, Body, Optional) -> +create_users_with_array_input(Ctx, PetstoreUserArray, Optional) -> _OptionalParams = maps:get(params, Optional, #{}), Cfg = maps:get(cfg, Optional, application:get_env(kuberl, config, #{})), @@ -46,19 +47,20 @@ create_users_with_array_input(Ctx, Body, Optional) -> Path = ["/user/createWithArray"], QS = [], Headers = [], - Body1 = Body, + Body1 = PetstoreUserArray, ContentTypeHeader = petstore_utils:select_header_content_type([]), Opts = maps:get(hackney_opts, Optional, []), petstore_utils:request(Ctx, Method, [?BASE_URL, Path], QS, ContentTypeHeader++Headers, Body1, Opts, Cfg). %% @doc Creates list of users with given input array +%% -spec create_users_with_list_input(ctx:ctx(), list()) -> {ok, [], petstore_utils:response_info()} | {ok, hackney:client_ref()} | {error, term(), petstore_utils:response_info()}. -create_users_with_list_input(Ctx, Body) -> - create_users_with_list_input(Ctx, Body, #{}). +create_users_with_list_input(Ctx, PetstoreUserArray) -> + create_users_with_list_input(Ctx, PetstoreUserArray, #{}). -spec create_users_with_list_input(ctx:ctx(), list(), maps:map()) -> {ok, [], petstore_utils:response_info()} | {ok, hackney:client_ref()} | {error, term(), petstore_utils:response_info()}. -create_users_with_list_input(Ctx, Body, Optional) -> +create_users_with_list_input(Ctx, PetstoreUserArray, Optional) -> _OptionalParams = maps:get(params, Optional, #{}), Cfg = maps:get(cfg, Optional, application:get_env(kuberl, config, #{})), @@ -66,7 +68,7 @@ create_users_with_list_input(Ctx, Body, Optional) -> Path = ["/user/createWithList"], QS = [], Headers = [], - Body1 = Body, + Body1 = PetstoreUserArray, ContentTypeHeader = petstore_utils:select_header_content_type([]), Opts = maps:get(hackney_opts, Optional, []), @@ -94,6 +96,7 @@ delete_user(Ctx, Username, Optional) -> petstore_utils:request(Ctx, Method, [?BASE_URL, Path], QS, ContentTypeHeader++Headers, Body1, Opts, Cfg). %% @doc Get user by user name +%% -spec get_user_by_name(ctx:ctx(), binary()) -> {ok, petstore_user:petstore_user(), petstore_utils:response_info()} | {ok, hackney:client_ref()} | {error, term(), petstore_utils:response_info()}. get_user_by_name(Ctx, Username) -> get_user_by_name(Ctx, Username, #{}). @@ -114,6 +117,7 @@ get_user_by_name(Ctx, Username, Optional) -> petstore_utils:request(Ctx, Method, [?BASE_URL, Path], QS, ContentTypeHeader++Headers, Body1, Opts, Cfg). %% @doc Logs user into the system +%% -spec login_user(ctx:ctx(), binary(), binary()) -> {ok, binary(), petstore_utils:response_info()} | {ok, hackney:client_ref()} | {error, term(), petstore_utils:response_info()}. login_user(Ctx, Username, Password) -> login_user(Ctx, Username, Password, #{}). @@ -134,6 +138,7 @@ login_user(Ctx, Username, Password, Optional) -> petstore_utils:request(Ctx, Method, [?BASE_URL, Path], QS, ContentTypeHeader++Headers, Body1, Opts, Cfg). %% @doc Logs out current logged in user session +%% -spec logout_user(ctx:ctx()) -> {ok, [], petstore_utils:response_info()} | {ok, hackney:client_ref()} | {error, term(), petstore_utils:response_info()}. logout_user(Ctx) -> logout_user(Ctx, #{}). @@ -156,11 +161,11 @@ logout_user(Ctx, Optional) -> %% @doc Updated user %% This can only be done by the logged in user. -spec update_user(ctx:ctx(), binary(), petstore_user:petstore_user()) -> {ok, [], petstore_utils:response_info()} | {ok, hackney:client_ref()} | {error, term(), petstore_utils:response_info()}. -update_user(Ctx, Username, Body) -> - update_user(Ctx, Username, Body, #{}). +update_user(Ctx, Username, PetstoreUser) -> + update_user(Ctx, Username, PetstoreUser, #{}). -spec update_user(ctx:ctx(), binary(), petstore_user:petstore_user(), maps:map()) -> {ok, [], petstore_utils:response_info()} | {ok, hackney:client_ref()} | {error, term(), petstore_utils:response_info()}. -update_user(Ctx, Username, Body, Optional) -> +update_user(Ctx, Username, PetstoreUser, Optional) -> _OptionalParams = maps:get(params, Optional, #{}), Cfg = maps:get(cfg, Optional, application:get_env(kuberl, config, #{})), @@ -168,7 +173,7 @@ update_user(Ctx, Username, Body, Optional) -> Path = ["/user/", Username, ""], QS = [], Headers = [], - Body1 = Body, + Body1 = PetstoreUser, ContentTypeHeader = petstore_utils:select_header_content_type([]), Opts = maps:get(hackney_opts, Optional, []),