Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,10 @@ public class ElixirClientCodegen extends DefaultCodegen {
// This is the name of elixir project name;
protected static final String defaultPackageName = "openapi_client";

String supportedElixirVersion = "1.10";
String supportedElixirVersion = "1.18";
List<String> extraApplications = Arrays.asList(":logger");
List<String> deps = Arrays.asList(
"{:tesla, \"~> 1.7\"}",
"{:jason, \"~> 1.4\"}",
"{:ex_doc, \"~> 0.30\", only: :dev, runtime: false}",
"{:dialyxir, \"~> 1.3\", only: [:dev, :test], runtime: false}");

Expand Down Expand Up @@ -694,7 +693,7 @@ public String codeMappingKey() {
}

public String decodedStruct() {
// Let Jason decode the entire response into a generic blob
// Decode the entire response into a generic blob
if (isMap) {
return "%{}";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ defmodule {{moduleName}}.Connection do

tesla_options = Application.get_env(:tesla, __MODULE__, [])
middleware = Keyword.get(tesla_options, :middleware, [])
json_engine = Keyword.get(tesla_options, :json, Jason)
json_engine = Keyword.get(tesla_options, :json, JSON)

user_agent =
Keyword.get(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ defmodule {{moduleName}}.Deserializer do
Helper functions for deserializing responses into models
"""

@jason_decode_opts [keys: :strings]

def jason_decode(json) do
Jason.decode(json, @jason_decode_opts)
def json_decode(json) do
JSON.decode(json)
end

def jason_decode(json, module) do
def json_decode(json, module) do
json
|> jason_decode()
|> json_decode()
|> case do
{:ok, decoded} -> {:ok, to_struct(decoded, module)}
{:error, _} = error -> error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{{&description}}
"""

@derive Jason.Encoder
@derive JSON.Encoder
defstruct [
{{#vars}}{{#atom}}{{&baseName}}{{/atom}}{{^-last}},
{{/-last}}{{/vars}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ defmodule {{moduleName}}.RequestBuilder do
Tesla.Multipart.add_field(
multipart,
key,
Jason.encode!(value),
JSON.encode!(value),
headers: [{:"Content-Type", "application/json"}]
)
end)
Expand Down Expand Up @@ -187,10 +187,10 @@ defmodule {{moduleName}}.RequestBuilder do
defp decode(%Tesla.Env{} = env, false), do: {:ok, env}

defp decode(%Tesla.Env{body: body}, %{}) do
{{moduleName}}.Deserializer.jason_decode(body)
{{moduleName}}.Deserializer.json_decode(body)
end

defp decode(%Tesla.Env{body: body}, module) do
{{moduleName}}.Deserializer.jason_decode(body, module)
{{moduleName}}.Deserializer.json_decode(body, module)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ defmodule OpenapiPetstore.Connection do

tesla_options = Application.get_env(:tesla, __MODULE__, [])
middleware = Keyword.get(tesla_options, :middleware, [])
json_engine = Keyword.get(tesla_options, :json, Jason)
json_engine = Keyword.get(tesla_options, :json, JSON)

user_agent =
Keyword.get(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ defmodule OpenapiPetstore.Deserializer do
Helper functions for deserializing responses into models
"""

@jason_decode_opts [keys: :strings]

def jason_decode(json) do
Jason.decode(json, @jason_decode_opts)
def json_decode(json) do
JSON.decode(json)
end

def jason_decode(json, module) do
def json_decode(json, module) do
json
|> jason_decode()
|> json_decode()
|> case do
{:ok, decoded} -> {:ok, to_struct(decoded, module)}
{:error, _} = error -> error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule OpenapiPetstore.Model.FooGetDefaultResponse do

"""

@derive Jason.Encoder
@derive JSON.Encoder
defstruct [
:string
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule OpenapiPetstore.Model.SpecialModelName do

"""

@derive Jason.Encoder
@derive JSON.Encoder
defstruct [
:"$special[property.name]"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule OpenapiPetstore.Model.AdditionalPropertiesClass do

"""

@derive Jason.Encoder
@derive JSON.Encoder
defstruct [
:map_property,
:map_of_map_property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule OpenapiPetstore.Model.AllOfWithSingleRef do

"""

@derive Jason.Encoder
@derive JSON.Encoder
defstruct [
:username,
:SingleRefType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule OpenapiPetstore.Model.Animal do

"""

@derive Jason.Encoder
@derive JSON.Encoder
defstruct [
:className,
:color
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule OpenapiPetstore.Model.Any do

"""

@derive Jason.Encoder
@derive JSON.Encoder
defstruct [
:"@type"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule OpenapiPetstore.Model.ApiResponse do

"""

@derive Jason.Encoder
@derive JSON.Encoder
defstruct [
:code,
:type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule OpenapiPetstore.Model.ArrayOfArrayOfNumberOnly do

"""

@derive Jason.Encoder
@derive JSON.Encoder
defstruct [
:ArrayArrayNumber
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule OpenapiPetstore.Model.ArrayOfNumberOnly do

"""

@derive Jason.Encoder
@derive JSON.Encoder
defstruct [
:ArrayNumber
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule OpenapiPetstore.Model.ArrayTest do

"""

@derive Jason.Encoder
@derive JSON.Encoder
defstruct [
:array_of_string,
:array_array_of_integer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule OpenapiPetstore.Model.Capitalization do

"""

@derive Jason.Encoder
@derive JSON.Encoder
defstruct [
:smallCamel,
:CapitalCamel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule OpenapiPetstore.Model.Cat do

"""

@derive Jason.Encoder
@derive JSON.Encoder
defstruct [
:className,
:color,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule OpenapiPetstore.Model.Category do

"""

@derive Jason.Encoder
@derive JSON.Encoder
defstruct [
:id,
:name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule OpenapiPetstore.Model.ChildWithNullable do

"""

@derive Jason.Encoder
@derive JSON.Encoder
defstruct [
:type,
:nullableProperty,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule OpenapiPetstore.Model.ClassModel do
Model for testing model with \"_class\" property
"""

@derive Jason.Encoder
@derive JSON.Encoder
defstruct [
:_class
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule OpenapiPetstore.Model.Client do

"""

@derive Jason.Encoder
@derive JSON.Encoder
defstruct [
:client
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule OpenapiPetstore.Model.DeprecatedModel do

"""

@derive Jason.Encoder
@derive JSON.Encoder
defstruct [
:name
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule OpenapiPetstore.Model.Dog do

"""

@derive Jason.Encoder
@derive JSON.Encoder
defstruct [
:className,
:color,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule OpenapiPetstore.Model.EnumArrays do

"""

@derive Jason.Encoder
@derive JSON.Encoder
defstruct [
:just_symbol,
:array_enum
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule OpenapiPetstore.Model.EnumClass do

"""

@derive Jason.Encoder
@derive JSON.Encoder
defstruct [

]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule OpenapiPetstore.Model.EnumTest do

"""

@derive Jason.Encoder
@derive JSON.Encoder
defstruct [
:enum_string,
:enum_string_required,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule OpenapiPetstore.Model.FakeBigDecimalMap200Response do

"""

@derive Jason.Encoder
@derive JSON.Encoder
defstruct [
:someId,
:someMap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule OpenapiPetstore.Model.File do
Must be named `File` for test.
"""

@derive Jason.Encoder
@derive JSON.Encoder
defstruct [
:sourceURI
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule OpenapiPetstore.Model.FileSchemaTestClass do

"""

@derive Jason.Encoder
@derive JSON.Encoder
defstruct [
:file,
:files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule OpenapiPetstore.Model.Foo do

"""

@derive Jason.Encoder
@derive JSON.Encoder
defstruct [
:bar
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule OpenapiPetstore.Model.FormatTest do

"""

@derive Jason.Encoder
@derive JSON.Encoder
defstruct [
:integer,
:int32,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule OpenapiPetstore.Model.HasOnlyReadOnly do

"""

@derive Jason.Encoder
@derive JSON.Encoder
defstruct [
:bar,
:foo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule OpenapiPetstore.Model.HealthCheckResult do
Just a string to inform instance is up and running. Make it nullable in hope to get it as pointer in generated model.
"""

@derive Jason.Encoder
@derive JSON.Encoder
defstruct [
:NullableMessage
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule OpenapiPetstore.Model.List do

"""

@derive Jason.Encoder
@derive JSON.Encoder
defstruct [
:"123-list"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule OpenapiPetstore.Model.MapTest do

"""

@derive Jason.Encoder
@derive JSON.Encoder
defstruct [
:map_map_of_string,
:map_of_enum_string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule OpenapiPetstore.Model.MixedPropertiesAndAdditionalPropertiesClass do

"""

@derive Jason.Encoder
@derive JSON.Encoder
defstruct [
:uuid,
:dateTime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule OpenapiPetstore.Model.Model200Response do
Model for testing model name starting with number
"""

@derive Jason.Encoder
@derive JSON.Encoder
defstruct [
:name,
:class
Expand Down
Loading
Loading