From 84b438abef8d16dc9328d6f376fd9be6088d9d17 Mon Sep 17 00:00:00 2001
From: William Cheng <wing328hk@gmail.com>
Date: Wed, 21 Nov 2018 13:26:13 +0800
Subject: [PATCH 1/3] update elixir samples

---
 .../elixir/.openapi-generator/VERSION         |  2 +-
 .../client/petstore/elixir/config/config.exs  |  4 +-
 .../lib/openapi_petstore/api/another_fake.ex  |  6 +-
 .../elixir/lib/openapi_petstore/api/fake.ex   | 70 +++++++++++++++++--
 .../elixir/lib/openapi_petstore/api/pet.ex    | 30 ++++++++
 .../elixir/lib/openapi_petstore/connection.ex |  2 +-
 .../lib/openapi_petstore/model/map_test.ex    |  8 ++-
 .../openapi_petstore/model/outer_composite.ex |  6 +-
 8 files changed, 112 insertions(+), 16 deletions(-)

diff --git a/samples/client/petstore/elixir/.openapi-generator/VERSION b/samples/client/petstore/elixir/.openapi-generator/VERSION
index 096bf47efe3..d077ffb477a 100644
--- a/samples/client/petstore/elixir/.openapi-generator/VERSION
+++ b/samples/client/petstore/elixir/.openapi-generator/VERSION
@@ -1 +1 @@
-3.0.0-SNAPSHOT
\ No newline at end of file
+3.3.4-SNAPSHOT
\ No newline at end of file
diff --git a/samples/client/petstore/elixir/config/config.exs b/samples/client/petstore/elixir/config/config.exs
index 7ce1553ff17..72508194de3 100644
--- a/samples/client/petstore/elixir/config/config.exs
+++ b/samples/client/petstore/elixir/config/config.exs
@@ -10,11 +10,11 @@ use Mix.Config
 
 # You can configure for your application as:
 #
-#     config :swagger_petstore, key: :value
+#     config :open_api_petstore, key: :value
 #
 # And access this configuration in your application as:
 #
-#     Application.get_env(:swagger_petstore, :key)
+#     Application.get_env(:open_api_petstore, :key)
 #
 # Or configure a 3rd-party app:
 #
diff --git a/samples/client/petstore/elixir/lib/openapi_petstore/api/another_fake.ex b/samples/client/petstore/elixir/lib/openapi_petstore/api/another_fake.ex
index fe8ba559f33..b5fa2e8b3cd 100644
--- a/samples/client/petstore/elixir/lib/openapi_petstore/api/another_fake.ex
+++ b/samples/client/petstore/elixir/lib/openapi_petstore/api/another_fake.ex
@@ -13,7 +13,7 @@ defmodule OpenapiPetstore.Api.AnotherFake do
 
   @doc """
   To test special tags
-  To test special tags
+  To test special tags and operation ID starting with number
 
   ## Parameters
 
@@ -25,8 +25,8 @@ defmodule OpenapiPetstore.Api.AnotherFake do
   {:ok, %OpenapiPetstore.Model.Client{}} on success
   {:error, info} on failure
   """
-  @spec test_special_tags(Tesla.Env.client, OpenapiPetstore.Model.Client.t, keyword()) :: {:ok, OpenapiPetstore.Model.Client.t} | {:error, Tesla.Env.t}
-  def test_special_tags(connection, client, _opts \\ []) do
+  @spec 123_test_special_tags(Tesla.Env.client, OpenapiPetstore.Model.Client.t, keyword()) :: {:ok, OpenapiPetstore.Model.Client.t} | {:error, Tesla.Env.t}
+  def 123_test_special_tags(connection, client, _opts \\ []) do
     %{}
     |> method(:patch)
     |> url("/another-fake/dummy")
diff --git a/samples/client/petstore/elixir/lib/openapi_petstore/api/fake.ex b/samples/client/petstore/elixir/lib/openapi_petstore/api/fake.ex
index 92281bc7f3c..6e04b911898 100644
--- a/samples/client/petstore/elixir/lib/openapi_petstore/api/fake.ex
+++ b/samples/client/petstore/elixir/lib/openapi_petstore/api/fake.ex
@@ -21,7 +21,7 @@ defmodule OpenapiPetstore.Api.Fake do
     - :body (boolean()): Input boolean as post body
   ## Returns
 
-  {:ok, %OpenapiPetstore.Model.Boolean{}} on success
+  {:ok, %OpenapiPetstore.Model.boolean(){}} on success
   {:error, info} on failure
   """
   @spec fake_outer_boolean_serialize(Tesla.Env.client, keyword()) :: {:ok, Boolean.t} | {:error, Tesla.Env.t}
@@ -75,7 +75,7 @@ defmodule OpenapiPetstore.Api.Fake do
     - :body (float()): Input number as post body
   ## Returns
 
-  {:ok, %OpenapiPetstore.Model.Float{}} on success
+  {:ok, %OpenapiPetstore.Model.float(){}} on success
   {:error, info} on failure
   """
   @spec fake_outer_number_serialize(Tesla.Env.client, keyword()) :: {:ok, Float.t} | {:error, Tesla.Env.t}
@@ -102,7 +102,7 @@ defmodule OpenapiPetstore.Api.Fake do
     - :body (String.t): Input string as post body
   ## Returns
 
-  {:ok, %OpenapiPetstore.Model.String{}} on success
+  {:ok, %OpenapiPetstore.Model.String.t{}} on success
   {:error, info} on failure
   """
   @spec fake_outer_string_serialize(Tesla.Env.client, keyword()) :: {:ok, String.t} | {:error, Tesla.Env.t}
@@ -119,6 +119,30 @@ defmodule OpenapiPetstore.Api.Fake do
     |> decode(false)
   end
 
+  @doc """
+  For this test, the body for this request much reference a schema named &#x60;File&#x60;.
+
+  ## Parameters
+
+  - connection (OpenapiPetstore.Connection): Connection to server
+  - file_schema_test_class (FileSchemaTestClass): 
+  - opts (KeywordList): [optional] Optional parameters
+  ## Returns
+
+  {:ok, %{}} on success
+  {:error, info} on failure
+  """
+  @spec test_body_with_file_schema(Tesla.Env.client, OpenapiPetstore.Model.FileSchemaTestClass.t, keyword()) :: {:ok, nil} | {:error, Tesla.Env.t}
+  def test_body_with_file_schema(connection, file_schema_test_class, _opts \\ []) do
+    %{}
+    |> method(:put)
+    |> url("/fake/body-with-file-schema")
+    |> add_param(:body, :"FileSchemaTestClass", file_schema_test_class)
+    |> Enum.into([])
+    |> (&Connection.request(connection, &1)).()
+    |> decode(false)
+  end
+
   @doc """
 
   ## Parameters
@@ -265,13 +289,51 @@ defmodule OpenapiPetstore.Api.Fake do
     |> decode(false)
   end
 
+  @doc """
+  Fake endpoint to test group parameters (optional)
+  Fake endpoint to test group parameters (optional)
+
+  ## Parameters
+
+  - connection (OpenapiPetstore.Connection): Connection to server
+  - required_string_group (integer()): Required String in group parameters
+  - required_boolean_group (boolean()): Required Boolean in group parameters
+  - required_int64_group (integer()): Required Integer in group parameters
+  - opts (KeywordList): [optional] Optional parameters
+    - :string_group (integer()): String in group parameters
+    - :boolean_group (boolean()): Boolean in group parameters
+    - :int64_group (integer()): Integer in group parameters
+  ## Returns
+
+  {:ok, %{}} on success
+  {:error, info} on failure
+  """
+  @spec test_group_parameters(Tesla.Env.client, integer(), boolean(), integer(), keyword()) :: {:ok, nil} | {:error, Tesla.Env.t}
+  def test_group_parameters(connection, required_string_group, required_boolean_group, required_int64_group, opts \\ []) do
+    optional_params = %{
+      :"string_group" => :query,
+      :"boolean_group" => :headers,
+      :"int64_group" => :query
+    }
+    %{}
+    |> method(:delete)
+    |> url("/fake")
+    |> add_param(:query, :"required_string_group", required_string_group)
+    |> add_param(:headers, :"required_boolean_group", required_boolean_group)
+    |> add_param(:query, :"required_int64_group", required_int64_group)
+    |> add_optional_params(optional_params, opts)
+    |> Enum.into([])
+    |> (&Connection.request(connection, &1)).()
+    |> decode(false)
+  end
+
   @doc """
   test inline additionalProperties
 
   ## Parameters
 
   - connection (OpenapiPetstore.Connection): Connection to server
-  - request_body (String.t): request body
+  - request_body (%{optional(String.t) &#x3D;&gt; String.t}): request body
   - opts (KeywordList): [optional] Optional parameters
   ## Returns
 
diff --git a/samples/client/petstore/elixir/lib/openapi_petstore/api/pet.ex b/samples/client/petstore/elixir/lib/openapi_petstore/api/pet.ex
index ba926165d6d..777f3102f8e 100644
--- a/samples/client/petstore/elixir/lib/openapi_petstore/api/pet.ex
+++ b/samples/client/petstore/elixir/lib/openapi_petstore/api/pet.ex
@@ -220,4 +220,34 @@ defmodule OpenapiPetstore.Api.Pet do
     |> (&Connection.request(connection, &1)).()
     |> decode(%OpenapiPetstore.Model.ApiResponse{})
   end
+
+  @doc """
+  uploads an image (required)
+
+  ## Parameters
+
+  - connection (OpenapiPetstore.Connection): Connection to server
+  - pet_id (integer()): ID of pet to update
+  - required_file (String.t): file to upload
+  - opts (KeywordList): [optional] Optional parameters
+    - :additional_metadata (String.t): Additional data to pass to server
+  ## Returns
+
+  {:ok, %OpenapiPetstore.Model.ApiResponse{}} on success
+  {:error, info} on failure
+  """
+  @spec upload_file_with_required_file(Tesla.Env.client, integer(), String.t, keyword()) :: {:ok, OpenapiPetstore.Model.ApiResponse.t} | {:error, Tesla.Env.t}
+  def upload_file_with_required_file(connection, pet_id, required_file, opts \\ []) do
+    optional_params = %{
+      :"additionalMetadata" => :form
+    }
+    %{}
+    |> method(:post)
+    |> url("/fake/#{pet_id}/uploadImageWithRequiredFile")
+    |> add_param(:file, :"requiredFile", required_file)
+    |> add_optional_params(optional_params, opts)
+    |> Enum.into([])
+    |> (&Connection.request(connection, &1)).()
+    |> decode(%OpenapiPetstore.Model.ApiResponse{})
+  end
 end
diff --git a/samples/client/petstore/elixir/lib/openapi_petstore/connection.ex b/samples/client/petstore/elixir/lib/openapi_petstore/connection.ex
index a26f0761812..834cc003d10 100644
--- a/samples/client/petstore/elixir/lib/openapi_petstore/connection.ex
+++ b/samples/client/petstore/elixir/lib/openapi_petstore/connection.ex
@@ -15,7 +15,7 @@ defmodule OpenapiPetstore.Connection do
   plug Tesla.Middleware.EncodeJson
 
   @doc """
-  Configure an client connection using Basic authentication.
+  Configure a client connection using Basic authentication.
 
   ## Parameters
 
diff --git a/samples/client/petstore/elixir/lib/openapi_petstore/model/map_test.ex b/samples/client/petstore/elixir/lib/openapi_petstore/model/map_test.ex
index a1fac422b3d..d3870aa0075 100644
--- a/samples/client/petstore/elixir/lib/openapi_petstore/model/map_test.ex
+++ b/samples/client/petstore/elixir/lib/openapi_petstore/model/map_test.ex
@@ -10,12 +10,16 @@ defmodule OpenapiPetstore.Model.MapTest do
   @derive [Poison.Encoder]
   defstruct [
     :"map_map_of_string",
-    :"map_of_enum_string"
+    :"map_of_enum_string",
+    :"direct_map",
+    :"indirect_map"
   ]
 
   @type t :: %__MODULE__{
     :"map_map_of_string" => %{optional(String.t) => %{optional(String.t) => String.t}},
-    :"map_of_enum_string" => %{optional(String.t) => String.t}
+    :"map_of_enum_string" => %{optional(String.t) => String.t},
+    :"direct_map" => %{optional(String.t) => boolean()},
+    :"indirect_map" => %{optional(String.t) => boolean()}
   }
 end
 
diff --git a/samples/client/petstore/elixir/lib/openapi_petstore/model/outer_composite.ex b/samples/client/petstore/elixir/lib/openapi_petstore/model/outer_composite.ex
index a64e58740f6..00c4df9228e 100644
--- a/samples/client/petstore/elixir/lib/openapi_petstore/model/outer_composite.ex
+++ b/samples/client/petstore/elixir/lib/openapi_petstore/model/outer_composite.ex
@@ -15,9 +15,9 @@ defmodule OpenapiPetstore.Model.OuterComposite do
   ]
 
   @type t :: %__MODULE__{
-    :"my_number" => Float,
-    :"my_string" => String,
-    :"my_boolean" => Boolean
+    :"my_number" => float(),
+    :"my_string" => String.t,
+    :"my_boolean" => boolean()
   }
 end
 
-- 
GitLab


From 7b449ca1c7168a1a4fd2bc1a71bbf348ba6843bf Mon Sep 17 00:00:00 2001
From: William Cheng <wing328hk@gmail.com>
Date: Wed, 21 Nov 2018 16:31:27 +0800
Subject: [PATCH 2/3] fix function name starting with numbers

---
 .../codegen/languages/ElixirClientCodegen.java     | 14 +++++++++++++-
 .../src/main/resources/elixir/api.mustache         |  2 +-
 .../lib/openapi_petstore/api/another_fake.ex       |  4 ++--
 3 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElixirClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElixirClientCodegen.java
index 230100673c7..427a28fd400 100644
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElixirClientCodegen.java
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElixirClientCodegen.java
@@ -431,7 +431,19 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig
             throw new RuntimeException("Empty method name (operationId) not allowed");
         }
 
-        return org.openapitools.codegen.utils.StringUtils.camelize(sanitizeName(operationId));
+        // method name cannot use reserved keyword, e.g. return
+        if (isReservedWord(operationId)) {
+            LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + org.openapitools.codegen.utils.StringUtils.underscore(sanitizeName("call_" + operationId)));
+            return org.openapitools.codegen.utils.StringUtils.underscore(sanitizeName("call_" + operationId));
+        }
+
+        // operationId starts with a number
+        if (operationId.matches("^\\d.*")) {
+            LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + org.openapitools.codegen.utils.StringUtils.underscore(sanitizeName("call_" + operationId)));
+            operationId = "call_" + operationId;
+        }
+
+        return org.openapitools.codegen.utils.StringUtils.underscore(sanitizeName(operationId));
     }
 
     /**
diff --git a/modules/openapi-generator/src/main/resources/elixir/api.mustache b/modules/openapi-generator/src/main/resources/elixir/api.mustache
index 90ffb40f756..48bb292aae1 100644
--- a/modules/openapi-generator/src/main/resources/elixir/api.mustache
+++ b/modules/openapi-generator/src/main/resources/elixir/api.mustache
@@ -34,7 +34,7 @@ defmodule {{moduleName}}.Api.{{classname}} do
   {:error, info} on failure
   """
   {{{typespec}}}
-  def {{#underscored}}{{{operationId}}}{{/underscored}}(connection, {{#requiredParams}}{{#underscored}}{{{paramName}}}{{/underscored}}, {{/requiredParams}}{{^hasOptionalParams}}_{{/hasOptionalParams}}opts \\ []) do
+  def {{{operationId}}}(connection, {{#requiredParams}}{{#underscored}}{{{paramName}}}{{/underscored}}, {{/requiredParams}}{{^hasOptionalParams}}_{{/hasOptionalParams}}opts \\ []) do
 {{#optionalParams}}
 {{#-first}}
     optional_params = %{
diff --git a/samples/client/petstore/elixir/lib/openapi_petstore/api/another_fake.ex b/samples/client/petstore/elixir/lib/openapi_petstore/api/another_fake.ex
index b5fa2e8b3cd..3a20ea4fa7d 100644
--- a/samples/client/petstore/elixir/lib/openapi_petstore/api/another_fake.ex
+++ b/samples/client/petstore/elixir/lib/openapi_petstore/api/another_fake.ex
@@ -25,8 +25,8 @@ defmodule OpenapiPetstore.Api.AnotherFake do
   {:ok, %OpenapiPetstore.Model.Client{}} on success
   {:error, info} on failure
   """
-  @spec 123_test_special_tags(Tesla.Env.client, OpenapiPetstore.Model.Client.t, keyword()) :: {:ok, OpenapiPetstore.Model.Client.t} | {:error, Tesla.Env.t}
-  def 123_test_special_tags(connection, client, _opts \\ []) do
+  @spec call_123_test_special_tags(Tesla.Env.client, OpenapiPetstore.Model.Client.t, keyword()) :: {:ok, OpenapiPetstore.Model.Client.t} | {:error, Tesla.Env.t}
+  def call_123_test_special_tags(connection, client, _opts \\ []) do
     %{}
     |> method(:patch)
     |> url("/another-fake/dummy")
-- 
GitLab


From 5e2aaad071dccb98e1063a2e8834de326b688679 Mon Sep 17 00:00:00 2001
From: William Cheng <wing328hk@gmail.com>
Date: Fri, 23 Nov 2018 00:38:59 +0800
Subject: [PATCH 3/3] add new files

---
 .../petstore/elixir/.openapi-generator-ignore | 23 ++++++++++++++
 .../model/file_schema_test_class.ex           | 30 +++++++++++++++++++
 .../model/string_boolean_map.ex               | 25 ++++++++++++++++
 3 files changed, 78 insertions(+)
 create mode 100644 samples/client/petstore/elixir/.openapi-generator-ignore
 create mode 100644 samples/client/petstore/elixir/lib/openapi_petstore/model/file_schema_test_class.ex
 create mode 100644 samples/client/petstore/elixir/lib/openapi_petstore/model/string_boolean_map.ex

diff --git a/samples/client/petstore/elixir/.openapi-generator-ignore b/samples/client/petstore/elixir/.openapi-generator-ignore
new file mode 100644
index 00000000000..7484ee590a3
--- /dev/null
+++ b/samples/client/petstore/elixir/.openapi-generator-ignore
@@ -0,0 +1,23 @@
+# OpenAPI Generator Ignore
+# Generated by openapi-generator https://github.com/openapitools/openapi-generator
+
+# Use this file to prevent files from being overwritten by the generator.
+# The patterns follow closely to .gitignore or .dockerignore.
+
+# As an example, the C# client generator defines ApiClient.cs.
+# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
+#ApiClient.cs
+
+# You can match any string of characters against a directory, file or extension with a single asterisk (*):
+#foo/*/qux
+# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
+
+# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
+#foo/**/qux
+# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
+
+# You can also negate patterns with an exclamation (!).
+# For example, you can ignore all files in a docs folder with the file extension .md:
+#docs/*.md
+# Then explicitly reverse the ignore rule for a single file:
+#!docs/README.md
diff --git a/samples/client/petstore/elixir/lib/openapi_petstore/model/file_schema_test_class.ex b/samples/client/petstore/elixir/lib/openapi_petstore/model/file_schema_test_class.ex
new file mode 100644
index 00000000000..3a52359a5f0
--- /dev/null
+++ b/samples/client/petstore/elixir/lib/openapi_petstore/model/file_schema_test_class.ex
@@ -0,0 +1,30 @@
+# NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
+# https://openapi-generator.tech
+# Do not edit the class manually.
+
+defmodule OpenapiPetstore.Model.FileSchemaTestClass do
+  @moduledoc """
+  
+  """
+
+  @derive [Poison.Encoder]
+  defstruct [
+    :"file",
+    :"files"
+  ]
+
+  @type t :: %__MODULE__{
+    :"file" => File,
+    :"files" => [File]
+  }
+end
+
+defimpl Poison.Decoder, for: OpenapiPetstore.Model.FileSchemaTestClass do
+  import OpenapiPetstore.Deserializer
+  def decode(value, options) do
+    value
+    |> deserialize(:"file", :struct, OpenapiPetstore.Model.File, options)
+    |> deserialize(:"files", :list, OpenapiPetstore.Model.File, options)
+  end
+end
+
diff --git a/samples/client/petstore/elixir/lib/openapi_petstore/model/string_boolean_map.ex b/samples/client/petstore/elixir/lib/openapi_petstore/model/string_boolean_map.ex
new file mode 100644
index 00000000000..68c76b6fe59
--- /dev/null
+++ b/samples/client/petstore/elixir/lib/openapi_petstore/model/string_boolean_map.ex
@@ -0,0 +1,25 @@
+# NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
+# https://openapi-generator.tech
+# Do not edit the class manually.
+
+defmodule OpenapiPetstore.Model.StringBooleanMap do
+  @moduledoc """
+  
+  """
+
+  @derive [Poison.Encoder]
+  defstruct [
+    
+  ]
+
+  @type t :: %__MODULE__{
+    
+  }
+end
+
+defimpl Poison.Decoder, for: OpenapiPetstore.Model.StringBooleanMap do
+  def decode(value, _options) do
+    value
+  end
+end
+
-- 
GitLab