Skip to content

Commit

Permalink
Add sample codes for elixir client
Browse files Browse the repository at this point in the history
  • Loading branch information
niku committed Jan 30, 2017
1 parent e0a4b0b commit 001b1c4
Show file tree
Hide file tree
Showing 40 changed files with 470 additions and 0 deletions.
23 changes: 23 additions & 0 deletions samples/client/petstore/elixir/.swagger-codegen-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Swagger Codegen Ignore
# Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
18 changes: 18 additions & 0 deletions samples/client/petstore/elixir/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# SwaggerPetstore

**TODO: Add description**

## Installation

If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `swagger_petstore` to your list of dependencies in `mix.exs`:

```elixir
def deps do
[{:swagger_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/swagger_petstore](https://hexdocs.pm/swagger_petstore).
30 changes: 30 additions & 0 deletions samples/client/petstore/elixir/config/config.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
use Mix.Config

# This configuration is loaded before any dependency and is restricted
# to this project. If another project depends on this project, this
# file won't be loaded nor affect the parent project. For this reason,
# if you want to provide default values for your application for
# 3rd-party users, it should be done in your "mix.exs" file.

# You can configure for your application as:
#
# config :swagger_petstore, key: :value
#
# And access this configuration in your application as:
#
# Application.get_env(:swagger_petstore, :key)
#
# Or configure a 3rd-party app:
#
# config :logger, level: :info
#

# It is also possible to import configuration files, relative to this
# directory. For example, you can emulate configuration per environment
# by uncommenting the line below and defining dev.exs, test.exs and such.
# Configuration from the imported file will override the ones defined
# here (which is why it is important to import them last).
#
# import_config "#{Mix.env}.exs"
52 changes: 52 additions & 0 deletions samples/client/petstore/elixir/lib/swagger_petstore/api/fake.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
defmodule SwaggerPetstore.Api.Fake do
@moduledoc """
Documentation for SwaggerPetstore.Api.Fake.
"""

use Tesla

plug Tesla.Middleware.BaseUrl, "http://petstore.swagger.io/v2"
plug Tesla.Middleware.JSON

def test_client_model(body) do
method = [method: :patch]
url = [url: "/fake"]
query_params = []
header_params = []
body_params = [body: body]
form_params = []
params = query_params ++ header_params ++ body_params ++ form_params
opts = []
options = method ++ url ++ params ++ opts

request(options)
end

def test_endpoint_parameters(number, double, pattern_without_delimiter, byte, integer, int32, int64, float, string, binary, date, date_time, password, callback) do
method = [method: :post]
url = [url: "/fake"]
query_params = []
header_params = []
body_params = []
form_params = [body: Enum.map_join([{:"integer", integer}, {:"int32", int32}, {:"int64", int64}, {:"number", number}, {:"float", float}, {:"double", double}, {:"string", string}, {:"patternWithoutDelimiter", pattern_without_delimiter}, {:"byte", byte}, {:"binary", binary}, {:"date", date}, {:"dateTime", date_time}, {:"password", password}, {:"callback", callback}], "&", &("#{elem(&1, 0)}=#{elem(&1, 1)}"))]
params = query_params ++ header_params ++ body_params ++ form_params
opts = []
options = method ++ url ++ params ++ opts

request(options)
end

def test_enum_parameters(enum_form_string_array, enum_form_string, enum_header_string_array, enum_header_string, enum_query_string_array, enum_query_string, enum_query_integer, enum_query_double) do
method = [method: :get]
url = [url: "/fake"]
query_params = [query: [{:"enumQueryStringArray", enum_query_string_array}, {:"enumQueryString", enum_query_string}, {:"enumQueryInteger", enum_query_integer}]]
header_params = [header: [{:"enumHeaderStringArray", enum_header_string_array}, {:"enumHeaderString", enum_header_string}]]
body_params = []
form_params = [body: Enum.map_join([{:"enumFormStringArray", enum_form_string_array}, {:"enumFormString", enum_form_string}, {:"enumQueryDouble", enum_query_double}], "&", &("#{elem(&1, 0)}=#{elem(&1, 1)}"))]
params = query_params ++ header_params ++ body_params ++ form_params
opts = []
options = method ++ url ++ params ++ opts

request(options)
end
end
122 changes: 122 additions & 0 deletions samples/client/petstore/elixir/lib/swagger_petstore/api/pet.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
defmodule SwaggerPetstore.Api.Pet do
@moduledoc """
Documentation for SwaggerPetstore.Api.Pet.
"""

use Tesla

plug Tesla.Middleware.BaseUrl, "http://petstore.swagger.io/v2"
plug Tesla.Middleware.JSON

def add_pet(body) do
method = [method: :post]
url = [url: "/pet"]
query_params = []
header_params = []
body_params = [body: body]
form_params = []
params = query_params ++ header_params ++ body_params ++ form_params
opts = []
options = method ++ url ++ params ++ opts

request(options)
end

def delete_pet(pet_id, api_key) do
method = [method: :delete]
url = [url: "/pet/#{pet_id}"]
query_params = []
header_params = [header: [{:"apiKey", api_key}]]
body_params = []
form_params = []
params = query_params ++ header_params ++ body_params ++ form_params
opts = []
options = method ++ url ++ params ++ opts

request(options)
end

def find_pets_by_status(status) do
method = [method: :get]
url = [url: "/pet/findByStatus"]
query_params = [query: [{:"status", status}]]
header_params = []
body_params = []
form_params = []
params = query_params ++ header_params ++ body_params ++ form_params
opts = []
options = method ++ url ++ params ++ opts

request(options)
end

def find_pets_by_tags(tags) do
method = [method: :get]
url = [url: "/pet/findByTags"]
query_params = [query: [{:"tags", tags}]]
header_params = []
body_params = []
form_params = []
params = query_params ++ header_params ++ body_params ++ form_params
opts = []
options = method ++ url ++ params ++ opts

request(options)
end

def get_pet_by_id(pet_id) do
method = [method: :get]
url = [url: "/pet/#{pet_id}"]
query_params = []
header_params = []
body_params = []
form_params = []
params = query_params ++ header_params ++ body_params ++ form_params
opts = []
options = method ++ url ++ params ++ opts

request(options)
end

def update_pet(body) do
method = [method: :put]
url = [url: "/pet"]
query_params = []
header_params = []
body_params = [body: body]
form_params = []
params = query_params ++ header_params ++ body_params ++ form_params
opts = []
options = method ++ url ++ params ++ opts

request(options)
end

def update_pet_with_form(pet_id, name, status) do
method = [method: :post]
url = [url: "/pet/#{pet_id}"]
query_params = []
header_params = []
body_params = []
form_params = [body: Enum.map_join([{:"name", name}, {:"status", status}], "&", &("#{elem(&1, 0)}=#{elem(&1, 1)}"))]
params = query_params ++ header_params ++ body_params ++ form_params
opts = []
options = method ++ url ++ params ++ opts

request(options)
end

def upload_file(pet_id, additional_metadata, file) do
method = [method: :post]
url = [url: "/pet/#{pet_id}/uploadImage"]
query_params = []
header_params = []
body_params = []
form_params = [body: Enum.map_join([{:"additionalMetadata", additional_metadata}, {:"file", file}], "&", &("#{elem(&1, 0)}=#{elem(&1, 1)}"))]
params = query_params ++ header_params ++ body_params ++ form_params
opts = []
options = method ++ url ++ params ++ opts

request(options)
end
end
66 changes: 66 additions & 0 deletions samples/client/petstore/elixir/lib/swagger_petstore/api/store.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
defmodule SwaggerPetstore.Api.Store do
@moduledoc """
Documentation for SwaggerPetstore.Api.Store.
"""

use Tesla

plug Tesla.Middleware.BaseUrl, "http://petstore.swagger.io/v2"
plug Tesla.Middleware.JSON

def delete_order(order_id) do
method = [method: :delete]
url = [url: "/store/order/#{order_id}"]
query_params = []
header_params = []
body_params = []
form_params = []
params = query_params ++ header_params ++ body_params ++ form_params
opts = []
options = method ++ url ++ params ++ opts

request(options)
end

def get_inventory() do
method = [method: :get]
url = [url: "/store/inventory"]
query_params = []
header_params = []
body_params = []
form_params = []
params = query_params ++ header_params ++ body_params ++ form_params
opts = []
options = method ++ url ++ params ++ opts

request(options)
end

def get_order_by_id(order_id) do
method = [method: :get]
url = [url: "/store/order/#{order_id}"]
query_params = []
header_params = []
body_params = []
form_params = []
params = query_params ++ header_params ++ body_params ++ form_params
opts = []
options = method ++ url ++ params ++ opts

request(options)
end

def place_order(body) do
method = [method: :post]
url = [url: "/store/order"]
query_params = []
header_params = []
body_params = [body: body]
form_params = []
params = query_params ++ header_params ++ body_params ++ form_params
opts = []
options = method ++ url ++ params ++ opts

request(options)
end
end
Loading

0 comments on commit 001b1c4

Please sign in to comment.