elm.api.mustache Maven / Gradle / Ivy
{{>licenseInfo}}
module Request.{{classname}} exposing ({{#operations}}{{#operation}}{{^-first}}, {{/-first}}{{operationId}}{{#allParams}}{{#isEnum}}, {{enumName}}(..){{/isEnum}}{{/allParams}}{{/operation}}{{/operations}})
{{>imports}}import Dict
import Http
import Json.Decode as Decode
import Url.Builder as Url
{{#operations}}
{{#operation}}
{{#allParams}}
{{#isEnum}}
type {{enumName}}
{{#allowableValues.enumVars}} {{#-first}}= {{/-first}}{{^-first}}| {{/-first}}{{name}}
{{/allowableValues.enumVars}}
stringify{{enumName}} : {{enumName}} -> String
stringify{{enumName}} value =
case value of
{{#allowableValues.enumVars}} {{name}} ->
{{{value}}}
{{/allowableValues.enumVars}}
{{/isEnum}}
{{/allParams}}
{{/operation}}
{{/operations}}
{{^enableCustomBasePaths}}basePath : String
basePath =
"{{basePath}}"
{{/enableCustomBasePaths}}
{{#operations}}
{{#operation}}
{{#notes}}
{-| {{{notes}}}
-}
{{/notes}}
{{operationId}} :
{{#headerParams}}
{{#-first}} { {{/-first}}{{^-first}} , {{/-first}}{{paramName}} : {{^required}}Maybe ({{/required}}{{#isListContainer}}List {{/isListContainer}}{{dataType}}{{^required}}){{/required}}
{{#-last}} } -> {{/-last}}
{{/headerParams}}
{ onSend : Result Http.Error {{^responses}}(){{/responses}}{{#responses}}{{#-first}}{{^dataType}}(){{/dataType}}{{#isMapContainer}}(Dict.Dict String {{/isMapContainer}}{{#isListContainer}}(List {{/isListContainer}}{{dataType}}{{#isListContainer}}){{/isListContainer}}{{#isMapContainer}}){{/isMapContainer}}{{/-first}}{{/responses}} -> msg
{{#enableCustomBasePaths}} , basePath : String{{/enableCustomBasePaths}}
{{#enableHttpRequestTrackers}} , tracker : Maybe String{{/enableHttpRequestTrackers}}
{{#bodyParam}} , body : {{^required}}Maybe {{/required}}{{dataType}}{{/bodyParam}}
{{#pathParams}} , {{paramName}} : {{#isListContainer}}List {{/isListContainer}}{{#datatypeWithEnum}}{{datatypeWithEnum}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{dataType}}{{/datatypeWithEnum}}{{/pathParams}}
{{#queryParams}} , {{paramName}} : {{^required}}Maybe ({{/required}}{{#isListContainer}}List {{/isListContainer}}{{#datatypeWithEnum}}{{datatypeWithEnum}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{dataType}}{{/datatypeWithEnum}}{{^required}}){{/required}}{{/queryParams}}
}
-> Cmd msg
{{operationId}} {{#headerParams.0}}headers {{/headerParams.0}}params =
Http.request
{ method = "{{httpMethod}}"
, headers = List.filterMap identity [{{#headerParams}}{{#required}}(Just << {{/required}}{{^required}}Maybe.map ({{/required}}Http.header "{{baseName}}" << {{>toString}}) {{^isElm018}}headers.{{/isElm018}}{{paramName}}{{^-last}}, {{/-last}}{{/headerParams}}]
, url = Url.crossOrigin {{#enableCustomBasePaths}}params.{{/enableCustomBasePaths}}basePath
[{{#vendorExtensions.x-path-params}}{{#paramName}}{{>toString}} params.{{paramName}}{{/paramName}}{{^paramName}}{{{.}}}{{/paramName}}{{^-last}}, {{/-last}}{{/vendorExtensions.x-path-params}}]
(List.filterMap identity [{{#queryParams}}{{#required}}(Just << {{/required}}{{^required}}Maybe.map ({{/required}}Url.string "{{baseName}}" << {{>toString}}) {{^isElm018}}params.{{/isElm018}}{{paramName}}{{^-last}}, {{/-last}}{{/queryParams}}])
, body = {{#bodyParam}}{{^required}}Maybe.withDefault Http.emptyBody <| Maybe.map ({{/required}}Http.jsonBody {{#required}}<|{{/required}}{{^required}}<<{{/required}} {{vendorExtensions.x-elm-encoder}}{{^required}}){{/required}} params.body{{/bodyParam}}{{^bodyParam}}Http.emptyBody{{/bodyParam}}
, expect = {{^responses}}Http.expectWhatever params.onSend{{/responses}}{{#responses}}{{#-first}}{{^dataType}}Http.expectWhatever params.onSend{{/dataType}}{{#dataType}}Http.expectJson params.onSend {{#isMapContainer}}(Decode.dict {{/isMapContainer}}{{#isListContainer}}(Decode.list {{/isListContainer}}{{#vendorExtensions}}{{elmDecoder}}{{/vendorExtensions}}{{#isListContainer}}){{/isListContainer}}{{#isMapContainer}}){{/isMapContainer}}{{/dataType}}{{/-first}}{{/responses}}
, timeout = Just 30000
, tracker = {{#enableHttpRequestTrackers}}params.tracker{{/enableHttpRequestTrackers}}{{^enableHttpRequestTrackers}}Nothing{{/enableHttpRequestTrackers}}
}
{{/operation}}
{{/operations}}