-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Elixir] Deserialize responses based on status code (#2355)
* Update Tesla dependency and replace Poison with Jason * Use new Tesla method to set headers * Fix jason dependency definition * Use list for Headers instead of a map * Rollback to Poison because Jason does not support 'as:' option to decode to arbitrary struct * Use new return signature from Tesla 1.0 in decode function * catch error when a struct is given as second parameter to RequestBuilder.decode * Update modules/openapi-generator/src/main/resources/elixir/request_builder.ex.mustache Co-Authored-By: yknx4 <[email protected]> * Update modules/openapi-generator/src/main/resources/elixir/request_builder.ex.mustache Co-Authored-By: yknx4 <[email protected]> * Evaluate response based on status code * Generate Petstore * pin poison to ~> 3.0.0 since 4.0.0 does not work atm * run ./bin/openapi3/elixir-petstore.sh
- Loading branch information
Showing
70 changed files
with
3,246 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
3.3.4-SNAPSHOT | ||
4.0.0-SNAPSHOT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
# OpenapiPetstore | ||
# OpenAPIPetstore | ||
|
||
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ | ||
|
||
## Installation | ||
|
||
If [available in Hex](https://hex.pm/docs/publish), the package can be installed | ||
by adding `openapi_petstore` to your list of dependencies in `mix.exs`: | ||
by adding `open_api_petstore` to your list of dependencies in `mix.exs`: | ||
|
||
```elixir | ||
def deps do | ||
[{:openapi_petstore, "~> 0.1.0"}] | ||
[{:open_api_petstore, "~> 0.1.0"}] | ||
end | ||
``` | ||
|
||
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc) | ||
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can | ||
be found at [https://hexdocs.pm/openapi_petstore](https://hexdocs.pm/openapi_petstore). | ||
be found at [https://hexdocs.pm/open_api_petstore](https://hexdocs.pm/open_api_petstore). |
40 changes: 40 additions & 0 deletions
40
samples/client/petstore/elixir/lib/open_api_petstore/api/another_fake.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). | ||
# https://openapi-generator.tech | ||
# Do not edit the class manually. | ||
|
||
defmodule OpenAPIPetstore.Api.AnotherFake do | ||
@moduledoc """ | ||
API calls for all endpoints tagged `AnotherFake`. | ||
""" | ||
|
||
alias OpenAPIPetstore.Connection | ||
import OpenAPIPetstore.RequestBuilder | ||
|
||
|
||
@doc """ | ||
To test special tags | ||
To test special tags and operation ID starting with number | ||
## Parameters | ||
- connection (OpenAPIPetstore.Connection): Connection to server | ||
- client (Client): client model | ||
- opts (KeywordList): [optional] Optional parameters | ||
## Returns | ||
{:ok, %OpenAPIPetstore.Model.Client{}} on success | ||
{:error, info} on failure | ||
""" | ||
@spec call_123_test_special_tags(Tesla.Env.client, OpenAPIPetstore.Model.Client.t, keyword()) :: {:ok, OpenAPIPetstore.Model.Client.t} | {:error, Tesla.Env.t} | ||
def call_123_test_special_tags(connection, client, _opts \\ []) do | ||
%{} | ||
|> method(:patch) | ||
|> url("/another-fake/dummy") | ||
|> add_param(:body, :body, client) | ||
|> Enum.into([]) | ||
|> (&Connection.request(connection, &1)).() | ||
|> evaluate_response([ | ||
{ 200, %OpenAPIPetstore.Model.Client{}} | ||
]) | ||
end | ||
end |
36 changes: 36 additions & 0 deletions
36
samples/client/petstore/elixir/lib/open_api_petstore/api/default.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). | ||
# https://openapi-generator.tech | ||
# Do not edit the class manually. | ||
|
||
defmodule OpenAPIPetstore.Api.Default do | ||
@moduledoc """ | ||
API calls for all endpoints tagged `Default`. | ||
""" | ||
|
||
alias OpenAPIPetstore.Connection | ||
import OpenAPIPetstore.RequestBuilder | ||
|
||
|
||
@doc """ | ||
## Parameters | ||
- connection (OpenAPIPetstore.Connection): Connection to server | ||
- opts (KeywordList): [optional] Optional parameters | ||
## Returns | ||
{:ok, %OpenAPIPetstore.Model.InlineResponseDefault{}} on success | ||
{:error, info} on failure | ||
""" | ||
@spec foo_get(Tesla.Env.client, keyword()) :: {:ok, OpenAPIPetstore.Model.InlineResponseDefault.t} | {:error, Tesla.Env.t} | ||
def foo_get(connection, _opts \\ []) do | ||
%{} | ||
|> method(:get) | ||
|> url("/foo") | ||
|> Enum.into([]) | ||
|> (&Connection.request(connection, &1)).() | ||
|> evaluate_response([ | ||
{ :default, %OpenAPIPetstore.Model.InlineResponseDefault{}} | ||
]) | ||
end | ||
end |
Oops, something went wrong.