All Downloads are FREE. Search and download functionalities are using the official Maven repository.

elixir.api.mustache Maven / Gradle / Ivy

There is a newer version: 3.0.0-rc1
Show newest version
defmodule {{#modulized}}{{appName}}{{/modulized}}.Api.{{classname}} do
  @moduledoc """
  Documentation for {{#modulized}}{{appName}}{{/modulized}}.Api.{{classname}}.
  """

  use Tesla

  plug Tesla.Middleware.BaseUrl, "{{{basePath}}}"
  plug Tesla.Middleware.JSON
{{#operations}}
    {{#operation}}

  @doc """
  {{summary}}
  {{^notes.isEmpty}}

  {{notes}}
  {{/notes.isEmpty}}
  """
  def {{#underscored}}{{operationId}}{{/underscored}}({{#allParams}}{{^-first}}, {{/-first}}{{#underscored}}{{paramName}}{{/underscored}}{{/allParams}}) do
    method = [method: :{{#underscored}}{{httpMethod}}{{/underscored}}]
    url = [url: "{{replacedPathName}}"]
    query_params = [{{^queryParams.isEmpty}}query: [{{#queryParams}}{{^-first}}, {{/-first}}{:"{{baseName}}", {{#underscored}}{{paramName}}{{/underscored}}}{{/queryParams}}]{{/queryParams.isEmpty}}]
    header_params = [{{^headerParams.isEmpty}}header: [{{#headerParams}}{{^-first}}, {{/-first}}{:"{{baseName}}", {{#underscored}}{{paramName}}{{/underscored}}}{{/headerParams}}]{{/headerParams.isEmpty}}]
    body_params = [{{^bodyParams.isEmpty}}body: {{#bodyParams}}{{#underscored}}{{paramName}}{{/underscored}}{{/bodyParams}}{{/bodyParams.isEmpty}}]
    form_params = [{{^formParams.isEmpty}}body: Enum.map_join([{{#formParams}}{{^-first}}, {{/-first}}{:"{{baseName}}", {{#underscored}}{{paramName}}{{/underscored}}}{{/formParams}}], "&", &("#{elem(&1, 0)}=#{elem(&1, 1)}")){{/formParams.isEmpty}}]
    params = query_params ++ header_params ++ body_params ++ form_params
    opts = []
    options = method ++ url ++ params ++ opts

    request(options)
  end
    {{/operation}}
{{/operations}}
end




© 2015 - 2025 Weber Informatics LLC | Privacy Policy