Skip to content

Commit

Permalink
[Elixir] Improve Elixir Client about primitive type spec (#6623)
Browse files Browse the repository at this point in the history
Fix following dialyzer warnings in the sample:

```
:0: Unknown type 'Elixir.Float':t/0
:0: Unknown type 'Elixir.Integer':t/0
```
  • Loading branch information
niku authored and wing328 committed Oct 6, 2017
1 parent 2644adb commit 86803c0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -590,9 +590,26 @@ private void buildTypespec(CodegenParameter param, StringBuilder sb) {
buildTypespec(param.items, sb);
sb.append("}");
} else if (param.isPrimitiveType) {
// <type>.t
sb.append(param.dataType);
sb.append(".t");
// <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);
} else if (param.isFile) {
sb.append("String.t");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ defmodule SwaggerPetstore.Api.Fake do
{:ok, %{}} on success
{:error, info} on failure
"""
@spec test_endpoint_parameters(Tesla.Env.client, Float.t, Float.t, String.t, String.t, keyword()) :: {:ok, nil} | {:error, Tesla.Env.t}
@spec test_endpoint_parameters(Tesla.Env.client, float(), float(), String.t, String.t, 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
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ defmodule SwaggerPetstore.Api.Pet do
{:ok, %{}} on success
{:error, info} on failure
"""
@spec delete_pet(Tesla.Env.client, Integer.t, keyword()) :: {:ok, nil} | {:error, Tesla.Env.t}
@spec delete_pet(Tesla.Env.client, integer(), keyword()) :: {:ok, nil} | {:error, Tesla.Env.t}
def delete_pet(connection, pet_id, opts \\ []) do
optional_params = %{
:"api_key" => :headers
Expand Down Expand Up @@ -134,7 +134,7 @@ defmodule SwaggerPetstore.Api.Pet do
{:ok, %SwaggerPetstore.Model.Pet{}} on success
{:error, info} on failure
"""
@spec get_pet_by_id(Tesla.Env.client, Integer.t, keyword()) :: {:ok, SwaggerPetstore.Model.Pet.t} | {:error, Tesla.Env.t}
@spec get_pet_by_id(Tesla.Env.client, integer(), keyword()) :: {:ok, SwaggerPetstore.Model.Pet.t} | {:error, Tesla.Env.t}
def get_pet_by_id(connection, pet_id, _opts \\ []) do
%{}
|> method(:get)
Expand Down Expand Up @@ -187,7 +187,7 @@ defmodule SwaggerPetstore.Api.Pet do
{:ok, %{}} on success
{:error, info} on failure
"""
@spec update_pet_with_form(Tesla.Env.client, Integer.t, keyword()) :: {:ok, nil} | {:error, Tesla.Env.t}
@spec update_pet_with_form(Tesla.Env.client, integer(), keyword()) :: {:ok, nil} | {:error, Tesla.Env.t}
def update_pet_with_form(connection, pet_id, opts \\ []) do
optional_params = %{
:"name" => :form,
Expand Down Expand Up @@ -219,7 +219,7 @@ defmodule SwaggerPetstore.Api.Pet do
{:ok, %SwaggerPetstore.Model.ApiResponse{}} on success
{:error, info} on failure
"""
@spec upload_file(Tesla.Env.client, Integer.t, keyword()) :: {:ok, SwaggerPetstore.Model.ApiResponse.t} | {:error, Tesla.Env.t}
@spec upload_file(Tesla.Env.client, integer(), keyword()) :: {:ok, SwaggerPetstore.Model.ApiResponse.t} | {:error, Tesla.Env.t}
def upload_file(connection, pet_id, opts \\ []) do
optional_params = %{
:"additionalMetadata" => :form,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ defmodule SwaggerPetstore.Api.Store do
{:ok, %SwaggerPetstore.Model.Order{}} on success
{:error, info} on failure
"""
@spec get_order_by_id(Tesla.Env.client, Integer.t, keyword()) :: {:ok, SwaggerPetstore.Model.Order.t} | {:error, Tesla.Env.t}
@spec get_order_by_id(Tesla.Env.client, integer(), keyword()) :: {:ok, SwaggerPetstore.Model.Order.t} | {:error, Tesla.Env.t}
def get_order_by_id(connection, order_id, _opts \\ []) do
%{}
|> method(:get)
Expand Down

0 comments on commit 86803c0

Please sign in to comment.