From 8edf6e52ad60dcdcb17507bbe30adc17d3b00655 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Fri, 4 May 2018 17:43:14 +0800 Subject: [PATCH] Update Elixir Petstore with OAS2 (#316) * restore elixir petstore original from codegen2x * update elixir generator to work with oas2 * minor fix to elixir generato * minor enhancement to templates * update elixir petstore with oas2 --- bin/elixir-petstore.sh | 2 +- .../languages/ElixirClientCodegen.java | 26 +++--- .../src/main/resources/elixir/api.mustache | 43 +++++---- .../elixir/.openapi-generator/VERSION | 2 +- .../lib/swagger_petstore/api/another_fake.ex | 7 +- .../elixir/lib/swagger_petstore/api/fake.ex | 90 +++++++++++-------- .../api/fake_classname_tags123.ex | 8 +- .../elixir/lib/swagger_petstore/api/pet.ex | 25 ++---- .../elixir/lib/swagger_petstore/api/store.ex | 11 +-- .../elixir/lib/swagger_petstore/api/user.ex | 39 +++----- .../lib/swagger_petstore/deserializer.ex | 14 +-- .../lib/swagger_petstore/model/enum_test.ex | 2 + .../lib/swagger_petstore/model/format_test.ex | 2 +- .../swagger_petstore/model/outer_boolean.ex | 25 ------ .../swagger_petstore/model/outer_composite.ex | 12 +-- .../swagger_petstore/model/outer_number.ex | 25 ------ .../swagger_petstore/model/outer_string.ex | 25 ------ 17 files changed, 137 insertions(+), 221 deletions(-) delete mode 100644 samples/client/petstore/elixir/lib/swagger_petstore/model/outer_boolean.ex delete mode 100644 samples/client/petstore/elixir/lib/swagger_petstore/model/outer_number.ex delete mode 100644 samples/client/petstore/elixir/lib/swagger_petstore/model/outer_string.ex diff --git a/bin/elixir-petstore.sh b/bin/elixir-petstore.sh index 2fe730aac8f..cfd1c765496 100755 --- a/bin/elixir-petstore.sh +++ b/bin/elixir-petstore.sh @@ -32,6 +32,6 @@ rm -Rf "samples/client/petstore/elixir/lib/swagger_petstore/lib/" # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" -args="$@ generate -t modules/openapi-generator/src/main/resources/elixir -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -l elixir -o samples/client/petstore/elixir" +args="generate -t modules/openapi-generator/src/main/resources/elixir -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -l elixir -o samples/client/petstore/elixir/ $@" java $JAVA_OPTS -jar $executable $args 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 b383d028195..d7d35146382 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 @@ -28,6 +28,8 @@ import io.swagger.v3.oas.models.media.*; import org.apache.commons.lang3.StringUtils; +import javax.jws.WebParam; +import java.io.File; import java.io.IOException; import java.io.Writer; import java.util.*; @@ -347,7 +349,7 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig for (String word : moduleName.split("\\.")) { underscoredWords.add(underscore(word)); } - return "lib/" + join("/", underscoredWords); + return ("lib/" + join("/", underscoredWords)).replace('/', File.separatorChar); } /** @@ -355,7 +357,7 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig * instantiated */ public String modelFileFolder() { - return outputFolder + "/" + sourceFolder() + "/" + "model"; + return outputFolder + File.separator + sourceFolder() + File.separator + "model"; } /** @@ -364,7 +366,7 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig */ @Override public String apiFileFolder() { - return outputFolder + "/" + sourceFolder() + "/" + "api"; + return outputFolder + File.separator + sourceFolder() + File.separator + "api"; } @Override @@ -456,14 +458,14 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig } else if (ModelUtils.isDateTimeSchema(p)) { return "DateTime.t"; } else if (ModelUtils.isObjectSchema(p)) { - // How to map it? + // TODO How to map it? return super.getTypeDeclaration(p); } else if (ModelUtils.isIntegerSchema(p)) { return "integer()"; } else if (ModelUtils.isNumberSchema(p)) { return "float()"; - } else if (ModelUtils.isBinarySchema(p)) { - return "binary()"; + } else if (ModelUtils.isBinarySchema(p) || ModelUtils.isFileSchema(p)) { + return "String.t"; } else if (ModelUtils.isBooleanSchema(p)) { return "boolean()"; } else if (!StringUtils.isEmpty(p.get$ref())) { // model @@ -546,6 +548,8 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig this.queryParams = o.queryParams; this.headerParams = o.headerParams; this.formParams = o.formParams; + this.requiredParams = o.requiredParams; + this.optionalParams = o.optionalParams; this.authMethods = o.authMethods; this.tags = o.tags; this.responses = o.responses; @@ -622,11 +626,7 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig } else if (param.isListContainer) { // list() sb.append("list("); - if (param.isBodyParam) { - buildTypespec(param.items.items, sb); - } else { - buildTypespec(param.items, sb); - } + buildTypespec(param.items, sb); sb.append(")"); } else if (param.isMapContainer) { // %{optional(String.t) => } @@ -636,7 +636,7 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig } else if (param.isPrimitiveType) { // like `integer()`, `String.t` sb.append(param.dataType); - } else if (param.isFile) { + } else if (param.isFile || param.isBinary) { sb.append("String.t"); } else { // .Model..t @@ -649,7 +649,7 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig private void buildTypespec(CodegenProperty property, StringBuilder sb) { if (property == null) { - LOGGER.warn("CodegenProperty cannot be null"); + LOGGER.error("CodegenProperty cannot be null. Please report the issue to https://github.com/openapitools/openapi-generator with the spec"); } else if (property.isListContainer) { sb.append("list("); buildTypespec(property.items, sb); diff --git a/modules/openapi-generator/src/main/resources/elixir/api.mustache b/modules/openapi-generator/src/main/resources/elixir/api.mustache index ece4d62da9a..90ffb40f756 100644 --- a/modules/openapi-generator/src/main/resources/elixir/api.mustache +++ b/modules/openapi-generator/src/main/resources/elixir/api.mustache @@ -21,35 +21,42 @@ defmodule {{moduleName}}.Api.{{classname}} do ## Parameters - connection ({{moduleName}}.Connection): Connection to server -{{#allParams}}{{#required}} - {{#underscored}}{{paramName}}{{/underscored}} ({{dataType}}): {{description}} -{{/required}}{{/allParams}} - opts (KeywordList): [optional] Optional parameters -{{#allParams}}{{^required}} - {{#underscored}}:{{paramName}}{{/underscored}} ({{dataType}}): {{description}} -{{/required}}{{/allParams}} +{{#requiredParams}} + - {{#underscored}}{{paramName}}{{/underscored}} ({{dataType}}): {{description}} +{{/requiredParams}} + - opts (KeywordList): [optional] Optional parameters +{{#optionalParams}} + - {{#underscored}}:{{paramName}}{{/underscored}} ({{dataType}}): {{description}} +{{/optionalParams}} ## Returns - {:ok, {{#isListContainer}}[%{{returnBaseType}}{}, ...]{{/isListContainer}}{{#isMapContainer}}%{}{{/isMapContainer}}{{^returnType}}%{}{{/returnType}}{{#returnSimpleType}}%{{#returnType}}{{#isMapContainer}}{{/isMapContainer}}{{moduleName}}.Model.{{{returnType}}}{{/returnType}}{}{{/returnSimpleType}}} on success + {:ok, {{#isListContainer}}[%{{returnBaseType}}{}, ...]{{/isListContainer}}{{#isMapContainer}}%{}{{/isMapContainer}}{{^returnType}}%{}{{/returnType}}{{#returnSimpleType}}%{{#returnType}}{{#isMapContainer}}{{/isMapContainer}}{{{moduleName}}}.Model.{{{returnType}}}{{/returnType}}{}{{/returnSimpleType}}} on success {:error, info} on failure """ - {{typespec}} - def {{#underscored}}{{operationId}}{{/underscored}}(connection, {{#allParams}}{{#required}}{{#underscored}}{{paramName}}{{/underscored}}, {{/required}}{{/allParams}}{{^hasOptionalParams}}_{{/hasOptionalParams}}opts \\ []) do -{{#hasOptionalParams}} + {{{typespec}}} + def {{#underscored}}{{{operationId}}}{{/underscored}}(connection, {{#requiredParams}}{{#underscored}}{{{paramName}}}{{/underscored}}, {{/requiredParams}}{{^hasOptionalParams}}_{{/hasOptionalParams}}opts \\ []) do +{{#optionalParams}} +{{#-first}} optional_params = %{ - {{#allParams}}{{^required}}{{^isPathParam}}:"{{baseName}}" => {{#isBodyParam}}:body{{/isBodyParam}}{{#isFormParam}}:form{{/isFormParam}}{{#isQueryParam}}:query{{/isQueryParam}}{{#isHeaderParam}}:headers{{/isHeaderParam}}{{/isPathParam}}{{#hasMore}}, - {{/hasMore}}{{/required}}{{/allParams}} +{{/-first}} + :"{{baseName}}" => {{#isBodyParam}}:body{{/isBodyParam}}{{#isFormParam}}:form{{/isFormParam}}{{#isQueryParam}}:query{{/isQueryParam}}{{#isHeaderParam}}:headers{{/isHeaderParam}}{{#hasMore}},{{/hasMore}} +{{#-last}} } -{{/hasOptionalParams}} +{{/-last}} +{{/optionalParams}} %{} |> method(:{{#underscored}}{{httpMethod}}{{/underscored}}) |> url("{{replacedPathName}}") -{{#allParams}} -{{#required}} -{{^isPathParam}} |> add_param({{#isBodyParam}}:body{{/isBodyParam}}{{#isFormParam}}{{#isMultipart}}{{#isFile}}:file{{/isFile}}{{^isFile}}:form{{/isFile}}{{/isMultipart}}{{^isMultipart}}:form{{/isMultipart}}{{/isFormParam}}{{#isQueryParam}}:query{{/isQueryParam}}{{#isHeaderParam}}:headers{{/isHeaderParam}}, :"{{baseName}}", {{#underscored}}{{paramName}}{{/underscored}}) +{{#requiredParams}} +{{^isPathParam}} + |> add_param({{#isBodyParam}}:body{{/isBodyParam}}{{#isFormParam}}{{#isMultipart}}{{#isFile}}:file{{/isFile}}{{^isFile}}:form{{/isFile}}{{/isMultipart}}{{^isMultipart}}:form{{/isMultipart}}{{/isFormParam}}{{#isQueryParam}}:query{{/isQueryParam}}{{#isHeaderParam}}:headers{{/isHeaderParam}}, :"{{baseName}}", {{#underscored}}{{paramName}}{{/underscored}}) {{/isPathParam}} -{{/required}} -{{/allParams}} -{{#hasOptionalParams}} +{{/requiredParams}} +{{#optionalParams}} +{{#-first}} |> add_optional_params(optional_params, opts) -{{/hasOptionalParams}} +{{/-first}} +{{/optionalParams}} |> Enum.into([]) |> (&Connection.request(connection, &1)).() |> decode({{decodedStruct}}) diff --git a/samples/client/petstore/elixir/.openapi-generator/VERSION b/samples/client/petstore/elixir/.openapi-generator/VERSION index f9f7450d135..096bf47efe3 100644 --- a/samples/client/petstore/elixir/.openapi-generator/VERSION +++ b/samples/client/petstore/elixir/.openapi-generator/VERSION @@ -1 +1 @@ -2.3.0-SNAPSHOT \ No newline at end of file +3.0.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/elixir/lib/swagger_petstore/api/another_fake.ex b/samples/client/petstore/elixir/lib/swagger_petstore/api/another_fake.ex index 43d707f09ee..eb9314edadc 100644 --- a/samples/client/petstore/elixir/lib/swagger_petstore/api/another_fake.ex +++ b/samples/client/petstore/elixir/lib/swagger_petstore/api/another_fake.ex @@ -18,20 +18,19 @@ defmodule SwaggerPetstore.Api.AnotherFake do ## Parameters - connection (SwaggerPetstore.Connection): Connection to server - - body (Client): client model + - client (Client): client model - opts (KeywordList): [optional] Optional parameters - ## Returns {:ok, %SwaggerPetstore.Model.Client{}} on success {:error, info} on failure """ @spec test_special_tags(Tesla.Env.client, SwaggerPetstore.Model.Client.t, keyword()) :: {:ok, SwaggerPetstore.Model.Client.t} | {:error, Tesla.Env.t} - def test_special_tags(connection, body, _opts \\ []) do + def test_special_tags(connection, client, _opts \\ []) do %{} |> method(:patch) |> url("/another-fake/dummy") - |> add_param(:body, :"body", body) + |> add_param(:body, :"Client", client) |> Enum.into([]) |> (&Connection.request(connection, &1)).() |> decode(%SwaggerPetstore.Model.Client{}) diff --git a/samples/client/petstore/elixir/lib/swagger_petstore/api/fake.ex b/samples/client/petstore/elixir/lib/swagger_petstore/api/fake.ex index 8dce861d196..df4e22db792 100644 --- a/samples/client/petstore/elixir/lib/swagger_petstore/api/fake.ex +++ b/samples/client/petstore/elixir/lib/swagger_petstore/api/fake.ex @@ -18,14 +18,13 @@ defmodule SwaggerPetstore.Api.Fake do - connection (SwaggerPetstore.Connection): Connection to server - opts (KeywordList): [optional] Optional parameters - - :body (OuterBoolean): Input boolean as post body - + - :body (boolean()): Input boolean as post body ## Returns - {:ok, %SwaggerPetstore.Model.OuterBoolean{}} on success + {:ok, %SwaggerPetstore.Model.Boolean{}} on success {:error, info} on failure """ - @spec fake_outer_boolean_serialize(Tesla.Env.client, keyword()) :: {:ok, SwaggerPetstore.Model.OuterBoolean.t} | {:error, Tesla.Env.t} + @spec fake_outer_boolean_serialize(Tesla.Env.client, keyword()) :: {:ok, Boolean.t} | {:error, Tesla.Env.t} def fake_outer_boolean_serialize(connection, opts \\ []) do optional_params = %{ :"body" => :body @@ -36,7 +35,7 @@ defmodule SwaggerPetstore.Api.Fake do |> add_optional_params(optional_params, opts) |> Enum.into([]) |> (&Connection.request(connection, &1)).() - |> decode(%SwaggerPetstore.Model.OuterBoolean{}) + |> decode(false) end @doc """ @@ -46,8 +45,7 @@ defmodule SwaggerPetstore.Api.Fake do - connection (SwaggerPetstore.Connection): Connection to server - opts (KeywordList): [optional] Optional parameters - - :body (OuterComposite): Input composite as post body - + - :outer_composite (OuterComposite): Input composite as post body ## Returns {:ok, %SwaggerPetstore.Model.OuterComposite{}} on success @@ -56,7 +54,7 @@ defmodule SwaggerPetstore.Api.Fake do @spec fake_outer_composite_serialize(Tesla.Env.client, keyword()) :: {:ok, SwaggerPetstore.Model.OuterComposite.t} | {:error, Tesla.Env.t} def fake_outer_composite_serialize(connection, opts \\ []) do optional_params = %{ - :"body" => :body + :"OuterComposite" => :body } %{} |> method(:post) @@ -74,14 +72,13 @@ defmodule SwaggerPetstore.Api.Fake do - connection (SwaggerPetstore.Connection): Connection to server - opts (KeywordList): [optional] Optional parameters - - :body (OuterNumber): Input number as post body - + - :body (float()): Input number as post body ## Returns - {:ok, %SwaggerPetstore.Model.OuterNumber{}} on success + {:ok, %SwaggerPetstore.Model.Float{}} on success {:error, info} on failure """ - @spec fake_outer_number_serialize(Tesla.Env.client, keyword()) :: {:ok, SwaggerPetstore.Model.OuterNumber.t} | {:error, Tesla.Env.t} + @spec fake_outer_number_serialize(Tesla.Env.client, keyword()) :: {:ok, Float.t} | {:error, Tesla.Env.t} def fake_outer_number_serialize(connection, opts \\ []) do optional_params = %{ :"body" => :body @@ -92,7 +89,7 @@ defmodule SwaggerPetstore.Api.Fake do |> add_optional_params(optional_params, opts) |> Enum.into([]) |> (&Connection.request(connection, &1)).() - |> decode(%SwaggerPetstore.Model.OuterNumber{}) + |> decode(false) end @doc """ @@ -102,14 +99,13 @@ defmodule SwaggerPetstore.Api.Fake do - connection (SwaggerPetstore.Connection): Connection to server - opts (KeywordList): [optional] Optional parameters - - :body (OuterString): Input string as post body - + - :body (String.t): Input string as post body ## Returns - {:ok, %SwaggerPetstore.Model.OuterString{}} on success + {:ok, %SwaggerPetstore.Model.String{}} on success {:error, info} on failure """ - @spec fake_outer_string_serialize(Tesla.Env.client, keyword()) :: {:ok, SwaggerPetstore.Model.OuterString.t} | {:error, Tesla.Env.t} + @spec fake_outer_string_serialize(Tesla.Env.client, keyword()) :: {:ok, String.t} | {:error, Tesla.Env.t} def fake_outer_string_serialize(connection, opts \\ []) do optional_params = %{ :"body" => :body @@ -120,7 +116,32 @@ defmodule SwaggerPetstore.Api.Fake do |> add_optional_params(optional_params, opts) |> Enum.into([]) |> (&Connection.request(connection, &1)).() - |> decode(%SwaggerPetstore.Model.OuterString{}) + |> decode(false) + end + + @doc """ + + ## Parameters + + - connection (SwaggerPetstore.Connection): Connection to server + - query (String.t): + - user (User): + - opts (KeywordList): [optional] Optional parameters + ## Returns + + {:ok, %{}} on success + {:error, info} on failure + """ + @spec test_body_with_query_params(Tesla.Env.client, String.t, SwaggerPetstore.Model.User.t, keyword()) :: {:ok, nil} | {:error, Tesla.Env.t} + def test_body_with_query_params(connection, query, user, _opts \\ []) do + %{} + |> method(:put) + |> url("/fake/body-with-query-params") + |> add_param(:query, :"query", query) + |> add_param(:body, :"User", user) + |> Enum.into([]) + |> (&Connection.request(connection, &1)).() + |> decode(false) end @doc """ @@ -130,20 +151,19 @@ defmodule SwaggerPetstore.Api.Fake do ## Parameters - connection (SwaggerPetstore.Connection): Connection to server - - body (Client): client model + - client (Client): client model - opts (KeywordList): [optional] Optional parameters - ## Returns {:ok, %SwaggerPetstore.Model.Client{}} on success {:error, info} on failure """ @spec test_client_model(Tesla.Env.client, SwaggerPetstore.Model.Client.t, keyword()) :: {:ok, SwaggerPetstore.Model.Client.t} | {:error, Tesla.Env.t} - def test_client_model(connection, body, _opts \\ []) do + def test_client_model(connection, client, _opts \\ []) do %{} |> method(:patch) |> url("/fake") - |> add_param(:body, :"body", body) + |> add_param(:body, :"Client", client) |> Enum.into([]) |> (&Connection.request(connection, &1)).() |> decode(%SwaggerPetstore.Model.Client{}) @@ -166,12 +186,11 @@ defmodule SwaggerPetstore.Api.Fake do - :int64 (integer()): None - :float (float()): None - :string (String.t): None - - :binary (binary()): None + - :binary (String.t): None - :date (Date.t): None - :date_time (DateTime.t): None - :password (String.t): None - :callback (String.t): None - ## Returns {:ok, %{}} on success @@ -212,15 +231,14 @@ defmodule SwaggerPetstore.Api.Fake do - connection (SwaggerPetstore.Connection): Connection to server - opts (KeywordList): [optional] Optional parameters - - :enum_form_string_array ([String.t]): Form parameter enum test (string array) - - :enum_form_string (String.t): Form parameter enum test (string) - :enum_header_string_array ([String.t]): Header parameter enum test (string array) - :enum_header_string (String.t): Header parameter enum test (string) - :enum_query_string_array ([String.t]): Query parameter enum test (string array) - :enum_query_string (String.t): Query parameter enum test (string) - :enum_query_integer (integer()): Query parameter enum test (double) - :enum_query_double (float()): Query parameter enum test (double) - + - :enum_form_string_array ([String.t]): Form parameter enum test (string array) + - :enum_form_string (String.t): Form parameter enum test (string) ## Returns {:ok, %{}} on success @@ -229,14 +247,14 @@ defmodule SwaggerPetstore.Api.Fake do @spec test_enum_parameters(Tesla.Env.client, keyword()) :: {:ok, nil} | {:error, Tesla.Env.t} def test_enum_parameters(connection, opts \\ []) do optional_params = %{ - :"enum_form_string_array" => :form, - :"enum_form_string" => :form, :"enum_header_string_array" => :headers, :"enum_header_string" => :headers, :"enum_query_string_array" => :query, :"enum_query_string" => :query, :"enum_query_integer" => :query, - :"enum_query_double" => :form + :"enum_query_double" => :query, + :"enum_form_string_array" => :form, + :"enum_form_string" => :form } %{} |> method(:get) @@ -249,25 +267,23 @@ defmodule SwaggerPetstore.Api.Fake do @doc """ test inline additionalProperties - ## Parameters - connection (SwaggerPetstore.Connection): Connection to server - - param (Object): request body + - request_body (String.t): request body - opts (KeywordList): [optional] Optional parameters - ## Returns {:ok, %{}} on success {:error, info} on failure """ - @spec test_inline_additional_properties(Tesla.Env.client, SwaggerPetstore.Model.Object.t, keyword()) :: {:ok, nil} | {:error, Tesla.Env.t} - def test_inline_additional_properties(connection, param, _opts \\ []) do + @spec test_inline_additional_properties(Tesla.Env.client, %{optional(String.t) => String.t}, keyword()) :: {:ok, nil} | {:error, Tesla.Env.t} + def test_inline_additional_properties(connection, request_body, _opts \\ []) do %{} |> method(:post) |> url("/fake/inline-additionalProperties") - |> add_param(:body, :"param", param) + |> add_param(:body, :"request_body", request_body) |> Enum.into([]) |> (&Connection.request(connection, &1)).() |> decode(false) @@ -275,7 +291,6 @@ defmodule SwaggerPetstore.Api.Fake do @doc """ test json serialization of form data - ## Parameters @@ -283,7 +298,6 @@ defmodule SwaggerPetstore.Api.Fake do - param (String.t): field1 - param2 (String.t): field2 - opts (KeywordList): [optional] Optional parameters - ## Returns {:ok, %{}} on success diff --git a/samples/client/petstore/elixir/lib/swagger_petstore/api/fake_classname_tags123.ex b/samples/client/petstore/elixir/lib/swagger_petstore/api/fake_classname_tags123.ex index 5d86755ec5d..530d2127cc8 100644 --- a/samples/client/petstore/elixir/lib/swagger_petstore/api/fake_classname_tags123.ex +++ b/samples/client/petstore/elixir/lib/swagger_petstore/api/fake_classname_tags123.ex @@ -13,24 +13,24 @@ defmodule SwaggerPetstore.Api.FakeClassnameTags123 do @doc """ To test class name in snake case + To test class name in snake case ## Parameters - connection (SwaggerPetstore.Connection): Connection to server - - body (Client): client model + - client (Client): client model - opts (KeywordList): [optional] Optional parameters - ## Returns {:ok, %SwaggerPetstore.Model.Client{}} on success {:error, info} on failure """ @spec test_classname(Tesla.Env.client, SwaggerPetstore.Model.Client.t, keyword()) :: {:ok, SwaggerPetstore.Model.Client.t} | {:error, Tesla.Env.t} - def test_classname(connection, body, _opts \\ []) do + def test_classname(connection, client, _opts \\ []) do %{} |> method(:patch) |> url("/fake_classname_test") - |> add_param(:body, :"body", body) + |> add_param(:body, :"Client", client) |> Enum.into([]) |> (&Connection.request(connection, &1)).() |> decode(%SwaggerPetstore.Model.Client{}) diff --git a/samples/client/petstore/elixir/lib/swagger_petstore/api/pet.ex b/samples/client/petstore/elixir/lib/swagger_petstore/api/pet.ex index 035ad7c8cb1..e2a4e3dd703 100644 --- a/samples/client/petstore/elixir/lib/swagger_petstore/api/pet.ex +++ b/samples/client/petstore/elixir/lib/swagger_petstore/api/pet.ex @@ -13,25 +13,23 @@ defmodule SwaggerPetstore.Api.Pet do @doc """ Add a new pet to the store - ## Parameters - connection (SwaggerPetstore.Connection): Connection to server - - body (Pet): Pet object that needs to be added to the store + - pet (Pet): Pet object that needs to be added to the store - opts (KeywordList): [optional] Optional parameters - ## Returns {:ok, %{}} on success {:error, info} on failure """ @spec add_pet(Tesla.Env.client, SwaggerPetstore.Model.Pet.t, keyword()) :: {:ok, nil} | {:error, Tesla.Env.t} - def add_pet(connection, body, _opts \\ []) do + def add_pet(connection, pet, _opts \\ []) do %{} |> method(:post) |> url("/pet") - |> add_param(:body, :"body", body) + |> add_param(:body, :"Pet", pet) |> Enum.into([]) |> (&Connection.request(connection, &1)).() |> decode(false) @@ -39,7 +37,6 @@ defmodule SwaggerPetstore.Api.Pet do @doc """ Deletes a pet - ## Parameters @@ -47,7 +44,6 @@ defmodule SwaggerPetstore.Api.Pet do - pet_id (integer()): Pet id to delete - opts (KeywordList): [optional] Optional parameters - :api_key (String.t): - ## Returns {:ok, %{}} on success @@ -76,7 +72,6 @@ defmodule SwaggerPetstore.Api.Pet do - connection (SwaggerPetstore.Connection): Connection to server - status ([String.t]): Status values that need to be considered for filter - opts (KeywordList): [optional] Optional parameters - ## Returns {:ok, [%Pet{}, ...]} on success @@ -102,7 +97,6 @@ defmodule SwaggerPetstore.Api.Pet do - connection (SwaggerPetstore.Connection): Connection to server - tags ([String.t]): Tags to filter by - opts (KeywordList): [optional] Optional parameters - ## Returns {:ok, [%Pet{}, ...]} on success @@ -128,7 +122,6 @@ defmodule SwaggerPetstore.Api.Pet do - connection (SwaggerPetstore.Connection): Connection to server - pet_id (integer()): ID of pet to return - opts (KeywordList): [optional] Optional parameters - ## Returns {:ok, %SwaggerPetstore.Model.Pet{}} on success @@ -146,25 +139,23 @@ defmodule SwaggerPetstore.Api.Pet do @doc """ Update an existing pet - ## Parameters - connection (SwaggerPetstore.Connection): Connection to server - - body (Pet): Pet object that needs to be added to the store + - pet (Pet): Pet object that needs to be added to the store - opts (KeywordList): [optional] Optional parameters - ## Returns {:ok, %{}} on success {:error, info} on failure """ @spec update_pet(Tesla.Env.client, SwaggerPetstore.Model.Pet.t, keyword()) :: {:ok, nil} | {:error, Tesla.Env.t} - def update_pet(connection, body, _opts \\ []) do + def update_pet(connection, pet, _opts \\ []) do %{} |> method(:put) |> url("/pet") - |> add_param(:body, :"body", body) + |> add_param(:body, :"Pet", pet) |> Enum.into([]) |> (&Connection.request(connection, &1)).() |> decode(false) @@ -172,7 +163,6 @@ defmodule SwaggerPetstore.Api.Pet do @doc """ Updates a pet in the store with form data - ## Parameters @@ -181,7 +171,6 @@ defmodule SwaggerPetstore.Api.Pet do - opts (KeywordList): [optional] Optional parameters - :name (String.t): Updated name of the pet - :status (String.t): Updated status of the pet - ## Returns {:ok, %{}} on success @@ -204,7 +193,6 @@ defmodule SwaggerPetstore.Api.Pet do @doc """ uploads an image - ## Parameters @@ -213,7 +201,6 @@ defmodule SwaggerPetstore.Api.Pet do - opts (KeywordList): [optional] Optional parameters - :additional_metadata (String.t): Additional data to pass to server - :file (String.t): file to upload - ## Returns {:ok, %SwaggerPetstore.Model.ApiResponse{}} on success diff --git a/samples/client/petstore/elixir/lib/swagger_petstore/api/store.ex b/samples/client/petstore/elixir/lib/swagger_petstore/api/store.ex index f604ecd82e7..67a8d86b5fe 100644 --- a/samples/client/petstore/elixir/lib/swagger_petstore/api/store.ex +++ b/samples/client/petstore/elixir/lib/swagger_petstore/api/store.ex @@ -20,7 +20,6 @@ defmodule SwaggerPetstore.Api.Store do - connection (SwaggerPetstore.Connection): Connection to server - order_id (String.t): ID of the order that needs to be deleted - opts (KeywordList): [optional] Optional parameters - ## Returns {:ok, %{}} on success @@ -44,7 +43,6 @@ defmodule SwaggerPetstore.Api.Store do - connection (SwaggerPetstore.Connection): Connection to server - opts (KeywordList): [optional] Optional parameters - ## Returns {:ok, %{}} on success @@ -69,7 +67,6 @@ defmodule SwaggerPetstore.Api.Store do - connection (SwaggerPetstore.Connection): Connection to server - order_id (integer()): ID of pet that needs to be fetched - opts (KeywordList): [optional] Optional parameters - ## Returns {:ok, %SwaggerPetstore.Model.Order{}} on success @@ -87,25 +84,23 @@ defmodule SwaggerPetstore.Api.Store do @doc """ Place an order for a pet - ## Parameters - connection (SwaggerPetstore.Connection): Connection to server - - body (Order): order placed for purchasing the pet + - order (Order): order placed for purchasing the pet - opts (KeywordList): [optional] Optional parameters - ## Returns {:ok, %SwaggerPetstore.Model.Order{}} on success {:error, info} on failure """ @spec place_order(Tesla.Env.client, SwaggerPetstore.Model.Order.t, keyword()) :: {:ok, SwaggerPetstore.Model.Order.t} | {:error, Tesla.Env.t} - def place_order(connection, body, _opts \\ []) do + def place_order(connection, order, _opts \\ []) do %{} |> method(:post) |> url("/store/order") - |> add_param(:body, :"body", body) + |> add_param(:body, :"Order", order) |> Enum.into([]) |> (&Connection.request(connection, &1)).() |> decode(%SwaggerPetstore.Model.Order{}) diff --git a/samples/client/petstore/elixir/lib/swagger_petstore/api/user.ex b/samples/client/petstore/elixir/lib/swagger_petstore/api/user.ex index cdcadfbea96..4f9baf55601 100644 --- a/samples/client/petstore/elixir/lib/swagger_petstore/api/user.ex +++ b/samples/client/petstore/elixir/lib/swagger_petstore/api/user.ex @@ -18,20 +18,19 @@ defmodule SwaggerPetstore.Api.User do ## Parameters - connection (SwaggerPetstore.Connection): Connection to server - - body (User): Created user object + - user (User): Created user object - opts (KeywordList): [optional] Optional parameters - ## Returns {:ok, %{}} on success {:error, info} on failure """ @spec create_user(Tesla.Env.client, SwaggerPetstore.Model.User.t, keyword()) :: {:ok, nil} | {:error, Tesla.Env.t} - def create_user(connection, body, _opts \\ []) do + def create_user(connection, user, _opts \\ []) do %{} |> method(:post) |> url("/user") - |> add_param(:body, :"body", body) + |> add_param(:body, :"User", user) |> Enum.into([]) |> (&Connection.request(connection, &1)).() |> decode(false) @@ -39,25 +38,23 @@ defmodule SwaggerPetstore.Api.User do @doc """ Creates list of users with given input array - ## Parameters - connection (SwaggerPetstore.Connection): Connection to server - - body ([User]): List of user object + - user ([User]): List of user object - opts (KeywordList): [optional] Optional parameters - ## Returns {:ok, %{}} on success {:error, info} on failure """ @spec create_users_with_array_input(Tesla.Env.client, list(SwaggerPetstore.Model.User.t), keyword()) :: {:ok, nil} | {:error, Tesla.Env.t} - def create_users_with_array_input(connection, body, _opts \\ []) do + def create_users_with_array_input(connection, user, _opts \\ []) do %{} |> method(:post) |> url("/user/createWithArray") - |> add_param(:body, :"body", body) + |> add_param(:body, :"User", user) |> Enum.into([]) |> (&Connection.request(connection, &1)).() |> decode(false) @@ -65,25 +62,23 @@ defmodule SwaggerPetstore.Api.User do @doc """ Creates list of users with given input array - ## Parameters - connection (SwaggerPetstore.Connection): Connection to server - - body ([User]): List of user object + - user ([User]): List of user object - opts (KeywordList): [optional] Optional parameters - ## Returns {:ok, %{}} on success {:error, info} on failure """ @spec create_users_with_list_input(Tesla.Env.client, list(SwaggerPetstore.Model.User.t), keyword()) :: {:ok, nil} | {:error, Tesla.Env.t} - def create_users_with_list_input(connection, body, _opts \\ []) do + def create_users_with_list_input(connection, user, _opts \\ []) do %{} |> method(:post) |> url("/user/createWithList") - |> add_param(:body, :"body", body) + |> add_param(:body, :"User", user) |> Enum.into([]) |> (&Connection.request(connection, &1)).() |> decode(false) @@ -98,7 +93,6 @@ defmodule SwaggerPetstore.Api.User do - connection (SwaggerPetstore.Connection): Connection to server - username (String.t): The name that needs to be deleted - opts (KeywordList): [optional] Optional parameters - ## Returns {:ok, %{}} on success @@ -116,14 +110,12 @@ defmodule SwaggerPetstore.Api.User do @doc """ Get user by user name - ## Parameters - connection (SwaggerPetstore.Connection): Connection to server - - username (String.t): The name that needs to be fetched. Use user1 for testing. + - username (String.t): The name that needs to be fetched. Use user1 for testing. - opts (KeywordList): [optional] Optional parameters - ## Returns {:ok, %SwaggerPetstore.Model.User{}} on success @@ -141,7 +133,6 @@ defmodule SwaggerPetstore.Api.User do @doc """ Logs user into the system - ## Parameters @@ -149,7 +140,6 @@ defmodule SwaggerPetstore.Api.User do - username (String.t): The user name for login - password (String.t): The password for login in clear text - opts (KeywordList): [optional] Optional parameters - ## Returns {:ok, %SwaggerPetstore.Model.String.t{}} on success @@ -169,13 +159,11 @@ defmodule SwaggerPetstore.Api.User do @doc """ Logs out current logged in user session - ## Parameters - connection (SwaggerPetstore.Connection): Connection to server - opts (KeywordList): [optional] Optional parameters - ## Returns {:ok, %{}} on success @@ -199,20 +187,19 @@ defmodule SwaggerPetstore.Api.User do - connection (SwaggerPetstore.Connection): Connection to server - username (String.t): name that need to be deleted - - body (User): Updated user object + - user (User): Updated user object - opts (KeywordList): [optional] Optional parameters - ## Returns {:ok, %{}} on success {:error, info} on failure """ @spec update_user(Tesla.Env.client, String.t, SwaggerPetstore.Model.User.t, keyword()) :: {:ok, nil} | {:error, Tesla.Env.t} - def update_user(connection, username, body, _opts \\ []) do + def update_user(connection, username, user, _opts \\ []) do %{} |> method(:put) |> url("/user/#{username}") - |> add_param(:body, :"body", body) + |> add_param(:body, :"User", user) |> Enum.into([]) |> (&Connection.request(connection, &1)).() |> decode(false) diff --git a/samples/client/petstore/elixir/lib/swagger_petstore/deserializer.ex b/samples/client/petstore/elixir/lib/swagger_petstore/deserializer.ex index 9af85b7d9ea..d2362fc698f 100644 --- a/samples/client/petstore/elixir/lib/swagger_petstore/deserializer.ex +++ b/samples/client/petstore/elixir/lib/swagger_petstore/deserializer.ex @@ -24,11 +24,15 @@ defmodule SwaggerPetstore.Deserializer do |> Map.update!(field, &(Map.new(&1, fn {key, val} -> {key, Poison.Decode.decode(val, Keyword.merge(options, [as: struct(mod)]))} end))) end def deserialize(model, field, :date, _, _options) do - case DateTime.from_iso8601(Map.get(model, field)) do - {:ok, datetime} -> - Map.put(model, field, datetime) - _ -> - model + value = Map.get(model, field) + case is_binary(value) do + true -> case DateTime.from_iso8601(value) do + {:ok, datetime, _offset} -> + Map.put(model, field, datetime) + _ -> + model + end + false -> model end end end diff --git a/samples/client/petstore/elixir/lib/swagger_petstore/model/enum_test.ex b/samples/client/petstore/elixir/lib/swagger_petstore/model/enum_test.ex index 0752b16e203..3ee1530c302 100644 --- a/samples/client/petstore/elixir/lib/swagger_petstore/model/enum_test.ex +++ b/samples/client/petstore/elixir/lib/swagger_petstore/model/enum_test.ex @@ -10,6 +10,7 @@ defmodule SwaggerPetstore.Model.EnumTest do @derive [Poison.Encoder] defstruct [ :"enum_string", + :"enum_string_required", :"enum_integer", :"enum_number", :"outerEnum" @@ -17,6 +18,7 @@ defmodule SwaggerPetstore.Model.EnumTest do @type t :: %__MODULE__{ :"enum_string" => String.t, + :"enum_string_required" => String.t, :"enum_integer" => integer(), :"enum_number" => float(), :"outerEnum" => OuterEnum diff --git a/samples/client/petstore/elixir/lib/swagger_petstore/model/format_test.ex b/samples/client/petstore/elixir/lib/swagger_petstore/model/format_test.ex index 4d271718a14..506d1cd7f67 100644 --- a/samples/client/petstore/elixir/lib/swagger_petstore/model/format_test.ex +++ b/samples/client/petstore/elixir/lib/swagger_petstore/model/format_test.ex @@ -33,7 +33,7 @@ defmodule SwaggerPetstore.Model.FormatTest do :"double" => float(), :"string" => String.t, :"byte" => binary(), - :"binary" => binary(), + :"binary" => String.t, :"date" => Date.t, :"dateTime" => DateTime.t, :"uuid" => String.t, diff --git a/samples/client/petstore/elixir/lib/swagger_petstore/model/outer_boolean.ex b/samples/client/petstore/elixir/lib/swagger_petstore/model/outer_boolean.ex deleted file mode 100644 index 67ae2d5b74d..00000000000 --- a/samples/client/petstore/elixir/lib/swagger_petstore/model/outer_boolean.ex +++ /dev/null @@ -1,25 +0,0 @@ -# NOTE: This class is auto generated by the swagger code generator program. -# https://github.com/swagger-api/swagger-codegen.git -# Do not edit the class manually. - -defmodule SwaggerPetstore.Model.OuterBoolean do - @moduledoc """ - - """ - - @derive [Poison.Encoder] - defstruct [ - - ] - - @type t :: %__MODULE__{ - - } -end - -defimpl Poison.Decoder, for: SwaggerPetstore.Model.OuterBoolean do - def decode(value, _options) do - value - end -end - diff --git a/samples/client/petstore/elixir/lib/swagger_petstore/model/outer_composite.ex b/samples/client/petstore/elixir/lib/swagger_petstore/model/outer_composite.ex index 3771cc731dc..58e195e6257 100644 --- a/samples/client/petstore/elixir/lib/swagger_petstore/model/outer_composite.ex +++ b/samples/client/petstore/elixir/lib/swagger_petstore/model/outer_composite.ex @@ -15,19 +15,15 @@ defmodule SwaggerPetstore.Model.OuterComposite do ] @type t :: %__MODULE__{ - :"my_number" => OuterNumber, - :"my_string" => OuterString, - :"my_boolean" => OuterBoolean + :"my_number" => Float, + :"my_string" => String, + :"my_boolean" => Boolean } end defimpl Poison.Decoder, for: SwaggerPetstore.Model.OuterComposite do - import SwaggerPetstore.Deserializer - def decode(value, options) do + def decode(value, _options) do value - |> deserialize(:"my_number", :struct, SwaggerPetstore.Model.OuterNumber, options) - |> deserialize(:"my_string", :struct, SwaggerPetstore.Model.OuterString, options) - |> deserialize(:"my_boolean", :struct, SwaggerPetstore.Model.OuterBoolean, options) end end diff --git a/samples/client/petstore/elixir/lib/swagger_petstore/model/outer_number.ex b/samples/client/petstore/elixir/lib/swagger_petstore/model/outer_number.ex deleted file mode 100644 index d2f4e4957bb..00000000000 --- a/samples/client/petstore/elixir/lib/swagger_petstore/model/outer_number.ex +++ /dev/null @@ -1,25 +0,0 @@ -# NOTE: This class is auto generated by the swagger code generator program. -# https://github.com/swagger-api/swagger-codegen.git -# Do not edit the class manually. - -defmodule SwaggerPetstore.Model.OuterNumber do - @moduledoc """ - - """ - - @derive [Poison.Encoder] - defstruct [ - - ] - - @type t :: %__MODULE__{ - - } -end - -defimpl Poison.Decoder, for: SwaggerPetstore.Model.OuterNumber do - def decode(value, _options) do - value - end -end - diff --git a/samples/client/petstore/elixir/lib/swagger_petstore/model/outer_string.ex b/samples/client/petstore/elixir/lib/swagger_petstore/model/outer_string.ex deleted file mode 100644 index c610adfe7e9..00000000000 --- a/samples/client/petstore/elixir/lib/swagger_petstore/model/outer_string.ex +++ /dev/null @@ -1,25 +0,0 @@ -# NOTE: This class is auto generated by the swagger code generator program. -# https://github.com/swagger-api/swagger-codegen.git -# Do not edit the class manually. - -defmodule SwaggerPetstore.Model.OuterString do - @moduledoc """ - - """ - - @derive [Poison.Encoder] - defstruct [ - - ] - - @type t :: %__MODULE__{ - - } -end - -defimpl Poison.Decoder, for: SwaggerPetstore.Model.OuterString do - def decode(value, _options) do - value - end -end -