Skip to content

add elixir workflow #21215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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 @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions samples/client/petstore/elixir/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/elixir/config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions samples/client/petstore/elixir/test/deserializer_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
6 changes: 3 additions & 3 deletions samples/client/petstore/elixir/test/format_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
4 changes: 2 additions & 2 deletions samples/client/petstore/elixir/test/outer_enum_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
42 changes: 30 additions & 12 deletions samples/client/petstore/elixir/test/pet_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down