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` (keyword): Optional parameters
{{#optionalParams}}
{{#isBodyParam}}
- `:body` ({{dataType}}): {{&description}}
{{/isBodyParam}}
{{^isBodyParam}}
- `{{#atom}}{{&baseName}}{{/atom}}` ({{&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}}
{{#atom}}{{baseName}}{{/atom}} => {{#isFormParam}}:form{{/isFormParam}}{{#isQueryParam}}:query{{/isQueryParam}}{{#isHeaderParam}}:headers{{/isHeaderParam}}{{^-last}},{{/-last}}
{{/isBodyParam}}
{{#-last}}
}
{{/-last}}
{{/optionalParams}}
request =
%{}
|> method({{#atom}}{{#underscored}}{{httpMethod}}{{/underscored}}{{/atom}})
|> 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}}{{#atom}}{{baseName}}{{/atom}}{{/isBodyParam}}, {{#underscored}}{{paramName}}{{/underscored}})
{{/isPathParam}}
{{/requiredParams}}
{{#optionalParams}}
{{#-first}}
|> add_optional_params(optional_params, opts)
{{/-first}}
{{/optionalParams}}
{{#requiresHttpcWorkaround}}
|> ensure_body()
{{/requiresHttpcWorkaround}}
|> Enum.into([])
connection
|> Connection.request(request)
|> evaluate_response({{#responses}}{{#-first}}[
{{/-first}}
{{=<% %>=}}{<%& codeMappingKey%>, <%decodedStruct%>}<%={{ }}=%>{{^-last}},{{/-last}}
{{#-last}} ]{{/-last}}{{/responses}})
end
{{/operation}}
{{/operations}}
end
© 2015 - 2024 Weber Informatics LLC | Privacy Policy