diff --git a/modules/openapi-generator/src/test/resources/3_0/elixir/petstore-with-fake-endpoints-models-for-testing.yaml b/modules/openapi-generator/src/test/resources/3_0/elixir/petstore-with-fake-endpoints-models-for-testing.yaml index b2dd68dfe060..7269571de890 100644 --- a/modules/openapi-generator/src/test/resources/3_0/elixir/petstore-with-fake-endpoints-models-for-testing.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/elixir/petstore-with-fake-endpoints-models-for-testing.yaml @@ -1361,6 +1361,7 @@ paths: schema: $ref: "#/components/schemas/AllOfWithSingleRef" servers: + - url: "https://petstore.swagger.io/v2" - url: "http://{server}.swagger.io:{port}/v2" description: petstore server variables: diff --git a/samples/client/petstore/elixir/README.md b/samples/client/petstore/elixir/README.md index 898f669267d0..367db2ea008f 100644 --- a/samples/client/petstore/elixir/README.md +++ b/samples/client/petstore/elixir/README.md @@ -31,14 +31,14 @@ You can override the URL of your server (e.g. if you have a separate development configuration files). ```elixir -config :openapi_petstore, base_url: "http://petstore.swagger.io:80/v2" +config :openapi_petstore, base_url: "https://petstore.swagger.io/v2" ``` Multiple clients for the same API with different URLs can be created passing different `base_url`s when calling `OpenapiPetstore.Connection.new/1`: ```elixir -client = OpenapiPetstore.Connection.new(base_url: "http://petstore.swagger.io:80/v2") +client = OpenapiPetstore.Connection.new(base_url: "https://petstore.swagger.io/v2") ``` [exdoc]: https://github.com/elixir-lang/ex_doc diff --git a/samples/client/petstore/elixir/config/config.exs b/samples/client/petstore/elixir/config/config.exs index a6e7708580ac..fd21e2e82d37 100644 --- a/samples/client/petstore/elixir/config/config.exs +++ b/samples/client/petstore/elixir/config/config.exs @@ -7,7 +7,7 @@ # General application configuration import Config -config :openapi_petstore, base_url: "http://petstore.swagger.io:80/v2" +config :openapi_petstore, base_url: "https://petstore.swagger.io/v2" # Import environment specific config. This must remain at the bottom # of this file so it overrides the configuration defined above. diff --git a/samples/client/petstore/elixir/test/deserializer_test.exs b/samples/client/petstore/elixir/test/deserializer_test.exs index 31b2b2cf45f5..d828974b7a5c 100644 --- a/samples/client/petstore/elixir/test/deserializer_test.exs +++ b/samples/client/petstore/elixir/test/deserializer_test.exs @@ -30,7 +30,7 @@ defmodule DeserializerTest do """ test "jason_decode/2 with valid JSON" do - assert Deserializer.jason_decode(@valid_json, Pet) == + assert Deserializer.json_decode(@valid_json, Pet) == {:ok, %Pet{ id: 14, @@ -43,7 +43,7 @@ defmodule DeserializerTest do end test "jason_decode/2 with invalid JSON" do - assert Deserializer.jason_decode(~s/{: 1}/, Pet) == - {:error, %Jason.DecodeError{data: "{: 1}", position: 1, token: nil}} + assert Deserializer.json_decode(~s/{: 1}/, Pet) == + {:error, {:invalid_byte, 1, 58}} end end diff --git a/samples/client/petstore/elixir/test/format_test.exs b/samples/client/petstore/elixir/test/format_test.exs index 22e545db6b70..aa896b855223 100644 --- a/samples/client/petstore/elixir/test/format_test.exs +++ b/samples/client/petstore/elixir/test/format_test.exs @@ -33,8 +33,8 @@ defmodule FormatTest do string: "Hello world!", byte: "U3dhZ2dlciByb2Nrcw==", binary: <<1, 2, 3>>, - date: ~D[2013-10-20], - dateTime: ~U[2013-10-20T18:20:30Z], + date: "2013-10-20", + dateTime: "2013-10-20T19:20:30+01:00", uuid: "3fa85f64-5717-4562-b3fc-2c963f66afa6", password: "green?horse", pattern_with_digits: "1234567890", @@ -73,7 +73,7 @@ defmodule FormatTest do string: nil, byte: "U3dhZ2dlciByb2Nrcw==", binary: nil, - date: ~D[2013-10-20], + date: "2013-10-20", dateTime: nil, uuid: nil, password: "green?horse", diff --git a/samples/client/petstore/elixir/test/mixed_properties_and_additional_properties_class_test.exs b/samples/client/petstore/elixir/test/mixed_properties_and_additional_properties_class_test.exs index 94e18ee9345a..1129a221749e 100644 --- a/samples/client/petstore/elixir/test/mixed_properties_and_additional_properties_class_test.exs +++ b/samples/client/petstore/elixir/test/mixed_properties_and_additional_properties_class_test.exs @@ -15,7 +15,7 @@ defmodule MixedPropertiesAndAdditionalPropertiesClass do |> Model.decode() == %Model{ uuid: "3fa85f64-5717-4562-b3fc-2c963f66afa6", - dateTime: ~U[2013-10-20T18:20:30Z], + dateTime: "2013-10-20T19:20:30+01:00", map: %{ # TODO values should be Dog and Cat structs instead of an Animal "doggie" => %Animal{ diff --git a/samples/client/petstore/elixir/test/outer_enum_test.exs b/samples/client/petstore/elixir/test/outer_enum_test.exs index d8a6f38cf061..b193b5f85816 100644 --- a/samples/client/petstore/elixir/test/outer_enum_test.exs +++ b/samples/client/petstore/elixir/test/outer_enum_test.exs @@ -14,8 +14,8 @@ defmodule OuterEnumTest do """ @tag timeout: :infinity - test "jason_decode/2 with valid JSON" do - assert Deserializer.jason_decode(@valid_json, EnumTest) == + test "json_decode/2 with valid JSON" do + assert Deserializer.json_decode(@valid_json, EnumTest) == {:ok, %EnumTest{ enum_string: "UPPER", diff --git a/samples/client/petstore/elixir/test/pet_test.exs b/samples/client/petstore/elixir/test/pet_test.exs index 0c8743062dbf..54d848f0b789 100644 --- a/samples/client/petstore/elixir/test/pet_test.exs +++ b/samples/client/petstore/elixir/test/pet_test.exs @@ -24,17 +24,21 @@ defmodule PetTest do {:ok, %Tesla.Env{} = response} = PetApi.add_pet(connection, pet) assert response.status == 200 - {:ok, pet} = PetApi.get_pet_by_id(connection, petId) - assert pet.id == petId - assert pet.name == "elixir client test" - assert pet.photoUrls == ["http://test_elixir_unit_test.com"] - assert pet.category == %Category{id: petId, name: "test elixir category"} - assert pet.tags == [%Tag{:id => petId, :name => "test elixir tag"}] + retry_assert(fn -> + {:ok, pet} = PetApi.get_pet_by_id(connection, petId) + assert pet.id == petId + assert pet.name == "elixir client test" + assert pet.photoUrls == ["http://test_elixir_unit_test.com"] + assert pet.category == %Category{id: petId, name: "test elixir category"} + assert pet.tags == [%Tag{:id => petId, :name => "test elixir tag"}] + end) {:ok, response} = PetApi.delete_pet(connection, petId) assert response.status == 200 - {:ok, response} = PetApi.get_pet_by_id(connection, petId) - assert response.status == 404 + retry_assert(fn -> + {:ok, response} = PetApi.get_pet_by_id(connection, petId) + assert response.status == 404 + end) end test "update a pet", %{connection: connection} do @@ -50,10 +54,24 @@ defmodule PetTest do {:ok, response} = PetApi.update_pet(connection, pet) assert response.status == 200 - {:ok, pet} = PetApi.get_pet_by_id(connection, petId) - assert pet.id == petId - assert pet.name == "elixir client updatePet" - assert pet.status == "pending" + retry_assert(fn -> + {:ok, pet} = PetApi.get_pet_by_id(connection, petId) + assert pet.id == petId + assert pet.name == "elixir client updatePet" + assert pet.status == "pending" + end, 5, 100) + end + + def retry_assert(fun, attempts \\ 3, delay \\ 100) + def retry_assert(_fun, 0, _delay), do: flunk("assertion failed after retries") + def retry_assert(fun, attempts, delay) do + try do + fun.() + rescue + _e -> + Process.sleep(delay) + retry_assert(fun, attempts - 1, delay) + end end test "find pet by status", %{connection: connection} do