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}}
{{notes}}
{{/notes}}
## Parameters
- connection ({{moduleName}}.Connection): Connection to server
{{#allParams}}{{#required}} - {{#underscored}}{{paramName}}{{/underscored}} ({{dataType}}): {{description}}
{{/required}}{{/allParams}} - opts (KeywordList): [optional] Optional parameters
{{#allParams}}{{^required}} - {{#underscored}}:{{paramName}}{{/underscored}} ({{dataType}}): {{description}}
{{/required}}{{/allParams}}
## Returns
{:ok, {{#isListContainer}}[%{{returnBaseType}}{}, ...]{{/isListContainer}}{{#isMapContainer}}%{}{{/isMapContainer}}{{^returnType}}%{}{{/returnType}}{{#returnSimpleType}}%{{#returnType}}{{#isMapContainer}}{{/isMapContainer}}{{moduleName}}.Model.{{{returnType}}}{{/returnType}}{}{{/returnSimpleType}}} on success
{:error, info} on failure
"""
{{typespec}}
def {{#underscored}}{{operationId}}{{/underscored}}(connection, {{#allParams}}{{#required}}{{#underscored}}{{paramName}}{{/underscored}}, {{/required}}{{/allParams}}{{^hasOptionalParams}}_{{/hasOptionalParams}}opts \\ []) do
{{#hasOptionalParams}}
optional_params = %{
{{#allParams}}{{^required}}{{^isPathParam}}:"{{baseName}}" => {{#isBodyParam}}:body{{/isBodyParam}}{{#isFormParam}}:form{{/isFormParam}}{{#isQueryParam}}:query{{/isQueryParam}}{{#isHeaderParam}}:headers{{/isHeaderParam}}{{/isPathParam}}{{#hasMore}},
{{/hasMore}}{{/required}}{{/allParams}}
}
{{/hasOptionalParams}}
%{}
|> method(:{{#underscored}}{{httpMethod}}{{/underscored}})
|> url("{{replacedPathName}}")
{{#allParams}}
{{#required}}
{{^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}}, :"{{baseName}}", {{#underscored}}{{paramName}}{{/underscored}})
{{/isPathParam}}
{{/required}}
{{/allParams}}
{{#hasOptionalParams}}
|> add_optional_params(optional_params, opts)
{{/hasOptionalParams}}
|> Enum.into([])
|> (&Connection.request(connection, &1)).()
|> decode({{decodedStruct}})
end
{{/operation}}
{{/operations}}
end
© 2015 - 2024 Weber Informatics LLC | Privacy Policy