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 @@ -3,9 +3,7 @@
import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.Template;
import io.swagger.codegen.*;
import io.swagger.models.properties.ArrayProperty;
import io.swagger.models.properties.MapProperty;
import io.swagger.models.properties.Property;
import io.swagger.models.properties.*;
import io.swagger.models.Info;
import io.swagger.models.Model;
import io.swagger.models.Swagger;
Expand All @@ -32,7 +30,6 @@ public class ElixirClientCodegen extends DefaultCodegen implements CodegenConfig
"{:poison, \">= 1.0.0\"}"
);


public ElixirClientCodegen() {
super();

Expand Down Expand Up @@ -420,14 +417,77 @@ public String toOperationId(String operationId) {
*/
@Override
public String getTypeDeclaration(Property p) {
// SubClasses of AbstractProperty
//
// ArrayProperty
// MapProperty
// PasswordProperty
// StringProperty
// EmailProperty
// ByteArrayProperty
// DateProperty
// UUIDProperty
// DateTimeProperty
// ObjectProperty
// AbstractNumericProperty
// BaseIntegerProperty
// IntegerProperty
// LongProperty
// DecimalProperty
// DoubleProperty
// FloatProperty
// BinaryProperty
// BooleanProperty
// RefProperty
// FileProperty
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are good references for other generators as well 👍

if (p instanceof ArrayProperty) {
ArrayProperty ap = (ArrayProperty) p;
Property inner = ap.getItems();
return getSwaggerType(p) + "[" + getTypeDeclaration(inner) + "]";
return "[" + getTypeDeclaration(inner) + "]";
} else if (p instanceof MapProperty) {
MapProperty mp = (MapProperty) p;
Property inner = mp.getAdditionalProperties();
return getSwaggerType(p) + "[String, " + getTypeDeclaration(inner) + "]";
return "%{optional(String.t) => " + getTypeDeclaration(inner) + "}";
} else if (p instanceof PasswordProperty) {
return "String.t";
} else if (p instanceof EmailProperty) {
return "String.t";
} else if (p instanceof ByteArrayProperty) {
return "binary()";
} else if (p instanceof StringProperty) {
return "String.t";
} else if (p instanceof DateProperty) {
return "Date.t";
} else if (p instanceof UUIDProperty) {
return "String.t";
} else if (p instanceof DateTimeProperty) {
return "DateTime.t";
} else if (p instanceof ObjectProperty) {
// How to map it?
return super.getTypeDeclaration(p);
} else if (p instanceof IntegerProperty) {
return "integer()";
} else if (p instanceof LongProperty) {
return "integer()";
} else if (p instanceof BaseIntegerProperty) {
return "integer()";
} else if (p instanceof DoubleProperty) {
return "float()";
} else if (p instanceof FloatProperty) {
return "float()";
} else if (p instanceof DecimalProperty) {
return "float()";
} else if (p instanceof AbstractNumericProperty) {
return "number()";
} else if (p instanceof BinaryProperty) {
return "binary()";
} else if (p instanceof BooleanProperty) {
return "boolean()";
} else if (p instanceof RefProperty) {
// How to map it?
return super.getTypeDeclaration(p);
} else if (p instanceof FileProperty) {
return "String.t";
}
return super.getTypeDeclaration(p);
}
Expand Down Expand Up @@ -590,26 +650,8 @@ private void buildTypespec(CodegenParameter param, StringBuilder sb) {
buildTypespec(param.items, sb);
sb.append("}");
} else if (param.isPrimitiveType) {
// <type>() OR <type>.t

// Primitive types in Elixir
// https://hexdocs.pm/elixir/1.5.2/typespecs.html#types-and-their-syntax
//
// NOTE: List, Tuple and Map are declared as primitive in a variable `languageSpecificPrimitives`.
HashMap map = new HashMap<String, String>();
map.put("Integer", "integer()");
map.put("Float", "float()");
map.put("Boolean", "boolean()");
map.put("String", "String.t");
map.put("List", "list()");
map.put("Atom", "atom()");
map.put("Map", "map()");
map.put("Tuple", "tuple()");
map.put("PID", "pid()");
map.put("DateTime", "DateTime.t");

String dataType = (String) map.get(param.dataType);
sb.append(dataType);
// like `integer()`, `String.t`
sb.append(param.dataType);
} else if (param.isFile) {
sb.append("String.t");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
{{#vars}}:"{{baseName}}"{{#hasMore}},
{{/hasMore}}{{/vars}}
]

@type t :: %__MODULE__{
{{#vars}}:"{{baseName}}" => {{{datatype}}}{{#hasMore}},
{{/hasMore}}{{/vars}}
}
end

defimpl Poison.Decoder, for: {{moduleName}}.Model.{{classname}} do
Expand Down
50 changes: 25 additions & 25 deletions samples/client/petstore/elixir/lib/swagger_petstore/api/fake.ex
Original file line number Diff line number Diff line change
Expand Up @@ -156,28 +156,28 @@ defmodule SwaggerPetstore.Api.Fake do
## Parameters

- connection (SwaggerPetstore.Connection): Connection to server
- number (Float): None
- double (Float): None
- pattern_without_delimiter (String): None
- byte (String): None
- number (float()): None
- double (float()): None
- pattern_without_delimiter (String.t): None
- byte (binary()): None
- opts (KeywordList): [optional] Optional parameters
- :integer (Integer): None
- :int32 (Integer): None
- :int64 (Integer): None
- :float (Float): None
- :string (String): None
- :binary (String): None
- :date (DateTime): None
- :date_time (DateTime): None
- :password (String): None
- :callback (String): None
- :integer (integer()): None
- :int32 (integer()): None
- :int64 (integer()): None
- :float (float()): None
- :string (String.t): None
- :binary (binary()): None
- :date (Date.t): None
- :date_time (DateTime.t): None
- :password (String.t): None
- :callback (String.t): None

## Returns

{:ok, %{}} on success
{:error, info} on failure
"""
@spec test_endpoint_parameters(Tesla.Env.client, float(), float(), String.t, String.t, keyword()) :: {:ok, nil} | {:error, Tesla.Env.t}
@spec test_endpoint_parameters(Tesla.Env.client, float(), float(), String.t, binary(), keyword()) :: {:ok, nil} | {:error, Tesla.Env.t}
def test_endpoint_parameters(connection, number, double, pattern_without_delimiter, byte, opts \\ []) do
optional_params = %{
:"integer" => :form,
Expand Down Expand Up @@ -212,14 +212,14 @@ defmodule SwaggerPetstore.Api.Fake do

- connection (SwaggerPetstore.Connection): Connection to server
- opts (KeywordList): [optional] Optional parameters
- :enum_form_string_array (List[String]): Form parameter enum test (string array)
- :enum_form_string (String): Form parameter enum test (string)
- :enum_header_string_array (List[String]): Header parameter enum test (string array)
- :enum_header_string (String): Header parameter enum test (string)
- :enum_query_string_array (List[String]): Query parameter enum test (string array)
- :enum_query_string (String): 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)
- :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)

## Returns

Expand Down Expand Up @@ -254,8 +254,8 @@ defmodule SwaggerPetstore.Api.Fake do
## Parameters

- connection (SwaggerPetstore.Connection): Connection to server
- param (String): field1
- param2 (String): field2
- param (String.t): field1
- param2 (String.t): field2
- opts (KeywordList): [optional] Optional parameters

## Returns
Expand Down
22 changes: 11 additions & 11 deletions samples/client/petstore/elixir/lib/swagger_petstore/api/pet.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ defmodule SwaggerPetstore.Api.Pet do
## Parameters

- connection (SwaggerPetstore.Connection): Connection to server
- pet_id (Integer): Pet id to delete
- pet_id (integer()): Pet id to delete
- opts (KeywordList): [optional] Optional parameters
- :api_key (String):
- :api_key (String.t):

## Returns

Expand Down Expand Up @@ -74,7 +74,7 @@ defmodule SwaggerPetstore.Api.Pet do
## Parameters

- connection (SwaggerPetstore.Connection): Connection to server
- status (List[String]): Status values that need to be considered for filter
- status ([String.t]): Status values that need to be considered for filter
- opts (KeywordList): [optional] Optional parameters

## Returns
Expand All @@ -100,7 +100,7 @@ defmodule SwaggerPetstore.Api.Pet do
## Parameters

- connection (SwaggerPetstore.Connection): Connection to server
- tags (List[String]): Tags to filter by
- tags ([String.t]): Tags to filter by
- opts (KeywordList): [optional] Optional parameters

## Returns
Expand All @@ -126,7 +126,7 @@ defmodule SwaggerPetstore.Api.Pet do
## Parameters

- connection (SwaggerPetstore.Connection): Connection to server
- pet_id (Integer): ID of pet to return
- pet_id (integer()): ID of pet to return
- opts (KeywordList): [optional] Optional parameters

## Returns
Expand Down Expand Up @@ -177,10 +177,10 @@ defmodule SwaggerPetstore.Api.Pet do
## Parameters

- connection (SwaggerPetstore.Connection): Connection to server
- pet_id (Integer): ID of pet that needs to be updated
- pet_id (integer()): ID of pet that needs to be updated
- opts (KeywordList): [optional] Optional parameters
- :name (String): Updated name of the pet
- :status (String): Updated status of the pet
- :name (String.t): Updated name of the pet
- :status (String.t): Updated status of the pet

## Returns

Expand Down Expand Up @@ -209,10 +209,10 @@ defmodule SwaggerPetstore.Api.Pet do
## Parameters

- connection (SwaggerPetstore.Connection): Connection to server
- pet_id (Integer): ID of pet to update
- pet_id (integer()): ID of pet to update
- opts (KeywordList): [optional] Optional parameters
- :additional_metadata (String): Additional data to pass to server
- :file (String): file to upload
- :additional_metadata (String.t): Additional data to pass to server
- :file (String.t): file to upload

## Returns

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ defmodule SwaggerPetstore.Api.Store do
## Parameters

- connection (SwaggerPetstore.Connection): Connection to server
- order_id (String): ID of the order that needs to be deleted
- order_id (String.t): ID of the order that needs to be deleted
- opts (KeywordList): [optional] Optional parameters

## Returns
Expand Down Expand Up @@ -67,7 +67,7 @@ defmodule SwaggerPetstore.Api.Store do
## Parameters

- connection (SwaggerPetstore.Connection): Connection to server
- order_id (Integer): ID of pet that needs to be fetched
- order_id (integer()): ID of pet that needs to be fetched
- opts (KeywordList): [optional] Optional parameters

## Returns
Expand Down
16 changes: 8 additions & 8 deletions samples/client/petstore/elixir/lib/swagger_petstore/api/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ defmodule SwaggerPetstore.Api.User do
## Parameters

- connection (SwaggerPetstore.Connection): Connection to server
- body (List[User]): List of user object
- body ([User]): List of user object
- opts (KeywordList): [optional] Optional parameters

## Returns
Expand All @@ -70,7 +70,7 @@ defmodule SwaggerPetstore.Api.User do
## Parameters

- connection (SwaggerPetstore.Connection): Connection to server
- body (List[User]): List of user object
- body ([User]): List of user object
- opts (KeywordList): [optional] Optional parameters

## Returns
Expand All @@ -96,7 +96,7 @@ defmodule SwaggerPetstore.Api.User do
## Parameters

- connection (SwaggerPetstore.Connection): Connection to server
- username (String): The name that needs to be deleted
- username (String.t): The name that needs to be deleted
- opts (KeywordList): [optional] Optional parameters

## Returns
Expand All @@ -121,7 +121,7 @@ defmodule SwaggerPetstore.Api.User do
## Parameters

- connection (SwaggerPetstore.Connection): Connection to server
- username (String): 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
Expand All @@ -146,13 +146,13 @@ defmodule SwaggerPetstore.Api.User do
## Parameters

- connection (SwaggerPetstore.Connection): Connection to server
- username (String): The user name for login
- password (String): The password for login in clear text
- 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{}} on success
{:ok, %SwaggerPetstore.Model.String.t{}} on success
{:error, info} on failure
"""
@spec login_user(Tesla.Env.client, String.t, String.t, keyword()) :: {:ok, String.t} | {:error, Tesla.Env.t}
Expand Down Expand Up @@ -198,7 +198,7 @@ defmodule SwaggerPetstore.Api.User do
## Parameters

- connection (SwaggerPetstore.Connection): Connection to server
- username (String): name that need to be deleted
- username (String.t): name that need to be deleted
- body (User): Updated user object
- opts (KeywordList): [optional] Optional parameters

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ defmodule SwaggerPetstore.Model.AdditionalPropertiesClass do
:"map_property",
:"map_of_map_property"
]

@type t :: %__MODULE__{
:"map_property" => %{optional(String.t) => String.t},
:"map_of_map_property" => %{optional(String.t) => %{optional(String.t) => String.t}}
}
end

defimpl Poison.Decoder, for: SwaggerPetstore.Model.AdditionalPropertiesClass do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ defmodule SwaggerPetstore.Model.Animal do
:"className",
:"color"
]

@type t :: %__MODULE__{
:"className" => String.t,
:"color" => String.t
}
end

defimpl Poison.Decoder, for: SwaggerPetstore.Model.Animal do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ defmodule SwaggerPetstore.Model.AnimalFarm do
defstruct [

]

@type t :: %__MODULE__{

}
end

defimpl Poison.Decoder, for: SwaggerPetstore.Model.AnimalFarm do
Expand Down
Loading