From 5047273f1e02eaf42944f92fcaaffb5a1577e75c Mon Sep 17 00:00:00 2001 From: Michael Ramstein <633688+mrmstn@users.noreply.github.com> Date: Tue, 24 Jan 2023 07:48:49 +0100 Subject: [PATCH] [elixir] Properly map AnyType (#14497) --- docs/generators/elixir.md | 4 ++- .../languages/ElixirClientCodegen.java | 27 +++++++++++++++---- .../model/all_of_with_single_ref.ex | 6 ++--- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/docs/generators/elixir.md b/docs/generators/elixir.md index a217d05ec06..e6aae929e43 100644 --- a/docs/generators/elixir.md +++ b/docs/generators/elixir.md @@ -45,6 +45,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl ## LANGUAGE PRIMITIVES @@ -103,7 +105,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |Uuid|✗| |Array|✓|OAS2,OAS3 |Null|✗|OAS3 -|AnyType|✗|OAS2,OAS3 +|AnyType|✓|OAS2,OAS3 |Object|✓|OAS2,OAS3 |Maps|✓|ToolingExtension |CollectionFormat|✓|OAS2 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 f66a51fdfb9..dbde8ce1b58 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 @@ -88,6 +88,9 @@ public class ElixirClientCodegen extends DefaultCodegen { .includeClientModificationFeatures( ClientModificationFeature.BasePath ) + .includeDataTypeFeatures( + DataTypeFeature.AnyType + ) ); // set the output folder here @@ -188,10 +191,12 @@ public class ElixirClientCodegen extends DefaultCodegen { "List", "Atom", "Map", + "AnyType", "Tuple", "PID", "DateTime", - "map()" // This is a workaround, since the DefaultCodeGen uses our elixir TypeSpec datetype to evaluate the primitive + "map()", // This is a workaround, since the DefaultCodeGen uses our elixir TypeSpec datetype to evaluate the primitive + "any()" ) ); @@ -575,6 +580,8 @@ public class ElixirClientCodegen extends DefaultCodegen { return "String.t"; } else if (ModelUtils.isStringSchema(p)) { return "String.t"; + } else if (p.getType() == null) { + return "any()"; } return super.getTypeDeclaration(p); } @@ -785,8 +792,13 @@ public class ElixirClientCodegen extends DefaultCodegen { returnEntry.append(moduleName); returnEntry.append(".Model."); } - returnEntry.append(exResponse.baseType); - returnEntry.append(".t"); + + if (exResponse.baseType.equals("AnyType")) { + returnEntry.append("any()"); + }else { + returnEntry.append(exResponse.baseType); + returnEntry.append(".t"); + } } else { if (exResponse.containerType.equals("array") || exResponse.containerType.equals("set")) { @@ -795,8 +807,13 @@ public class ElixirClientCodegen extends DefaultCodegen { returnEntry.append(moduleName); returnEntry.append(".Model."); } - returnEntry.append(exResponse.baseType); - returnEntry.append(".t)"); + + if (exResponse.baseType.equals("AnyType")) { + returnEntry.append("any())"); + }else { + returnEntry.append(exResponse.baseType); + returnEntry.append(".t)"); + } } else if (exResponse.containerType.equals("map")) { returnEntry.append("map()"); } diff --git a/samples/client/petstore/elixir/lib/openapi_petstore/model/all_of_with_single_ref.ex b/samples/client/petstore/elixir/lib/openapi_petstore/model/all_of_with_single_ref.ex index 18a9b072d88..baf71920d23 100644 --- a/samples/client/petstore/elixir/lib/openapi_petstore/model/all_of_with_single_ref.ex +++ b/samples/client/petstore/elixir/lib/openapi_petstore/model/all_of_with_single_ref.ex @@ -14,15 +14,13 @@ defmodule OpenapiPetstore.Model.AllOfWithSingleRef do @type t :: %__MODULE__{ :username => String.t | nil, - :SingleRefType => SingleRefType | nil + :SingleRefType => any() | nil } end defimpl Poison.Decoder, for: OpenapiPetstore.Model.AllOfWithSingleRef do - import OpenapiPetstore.Deserializer - def decode(value, options) do + def decode(value, _options) do value - |> deserialize(:SingleRefType, :struct, OpenapiPetstore.Model.SingleRefType, options) end end