elixir.api.mustache Maven / Gradle / Ivy
{{>licenseInfo}}
defmodule {{moduleName}}.Api.{{classname}} do
@moduledoc """
API calls for all endpoints tagged `{{baseName}}`.
"""
alias {{moduleName}}.Connection
import {{moduleName}}.RequestBuilder
{{#operations}}
{{#operation}}
@doc """
{{#summary}}
{{&summary}}
{{/summary}}
{{#notes}}
{{¬es}}
{{/notes}}
## Parameters
- connection ({{&moduleName}}.Connection): Connection to server
{{#requiredParams}}
- {{#underscored}}{{¶mName}}{{/underscored}} ({{&dataType}}): {{&description}}
{{/requiredParams}}
- opts (KeywordList): [optional] Optional parameters
{{#optionalParams}}
{{#isBodyParam}}
- :body ({{dataType}}): {{&description}}
{{/isBodyParam}}
{{^isBodyParam}}
- {{#underscored}}:{{¶mName}}{{/underscored}} ({{&dataType}}): {{&description}}
{{/isBodyParam}}
{{/optionalParams}}
## Returns
{:ok, {{#isArray}}[%{{&returnBaseType}}{}, ...]{{/isArray}}{{#isMap}}%{}{{/isMap}}{{^returnType}}nil{{/returnType}}{{#returnSimpleType}}{{#returnType}}{{{.}}}{{/returnType}}{{/returnSimpleType}}} on success
{:error, Tesla.Env.t} on failure
"""
{{{typespec}}}
def {{{operationId}}}(connection, {{#requiredParams}}{{#underscored}}{{{paramName}}}{{/underscored}}, {{/requiredParams}}{{^hasOptionalParams}}_{{/hasOptionalParams}}opts \\ []) do
{{#optionalParams}}
{{#-first}}
optional_params = %{
{{/-first}}
{{#isBodyParam}}
:body => :body
{{/isBodyParam}}
{{^isBodyParam}}
:"{{baseName}}" => {{#isFormParam}}:form{{/isFormParam}}{{#isQueryParam}}:query{{/isQueryParam}}{{#isHeaderParam}}:headers{{/isHeaderParam}}{{^-last}},{{/-last}}
{{/isBodyParam}}
{{#-last}}
}
{{/-last}}
{{/optionalParams}}
%{}
|> method(:{{#underscored}}{{httpMethod}}{{/underscored}})
|> url("{{replacedPathName}}")
{{#requiredParams}}
{{^isPathParam}}
|> add_param({{#isBodyParam}}:body{{/isBodyParam}}{{#isFormParam}}{{#isMultipart}}{{#isFile}}:file{{/isFile}}{{^isFile}}:form{{/isFile}}{{/isMultipart}}{{^isMultipart}}:form{{/isMultipart}}{{/isFormParam}}{{#isQueryParam}}:query{{/isQueryParam}}{{#isHeaderParam}}:headers{{/isHeaderParam}}, {{#isBodyParam}}:body, {{/isBodyParam}}{{^isBodyParam}}:"{{baseName}}", {{/isBodyParam}}{{#underscored}}{{paramName}}{{/underscored}})
{{/isPathParam}}
{{/requiredParams}}
{{#optionalParams}}
{{#-first}}
|> add_optional_params(optional_params, opts)
{{/-first}}
{{/optionalParams}}
{{#requiresHttpcWorkaround}}
|> ensure_body()
{{/requiresHttpcWorkaround}}
|> Enum.into([])
|> (&Connection.request(connection, &1)).()
|> evaluate_response({{#responses}}{{#-first}}[
{{/-first}}
{ {{& codeMappingKey}}, {{decodedStruct}}}{{^-last}},{{/-last}}
{{#-last}} ]{{/-last}}{{/responses}})
end
{{/operation}}
{{/operations}}
end