From 02d3f6e9ae00f7234e19ed8dd43106d6429f100b Mon Sep 17 00:00:00 2001 From: Paul Balomiri Date: Sat, 19 Nov 2022 19:28:27 +0200 Subject: [PATCH 1/4] allow atoms as params for headers. httpc needs binary header pair tuples --- .../src/main/resources/elixir/request_builder.ex.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/resources/elixir/request_builder.ex.mustache b/modules/openapi-generator/src/main/resources/elixir/request_builder.ex.mustache index 825beac5a436..431fcb8544be 100644 --- a/modules/openapi-generator/src/main/resources/elixir/request_builder.ex.mustache +++ b/modules/openapi-generator/src/main/resources/elixir/request_builder.ex.mustache @@ -101,7 +101,7 @@ defmodule {{moduleName}}.RequestBuilder do end def add_param(request, :headers, key, value) do - Tesla.put_header(request, key, value) + Tesla.put_header(request, to_string(key), value) end def add_param(request, :file, name, path) do From f0625b83fbbb90036d6ce983fa738274aedbd625 Mon Sep 17 00:00:00 2001 From: Paul Balomiri Date: Sat, 19 Nov 2022 20:12:58 +0200 Subject: [PATCH 2/4] fixes #14070 --- docs/generators/elixir.md | 5 +- .../languages/ElixirClientCodegen.java | 63 +++++--- .../src/main/resources/elixir/api.mustache | 10 +- .../resources/elixir/deserializer.ex.mustache | 5 +- .../src/main/resources/elixir/model.mustache | 4 +- .../lib/openapi_petstore/api/another_fake.ex | 8 +- .../lib/openapi_petstore/api/default.ex | 8 +- .../elixir/lib/openapi_petstore/api/fake.ex | 136 +++++++++++------- .../api/fake_classname_tags123.ex | 8 +- .../elixir/lib/openapi_petstore/api/pet.ex | 72 ++++++---- .../elixir/lib/openapi_petstore/api/store.ex | 32 +++-- .../elixir/lib/openapi_petstore/api/user.ex | 64 +++++---- .../lib/openapi_petstore/deserializer.ex | 2 +- .../model/all_of_with_single_ref.ex | 2 +- .../lib/openapi_petstore/request_builder.ex | 2 +- 15 files changed, 268 insertions(+), 153 deletions(-) diff --git a/docs/generators/elixir.md b/docs/generators/elixir.md index a217d05ec06c..71613cd36bef 100644 --- a/docs/generators/elixir.md +++ b/docs/generators/elixir.md @@ -1,7 +1,8 @@ --- title: Documentation for the elixir Generator --- - +## Changes +`2022-11-19` Added rump support for `AnyType`. `AnyType` fields just forward whatever the deserialization result was. See [#14070](https://github.com/OpenAPITools/openapi-generator/issues/14070). ## METADATA | Property | Value | Notes | @@ -103,7 +104,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 f66a51fdfb95..e28ad532b585 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 @@ -17,16 +17,41 @@ package org.openapitools.codegen.languages; -import com.samskivert.mustache.Mustache; -import com.samskivert.mustache.Template; -import io.swagger.v3.oas.models.OpenAPI; -import io.swagger.v3.oas.models.info.Info; -import io.swagger.v3.oas.models.media.ArraySchema; -import io.swagger.v3.oas.models.media.Schema; -import io.swagger.v3.oas.models.responses.ApiResponse; +import static org.openapitools.codegen.utils.StringUtils.camelize; +import static org.openapitools.codegen.utils.StringUtils.underscore; + +import java.io.File; +import java.io.IOException; +import java.io.Writer; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + import org.apache.commons.lang3.StringUtils; -import org.openapitools.codegen.*; -import org.openapitools.codegen.meta.features.*; +import org.openapitools.codegen.CliOption; +import org.openapitools.codegen.CodegenConstants; +import org.openapitools.codegen.CodegenModel; +import org.openapitools.codegen.CodegenOperation; +import org.openapitools.codegen.CodegenParameter; +import org.openapitools.codegen.CodegenProperty; +import org.openapitools.codegen.CodegenResponse; +import org.openapitools.codegen.CodegenType; +import org.openapitools.codegen.DefaultCodegen; +import org.openapitools.codegen.GeneratorLanguage; +import org.openapitools.codegen.SupportingFile; +import org.openapitools.codegen.meta.features.ClientModificationFeature; +import org.openapitools.codegen.meta.features.DocumentationFeature; +import org.openapitools.codegen.meta.features.GlobalFeature; +import org.openapitools.codegen.meta.features.ParameterFeature; +import org.openapitools.codegen.meta.features.SchemaSupportFeature; +import org.openapitools.codegen.meta.features.SecurityFeature; import org.openapitools.codegen.model.ModelMap; import org.openapitools.codegen.model.OperationMap; import org.openapitools.codegen.model.OperationsMap; @@ -34,15 +59,14 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; -import java.io.IOException; -import java.io.Writer; -import java.util.*; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +import com.samskivert.mustache.Mustache; +import com.samskivert.mustache.Template; -import static org.openapitools.codegen.utils.StringUtils.camelize; -import static org.openapitools.codegen.utils.StringUtils.underscore; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Info; +import io.swagger.v3.oas.models.media.ArraySchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.responses.ApiResponse; public class ElixirClientCodegen extends DefaultCodegen { private final Logger LOGGER = LoggerFactory.getLogger(ElixirClientCodegen.class); @@ -573,6 +597,8 @@ public String getTypeDeclaration(Schema p) { return this.moduleName + ".Model." + super.getTypeDeclaration(p) + ".t"; } else if (ModelUtils.isFileSchema(p)) { return "String.t"; + } else if (ModelUtils.isAnyType(p)) { + return "any"; } else if (ModelUtils.isStringSchema(p)) { return "String.t"; } @@ -634,6 +660,7 @@ public ExtendedCodegenResponse(CodegenResponse o) { this.isArray = o.isArray; this.isBinary = o.isBinary; this.isFile = o.isFile; + this.isAnyType = o.isAnyType; this.schema = o.schema; this.jsonSchema = o.jsonSchema; this.vendorExtensions = o.vendorExtensions; @@ -830,6 +857,8 @@ private void buildTypespec(CodegenParameter param, StringBuilder sb) { sb.append(param.dataType); } else if (param.isFile || param.isBinary) { sb.append("String.t"); + } else if (param.isAnyType) { + sb.append("any"); } else if ("String.t".equals(param.dataType)) { // uuid, password, etc sb.append(param.dataType); diff --git a/modules/openapi-generator/src/main/resources/elixir/api.mustache b/modules/openapi-generator/src/main/resources/elixir/api.mustache index cc072de07281..3a57daede573 100644 --- a/modules/openapi-generator/src/main/resources/elixir/api.mustache +++ b/modules/openapi-generator/src/main/resources/elixir/api.mustache @@ -48,7 +48,7 @@ defmodule {{moduleName}}.Api.{{classname}} do :body => :body {{/isBodyParam}} {{^isBodyParam}} - {{#atom}}{{baseName}}{{/atom}} => {{#isFormParam}}:form{{/isFormParam}}{{#isQueryParam}}:query{{/isQueryParam}}{{#isHeaderParam}}:headers{{/isHeaderParam}}{{^-last}},{{/-last}} + {{#atom}}{{&baseName}}{{/atom}} => {{#isFormParam}}:form{{/isFormParam}}{{#isQueryParam}}:query{{/isQueryParam}}{{#isHeaderParam}}:headers{{/isHeaderParam}}{{^-last}},{{/-last}} {{/isBodyParam}} {{#-last}} } @@ -56,9 +56,10 @@ defmodule {{moduleName}}.Api.{{classname}} do {{/-last}} {{/optionalParams}} request = - %{} - |> method({{#atom}}{{#underscored}}{{httpMethod}}{{/underscored}}{{/atom}}) - |> url("{{replacedPathName}}") + %Tesla.Env{ + method: {{#atom}}{{#underscored}}{{httpMethod}}{{/underscored}}{{/atom}}, + url: "{{replacedPathName}}", + } {{#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}}, {{#isBodyParam}}:body{{/isBodyParam}}{{^isBodyParam}}{{#atom}}{{baseName}}{{/atom}}{{/isBodyParam}}, {{#underscored}}{{paramName}}{{/underscored}}) @@ -72,6 +73,7 @@ defmodule {{moduleName}}.Api.{{classname}} do {{#requiresHttpcWorkaround}} |> ensure_body() {{/requiresHttpcWorkaround}} + |> Map.from_struct() |> Enum.into([]) connection diff --git a/modules/openapi-generator/src/main/resources/elixir/deserializer.ex.mustache b/modules/openapi-generator/src/main/resources/elixir/deserializer.ex.mustache index a5c4da88658e..685e302ccebc 100644 --- a/modules/openapi-generator/src/main/resources/elixir/deserializer.ex.mustache +++ b/modules/openapi-generator/src/main/resources/elixir/deserializer.ex.mustache @@ -12,12 +12,13 @@ defmodule {{moduleName}}.Deserializer do model |> Map.update!(field, &(Poison.Decode.decode(&1, Keyword.merge(options, [as: [struct(mod)]])))) end - + def deserialize(model, field, :struct, mod, options) do model |> Map.update!(field, &(Poison.Decode.decode(&1, Keyword.merge(options, [as: struct(mod)])))) end - + # Just keep the value parsed from json for any + def deserialize(model, field, :any, mod, options), do: model def deserialize(model, field, :map, mod, options) do maybe_transform_map = fn nil -> diff --git a/modules/openapi-generator/src/main/resources/elixir/model.mustache b/modules/openapi-generator/src/main/resources/elixir/model.mustache index 0f9cc57a8938..04ab18467ff1 100644 --- a/modules/openapi-generator/src/main/resources/elixir/model.mustache +++ b/modules/openapi-generator/src/main/resources/elixir/model.mustache @@ -11,7 +11,7 @@ ] @type t :: %__MODULE__{ - {{#vars}}{{#atom}}{{&baseName}}{{/atom}} => {{{datatype}}}{{#isNullable}} | nil{{/isNullable}}{{^isNullable}}{{^required}} | nil{{/required}}{{/isNullable}}{{^-last}}, + {{#vars}}{{#atom}}{{&baseName}}{{/atom}} => {{#isAnyType}}any(){{/isAnyType}}{{^isAnyType}}{{{datatype}}}{{/isAnyType}}{{#isNullable}} | nil{{/isNullable}}{{^isNullable}}{{^required}} | nil{{/required}}{{/isNullable}}{{^-last}}, {{/-last}}{{/vars}} } end @@ -23,7 +23,7 @@ defimpl Poison.Decoder, for: {{&moduleName}}.Model.{{&classname}} do value {{#vars}} {{^isPrimitiveType}} - {{#baseType}}|> deserialize({{#atom}}{{&baseName}}{{/atom}}, {{#isArray}}:list, {{&moduleName}}.Model.{{{items.baseType}}}{{/isArray}}{{#isMap}}:map, {{&moduleName}}.Model.{{{items.baseType}}}{{/isMap}}{{#isDate}}:date, nil{{/isDate}}{{#isDateTime}}:date, nil{{/isDateTime}}{{^isDate}}{{^isDateTime}}{{^isMap}}{{^isArray}}:struct, {{moduleName}}.Model.{{baseType}}{{/isArray}}{{/isMap}}{{/isDateTime}}{{/isDate}}, options) + {{#baseType}}|> deserialize({{#atom}}{{&baseName}}{{/atom}}, {{#isAnyType}}:any, :any{{/isAnyType}}{{#isArray}}:list, {{&moduleName}}.Model.{{{items.baseType}}}{{/isArray}}{{#isMap}}:map, {{&moduleName}}.Model.{{{items.baseType}}}{{/isMap}}{{#isDate}}:date, nil{{/isDate}}{{#isDateTime}}:date, nil{{/isDateTime}}{{^isDate}}{{^isDateTime}}{{^isMap}}{{^isArray}}{{^isAnyType}}:struct, {{moduleName}}.Model.{{baseType}}{{/isAnyType}}{{/isArray}}{{/isMap}}{{/isDateTime}}{{/isDate}}, options) {{/baseType}} {{/isPrimitiveType}} {{/vars}} 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 bc62e73434ec..b3689a7394b2 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 @@ -27,10 +27,12 @@ defmodule OpenapiPetstore.Api.AnotherFake 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 request = - %{} - |> method(:patch) - |> url("/another-fake/dummy") + %Tesla.Env{ + method: :patch, + url: "/another-fake/dummy", + } |> add_param(:body, :body, client) + |> Map.from_struct() |> Enum.into([]) connection diff --git a/samples/client/petstore/elixir/lib/openapi_petstore/api/default.ex b/samples/client/petstore/elixir/lib/openapi_petstore/api/default.ex index 0507c0967d04..ff81ddc35a53 100644 --- a/samples/client/petstore/elixir/lib/openapi_petstore/api/default.ex +++ b/samples/client/petstore/elixir/lib/openapi_petstore/api/default.ex @@ -24,9 +24,11 @@ defmodule OpenapiPetstore.Api.Default do @spec foo_get(Tesla.Env.client, keyword()) :: {:ok, OpenapiPetstore.Model.FooGetDefaultResponse.t} | {:error, Tesla.Env.t} def foo_get(connection, _opts \\ []) do request = - %{} - |> method(:get) - |> url("/foo") + %Tesla.Env{ + method: :get, + url: "/foo", + } + |> Map.from_struct() |> Enum.into([]) connection 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 bc3b06c40875..85aaaa63a689 100644 --- a/samples/client/petstore/elixir/lib/openapi_petstore/api/fake.ex +++ b/samples/client/petstore/elixir/lib/openapi_petstore/api/fake.ex @@ -25,9 +25,11 @@ defmodule OpenapiPetstore.Api.Fake do @spec fake_health_get(Tesla.Env.client, keyword()) :: {:ok, OpenapiPetstore.Model.HealthCheckResult.t} | {:error, Tesla.Env.t} def fake_health_get(connection, _opts \\ []) do request = - %{} - |> method(:get) - |> url("/fake/health") + %Tesla.Env{ + method: :get, + url: "/fake/health", + } + |> Map.from_struct() |> Enum.into([]) connection @@ -61,11 +63,13 @@ defmodule OpenapiPetstore.Api.Fake do } request = - %{} - |> method(:get) - |> url("/fake/http-signature-test") + %Tesla.Env{ + method: :get, + url: "/fake/http-signature-test", + } |> add_param(:body, :body, pet) |> add_optional_params(optional_params, opts) + |> Map.from_struct() |> Enum.into([]) connection @@ -96,11 +100,13 @@ defmodule OpenapiPetstore.Api.Fake do } request = - %{} - |> method(:post) - |> url("/fake/outer/boolean") + %Tesla.Env{ + method: :post, + url: "/fake/outer/boolean", + } |> add_optional_params(optional_params, opts) |> ensure_body() + |> Map.from_struct() |> Enum.into([]) connection @@ -131,11 +137,13 @@ defmodule OpenapiPetstore.Api.Fake do } request = - %{} - |> method(:post) - |> url("/fake/outer/composite") + %Tesla.Env{ + method: :post, + url: "/fake/outer/composite", + } |> add_optional_params(optional_params, opts) |> ensure_body() + |> Map.from_struct() |> Enum.into([]) connection @@ -166,11 +174,13 @@ defmodule OpenapiPetstore.Api.Fake do } request = - %{} - |> method(:post) - |> url("/fake/outer/number") + %Tesla.Env{ + method: :post, + url: "/fake/outer/number", + } |> add_optional_params(optional_params, opts) |> ensure_body() + |> Map.from_struct() |> Enum.into([]) connection @@ -201,11 +211,13 @@ defmodule OpenapiPetstore.Api.Fake do } request = - %{} - |> method(:post) - |> url("/fake/outer/string") + %Tesla.Env{ + method: :post, + url: "/fake/outer/string", + } |> add_optional_params(optional_params, opts) |> ensure_body() + |> Map.from_struct() |> Enum.into([]) connection @@ -232,10 +244,12 @@ defmodule OpenapiPetstore.Api.Fake do @spec fake_property_enum_integer_serialize(Tesla.Env.client, OpenapiPetstore.Model.OuterObjectWithEnumProperty.t, keyword()) :: {:ok, OpenapiPetstore.Model.OuterObjectWithEnumProperty.t} | {:error, Tesla.Env.t} def fake_property_enum_integer_serialize(connection, outer_object_with_enum_property, _opts \\ []) do request = - %{} - |> method(:post) - |> url("/fake/property/enum-int") + %Tesla.Env{ + method: :post, + url: "/fake/property/enum-int", + } |> add_param(:body, :body, outer_object_with_enum_property) + |> Map.from_struct() |> Enum.into([]) connection @@ -262,10 +276,12 @@ defmodule OpenapiPetstore.Api.Fake do @spec test_body_with_binary(Tesla.Env.client, String.t, keyword()) :: {:ok, nil} | {:error, Tesla.Env.t} def test_body_with_binary(connection, body, _opts \\ []) do request = - %{} - |> method(:put) - |> url("/fake/body-with-binary") + %Tesla.Env{ + method: :put, + url: "/fake/body-with-binary", + } |> add_param(:body, :body, body) + |> Map.from_struct() |> Enum.into([]) connection @@ -292,10 +308,12 @@ defmodule OpenapiPetstore.Api.Fake do @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 request = - %{} - |> method(:put) - |> url("/fake/body-with-file-schema") + %Tesla.Env{ + method: :put, + url: "/fake/body-with-file-schema", + } |> add_param(:body, :body, file_schema_test_class) + |> Map.from_struct() |> Enum.into([]) connection @@ -322,11 +340,13 @@ defmodule OpenapiPetstore.Api.Fake do @spec test_body_with_query_params(Tesla.Env.client, String.t, OpenapiPetstore.Model.User.t, keyword()) :: {:ok, nil} | {:error, Tesla.Env.t} def test_body_with_query_params(connection, query, user, _opts \\ []) do request = - %{} - |> method(:put) - |> url("/fake/body-with-query-params") + %Tesla.Env{ + method: :put, + url: "/fake/body-with-query-params", + } |> add_param(:query, :query, query) |> add_param(:body, :body, user) + |> Map.from_struct() |> Enum.into([]) connection @@ -354,10 +374,12 @@ defmodule OpenapiPetstore.Api.Fake do @spec test_client_model(Tesla.Env.client, OpenapiPetstore.Model.Client.t, keyword()) :: {:ok, OpenapiPetstore.Model.Client.t} | {:error, Tesla.Env.t} def test_client_model(connection, client, _opts \\ []) do request = - %{} - |> method(:patch) - |> url("/fake") + %Tesla.Env{ + method: :patch, + url: "/fake", + } |> add_param(:body, :body, client) + |> Map.from_struct() |> Enum.into([]) connection @@ -411,14 +433,16 @@ defmodule OpenapiPetstore.Api.Fake do } request = - %{} - |> method(:post) - |> url("/fake") + %Tesla.Env{ + method: :post, + url: "/fake", + } |> add_param(:form, :number, number) |> add_param(:form, :double, double) |> add_param(:form, :pattern_without_delimiter, pattern_without_delimiter) |> add_param(:form, :byte, byte) |> add_optional_params(optional_params, opts) + |> Map.from_struct() |> Enum.into([]) connection @@ -467,10 +491,12 @@ defmodule OpenapiPetstore.Api.Fake do } request = - %{} - |> method(:get) - |> url("/fake") + %Tesla.Env{ + method: :get, + url: "/fake", + } |> add_optional_params(optional_params, opts) + |> Map.from_struct() |> Enum.into([]) connection @@ -510,13 +536,15 @@ defmodule OpenapiPetstore.Api.Fake do } request = - %{} - |> method(:delete) - |> url("/fake") + %Tesla.Env{ + 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) + |> Map.from_struct() |> Enum.into([]) connection @@ -544,10 +572,12 @@ defmodule OpenapiPetstore.Api.Fake 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 request = - %{} - |> method(:post) - |> url("/fake/inline-additionalProperties") + %Tesla.Env{ + method: :post, + url: "/fake/inline-additionalProperties", + } |> add_param(:body, :body, request_body) + |> Map.from_struct() |> Enum.into([]) connection @@ -576,11 +606,13 @@ defmodule OpenapiPetstore.Api.Fake do @spec test_json_form_data(Tesla.Env.client, String.t, String.t, keyword()) :: {:ok, nil} | {:error, Tesla.Env.t} def test_json_form_data(connection, param, param2, _opts \\ []) do request = - %{} - |> method(:get) - |> url("/fake/jsonFormData") + %Tesla.Env{ + method: :get, + url: "/fake/jsonFormData", + } |> add_param(:form, :param, param) |> add_param(:form, :param2, param2) + |> Map.from_struct() |> Enum.into([]) connection @@ -617,9 +649,10 @@ defmodule OpenapiPetstore.Api.Fake do } request = - %{} - |> method(:put) - |> url("/fake/test-query-parameters") + %Tesla.Env{ + method: :put, + url: "/fake/test-query-parameters", + } |> add_param(:query, :pipe, pipe) |> add_param(:query, :ioutil, ioutil) |> add_param(:query, :http, http) @@ -628,6 +661,7 @@ defmodule OpenapiPetstore.Api.Fake do |> add_param(:query, :allowEmpty, allow_empty) |> add_optional_params(optional_params, opts) |> ensure_body() + |> Map.from_struct() |> Enum.into([]) connection diff --git a/samples/client/petstore/elixir/lib/openapi_petstore/api/fake_classname_tags123.ex b/samples/client/petstore/elixir/lib/openapi_petstore/api/fake_classname_tags123.ex index 4311357aa6f3..3178e3029cff 100644 --- a/samples/client/petstore/elixir/lib/openapi_petstore/api/fake_classname_tags123.ex +++ b/samples/client/petstore/elixir/lib/openapi_petstore/api/fake_classname_tags123.ex @@ -27,10 +27,12 @@ defmodule OpenapiPetstore.Api.FakeClassnameTags123 do @spec test_classname(Tesla.Env.client, OpenapiPetstore.Model.Client.t, keyword()) :: {:ok, OpenapiPetstore.Model.Client.t} | {:error, Tesla.Env.t} def test_classname(connection, client, _opts \\ []) do request = - %{} - |> method(:patch) - |> url("/fake_classname_test") + %Tesla.Env{ + method: :patch, + url: "/fake_classname_test", + } |> add_param(:body, :body, client) + |> Map.from_struct() |> Enum.into([]) connection 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 db1b9a5e4323..1dcd90078842 100644 --- a/samples/client/petstore/elixir/lib/openapi_petstore/api/pet.ex +++ b/samples/client/petstore/elixir/lib/openapi_petstore/api/pet.ex @@ -27,10 +27,12 @@ defmodule OpenapiPetstore.Api.Pet do @spec add_pet(Tesla.Env.client, OpenapiPetstore.Model.Pet.t, keyword()) :: {:ok, nil} | {:error, Tesla.Env.t} def add_pet(connection, pet, _opts \\ []) do request = - %{} - |> method(:post) - |> url("/pet") + %Tesla.Env{ + method: :post, + url: "/pet", + } |> add_param(:body, :body, pet) + |> Map.from_struct() |> Enum.into([]) connection @@ -64,10 +66,12 @@ defmodule OpenapiPetstore.Api.Pet do } request = - %{} - |> method(:delete) - |> url("/pet/#{pet_id}") + %Tesla.Env{ + method: :delete, + url: "/pet/#{pet_id}", + } |> add_optional_params(optional_params, opts) + |> Map.from_struct() |> Enum.into([]) connection @@ -96,10 +100,12 @@ defmodule OpenapiPetstore.Api.Pet do @spec find_pets_by_status(Tesla.Env.client, list(String.t), keyword()) :: {:ok, nil} | {:ok, list(OpenapiPetstore.Model.Pet.t)} | {:error, Tesla.Env.t} def find_pets_by_status(connection, status, _opts \\ []) do request = - %{} - |> method(:get) - |> url("/pet/findByStatus") + %Tesla.Env{ + method: :get, + url: "/pet/findByStatus", + } |> add_param(:query, :status, status) + |> Map.from_struct() |> Enum.into([]) connection @@ -128,10 +134,12 @@ defmodule OpenapiPetstore.Api.Pet do @spec find_pets_by_tags(Tesla.Env.client, list(String.t), keyword()) :: {:ok, nil} | {:ok, list(OpenapiPetstore.Model.Pet.t)} | {:error, Tesla.Env.t} def find_pets_by_tags(connection, tags, _opts \\ []) do request = - %{} - |> method(:get) - |> url("/pet/findByTags") + %Tesla.Env{ + method: :get, + url: "/pet/findByTags", + } |> add_param(:query, :tags, tags) + |> Map.from_struct() |> Enum.into([]) connection @@ -160,9 +168,11 @@ defmodule OpenapiPetstore.Api.Pet do @spec get_pet_by_id(Tesla.Env.client, integer(), keyword()) :: {:ok, nil} | {:ok, OpenapiPetstore.Model.Pet.t} | {:error, Tesla.Env.t} def get_pet_by_id(connection, pet_id, _opts \\ []) do request = - %{} - |> method(:get) - |> url("/pet/#{pet_id}") + %Tesla.Env{ + method: :get, + url: "/pet/#{pet_id}", + } + |> Map.from_struct() |> Enum.into([]) connection @@ -192,10 +202,12 @@ defmodule OpenapiPetstore.Api.Pet do @spec update_pet(Tesla.Env.client, OpenapiPetstore.Model.Pet.t, keyword()) :: {:ok, nil} | {:error, Tesla.Env.t} def update_pet(connection, pet, _opts \\ []) do request = - %{} - |> method(:put) - |> url("/pet") + %Tesla.Env{ + method: :put, + url: "/pet", + } |> add_param(:body, :body, pet) + |> Map.from_struct() |> Enum.into([]) connection @@ -233,11 +245,13 @@ defmodule OpenapiPetstore.Api.Pet do } request = - %{} - |> method(:post) - |> url("/pet/#{pet_id}") + %Tesla.Env{ + method: :post, + url: "/pet/#{pet_id}", + } |> add_optional_params(optional_params, opts) |> ensure_body() + |> Map.from_struct() |> Enum.into([]) connection @@ -273,11 +287,13 @@ defmodule OpenapiPetstore.Api.Pet do } request = - %{} - |> method(:post) - |> url("/pet/#{pet_id}/uploadImage") + %Tesla.Env{ + method: :post, + url: "/pet/#{pet_id}/uploadImage", + } |> add_optional_params(optional_params, opts) |> ensure_body() + |> Map.from_struct() |> Enum.into([]) connection @@ -311,11 +327,13 @@ defmodule OpenapiPetstore.Api.Pet do } request = - %{} - |> method(:post) - |> url("/fake/#{pet_id}/uploadImageWithRequiredFile") + %Tesla.Env{ + method: :post, + url: "/fake/#{pet_id}/uploadImageWithRequiredFile", + } |> add_param(:file, :requiredFile, required_file) |> add_optional_params(optional_params, opts) + |> Map.from_struct() |> Enum.into([]) connection diff --git a/samples/client/petstore/elixir/lib/openapi_petstore/api/store.ex b/samples/client/petstore/elixir/lib/openapi_petstore/api/store.ex index ae694541fba0..5aff67eb484f 100644 --- a/samples/client/petstore/elixir/lib/openapi_petstore/api/store.ex +++ b/samples/client/petstore/elixir/lib/openapi_petstore/api/store.ex @@ -27,9 +27,11 @@ defmodule OpenapiPetstore.Api.Store do @spec delete_order(Tesla.Env.client, String.t, keyword()) :: {:ok, nil} | {:error, Tesla.Env.t} def delete_order(connection, order_id, _opts \\ []) do request = - %{} - |> method(:delete) - |> url("/store/order/#{order_id}") + %Tesla.Env{ + method: :delete, + url: "/store/order/#{order_id}", + } + |> Map.from_struct() |> Enum.into([]) connection @@ -57,9 +59,11 @@ defmodule OpenapiPetstore.Api.Store do @spec get_inventory(Tesla.Env.client, keyword()) :: {:ok, map()} | {:error, Tesla.Env.t} def get_inventory(connection, _opts \\ []) do request = - %{} - |> method(:get) - |> url("/store/inventory") + %Tesla.Env{ + method: :get, + url: "/store/inventory", + } + |> Map.from_struct() |> Enum.into([]) connection @@ -87,9 +91,11 @@ defmodule OpenapiPetstore.Api.Store do @spec get_order_by_id(Tesla.Env.client, integer(), keyword()) :: {:ok, nil} | {:ok, OpenapiPetstore.Model.Order.t} | {:error, Tesla.Env.t} def get_order_by_id(connection, order_id, _opts \\ []) do request = - %{} - |> method(:get) - |> url("/store/order/#{order_id}") + %Tesla.Env{ + method: :get, + url: "/store/order/#{order_id}", + } + |> Map.from_struct() |> Enum.into([]) connection @@ -119,10 +125,12 @@ defmodule OpenapiPetstore.Api.Store do @spec place_order(Tesla.Env.client, OpenapiPetstore.Model.Order.t, keyword()) :: {:ok, nil} | {:ok, OpenapiPetstore.Model.Order.t} | {:error, Tesla.Env.t} def place_order(connection, order, _opts \\ []) do request = - %{} - |> method(:post) - |> url("/store/order") + %Tesla.Env{ + method: :post, + url: "/store/order", + } |> add_param(:body, :body, order) + |> Map.from_struct() |> Enum.into([]) connection diff --git a/samples/client/petstore/elixir/lib/openapi_petstore/api/user.ex b/samples/client/petstore/elixir/lib/openapi_petstore/api/user.ex index ce02be28d3ba..755c7b16e864 100644 --- a/samples/client/petstore/elixir/lib/openapi_petstore/api/user.ex +++ b/samples/client/petstore/elixir/lib/openapi_petstore/api/user.ex @@ -27,10 +27,12 @@ defmodule OpenapiPetstore.Api.User do @spec create_user(Tesla.Env.client, OpenapiPetstore.Model.User.t, keyword()) :: {:ok, nil} | {:error, Tesla.Env.t} def create_user(connection, user, _opts \\ []) do request = - %{} - |> method(:post) - |> url("/user") + %Tesla.Env{ + method: :post, + url: "/user", + } |> add_param(:body, :body, user) + |> Map.from_struct() |> Enum.into([]) connection @@ -58,10 +60,12 @@ defmodule OpenapiPetstore.Api.User do @spec create_users_with_array_input(Tesla.Env.client, list(OpenapiPetstore.Model.User.t), keyword()) :: {:ok, nil} | {:error, Tesla.Env.t} def create_users_with_array_input(connection, user, _opts \\ []) do request = - %{} - |> method(:post) - |> url("/user/createWithArray") + %Tesla.Env{ + method: :post, + url: "/user/createWithArray", + } |> add_param(:body, :body, user) + |> Map.from_struct() |> Enum.into([]) connection @@ -89,10 +93,12 @@ defmodule OpenapiPetstore.Api.User do @spec create_users_with_list_input(Tesla.Env.client, list(OpenapiPetstore.Model.User.t), keyword()) :: {:ok, nil} | {:error, Tesla.Env.t} def create_users_with_list_input(connection, user, _opts \\ []) do request = - %{} - |> method(:post) - |> url("/user/createWithList") + %Tesla.Env{ + method: :post, + url: "/user/createWithList", + } |> add_param(:body, :body, user) + |> Map.from_struct() |> Enum.into([]) connection @@ -120,9 +126,11 @@ defmodule OpenapiPetstore.Api.User do @spec delete_user(Tesla.Env.client, String.t, keyword()) :: {:ok, nil} | {:error, Tesla.Env.t} def delete_user(connection, username, _opts \\ []) do request = - %{} - |> method(:delete) - |> url("/user/#{username}") + %Tesla.Env{ + method: :delete, + url: "/user/#{username}", + } + |> Map.from_struct() |> Enum.into([]) connection @@ -151,9 +159,11 @@ defmodule OpenapiPetstore.Api.User do @spec get_user_by_name(Tesla.Env.client, String.t, keyword()) :: {:ok, nil} | {:ok, OpenapiPetstore.Model.User.t} | {:error, Tesla.Env.t} def get_user_by_name(connection, username, _opts \\ []) do request = - %{} - |> method(:get) - |> url("/user/#{username}") + %Tesla.Env{ + method: :get, + url: "/user/#{username}", + } + |> Map.from_struct() |> Enum.into([]) connection @@ -184,11 +194,13 @@ defmodule OpenapiPetstore.Api.User do @spec login_user(Tesla.Env.client, String.t, String.t, keyword()) :: {:ok, nil} | {:ok, String.t} | {:error, Tesla.Env.t} def login_user(connection, username, password, _opts \\ []) do request = - %{} - |> method(:get) - |> url("/user/login") + %Tesla.Env{ + method: :get, + url: "/user/login", + } |> add_param(:query, :username, username) |> add_param(:query, :password, password) + |> Map.from_struct() |> Enum.into([]) connection @@ -216,9 +228,11 @@ defmodule OpenapiPetstore.Api.User do @spec logout_user(Tesla.Env.client, keyword()) :: {:ok, nil} | {:error, Tesla.Env.t} def logout_user(connection, _opts \\ []) do request = - %{} - |> method(:get) - |> url("/user/logout") + %Tesla.Env{ + method: :get, + url: "/user/logout", + } + |> Map.from_struct() |> Enum.into([]) connection @@ -247,10 +261,12 @@ defmodule OpenapiPetstore.Api.User do @spec update_user(Tesla.Env.client, String.t, OpenapiPetstore.Model.User.t, keyword()) :: {:ok, nil} | {:error, Tesla.Env.t} def update_user(connection, username, user, _opts \\ []) do request = - %{} - |> method(:put) - |> url("/user/#{username}") + %Tesla.Env{ + method: :put, + url: "/user/#{username}", + } |> add_param(:body, :body, user) + |> Map.from_struct() |> Enum.into([]) connection diff --git a/samples/client/petstore/elixir/lib/openapi_petstore/deserializer.ex b/samples/client/petstore/elixir/lib/openapi_petstore/deserializer.ex index bdd072f0897e..08af208898da 100644 --- a/samples/client/petstore/elixir/lib/openapi_petstore/deserializer.ex +++ b/samples/client/petstore/elixir/lib/openapi_petstore/deserializer.ex @@ -14,7 +14,7 @@ defmodule OpenapiPetstore.Deserializer do model |> Map.update!(field, &(Poison.Decode.decode(&1, Keyword.merge(options, [as: [struct(mod)]])))) end - + def deserialize(model, field, :struct, mod, options) do model |> Map.update!(field, &(Poison.Decode.decode(&1, Keyword.merge(options, [as: struct(mod)])))) 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 18a9b072d887..ce23e4283584 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,7 +14,7 @@ defmodule OpenapiPetstore.Model.AllOfWithSingleRef do @type t :: %__MODULE__{ :username => String.t | nil, - :SingleRefType => SingleRefType | nil + :SingleRefType => any | nil } end diff --git a/samples/client/petstore/elixir/lib/openapi_petstore/request_builder.ex b/samples/client/petstore/elixir/lib/openapi_petstore/request_builder.ex index 97b0e434acdd..eb073db1c7cc 100644 --- a/samples/client/petstore/elixir/lib/openapi_petstore/request_builder.ex +++ b/samples/client/petstore/elixir/lib/openapi_petstore/request_builder.ex @@ -103,7 +103,7 @@ defmodule OpenapiPetstore.RequestBuilder do end def add_param(request, :headers, key, value) do - Tesla.put_header(request, key, value) + Tesla.put_header(request, to_string(key), value) end def add_param(request, :file, name, path) do From eed360e6f86ca6c1b42ab94a177037fd638eec7f Mon Sep 17 00:00:00 2001 From: Paul Balomiri Date: Sat, 19 Nov 2022 20:53:34 +0200 Subject: [PATCH 3/4] AnyType DataTypeFeature activated --- docs/generators/elixir.md | 3 +-- .../openapitools/codegen/languages/ElixirClientCodegen.java | 4 ++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/generators/elixir.md b/docs/generators/elixir.md index 71613cd36bef..f050f6207540 100644 --- a/docs/generators/elixir.md +++ b/docs/generators/elixir.md @@ -1,8 +1,7 @@ --- title: Documentation for the elixir Generator --- -## Changes -`2022-11-19` Added rump support for `AnyType`. `AnyType` fields just forward whatever the deserialization result was. See [#14070](https://github.com/OpenAPITools/openapi-generator/issues/14070). + ## METADATA | Property | Value | Notes | 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 e28ad532b585..6c0a34a694bb 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 @@ -47,6 +47,7 @@ import org.openapitools.codegen.GeneratorLanguage; import org.openapitools.codegen.SupportingFile; import org.openapitools.codegen.meta.features.ClientModificationFeature; +import org.openapitools.codegen.meta.features.DataTypeFeature; import org.openapitools.codegen.meta.features.DocumentationFeature; import org.openapitools.codegen.meta.features.GlobalFeature; import org.openapitools.codegen.meta.features.ParameterFeature; @@ -112,6 +113,9 @@ public ElixirClientCodegen() { .includeClientModificationFeatures( ClientModificationFeature.BasePath ) + .includeDataTypeFeatures( + DataTypeFeature.AnyType + ) ); // set the output folder here From c3de0b80f187058ad189fa233d83081c015b6349 Mon Sep 17 00:00:00 2001 From: Paul Balomiri Date: Sat, 19 Nov 2022 20:54:10 +0200 Subject: [PATCH 4/4] samples change --- .../petstore/elixir/lib/openapi_petstore/deserializer.ex | 3 ++- .../lib/openapi_petstore/model/all_of_with_single_ref.ex | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/samples/client/petstore/elixir/lib/openapi_petstore/deserializer.ex b/samples/client/petstore/elixir/lib/openapi_petstore/deserializer.ex index 08af208898da..4bafd2236cd3 100644 --- a/samples/client/petstore/elixir/lib/openapi_petstore/deserializer.ex +++ b/samples/client/petstore/elixir/lib/openapi_petstore/deserializer.ex @@ -19,7 +19,8 @@ defmodule OpenapiPetstore.Deserializer do model |> Map.update!(field, &(Poison.Decode.decode(&1, Keyword.merge(options, [as: struct(mod)])))) end - + # Just keep the value parsed from json for any + def deserialize(model, field, :any, mod, options), do: model def deserialize(model, field, :map, mod, options) do maybe_transform_map = fn nil -> 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 ce23e4283584..2624115fa369 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,7 +14,7 @@ defmodule OpenapiPetstore.Model.AllOfWithSingleRef do @type t :: %__MODULE__{ :username => String.t | nil, - :SingleRefType => any | nil + :SingleRefType => any() | nil } end @@ -22,7 +22,7 @@ defimpl Poison.Decoder, for: OpenapiPetstore.Model.AllOfWithSingleRef do import OpenapiPetstore.Deserializer def decode(value, options) do value - |> deserialize(:SingleRefType, :struct, OpenapiPetstore.Model.SingleRefType, options) + |> deserialize(:SingleRefType, :any, :any, options) end end