forked from loafle/openapi-generator-original
[Elm] Add support for petstore spec (#15257)
* Add petstore config * Expand lambda to allow formatting of partials * Fix order of operation with parenthesis * Fix not exposing needed enum to string converters * Add support for form params including files * Add generated petstore client * Regenerate existing elm client * Add script that all files compile successfully * Remove old unmaintained petstore client * Add pipeline to try and compile elm clients
This commit is contained in:
parent
961980f284
commit
42fa07dd33
32
.github/workflows/samples-elm.yaml
vendored
Normal file
32
.github/workflows/samples-elm.yaml
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
name: Samples Elm
|
||||
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
- samples/client/petstore/elm/**
|
||||
pull_request:
|
||||
paths:
|
||||
- samples/client/petstore/elm/**
|
||||
jobs:
|
||||
build:
|
||||
name: Build Elm clients
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
sample:
|
||||
# clients
|
||||
- samples/client/petstore/elm
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: jorelali/setup-elm@v5
|
||||
with:
|
||||
elm-version: 0.19.1
|
||||
- name: Build
|
||||
working-directory: ${{ matrix.sample }}
|
||||
# Try to compile all .elm files
|
||||
# This fails if:
|
||||
# An .elm file couldn't be compiled
|
||||
# No .elm files were found
|
||||
# No elm.json file could be found in the root of the working directory
|
||||
run: elm make $(find . -name *.elm) --output=/dev/null
|
4
bin/configs/elm-petstore.yaml
Normal file
4
bin/configs/elm-petstore.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
generatorName: elm
|
||||
outputDir: samples/client/petstore/elm
|
||||
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
|
||||
templateDir: modules/openapi-generator/src/main/resources/elm
|
@ -147,7 +147,7 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
typeMapping.put("DateTime", "Posix");
|
||||
typeMapping.put("password", "String");
|
||||
typeMapping.put("ByteArray", "String");
|
||||
typeMapping.put("file", "String");
|
||||
typeMapping.put("file", "File");
|
||||
typeMapping.put("binary", "String");
|
||||
typeMapping.put("UUID", "Uuid");
|
||||
typeMapping.put("URI", "String");
|
||||
@ -383,8 +383,12 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
anyOperationParam(ops, param -> (param.isDate || param.isDateTime) || itemsIncludesType(param.items, p -> p.isDate || p.isDateTime));
|
||||
final boolean includeUuid = anyOperationResponse(ops, response -> response.isUuid) ||
|
||||
anyOperationParam(ops, param -> param.isUuid || itemsIncludesType(param.items, p -> p.isUuid));
|
||||
final boolean includeFile = anyOperationResponse(ops, response -> response.isFile) ||
|
||||
anyOperationParam(ops, param -> param.isFile || itemsIncludesType(param.items, p -> p.isFile));
|
||||
|
||||
operations.put("includeTime", includeTime);
|
||||
operations.put("includeUuid", includeUuid);
|
||||
operations.put("includeFile", includeFile);
|
||||
|
||||
return operations;
|
||||
}
|
||||
@ -473,7 +477,7 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
private static class RemoveWhitespaceLambda implements Mustache.Lambda {
|
||||
@Override
|
||||
public void execute(final Template.Fragment fragment, final Writer writer) throws IOException {
|
||||
writer.write(fragment.execute().replaceAll("\\s+", ""));
|
||||
writer.write(fragment.execute().replaceAll("\\s+", " ").trim());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ type Request a =
|
||||
}
|
||||
|
||||
|
||||
request : String -> String -> List ( String, String ) -> List (String, Maybe String) -> List (String, Maybe String) -> Maybe Json.Encode.Value -> Json.Decode.Decoder a -> Request a
|
||||
request : String -> String -> List ( String, String ) -> List (String, Maybe String) -> List (String, Maybe String) -> Maybe Http.Body -> Json.Decode.Decoder a -> Request a
|
||||
request method path pathParams queryParams headerParams body decoder =
|
||||
Request
|
||||
{ method = method
|
||||
@ -43,7 +43,7 @@ request method path pathParams queryParams headerParams body decoder =
|
||||
, basePath = "{{basePath}}"
|
||||
, pathParams = interpolatePath path pathParams
|
||||
, queryParams = queries queryParams
|
||||
, body = Maybe.withDefault Http.emptyBody (Maybe.map Http.jsonBody body)
|
||||
, body = Maybe.withDefault Http.emptyBody body
|
||||
, decoder = decoder
|
||||
, timeout = Nothing
|
||||
, tracker = Nothing
|
||||
|
@ -9,6 +9,7 @@
|
||||
"danyx23/elm-uuid": "2.1.2",
|
||||
"elm/browser": "1.0.1",
|
||||
"elm/core": "1.0.2",
|
||||
"elm/file": "1.0.1",
|
||||
"elm/html": "1.0.0",
|
||||
"elm/http": "2.0.0",
|
||||
"elm/json": "1.1.2",
|
||||
@ -18,7 +19,6 @@
|
||||
},
|
||||
"indirect": {
|
||||
"elm/bytes": "1.0.5",
|
||||
"elm/file": "1.0.1",
|
||||
"elm/parser": "1.1.0",
|
||||
"elm/random": "1.0.0",
|
||||
"elm/regex": "1.0.0",
|
||||
|
@ -2,7 +2,8 @@
|
||||
{{#isDateTime}}Api.Time.dateTimeDecoder{{/isDateTime}}
|
||||
{{#isDate}}Api.Time.dateDecoder{{/isDate}}
|
||||
{{#isByteArray}}Json.Decode.string{{/isByteArray}}
|
||||
{{#isBinary}}Json.Decode.string{{/isBinary}}
|
||||
{{#isBinary}}{{^isFile}}Json.Decode.string{{/isFile}}{{/isBinary}}
|
||||
{{#isFile}}File.decoder{{/isFile}}
|
||||
{{#isString}}{{^isEnum}}{{^isUuid}}Json.Decode.string{{/isUuid}}{{/isEnum}}{{/isString}}
|
||||
{{#isInteger}}Json.Decode.int{{/isInteger}}
|
||||
{{#isLong}}Json.Decode.int{{/isLong}}
|
||||
|
1
modules/openapi-generator/src/main/resources/elm/formParamEncoder.mustache
vendored
Normal file
1
modules/openapi-generator/src/main/resources/elm/formParamEncoder.mustache
vendored
Normal file
@ -0,0 +1 @@
|
||||
{{^required}}Maybe.map ({{/required}}{{#required}}Just <| {{/required}}{{^isFile}}Http.stringPart {{/isFile}}{{#isFile}}Http.filePart {{/isFile}}"{{paramName}}"{{#isBoolean}}(\val -> if val then "true" else "false"){{/isBoolean}}{{#isDateTime}}Api.Time.dateTimeToString{{/isDateTime}}{{#isDate}}Api.Time.dateToString{{/isDate}}{{#isInteger}}String.fromInt{{/isInteger}}{{#isLong}}String.fromInt{{/isLong}}{{#isNumber}}String.fromFloat{{/isNumber}}{{#isFloat}}String.fromFloat{{/isFloat}}{{#isDouble}}String.fromFloat{{/isDouble}}{{#allowableValues}}Api.Data.stringFrom{{#datatypeWithEnum}}{{datatypeWithEnum}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{dataType}}{{/datatypeWithEnum}}{{/allowableValues}}{{#isUuid}}Uuid.toString{{/isUuid}}{{^required}}){{/required}} {{paramName}}
|
@ -3,7 +3,8 @@
|
||||
module Api.Data exposing
|
||||
{{#models}}{{#model}} {{#-first}}( {{/-first}}{{^-first}}, {{/-first}}{{classname}}{{#discriminator}}(..){{/discriminator}}{{^discriminator}}{{#oneOf}}{{#-first}}(..){{/-first}}{{/oneOf}}{{/discriminator}}{{#isEnum}}(..), {{#lambda.camelcase}}{{classname}}{{/lambda.camelcase}}Variants{{/isEnum}}{{^isEnum}}{{#vars}}{{#isCircularReference}}, {{classname}}{{nameInCamelCase}}(..){{/isCircularReference}}{{#isEnum}}, {{classname}}{{nameInCamelCase}}(..), {{#lambda.camelcase}}{{classname}}{{nameInCamelCase}}{{/lambda.camelcase}}Variants{{/isEnum}}{{/vars}}{{/isEnum}}
|
||||
{{/model}}{{/models}}{{#models}}{{#model}} , {{#lambda.camelcase}}encode{{classname}}{{/lambda.camelcase}}
|
||||
{{/model}}{{/models}}{{#models}}{{#model}} , {{#lambda.camelcase}}{{classname}}{{/lambda.camelcase}}Decoder
|
||||
{{/model}}{{/models}}{{#models}}{{#model}}{{#isEnum}} , stringFrom{{^paramName}}{{classname}}{{/paramName}}{{enumName}}
|
||||
{{/isEnum}}{{/model}}{{/models}}{{#models}}{{#model}} , {{#lambda.camelcase}}{{classname}}{{/lambda.camelcase}}Decoder
|
||||
{{/model}}{{/models}} )
|
||||
|
||||
import Api{{#includeTime}}
|
||||
|
@ -5,13 +5,14 @@ module Api.Request.{{classname}} exposing
|
||||
{{/operation}}{{/operations}} )
|
||||
|
||||
import Api
|
||||
import Api.Data{{#includeTime}}
|
||||
import Api.Data exposing (..){{#includeTime}}
|
||||
import Api.Time exposing (Posix){{/includeTime}}
|
||||
import Dict
|
||||
import Http
|
||||
import Json.Decode
|
||||
import Json.Encode{{#includeUuid}}
|
||||
import Uuid exposing (Uuid){{/includeUuid}}
|
||||
import Uuid exposing (Uuid){{/includeUuid}}{{#includeFile}}
|
||||
import File exposing (File){{/includeFile}}
|
||||
{{#operations}}
|
||||
{{#operation}}
|
||||
{{#allParams}}
|
||||
@ -26,14 +27,28 @@ import Uuid exposing (Uuid){{/includeUuid}}
|
||||
{{/allParams}}
|
||||
{{/operation}}
|
||||
{{/operations}}
|
||||
{{#operations}}{{#operation}}
|
||||
|
||||
{{#operations}}
|
||||
{{#operation}}
|
||||
|
||||
{{#notes}}
|
||||
{-| {{{notes}}}
|
||||
-}
|
||||
{{/notes}}
|
||||
{{operationId}} : {{#allParams}}{{^required}}Maybe {{/required}}{{#isArray}}List {{/isArray}}{{datatypeWithEnum}}{{^datatypeWithEnum}}{{#isModel}}Api.Data.{{/isModel}}{{dataType}}{{/datatypeWithEnum}} -> {{/allParams}}{{#authMethods}}{{#isBasicBearer}}String -> {{/isBasicBearer}}{{/authMethods}}Api.Request {{^responses}}(){{/responses}}{{#responses}}{{#is2xx}}{{^dataType}}(){{/dataType}}{{#isMap}}(Dict.Dict String {{/isMap}}{{#isArray}}(List {{#items}}{{#isModel}}Api.Data.{{/isModel}}{{/items}}{{/isArray}}{{^isArray}}{{^primitiveType}}{{^isUuid}}Api.Data.{{/isUuid}}{{/primitiveType}}{{/isArray}}{{dataType}}{{#isArray}}){{/isArray}}{{#isMap}}){{/isMap}}{{/is2xx}}{{/responses}}
|
||||
{{#lambda.removeWhitespace}}
|
||||
{{operationId}} : {{#allParams}}{{>operationParameter}} -> {{/allParams}}
|
||||
{{#authMethods}}{{#isBasicBearer}}String -> {{/isBasicBearer}}{{/authMethods}}Api.Request
|
||||
{{#responses}} {{!-- This iterates through all different responses, some might not be 200 }}
|
||||
{{#-first}} {{!-- We have no way to handle multiple return types today so we just handle the first }}
|
||||
{{#is2xx}}
|
||||
{{^dataType}}(){{/dataType}}
|
||||
{{#isMap}}(Dict.Dict String {{/isMap}}
|
||||
{{#isArray}}(List {{#items}}{{#isModel}}Api.Data.{{/isModel}}{{/items}}{{/isArray}}{{^isArray}}{{^primitiveType}}{{^isUuid}}{{^isFile}}Api.Data.{{/isFile}}{{/isUuid}}{{/primitiveType}}{{/isArray}}{{dataType}}{{#isArray}}){{/isArray}}{{#isMap}}){{/isMap}}
|
||||
{{/is2xx}}
|
||||
{{^is2xx}}(){{/is2xx}}
|
||||
{{/-first}}
|
||||
{{/responses}}
|
||||
{{/lambda.removeWhitespace}}
|
||||
|
||||
{{operationId}}{{#allParams}} {{>paramName}}{{/allParams}}{{#authMethods}}{{#isBasicBearer}} auth_token{{/isBasicBearer}}{{/authMethods}} =
|
||||
Api.request
|
||||
"{{httpMethod}}"
|
||||
@ -41,7 +56,18 @@ import Uuid exposing (Uuid){{/includeUuid}}
|
||||
[{{#pathParams}} ( "{{paramName}}", {{>paramToString}} {{>paramName}} ){{#-last}} {{/-last}}{{^-last}},{{/-last}}{{/pathParams}}]
|
||||
[{{#queryParams}} ( "{{baseName}}", {{#required}}Just <| {{/required}}{{^required}}Maybe.map {{/required}}{{>paramToString}} {{>paramName}} ){{#-last}} {{/-last}}{{^-last}},{{/-last}}{{/queryParams}}]
|
||||
[{{#headerParams}} ( "{{baseName}}", {{#required}}Just <| {{/required}}{{^required}}Maybe.map {{/required}}{{>paramToString}} {{>paramName}} ){{#-last}} {{/-last}}{{^-last}},{{/-last}}{{/headerParams}}]
|
||||
{{#bodyParam}}({{#required}}Just ({{/required}}{{^required}}Maybe.map {{/required}}{{#isModel}}Api.Data.{{/isModel}}{{>recordFieldValueEncoder}} {{>paramName}}{{#required}}){{/required}}){{/bodyParam}}{{^bodyParam}}Nothing{{/bodyParam}}
|
||||
{{^responses}}(Json.Decode.succeed ()){{/responses}}{{#responses}}{{#is2xx}}{{^dataType}}(Json.Decode.succeed ()){{/dataType}}{{#dataType}}{{>recordFieldValueDecoder}}{{/dataType}}{{/is2xx}}{{/responses}}{{#authMethods}}{{#isBasicBearer}}
|
||||
|> Api.withBearerToken auth_token{{/isBasicBearer}}{{/authMethods}}
|
||||
{{/operation}}{{/operations}}
|
||||
{{#bodyParam}}
|
||||
(Maybe.map Http.jsonBody ({{#required}}Just ({{/required}}{{^required}}Maybe.map {{/required}}{{#isModel}}Api.Data.{{/isModel}}{{>recordFieldValueEncoder}} {{>paramName}}{{#required}}){{/required}}))
|
||||
{{/bodyParam}}
|
||||
{{#formParams.0}}
|
||||
(Just <| Http.multipartBody <| List.filterMap identity [ {{#formParams}}{{>formParamEncoder}}{{^-last}}, {{/-last}}{{/formParams}} ])
|
||||
{{/formParams.0}}
|
||||
{{^bodyParam}}
|
||||
{{^formParams}}
|
||||
Nothing
|
||||
{{/formParams}}
|
||||
{{/bodyParam}}
|
||||
{{#responses}}{{#-first}}{{#is2xx}}{{^dataType}}(Json.Decode.succeed ()){{/dataType}}{{#dataType}}{{>recordFieldValueDecoder}}{{/dataType}}{{/is2xx}}{{^is2xx}}(Json.Decode.succeed ()){{/is2xx}}{{/-first}}{{/responses}}{{^responses}}(Json.Decode.succeed ()){{/responses}}
|
||||
{{#authMethods}}{{#isBasicBearer}} |> Api.withBearerToken auth_token{{/isBasicBearer}}{{/authMethods}}
|
||||
{{/operation}}
|
||||
{{/operations}}
|
1
modules/openapi-generator/src/main/resources/elm/operationParameter.mustache
vendored
Normal file
1
modules/openapi-generator/src/main/resources/elm/operationParameter.mustache
vendored
Normal file
@ -0,0 +1 @@
|
||||
{{^required}}Maybe {{/required}}{{#isArray}}{{^required}}({{/required}}List {{/isArray}}{{#isModel}}Api.Data.{{/isModel}}{{#items.isModel}}Api.Data.{{/items.isModel}}{{#isAnyType}}Api.Data.{{/isAnyType}}{{datatypeWithEnum}}{{^datatypeWithEnum}}{{dataType}}{{/datatypeWithEnum}}{{#isArray}}{{^required}}){{/required}}{{/isArray}}
|
@ -1 +1,22 @@
|
||||
{{#isArray}}String.join "," << List.map {{#items}}{{>paramToString}}{{/items}}{{/isArray}}{{^isArray}}{{^isEnum}}{{^isUuid}}{{#isString}}identity{{/isString}}{{#isBinary}}identity{{/isBinary}}{{#isByteArray}}identity{{/isByteArray}}{{/isUuid}}{{/isEnum}}{{#isBoolean}}(\val -> if val then "true" else "false"){{/isBoolean}}{{#isDateTime}}Api.Time.dateTimeToString{{/isDateTime}}{{#isDate}}Api.Time.dateToString{{/isDate}}{{#isInteger}}String.fromInt{{/isInteger}}{{#isLong}}String.fromInt{{/isLong}}{{#isNumber}}String.fromFloat{{/isNumber}}{{#isFloat}}String.fromFloat{{/isFloat}}{{#isDouble}}String.fromFloat{{/isDouble}}{{#isEnum}}stringFrom{{^paramName}}Api.Data.{{classname}}{{/paramName}}{{enumName}}{{/isEnum}}{{#isUuid}}Uuid.toString{{/isUuid}}{{/isArray}}
|
||||
{{#lambda.removeWhitespace}}
|
||||
{{#isArray}}(String.join "," << List.map {{#isEnum}}stringFrom{{#datatypeWithEnum}}{{datatypeWithEnum}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{dataType}}{{/datatypeWithEnum}}{{/isEnum}}{{^isEnum}} {{#items}}{{>paramToString}}{{/items}}{{/isEnum}}){{/isArray}}
|
||||
{{^isArray}}
|
||||
{{^isEnum}}
|
||||
{{^isUuid}}
|
||||
{{#isString}}identity{{/isString}}
|
||||
{{#isBinary}}identity{{/isBinary}}
|
||||
{{#isByteArray}}identity{{/isByteArray}}
|
||||
{{/isUuid}}
|
||||
{{/isEnum}}
|
||||
{{#isBoolean}}(\val -> if val then "true" else "false"){{/isBoolean}}
|
||||
{{#isDateTime}}Api.Time.dateTimeToString{{/isDateTime}}
|
||||
{{#isDate}}Api.Time.dateToString{{/isDate}}
|
||||
{{#isInteger}}String.fromInt{{/isInteger}}
|
||||
{{#isLong}}String.fromInt{{/isLong}}
|
||||
{{#isNumber}}String.fromFloat{{/isNumber}}
|
||||
{{#isFloat}}String.fromFloat{{/isFloat}}
|
||||
{{#isDouble}}String.fromFloat{{/isDouble}}
|
||||
{{#allowableValues}}{{^isEnum}}Api.Data.{{/isEnum}}stringFrom{{#datatypeWithEnum}}{{datatypeWithEnum}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{dataType}}{{/datatypeWithEnum}}{{/allowableValues}}
|
||||
{{#isUuid}}Uuid.toString{{/isUuid}}
|
||||
{{/isArray}}
|
||||
{{/lambda.removeWhitespace}}
|
@ -1 +1,9 @@
|
||||
{{#isNullable}}Maybe {{#isContainer}}({{/isContainer}}{{/isNullable}}{{^isNullable}}{{^required}}Maybe {{#isContainer}}({{/isContainer}}{{/required}}{{/isNullable}}{{#isArray}}List {{/isArray}}{{#isMap}}Dict.Dict String {{/isMap}}{{#isEnum}}{{classname}}{{enumName}}{{/isEnum}}{{^isEnum}}{{#items}}({{>recordField}}){{/items}}{{^isContainer}}{{dataType}}{{/isContainer}}{{/isEnum}}{{#isContainer}}{{#isNullable}}){{/isNullable}}{{^isNullable}}{{^required}}){{/required}}{{/isNullable}}{{/isContainer}}
|
||||
{{#lambda.removeWhitespace}}
|
||||
{{#isNullable}}Maybe {{#isContainer}}({{/isContainer}}{{/isNullable}}
|
||||
{{^isNullable}}{{^required}}Maybe {{#isContainer}}({{/isContainer}}{{/required}}{{/isNullable}}
|
||||
{{#isArray}}List {{/isArray}}
|
||||
{{#isMap}}Dict.Dict String {{/isMap}}
|
||||
{{#isEnum}}{{classname}}{{enumName}}{{/isEnum}}
|
||||
{{^isEnum}}{{#items}}{{#isContainer}}({{/isContainer}}{{>recordField}}{{#isContainer}}){{/isContainer}}{{/items}}{{^isContainer}}{{dataType}}{{/isContainer}}{{/isEnum}}
|
||||
{{#isContainer}}{{#isNullable}}){{/isNullable}}{{^isNullable}}{{^required}}){{/required}}{{/isNullable}}{{/isContainer}}
|
||||
{{/lambda.removeWhitespace}}
|
@ -1 +1 @@
|
||||
{{#required}}encode{{/required}}{{^required}}maybeEncode{{/required}}{{#isNullable}}Nullable{{/isNullable}} "{{baseName}}" {{>recordFieldValueEncoder}} {{#isCircularReference}}<| unwrap{{classname}}{{nameInCamelCase}} {{/isCircularReference}}model.{{name}}
|
||||
{{#required}}encode{{/required}}{{^required}}maybeEncode{{/required}}{{#isNullable}}Nullable{{/isNullable}} "{{baseName}}" {{#isContainer}}({{/isContainer}}{{>recordFieldValueEncoder}}{{#isContainer}}){{/isContainer}} {{#isCircularReference}}<| unwrap{{classname}}{{nameInCamelCase}} {{/isCircularReference}}model.{{name}}
|
@ -1 +1 @@
|
||||
{{#isContainer}}({{#isArray}}Json.Encode.list{{/isArray}}{{#isMap}}Json.Encode.dict identity{{/isMap}} {{#items}}{{>recordFieldValueEncoder}}{{/items}}{{/isContainer}}{{^isContainer}}{{>fieldEncoder}}{{/isContainer}}{{#isContainer}}){{/isContainer}}
|
||||
{{#isContainer}}{{#isArray}}Json.Encode.list{{/isArray}}{{#isMap}}Json.Encode.dict identity{{/isMap}} {{#items}}{{#isContainer}}({{/isContainer}}{{>recordFieldValueEncoder}}{{#isContainer}}){{/isContainer}}{{/items}}{{/isContainer}}{{^isContainer}}{{>fieldEncoder}}{{/isContainer}}
|
9
samples/client/petstore/elm/.openapi-generator/FILES
Normal file
9
samples/client/petstore/elm/.openapi-generator/FILES
Normal file
@ -0,0 +1,9 @@
|
||||
.gitignore
|
||||
README.md
|
||||
elm.json
|
||||
src/Api.elm
|
||||
src/Api/Data.elm
|
||||
src/Api/Request/Pet.elm
|
||||
src/Api/Request/Store.elm
|
||||
src/Api/Request/User.elm
|
||||
src/Api/Time.elm
|
1
samples/client/petstore/elm/.openapi-generator/VERSION
Normal file
1
samples/client/petstore/elm/.openapi-generator/VERSION
Normal file
@ -0,0 +1 @@
|
||||
6.6.0-SNAPSHOT
|
14
samples/client/petstore/elm/elm-compile-test
Executable file
14
samples/client/petstore/elm/elm-compile-test
Executable file
@ -0,0 +1,14 @@
|
||||
#!/bin/bash -e
|
||||
# elm make all elm files under src
|
||||
|
||||
for ELM in `find src -name "*.elm"`
|
||||
do
|
||||
echo "Compiling $ELM"
|
||||
elm make $ELM --output /dev/null
|
||||
rc=$?
|
||||
if [[ $rc != 0 ]]
|
||||
then
|
||||
echo "ERROR!! FAILED TO COMPILE $ELM"
|
||||
exit $rc;
|
||||
fi
|
||||
done
|
@ -3,13 +3,13 @@
|
||||
"source-directories": [
|
||||
"src"
|
||||
],
|
||||
"elm-version": "0.19.0",
|
||||
"elm-version": "0.19.1",
|
||||
"dependencies": {
|
||||
"direct": {
|
||||
"NoRedInk/elm-json-decode-pipeline": "1.0.0",
|
||||
"danyx23/elm-uuid": "2.1.2",
|
||||
"elm/browser": "1.0.1",
|
||||
"elm/core": "1.0.2",
|
||||
"elm/file": "1.0.1",
|
||||
"elm/html": "1.0.0",
|
||||
"elm/http": "2.0.0",
|
||||
"elm/json": "1.1.2",
|
||||
@ -19,7 +19,6 @@
|
||||
},
|
||||
"indirect": {
|
||||
"elm/bytes": "1.0.5",
|
||||
"elm/file": "1.0.1",
|
||||
"elm/parser": "1.1.0",
|
||||
"elm/random": "1.0.0",
|
||||
"elm/regex": "1.0.0",
|
202
samples/client/petstore/elm/src/Api.elm
Normal file
202
samples/client/petstore/elm/src/Api.elm
Normal file
@ -0,0 +1,202 @@
|
||||
module Api exposing
|
||||
( Request
|
||||
, request
|
||||
, send
|
||||
, sendWithCustomError
|
||||
, sendWithCustomExpect
|
||||
, task
|
||||
, map
|
||||
, withBasePath
|
||||
, withTimeout
|
||||
, withTracker
|
||||
, withBearerToken
|
||||
, withHeader
|
||||
, withHeaders
|
||||
)
|
||||
|
||||
import Http
|
||||
import Json.Decode
|
||||
import Json.Encode
|
||||
import Task
|
||||
import Url.Builder
|
||||
|
||||
|
||||
type Request a =
|
||||
Request
|
||||
{ method : String
|
||||
, headers : List Http.Header
|
||||
, basePath : String
|
||||
, pathParams : List String
|
||||
, queryParams : List Url.Builder.QueryParameter
|
||||
, body : Http.Body
|
||||
, decoder : Json.Decode.Decoder a
|
||||
, timeout : Maybe Float
|
||||
, tracker : Maybe String
|
||||
}
|
||||
|
||||
|
||||
request : String -> String -> List ( String, String ) -> List (String, Maybe String) -> List (String, Maybe String) -> Maybe Http.Body -> Json.Decode.Decoder a -> Request a
|
||||
request method path pathParams queryParams headerParams body decoder =
|
||||
Request
|
||||
{ method = method
|
||||
, headers = headers headerParams
|
||||
, basePath = "http://petstore.swagger.io/v2"
|
||||
, pathParams = interpolatePath path pathParams
|
||||
, queryParams = queries queryParams
|
||||
, body = Maybe.withDefault Http.emptyBody body
|
||||
, decoder = decoder
|
||||
, timeout = Nothing
|
||||
, tracker = Nothing
|
||||
}
|
||||
|
||||
|
||||
send : (Result Http.Error a -> msg) -> Request a -> Cmd msg
|
||||
send toMsg req =
|
||||
sendWithCustomError identity toMsg req
|
||||
|
||||
|
||||
sendWithCustomError : (Http.Error -> e) -> (Result e a -> msg) -> Request a -> Cmd msg
|
||||
sendWithCustomError mapError toMsg req =
|
||||
sendWithCustomExpect (expectJson mapError toMsg) req
|
||||
|
||||
|
||||
sendWithCustomExpect : (Json.Decode.Decoder a -> Http.Expect msg) -> Request a -> Cmd msg
|
||||
sendWithCustomExpect expect (Request req) =
|
||||
Http.request
|
||||
{ method = req.method
|
||||
, headers = req.headers
|
||||
, url = Url.Builder.crossOrigin req.basePath req.pathParams req.queryParams
|
||||
, body = req.body
|
||||
, expect = expect req.decoder
|
||||
, timeout = req.timeout
|
||||
, tracker = req.tracker
|
||||
}
|
||||
|
||||
|
||||
task : Request a -> Task.Task Http.Error a
|
||||
task (Request req) =
|
||||
Http.task
|
||||
{ method = req.method
|
||||
, headers = req.headers
|
||||
, url = Url.Builder.crossOrigin req.basePath req.pathParams req.queryParams
|
||||
, body = req.body
|
||||
, resolver = jsonResolver req.decoder
|
||||
, timeout = req.timeout
|
||||
}
|
||||
|
||||
|
||||
map : (a -> b) -> Request a -> Request b
|
||||
map fn (Request req) =
|
||||
Request
|
||||
{ method = req.method
|
||||
, headers = req.headers
|
||||
, basePath = req.basePath
|
||||
, pathParams = req.pathParams
|
||||
, queryParams = req.queryParams
|
||||
, body = req.body
|
||||
, decoder = Json.Decode.map fn req.decoder
|
||||
, timeout = req.timeout
|
||||
, tracker = req.tracker
|
||||
}
|
||||
|
||||
withBasePath : String -> Request a -> Request a
|
||||
withBasePath basePath (Request req) =
|
||||
Request { req | basePath = basePath }
|
||||
|
||||
|
||||
withTimeout : Float -> Request a -> Request a
|
||||
withTimeout timeout (Request req) =
|
||||
Request { req | timeout = Just timeout }
|
||||
|
||||
|
||||
withTracker : String -> Request a -> Request a
|
||||
withTracker tracker (Request req) =
|
||||
Request { req | tracker = Just tracker }
|
||||
|
||||
|
||||
withBearerToken : String -> Request a -> Request a
|
||||
withBearerToken token (Request req) =
|
||||
Request { req | headers = Http.header "Authorization" ("Bearer " ++ token) :: req.headers }
|
||||
|
||||
|
||||
withHeader : String -> String -> Request a -> Request a
|
||||
withHeader key value (Request req) =
|
||||
Request { req | headers = req.headers ++ [ Http.header key value ] }
|
||||
|
||||
|
||||
withHeaders : List ( String, String ) -> Request a -> Request a
|
||||
withHeaders headers_ (Request req) =
|
||||
Request { req | headers = req.headers ++ headers (List.map (Tuple.mapSecond Just) headers_) }
|
||||
|
||||
|
||||
-- HELPER
|
||||
|
||||
|
||||
headers : List (String, Maybe String) -> List Http.Header
|
||||
headers =
|
||||
List.filterMap (\(key, value) -> Maybe.map (Http.header key) value)
|
||||
|
||||
|
||||
interpolatePath : String -> List ( String, String ) -> List String
|
||||
interpolatePath rawPath pathParams =
|
||||
let
|
||||
interpolate =
|
||||
(\(name, value) path -> String.replace ("{" ++ name ++ "}") value path)
|
||||
in
|
||||
List.foldl interpolate rawPath pathParams
|
||||
|> String.split "/"
|
||||
|> List.drop 1
|
||||
|
||||
|
||||
queries : List (String, Maybe String) -> List Url.Builder.QueryParameter
|
||||
queries =
|
||||
List.filterMap (\(key, value) -> Maybe.map (Url.Builder.string key) value)
|
||||
|
||||
|
||||
expectJson : (Http.Error -> e) -> (Result e a -> msg) -> Json.Decode.Decoder a -> Http.Expect msg
|
||||
expectJson mapError toMsg decoder =
|
||||
Http.expectStringResponse toMsg (Result.mapError mapError << decodeResponse decoder)
|
||||
|
||||
|
||||
jsonResolver : Json.Decode.Decoder a -> Http.Resolver Http.Error a
|
||||
jsonResolver decoder =
|
||||
Http.stringResolver (decodeResponse decoder)
|
||||
|
||||
|
||||
decodeResponse : Json.Decode.Decoder a -> Http.Response String -> Result Http.Error a
|
||||
decodeResponse decoder response =
|
||||
case response of
|
||||
Http.BadUrl_ url ->
|
||||
Err (Http.BadUrl url)
|
||||
|
||||
Http.Timeout_ ->
|
||||
Err Http.Timeout
|
||||
|
||||
Http.NetworkError_ ->
|
||||
Err Http.NetworkError
|
||||
|
||||
Http.BadStatus_ metadata _ ->
|
||||
Err (Http.BadStatus metadata.statusCode)
|
||||
|
||||
Http.GoodStatus_ _ body ->
|
||||
if String.isEmpty body then
|
||||
-- we might 'expect' no body if the return type is `()`
|
||||
case Json.Decode.decodeString decoder "{}" of
|
||||
Ok value ->
|
||||
Ok value
|
||||
|
||||
Err _ ->
|
||||
decodeBody decoder body
|
||||
|
||||
else
|
||||
decodeBody decoder body
|
||||
|
||||
|
||||
decodeBody : Json.Decode.Decoder a -> String -> Result Http.Error a
|
||||
decodeBody decoder body =
|
||||
case Json.Decode.decodeString decoder body of
|
||||
Ok value ->
|
||||
Ok value
|
||||
|
||||
Err err ->
|
||||
Err (Http.BadBody (Json.Decode.errorToString err))
|
529
samples/client/petstore/elm/src/Api/Data.elm
Normal file
529
samples/client/petstore/elm/src/Api/Data.elm
Normal file
@ -0,0 +1,529 @@
|
||||
{-
|
||||
OpenAPI Petstore
|
||||
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
|
||||
The version of the OpenAPI document: 1.0.0
|
||||
|
||||
NOTE: This file is auto generated by the openapi-generator.
|
||||
https://github.com/openapitools/openapi-generator.git
|
||||
|
||||
DO NOT EDIT THIS FILE MANUALLY.
|
||||
|
||||
For more info on generating Elm code, see https://eriktim.github.io/openapi-elm/
|
||||
-}
|
||||
|
||||
|
||||
module Api.Data exposing
|
||||
( ApiResponse
|
||||
, Category
|
||||
, Order_, Order_Status(..), orderStatusVariants
|
||||
, Pet, PetStatus(..), petStatusVariants
|
||||
, Tag
|
||||
, User
|
||||
, encodeApiResponse
|
||||
, encodeCategory
|
||||
, encodeOrder
|
||||
, encodePet
|
||||
, encodeTag
|
||||
, encodeUser
|
||||
, apiResponseDecoder
|
||||
, categoryDecoder
|
||||
, orderDecoder
|
||||
, petDecoder
|
||||
, tagDecoder
|
||||
, userDecoder
|
||||
)
|
||||
|
||||
import Api
|
||||
import Api.Time exposing (Posix)
|
||||
import Dict
|
||||
import Json.Decode
|
||||
import Json.Encode
|
||||
|
||||
|
||||
-- MODEL
|
||||
|
||||
|
||||
{-| Describes the result of uploading an image resource
|
||||
-}
|
||||
type alias ApiResponse =
|
||||
{ code : Maybe Int
|
||||
, type_ : Maybe String
|
||||
, message : Maybe String
|
||||
}
|
||||
|
||||
|
||||
{-| A category for a pet
|
||||
-}
|
||||
type alias Category =
|
||||
{ id : Maybe Int
|
||||
, name : Maybe String
|
||||
}
|
||||
|
||||
|
||||
{-| An order for a pets from the pet store
|
||||
-}
|
||||
type alias Order_ =
|
||||
{ id : Maybe Int
|
||||
, petId : Maybe Int
|
||||
, quantity : Maybe Int
|
||||
, shipDate : Maybe Posix
|
||||
, status : Maybe Order_Status
|
||||
, complete : Maybe Bool
|
||||
}
|
||||
|
||||
|
||||
type Order_Status
|
||||
= Order_StatusPlaced
|
||||
| Order_StatusApproved
|
||||
| Order_StatusDelivered
|
||||
|
||||
|
||||
orderStatusVariants : List Order_Status
|
||||
orderStatusVariants =
|
||||
[ Order_StatusPlaced
|
||||
, Order_StatusApproved
|
||||
, Order_StatusDelivered
|
||||
]
|
||||
|
||||
|
||||
{-| A pet for sale in the pet store
|
||||
-}
|
||||
type alias Pet =
|
||||
{ id : Maybe Int
|
||||
, category : Maybe Category
|
||||
, name : String
|
||||
, photoUrls : List String
|
||||
, tags : Maybe ( List Tag )
|
||||
, status : Maybe PetStatus
|
||||
}
|
||||
|
||||
|
||||
type PetStatus
|
||||
= PetStatusAvailable
|
||||
| PetStatusPending
|
||||
| PetStatusSold
|
||||
|
||||
|
||||
petStatusVariants : List PetStatus
|
||||
petStatusVariants =
|
||||
[ PetStatusAvailable
|
||||
, PetStatusPending
|
||||
, PetStatusSold
|
||||
]
|
||||
|
||||
|
||||
{-| A tag for a pet
|
||||
-}
|
||||
type alias Tag =
|
||||
{ id : Maybe Int
|
||||
, name : Maybe String
|
||||
}
|
||||
|
||||
|
||||
{-| A User who is purchasing from the pet store
|
||||
-}
|
||||
type alias User =
|
||||
{ id : Maybe Int
|
||||
, username : Maybe String
|
||||
, firstName : Maybe String
|
||||
, lastName : Maybe String
|
||||
, email : Maybe String
|
||||
, password : Maybe String
|
||||
, phone : Maybe String
|
||||
, userStatus : Maybe Int
|
||||
}
|
||||
|
||||
|
||||
-- ENCODER
|
||||
|
||||
|
||||
encodeApiResponse : ApiResponse -> Json.Encode.Value
|
||||
encodeApiResponse =
|
||||
encodeObject << encodeApiResponsePairs
|
||||
|
||||
|
||||
encodeApiResponseWithTag : ( String, String ) -> ApiResponse -> Json.Encode.Value
|
||||
encodeApiResponseWithTag (tagField, tag) model =
|
||||
encodeObject (encodeApiResponsePairs model ++ [ encode tagField Json.Encode.string tag ])
|
||||
|
||||
|
||||
encodeApiResponsePairs : ApiResponse -> List EncodedField
|
||||
encodeApiResponsePairs model =
|
||||
let
|
||||
pairs =
|
||||
[ maybeEncode "code" Json.Encode.int model.code
|
||||
, maybeEncode "type" Json.Encode.string model.type_
|
||||
, maybeEncode "message" Json.Encode.string model.message
|
||||
]
|
||||
in
|
||||
pairs
|
||||
|
||||
|
||||
encodeCategory : Category -> Json.Encode.Value
|
||||
encodeCategory =
|
||||
encodeObject << encodeCategoryPairs
|
||||
|
||||
|
||||
encodeCategoryWithTag : ( String, String ) -> Category -> Json.Encode.Value
|
||||
encodeCategoryWithTag (tagField, tag) model =
|
||||
encodeObject (encodeCategoryPairs model ++ [ encode tagField Json.Encode.string tag ])
|
||||
|
||||
|
||||
encodeCategoryPairs : Category -> List EncodedField
|
||||
encodeCategoryPairs model =
|
||||
let
|
||||
pairs =
|
||||
[ maybeEncode "id" Json.Encode.int model.id
|
||||
, maybeEncode "name" Json.Encode.string model.name
|
||||
]
|
||||
in
|
||||
pairs
|
||||
|
||||
|
||||
encodeOrder : Order_ -> Json.Encode.Value
|
||||
encodeOrder =
|
||||
encodeObject << encodeOrderPairs
|
||||
|
||||
|
||||
encodeOrderWithTag : ( String, String ) -> Order_ -> Json.Encode.Value
|
||||
encodeOrderWithTag (tagField, tag) model =
|
||||
encodeObject (encodeOrderPairs model ++ [ encode tagField Json.Encode.string tag ])
|
||||
|
||||
|
||||
encodeOrderPairs : Order_ -> List EncodedField
|
||||
encodeOrderPairs model =
|
||||
let
|
||||
pairs =
|
||||
[ maybeEncode "id" Json.Encode.int model.id
|
||||
, maybeEncode "petId" Json.Encode.int model.petId
|
||||
, maybeEncode "quantity" Json.Encode.int model.quantity
|
||||
, maybeEncode "shipDate" Api.Time.encodeDateTime model.shipDate
|
||||
, maybeEncode "status" encodeOrderStatus model.status
|
||||
, maybeEncode "complete" Json.Encode.bool model.complete
|
||||
]
|
||||
in
|
||||
pairs
|
||||
|
||||
stringFromOrder_Status : Order_Status -> String
|
||||
stringFromOrder_Status model =
|
||||
case model of
|
||||
Order_StatusPlaced ->
|
||||
"placed"
|
||||
|
||||
Order_StatusApproved ->
|
||||
"approved"
|
||||
|
||||
Order_StatusDelivered ->
|
||||
"delivered"
|
||||
|
||||
|
||||
encodeOrderStatus : Order_Status -> Json.Encode.Value
|
||||
encodeOrderStatus =
|
||||
Json.Encode.string << stringFromOrder_Status
|
||||
|
||||
|
||||
|
||||
encodePet : Pet -> Json.Encode.Value
|
||||
encodePet =
|
||||
encodeObject << encodePetPairs
|
||||
|
||||
|
||||
encodePetWithTag : ( String, String ) -> Pet -> Json.Encode.Value
|
||||
encodePetWithTag (tagField, tag) model =
|
||||
encodeObject (encodePetPairs model ++ [ encode tagField Json.Encode.string tag ])
|
||||
|
||||
|
||||
encodePetPairs : Pet -> List EncodedField
|
||||
encodePetPairs model =
|
||||
let
|
||||
pairs =
|
||||
[ maybeEncode "id" Json.Encode.int model.id
|
||||
, maybeEncode "category" encodeCategory model.category
|
||||
, encode "name" Json.Encode.string model.name
|
||||
, encode "photoUrls" (Json.Encode.list Json.Encode.string) model.photoUrls
|
||||
, maybeEncode "tags" (Json.Encode.list encodeTag) model.tags
|
||||
, maybeEncode "status" encodePetStatus model.status
|
||||
]
|
||||
in
|
||||
pairs
|
||||
|
||||
stringFromPetStatus : PetStatus -> String
|
||||
stringFromPetStatus model =
|
||||
case model of
|
||||
PetStatusAvailable ->
|
||||
"available"
|
||||
|
||||
PetStatusPending ->
|
||||
"pending"
|
||||
|
||||
PetStatusSold ->
|
||||
"sold"
|
||||
|
||||
|
||||
encodePetStatus : PetStatus -> Json.Encode.Value
|
||||
encodePetStatus =
|
||||
Json.Encode.string << stringFromPetStatus
|
||||
|
||||
|
||||
|
||||
encodeTag : Tag -> Json.Encode.Value
|
||||
encodeTag =
|
||||
encodeObject << encodeTagPairs
|
||||
|
||||
|
||||
encodeTagWithTag : ( String, String ) -> Tag -> Json.Encode.Value
|
||||
encodeTagWithTag (tagField, tag) model =
|
||||
encodeObject (encodeTagPairs model ++ [ encode tagField Json.Encode.string tag ])
|
||||
|
||||
|
||||
encodeTagPairs : Tag -> List EncodedField
|
||||
encodeTagPairs model =
|
||||
let
|
||||
pairs =
|
||||
[ maybeEncode "id" Json.Encode.int model.id
|
||||
, maybeEncode "name" Json.Encode.string model.name
|
||||
]
|
||||
in
|
||||
pairs
|
||||
|
||||
|
||||
encodeUser : User -> Json.Encode.Value
|
||||
encodeUser =
|
||||
encodeObject << encodeUserPairs
|
||||
|
||||
|
||||
encodeUserWithTag : ( String, String ) -> User -> Json.Encode.Value
|
||||
encodeUserWithTag (tagField, tag) model =
|
||||
encodeObject (encodeUserPairs model ++ [ encode tagField Json.Encode.string tag ])
|
||||
|
||||
|
||||
encodeUserPairs : User -> List EncodedField
|
||||
encodeUserPairs model =
|
||||
let
|
||||
pairs =
|
||||
[ maybeEncode "id" Json.Encode.int model.id
|
||||
, maybeEncode "username" Json.Encode.string model.username
|
||||
, maybeEncode "firstName" Json.Encode.string model.firstName
|
||||
, maybeEncode "lastName" Json.Encode.string model.lastName
|
||||
, maybeEncode "email" Json.Encode.string model.email
|
||||
, maybeEncode "password" Json.Encode.string model.password
|
||||
, maybeEncode "phone" Json.Encode.string model.phone
|
||||
, maybeEncode "userStatus" Json.Encode.int model.userStatus
|
||||
]
|
||||
in
|
||||
pairs
|
||||
|
||||
|
||||
-- DECODER
|
||||
|
||||
|
||||
apiResponseDecoder : Json.Decode.Decoder ApiResponse
|
||||
apiResponseDecoder =
|
||||
Json.Decode.succeed ApiResponse
|
||||
|> maybeDecode "code" Json.Decode.int Nothing
|
||||
|> maybeDecode "type" Json.Decode.string Nothing
|
||||
|> maybeDecode "message" Json.Decode.string Nothing
|
||||
|
||||
|
||||
categoryDecoder : Json.Decode.Decoder Category
|
||||
categoryDecoder =
|
||||
Json.Decode.succeed Category
|
||||
|> maybeDecode "id" Json.Decode.int Nothing
|
||||
|> maybeDecode "name" Json.Decode.string Nothing
|
||||
|
||||
|
||||
orderDecoder : Json.Decode.Decoder Order_
|
||||
orderDecoder =
|
||||
Json.Decode.succeed Order_
|
||||
|> maybeDecode "id" Json.Decode.int Nothing
|
||||
|> maybeDecode "petId" Json.Decode.int Nothing
|
||||
|> maybeDecode "quantity" Json.Decode.int Nothing
|
||||
|> maybeDecode "shipDate" Api.Time.dateTimeDecoder Nothing
|
||||
|> maybeDecode "status" orderStatusDecoder Nothing
|
||||
|> maybeDecode "complete" Json.Decode.bool (Just False)
|
||||
|
||||
|
||||
orderStatusDecoder : Json.Decode.Decoder Order_Status
|
||||
orderStatusDecoder =
|
||||
Json.Decode.string
|
||||
|> Json.Decode.andThen
|
||||
(\value ->
|
||||
case value of
|
||||
"placed" ->
|
||||
Json.Decode.succeed Order_StatusPlaced
|
||||
|
||||
"approved" ->
|
||||
Json.Decode.succeed Order_StatusApproved
|
||||
|
||||
"delivered" ->
|
||||
Json.Decode.succeed Order_StatusDelivered
|
||||
|
||||
other ->
|
||||
Json.Decode.fail <| "Unknown type: " ++ other
|
||||
)
|
||||
|
||||
|
||||
|
||||
petDecoder : Json.Decode.Decoder Pet
|
||||
petDecoder =
|
||||
Json.Decode.succeed Pet
|
||||
|> maybeDecode "id" Json.Decode.int Nothing
|
||||
|> maybeDecode "category" categoryDecoder Nothing
|
||||
|> decode "name" Json.Decode.string
|
||||
|> decode "photoUrls" (Json.Decode.list Json.Decode.string)
|
||||
|> maybeDecode "tags" (Json.Decode.list tagDecoder) Nothing
|
||||
|> maybeDecode "status" petStatusDecoder Nothing
|
||||
|
||||
|
||||
petStatusDecoder : Json.Decode.Decoder PetStatus
|
||||
petStatusDecoder =
|
||||
Json.Decode.string
|
||||
|> Json.Decode.andThen
|
||||
(\value ->
|
||||
case value of
|
||||
"available" ->
|
||||
Json.Decode.succeed PetStatusAvailable
|
||||
|
||||
"pending" ->
|
||||
Json.Decode.succeed PetStatusPending
|
||||
|
||||
"sold" ->
|
||||
Json.Decode.succeed PetStatusSold
|
||||
|
||||
other ->
|
||||
Json.Decode.fail <| "Unknown type: " ++ other
|
||||
)
|
||||
|
||||
|
||||
|
||||
tagDecoder : Json.Decode.Decoder Tag
|
||||
tagDecoder =
|
||||
Json.Decode.succeed Tag
|
||||
|> maybeDecode "id" Json.Decode.int Nothing
|
||||
|> maybeDecode "name" Json.Decode.string Nothing
|
||||
|
||||
|
||||
userDecoder : Json.Decode.Decoder User
|
||||
userDecoder =
|
||||
Json.Decode.succeed User
|
||||
|> maybeDecode "id" Json.Decode.int Nothing
|
||||
|> maybeDecode "username" Json.Decode.string Nothing
|
||||
|> maybeDecode "firstName" Json.Decode.string Nothing
|
||||
|> maybeDecode "lastName" Json.Decode.string Nothing
|
||||
|> maybeDecode "email" Json.Decode.string Nothing
|
||||
|> maybeDecode "password" Json.Decode.string Nothing
|
||||
|> maybeDecode "phone" Json.Decode.string Nothing
|
||||
|> maybeDecode "userStatus" Json.Decode.int Nothing
|
||||
|
||||
|
||||
|
||||
|
||||
-- HELPER
|
||||
|
||||
|
||||
type alias EncodedField =
|
||||
Maybe ( String, Json.Encode.Value )
|
||||
|
||||
|
||||
encodeObject : List EncodedField -> Json.Encode.Value
|
||||
encodeObject =
|
||||
Json.Encode.object << List.filterMap identity
|
||||
|
||||
|
||||
encode : String -> (a -> Json.Encode.Value) -> a -> EncodedField
|
||||
encode key encoder value =
|
||||
Just ( key, encoder value )
|
||||
|
||||
|
||||
encodeNullable : String -> (a -> Json.Encode.Value) -> Maybe a -> EncodedField
|
||||
encodeNullable key encoder value =
|
||||
Just ( key, Maybe.withDefault Json.Encode.null (Maybe.map encoder value) )
|
||||
|
||||
|
||||
maybeEncode : String -> (a -> Json.Encode.Value) -> Maybe a -> EncodedField
|
||||
maybeEncode key encoder =
|
||||
Maybe.map (Tuple.pair key << encoder)
|
||||
|
||||
|
||||
maybeEncodeNullable : String -> (a -> Json.Encode.Value) -> Maybe a -> EncodedField
|
||||
maybeEncodeNullable =
|
||||
encodeNullable
|
||||
|
||||
|
||||
decode : String -> Json.Decode.Decoder a -> Json.Decode.Decoder (a -> b) -> Json.Decode.Decoder b
|
||||
decode key decoder =
|
||||
decodeChain (Json.Decode.field key decoder)
|
||||
|
||||
|
||||
decodeLazy : (a -> c) -> String -> Json.Decode.Decoder a -> Json.Decode.Decoder (c -> b) -> Json.Decode.Decoder b
|
||||
decodeLazy f key decoder =
|
||||
decodeChainLazy f (Json.Decode.field key decoder)
|
||||
|
||||
|
||||
decodeNullable : String -> Json.Decode.Decoder a -> Json.Decode.Decoder (Maybe a -> b) -> Json.Decode.Decoder b
|
||||
decodeNullable key decoder =
|
||||
decodeChain (maybeField key decoder Nothing)
|
||||
|
||||
|
||||
decodeNullableLazy : (Maybe a -> c) -> String -> Json.Decode.Decoder a -> Json.Decode.Decoder (c -> b) -> Json.Decode.Decoder b
|
||||
decodeNullableLazy f key decoder =
|
||||
decodeChainLazy f (maybeField key decoder Nothing)
|
||||
|
||||
|
||||
maybeDecode : String -> Json.Decode.Decoder a -> Maybe a -> Json.Decode.Decoder (Maybe a -> b) -> Json.Decode.Decoder b
|
||||
maybeDecode key decoder fallback =
|
||||
-- let's be kind to null-values as well
|
||||
decodeChain (maybeField key decoder fallback)
|
||||
|
||||
|
||||
maybeDecodeLazy : (Maybe a -> c) -> String -> Json.Decode.Decoder a -> Maybe a -> Json.Decode.Decoder (c -> b) -> Json.Decode.Decoder b
|
||||
maybeDecodeLazy f key decoder fallback =
|
||||
-- let's be kind to null-values as well
|
||||
decodeChainLazy f (maybeField key decoder fallback)
|
||||
|
||||
|
||||
maybeDecodeNullable : String -> Json.Decode.Decoder a -> Maybe a -> Json.Decode.Decoder (Maybe a -> b) -> Json.Decode.Decoder b
|
||||
maybeDecodeNullable key decoder fallback =
|
||||
decodeChain (maybeField key decoder fallback)
|
||||
|
||||
|
||||
maybeDecodeNullableLazy : (Maybe a -> c) -> String -> Json.Decode.Decoder a -> Maybe a -> Json.Decode.Decoder (c -> b) -> Json.Decode.Decoder b
|
||||
maybeDecodeNullableLazy f key decoder fallback =
|
||||
decodeChainLazy f (maybeField key decoder fallback)
|
||||
|
||||
|
||||
maybeField : String -> Json.Decode.Decoder a -> Maybe a -> Json.Decode.Decoder (Maybe a)
|
||||
maybeField key decoder fallback =
|
||||
let
|
||||
fieldDecoder =
|
||||
Json.Decode.field key Json.Decode.value
|
||||
|
||||
valueDecoder =
|
||||
Json.Decode.oneOf [ Json.Decode.map Just decoder, Json.Decode.null fallback ]
|
||||
|
||||
decodeObject rawObject =
|
||||
case Json.Decode.decodeValue fieldDecoder rawObject of
|
||||
Ok rawValue ->
|
||||
case Json.Decode.decodeValue valueDecoder rawValue of
|
||||
Ok value ->
|
||||
Json.Decode.succeed value
|
||||
|
||||
Err error ->
|
||||
Json.Decode.fail (Json.Decode.errorToString error)
|
||||
|
||||
Err _ ->
|
||||
Json.Decode.succeed fallback
|
||||
in
|
||||
Json.Decode.value
|
||||
|> Json.Decode.andThen decodeObject
|
||||
|
||||
|
||||
decodeChain : Json.Decode.Decoder a -> Json.Decode.Decoder (a -> b) -> Json.Decode.Decoder b
|
||||
decodeChain =
|
||||
Json.Decode.map2 (|>)
|
||||
|
||||
|
||||
decodeChainLazy : (a -> c) -> Json.Decode.Decoder a -> Json.Decode.Decoder (c -> b) -> Json.Decode.Decoder b
|
||||
decodeChainLazy f =
|
||||
decodeChain << Json.Decode.map f
|
164
samples/client/petstore/elm/src/Api/Request/Pet.elm
Normal file
164
samples/client/petstore/elm/src/Api/Request/Pet.elm
Normal file
@ -0,0 +1,164 @@
|
||||
{-
|
||||
OpenAPI Petstore
|
||||
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
|
||||
The version of the OpenAPI document: 1.0.0
|
||||
|
||||
NOTE: This file is auto generated by the openapi-generator.
|
||||
https://github.com/openapitools/openapi-generator.git
|
||||
|
||||
DO NOT EDIT THIS FILE MANUALLY.
|
||||
|
||||
For more info on generating Elm code, see https://eriktim.github.io/openapi-elm/
|
||||
-}
|
||||
|
||||
|
||||
module Api.Request.Pet exposing
|
||||
( addPet
|
||||
, deletePet
|
||||
, findPetsByStatus, Status(..), statusVariants
|
||||
, findPetsByTags
|
||||
, getPetById
|
||||
, updatePet
|
||||
, updatePetWithForm
|
||||
, uploadFile
|
||||
)
|
||||
|
||||
import Api
|
||||
import Api.Data exposing (..)
|
||||
import Dict
|
||||
import Http
|
||||
import Json.Decode
|
||||
import Json.Encode
|
||||
import File exposing (File)
|
||||
|
||||
|
||||
type Status
|
||||
= StatusAvailable
|
||||
| StatusPending
|
||||
| StatusSold
|
||||
|
||||
|
||||
statusVariants : List Status
|
||||
statusVariants =
|
||||
[ StatusAvailable
|
||||
, StatusPending
|
||||
, StatusSold
|
||||
]
|
||||
|
||||
|
||||
stringFromStatus : Status -> String
|
||||
stringFromStatus model =
|
||||
case model of
|
||||
StatusAvailable ->
|
||||
"available"
|
||||
|
||||
StatusPending ->
|
||||
"pending"
|
||||
|
||||
StatusSold ->
|
||||
"sold"
|
||||
|
||||
|
||||
|
||||
addPet : Api.Data.Pet -> Api.Request Api.Data.Pet
|
||||
addPet pet_body =
|
||||
Api.request
|
||||
"POST"
|
||||
"/pet"
|
||||
[]
|
||||
[]
|
||||
[]
|
||||
(Maybe.map Http.jsonBody (Just (Api.Data.encodePet pet_body)))
|
||||
Api.Data.petDecoder
|
||||
|
||||
|
||||
deletePet : Int -> Maybe String -> Api.Request ()
|
||||
deletePet petId_path apiKey_header =
|
||||
Api.request
|
||||
"DELETE"
|
||||
"/pet/{petId}"
|
||||
[ ( "petId", String.fromInt petId_path ) ]
|
||||
[]
|
||||
[ ( "api_key", Maybe.map identity apiKey_header ) ]
|
||||
Nothing
|
||||
(Json.Decode.succeed ())
|
||||
|
||||
|
||||
{-| Multiple status values can be provided with comma separated strings
|
||||
-}
|
||||
findPetsByStatus : List Status -> Api.Request (List Api.Data.Pet)
|
||||
findPetsByStatus status_query =
|
||||
Api.request
|
||||
"GET"
|
||||
"/pet/findByStatus"
|
||||
[]
|
||||
[ ( "status", Just <| (String.join "," << List.map stringFromStatus) status_query ) ]
|
||||
[]
|
||||
Nothing
|
||||
(Json.Decode.list Api.Data.petDecoder)
|
||||
|
||||
|
||||
{-| Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
||||
-}
|
||||
findPetsByTags : List String -> Api.Request (List Api.Data.Pet)
|
||||
findPetsByTags tags_query =
|
||||
Api.request
|
||||
"GET"
|
||||
"/pet/findByTags"
|
||||
[]
|
||||
[ ( "tags", Just <| (String.join "," << List.map identity) tags_query ) ]
|
||||
[]
|
||||
Nothing
|
||||
(Json.Decode.list Api.Data.petDecoder)
|
||||
|
||||
|
||||
{-| Returns a single pet
|
||||
-}
|
||||
getPetById : Int -> Api.Request Api.Data.Pet
|
||||
getPetById petId_path =
|
||||
Api.request
|
||||
"GET"
|
||||
"/pet/{petId}"
|
||||
[ ( "petId", String.fromInt petId_path ) ]
|
||||
[]
|
||||
[]
|
||||
Nothing
|
||||
Api.Data.petDecoder
|
||||
|
||||
|
||||
updatePet : Api.Data.Pet -> Api.Request Api.Data.Pet
|
||||
updatePet pet_body =
|
||||
Api.request
|
||||
"PUT"
|
||||
"/pet"
|
||||
[]
|
||||
[]
|
||||
[]
|
||||
(Maybe.map Http.jsonBody (Just (Api.Data.encodePet pet_body)))
|
||||
Api.Data.petDecoder
|
||||
|
||||
|
||||
updatePetWithForm : Int -> Maybe String -> Maybe String -> Api.Request ()
|
||||
updatePetWithForm petId_path name status =
|
||||
Api.request
|
||||
"POST"
|
||||
"/pet/{petId}"
|
||||
[ ( "petId", String.fromInt petId_path ) ]
|
||||
[]
|
||||
[]
|
||||
(Just <| Http.multipartBody <| List.filterMap identity [ Maybe.map (Http.stringPart "name") name, Maybe.map (Http.stringPart "status") status ])
|
||||
(Json.Decode.succeed ())
|
||||
|
||||
|
||||
uploadFile : Int -> Maybe String -> Maybe File -> Api.Request Api.Data.ApiResponse
|
||||
uploadFile petId_path additionalMetadata file =
|
||||
Api.request
|
||||
"POST"
|
||||
"/pet/{petId}/uploadImage"
|
||||
[ ( "petId", String.fromInt petId_path ) ]
|
||||
[]
|
||||
[]
|
||||
(Just <| Http.multipartBody <| List.filterMap identity [ Maybe.map (Http.stringPart "additionalMetadata") additionalMetadata, Maybe.map (Http.filePart "file") file ])
|
||||
Api.Data.apiResponseDecoder
|
||||
|
82
samples/client/petstore/elm/src/Api/Request/Store.elm
Normal file
82
samples/client/petstore/elm/src/Api/Request/Store.elm
Normal file
@ -0,0 +1,82 @@
|
||||
{-
|
||||
OpenAPI Petstore
|
||||
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
|
||||
The version of the OpenAPI document: 1.0.0
|
||||
|
||||
NOTE: This file is auto generated by the openapi-generator.
|
||||
https://github.com/openapitools/openapi-generator.git
|
||||
|
||||
DO NOT EDIT THIS FILE MANUALLY.
|
||||
|
||||
For more info on generating Elm code, see https://eriktim.github.io/openapi-elm/
|
||||
-}
|
||||
|
||||
|
||||
module Api.Request.Store exposing
|
||||
( deleteOrder
|
||||
, getInventory
|
||||
, getOrderById
|
||||
, placeOrder
|
||||
)
|
||||
|
||||
import Api
|
||||
import Api.Data exposing (..)
|
||||
import Dict
|
||||
import Http
|
||||
import Json.Decode
|
||||
import Json.Encode
|
||||
|
||||
{-| For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
-}
|
||||
deleteOrder : String -> Api.Request ()
|
||||
deleteOrder orderId_path =
|
||||
Api.request
|
||||
"DELETE"
|
||||
"/store/order/{orderId}"
|
||||
[ ( "orderId", identity orderId_path ) ]
|
||||
[]
|
||||
[]
|
||||
Nothing
|
||||
(Json.Decode.succeed ())
|
||||
|
||||
|
||||
{-| Returns a map of status codes to quantities
|
||||
-}
|
||||
getInventory : Api.Request (Dict.Dict String Int)
|
||||
getInventory =
|
||||
Api.request
|
||||
"GET"
|
||||
"/store/inventory"
|
||||
[]
|
||||
[]
|
||||
[]
|
||||
Nothing
|
||||
(Json.Decode.dict Json.Decode.int)
|
||||
|
||||
|
||||
{-| For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions
|
||||
-}
|
||||
getOrderById : Int -> Api.Request Api.Data.Order_
|
||||
getOrderById orderId_path =
|
||||
Api.request
|
||||
"GET"
|
||||
"/store/order/{orderId}"
|
||||
[ ( "orderId", String.fromInt orderId_path ) ]
|
||||
[]
|
||||
[]
|
||||
Nothing
|
||||
Api.Data.orderDecoder
|
||||
|
||||
|
||||
placeOrder : Api.Data.Order_ -> Api.Request Api.Data.Order_
|
||||
placeOrder order_body =
|
||||
Api.request
|
||||
"POST"
|
||||
"/store/order"
|
||||
[]
|
||||
[]
|
||||
[]
|
||||
(Maybe.map Http.jsonBody (Just (Api.Data.encodeOrder order_body)))
|
||||
Api.Data.orderDecoder
|
||||
|
134
samples/client/petstore/elm/src/Api/Request/User.elm
Normal file
134
samples/client/petstore/elm/src/Api/Request/User.elm
Normal file
@ -0,0 +1,134 @@
|
||||
{-
|
||||
OpenAPI Petstore
|
||||
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
|
||||
The version of the OpenAPI document: 1.0.0
|
||||
|
||||
NOTE: This file is auto generated by the openapi-generator.
|
||||
https://github.com/openapitools/openapi-generator.git
|
||||
|
||||
DO NOT EDIT THIS FILE MANUALLY.
|
||||
|
||||
For more info on generating Elm code, see https://eriktim.github.io/openapi-elm/
|
||||
-}
|
||||
|
||||
|
||||
module Api.Request.User exposing
|
||||
( createUser
|
||||
, createUsersWithArrayInput
|
||||
, createUsersWithListInput
|
||||
, deleteUser
|
||||
, getUserByName
|
||||
, loginUser
|
||||
, logoutUser
|
||||
, updateUser
|
||||
)
|
||||
|
||||
import Api
|
||||
import Api.Data exposing (..)
|
||||
import Dict
|
||||
import Http
|
||||
import Json.Decode
|
||||
import Json.Encode
|
||||
|
||||
{-| This can only be done by the logged in user.
|
||||
-}
|
||||
createUser : Api.Data.User -> Api.Request ()
|
||||
createUser user_body =
|
||||
Api.request
|
||||
"POST"
|
||||
"/user"
|
||||
[]
|
||||
[]
|
||||
[]
|
||||
(Maybe.map Http.jsonBody (Just (Api.Data.encodeUser user_body)))
|
||||
(Json.Decode.succeed ())
|
||||
|
||||
|
||||
createUsersWithArrayInput : List Api.Data.User -> Api.Request ()
|
||||
createUsersWithArrayInput user_body =
|
||||
Api.request
|
||||
"POST"
|
||||
"/user/createWithArray"
|
||||
[]
|
||||
[]
|
||||
[]
|
||||
(Maybe.map Http.jsonBody (Just (Json.Encode.list encodeUser user_body)))
|
||||
(Json.Decode.succeed ())
|
||||
|
||||
|
||||
createUsersWithListInput : List Api.Data.User -> Api.Request ()
|
||||
createUsersWithListInput user_body =
|
||||
Api.request
|
||||
"POST"
|
||||
"/user/createWithList"
|
||||
[]
|
||||
[]
|
||||
[]
|
||||
(Maybe.map Http.jsonBody (Just (Json.Encode.list encodeUser user_body)))
|
||||
(Json.Decode.succeed ())
|
||||
|
||||
|
||||
{-| This can only be done by the logged in user.
|
||||
-}
|
||||
deleteUser : String -> Api.Request ()
|
||||
deleteUser username_path =
|
||||
Api.request
|
||||
"DELETE"
|
||||
"/user/{username}"
|
||||
[ ( "username", identity username_path ) ]
|
||||
[]
|
||||
[]
|
||||
Nothing
|
||||
(Json.Decode.succeed ())
|
||||
|
||||
|
||||
getUserByName : String -> Api.Request Api.Data.User
|
||||
getUserByName username_path =
|
||||
Api.request
|
||||
"GET"
|
||||
"/user/{username}"
|
||||
[ ( "username", identity username_path ) ]
|
||||
[]
|
||||
[]
|
||||
Nothing
|
||||
Api.Data.userDecoder
|
||||
|
||||
|
||||
loginUser : String -> String -> Api.Request String
|
||||
loginUser username_query password_query =
|
||||
Api.request
|
||||
"GET"
|
||||
"/user/login"
|
||||
[]
|
||||
[ ( "username", Just <| identity username_query ), ( "password", Just <| identity password_query ) ]
|
||||
[]
|
||||
Nothing
|
||||
Json.Decode.string
|
||||
|
||||
|
||||
logoutUser : Api.Request ()
|
||||
logoutUser =
|
||||
Api.request
|
||||
"GET"
|
||||
"/user/logout"
|
||||
[]
|
||||
[]
|
||||
[]
|
||||
Nothing
|
||||
(Json.Decode.succeed ())
|
||||
|
||||
|
||||
{-| This can only be done by the logged in user.
|
||||
-}
|
||||
updateUser : String -> Api.Data.User -> Api.Request ()
|
||||
updateUser username_path user_body =
|
||||
Api.request
|
||||
"PUT"
|
||||
"/user/{username}"
|
||||
[ ( "username", identity username_path ) ]
|
||||
[]
|
||||
[]
|
||||
(Maybe.map Http.jsonBody (Just (Api.Data.encodeUser user_body)))
|
||||
(Json.Decode.succeed ())
|
||||
|
70
samples/client/petstore/elm/src/Api/Time.elm
Normal file
70
samples/client/petstore/elm/src/Api/Time.elm
Normal file
@ -0,0 +1,70 @@
|
||||
module Api.Time exposing
|
||||
( Posix
|
||||
, dateToString
|
||||
, dateTimeToString
|
||||
, encodeDate
|
||||
, encodeDateTime
|
||||
, dateDecoder
|
||||
, dateTimeDecoder
|
||||
)
|
||||
|
||||
import Http
|
||||
import Iso8601
|
||||
import Json.Decode
|
||||
import Json.Encode
|
||||
import Time
|
||||
|
||||
|
||||
type alias Posix = Time.Posix
|
||||
|
||||
|
||||
dateToString : Posix -> String
|
||||
dateToString =
|
||||
String.left 10 << dateTimeToString
|
||||
|
||||
|
||||
dateTimeToString : Posix -> String
|
||||
dateTimeToString =
|
||||
Iso8601.fromTime
|
||||
|
||||
|
||||
encodeDate : Posix -> Json.Encode.Value
|
||||
encodeDate =
|
||||
Json.Encode.string << dateToString
|
||||
|
||||
|
||||
encodeDateTime : Posix -> Json.Encode.Value
|
||||
encodeDateTime =
|
||||
Json.Encode.string << dateTimeToString
|
||||
|
||||
|
||||
dateDecoder : Json.Decode.Decoder Posix
|
||||
dateDecoder =
|
||||
Json.Decode.string
|
||||
|> Json.Decode.andThen decodeDateIsoString
|
||||
|
||||
|
||||
decodeDateIsoString : String -> Json.Decode.Decoder Posix
|
||||
decodeDateIsoString str =
|
||||
case Iso8601.toTime (str ++ "T00:00:00.000Z") of
|
||||
Result.Ok posix ->
|
||||
Json.Decode.succeed posix
|
||||
|
||||
Result.Err _ ->
|
||||
Json.Decode.fail ("Invalid calendar date: " ++ str)
|
||||
|
||||
|
||||
dateTimeDecoder : Json.Decode.Decoder Posix
|
||||
dateTimeDecoder =
|
||||
Json.Decode.string
|
||||
|> Json.Decode.andThen decodeDateTimeIsoString
|
||||
|
||||
|
||||
decodeDateTimeIsoString : String -> Json.Decode.Decoder Posix
|
||||
decodeDateTimeIsoString str =
|
||||
case Iso8601.toTime str of
|
||||
Result.Ok posix ->
|
||||
Json.Decode.succeed posix
|
||||
|
||||
Result.Err _ ->
|
||||
Json.Decode.fail ("Invalid ISO date: " ++ str)
|
@ -9,6 +9,7 @@
|
||||
"danyx23/elm-uuid": "2.1.2",
|
||||
"elm/browser": "1.0.1",
|
||||
"elm/core": "1.0.2",
|
||||
"elm/file": "1.0.1",
|
||||
"elm/html": "1.0.0",
|
||||
"elm/http": "2.0.0",
|
||||
"elm/json": "1.1.2",
|
||||
@ -18,7 +19,6 @@
|
||||
},
|
||||
"indirect": {
|
||||
"elm/bytes": "1.0.5",
|
||||
"elm/file": "1.0.1",
|
||||
"elm/parser": "1.1.0",
|
||||
"elm/random": "1.0.0",
|
||||
"elm/regex": "1.0.0",
|
||||
|
@ -35,7 +35,7 @@ type Request a =
|
||||
}
|
||||
|
||||
|
||||
request : String -> String -> List ( String, String ) -> List (String, Maybe String) -> List (String, Maybe String) -> Maybe Json.Encode.Value -> Json.Decode.Decoder a -> Request a
|
||||
request : String -> String -> List ( String, String ) -> List (String, Maybe String) -> List (String, Maybe String) -> Maybe Http.Body -> Json.Decode.Decoder a -> Request a
|
||||
request method path pathParams queryParams headerParams body decoder =
|
||||
Request
|
||||
{ method = method
|
||||
@ -43,7 +43,7 @@ request method path pathParams queryParams headerParams body decoder =
|
||||
, basePath = "http://localhost:9000"
|
||||
, pathParams = interpolatePath path pathParams
|
||||
, queryParams = queries queryParams
|
||||
, body = Maybe.withDefault Http.emptyBody (Maybe.map Http.jsonBody body)
|
||||
, body = Maybe.withDefault Http.emptyBody body
|
||||
, decoder = decoder
|
||||
, timeout = Nothing
|
||||
, tracker = Nothing
|
||||
|
@ -48,6 +48,8 @@ module Api.Data exposing
|
||||
, encodeRecursion
|
||||
, encodeRecursionLoop
|
||||
, encodeUnsafeCharacters
|
||||
, stringFromEnum
|
||||
, stringFromEnumeric
|
||||
, absentDecoder
|
||||
, arrayDecoder
|
||||
, composedDecoder
|
||||
@ -89,10 +91,10 @@ type alias Absent =
|
||||
{-| Model with arrays
|
||||
-}
|
||||
type alias Array =
|
||||
{ array : List (String)
|
||||
, arrayOfArray : List (List (String))
|
||||
, arrayOfPrimitive : Maybe (List (Primitive))
|
||||
, arrayOfEnum : Maybe (List (Enum))
|
||||
{ array : List String
|
||||
, arrayOfArray : List (List String)
|
||||
, arrayOfPrimitive : Maybe ( List Primitive )
|
||||
, arrayOfEnum : Maybe ( List Enum )
|
||||
}
|
||||
|
||||
|
||||
@ -216,10 +218,10 @@ unwrapRecursionMaybe : RecursionMaybe -> Maybe Recursion
|
||||
unwrapRecursionMaybe (RecursionMaybe maybe) = maybe
|
||||
|
||||
|
||||
type RecursionList = RecursionList (Maybe (List (Recursion)))
|
||||
type RecursionList = RecursionList (Maybe ( List Recursion ))
|
||||
|
||||
|
||||
unwrapRecursionList : RecursionList -> Maybe (List (Recursion))
|
||||
unwrapRecursionList : RecursionList -> Maybe ( List Recursion )
|
||||
unwrapRecursionList (RecursionList list) = list
|
||||
|
||||
|
||||
|
@ -23,7 +23,7 @@ module Api.Request.Default exposing
|
||||
)
|
||||
|
||||
import Api
|
||||
import Api.Data
|
||||
import Api.Data exposing (..)
|
||||
import Dict
|
||||
import Http
|
||||
import Json.Decode
|
||||
@ -112,8 +112,6 @@ stringFromEnum model =
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
headerPost : String -> Maybe Int -> Maybe HeaderType -> Api.Request String
|
||||
headerPost string_header integer_header headerType_header =
|
||||
Api.request
|
||||
@ -126,7 +124,6 @@ headerPost string_header integer_header headerType_header =
|
||||
Json.Decode.string
|
||||
|
||||
|
||||
|
||||
maybeGet : Api.Request Api.Data.Maybe_
|
||||
maybeGet =
|
||||
Api.request
|
||||
@ -139,7 +136,6 @@ maybeGet =
|
||||
Api.Data.maybeDecoder
|
||||
|
||||
|
||||
|
||||
pathStringIntegerEnumerationGet : String -> Int -> Enumeration -> Api.Request ()
|
||||
pathStringIntegerEnumerationGet string_path integer_path enumeration_path =
|
||||
Api.request
|
||||
@ -152,7 +148,6 @@ pathStringIntegerEnumerationGet string_path integer_path enumeration_path =
|
||||
(Json.Decode.succeed ())
|
||||
|
||||
|
||||
|
||||
queryGet : Maybe String -> Maybe Int -> Maybe Enum -> Api.Request ()
|
||||
queryGet string_query int_query enum_query =
|
||||
Api.request
|
||||
@ -165,7 +160,6 @@ queryGet string_query int_query enum_query =
|
||||
(Json.Decode.succeed ())
|
||||
|
||||
|
||||
|
||||
securedPost : String -> Api.Request ()
|
||||
securedPost auth_token =
|
||||
Api.request
|
||||
@ -178,8 +172,6 @@ securedPost auth_token =
|
||||
(Json.Decode.succeed ())
|
||||
|> Api.withBearerToken auth_token
|
||||
|
||||
|
||||
|
||||
uuidGet : Maybe Uuid -> Api.Request Uuid
|
||||
uuidGet value_query =
|
||||
Api.request
|
||||
@ -190,3 +182,4 @@ uuidGet value_query =
|
||||
[]
|
||||
Nothing
|
||||
Uuid.decoder
|
||||
|
||||
|
@ -18,14 +18,12 @@ module Api.Request.Primitive exposing
|
||||
)
|
||||
|
||||
import Api
|
||||
import Api.Data
|
||||
import Api.Data exposing (..)
|
||||
import Dict
|
||||
import Http
|
||||
import Json.Decode
|
||||
import Json.Encode
|
||||
|
||||
|
||||
|
||||
update : Api.Data.Primitive -> Api.Request Api.Data.Primitive
|
||||
update primitive_body =
|
||||
Api.request
|
||||
@ -34,5 +32,6 @@ update primitive_body =
|
||||
[]
|
||||
[]
|
||||
[]
|
||||
(Just (Api.Data.encodePrimitive primitive_body))
|
||||
(Maybe.map Http.jsonBody (Just (Api.Data.encodePrimitive primitive_body)))
|
||||
Api.Data.primitiveDecoder
|
||||
|
||||
|
@ -1 +0,0 @@
|
||||
5.0.0-SNAPSHOT
|
@ -1,18 +0,0 @@
|
||||
module Byte exposing (Byte, decoder, encode)
|
||||
|
||||
import Json.Decode as Decode exposing (Decoder)
|
||||
import Json.Encode as Encode
|
||||
|
||||
|
||||
type alias Byte =
|
||||
String
|
||||
|
||||
|
||||
decoder : Decoder Byte
|
||||
decoder =
|
||||
Decode.string
|
||||
|
||||
|
||||
encode : Byte -> Encode.Value
|
||||
encode model =
|
||||
Encode.string model
|
@ -1,64 +0,0 @@
|
||||
{-
|
||||
OpenAPI Petstore
|
||||
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
|
||||
The version of the OpenAPI document: 1.0.0
|
||||
|
||||
NOTE: This file is auto generated by the openapi-generator.
|
||||
https://github.com/openapitools/openapi-generator.git
|
||||
Do not edit this file manually.
|
||||
-}
|
||||
|
||||
|
||||
module Data.ApiResponse exposing (ApiResponse, decoder, encode, encodeWithTag, toString)
|
||||
|
||||
import Dict exposing (Dict)
|
||||
import Json.Decode as Decode exposing (Decoder)
|
||||
import Json.Decode.Pipeline exposing (optional, required)
|
||||
import Json.Encode as Encode
|
||||
|
||||
|
||||
{-| Describes the result of uploading an image resource
|
||||
-}
|
||||
type alias ApiResponse =
|
||||
{ code : Maybe (Int)
|
||||
, type_ : Maybe (String)
|
||||
, message : Maybe (String)
|
||||
}
|
||||
|
||||
|
||||
decoder : Decoder ApiResponse
|
||||
decoder =
|
||||
Decode.succeed ApiResponse
|
||||
|> optional "code" (Decode.nullable Decode.int) Nothing
|
||||
|> optional "type" (Decode.nullable Decode.string) Nothing
|
||||
|> optional "message" (Decode.nullable Decode.string) Nothing
|
||||
|
||||
|
||||
|
||||
encode : ApiResponse -> Encode.Value
|
||||
encode =
|
||||
Encode.object << encodePairs
|
||||
|
||||
|
||||
encodeWithTag : ( String, String ) -> ApiResponse -> Encode.Value
|
||||
encodeWithTag (tagField, tag) model =
|
||||
Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ]
|
||||
|
||||
|
||||
encodePairs : ApiResponse -> List (String, Encode.Value)
|
||||
encodePairs model =
|
||||
[ ( "code", Maybe.withDefault Encode.null (Maybe.map Encode.int model.code) )
|
||||
, ( "type", Maybe.withDefault Encode.null (Maybe.map Encode.string model.type_) )
|
||||
, ( "message", Maybe.withDefault Encode.null (Maybe.map Encode.string model.message) )
|
||||
]
|
||||
|
||||
|
||||
|
||||
toString : ApiResponse -> String
|
||||
toString =
|
||||
Encode.encode 0 << encode
|
||||
|
||||
|
||||
|
||||
|
@ -1,61 +0,0 @@
|
||||
{-
|
||||
OpenAPI Petstore
|
||||
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
|
||||
The version of the OpenAPI document: 1.0.0
|
||||
|
||||
NOTE: This file is auto generated by the openapi-generator.
|
||||
https://github.com/openapitools/openapi-generator.git
|
||||
Do not edit this file manually.
|
||||
-}
|
||||
|
||||
|
||||
module Data.Category exposing (Category, decoder, encode, encodeWithTag, toString)
|
||||
|
||||
import Dict exposing (Dict)
|
||||
import Json.Decode as Decode exposing (Decoder)
|
||||
import Json.Decode.Pipeline exposing (optional, required)
|
||||
import Json.Encode as Encode
|
||||
|
||||
|
||||
{-| A category for a pet
|
||||
-}
|
||||
type alias Category =
|
||||
{ id : Maybe (Int)
|
||||
, name : Maybe (String)
|
||||
}
|
||||
|
||||
|
||||
decoder : Decoder Category
|
||||
decoder =
|
||||
Decode.succeed Category
|
||||
|> optional "id" (Decode.nullable Decode.int) Nothing
|
||||
|> optional "name" (Decode.nullable Decode.string) Nothing
|
||||
|
||||
|
||||
|
||||
encode : Category -> Encode.Value
|
||||
encode =
|
||||
Encode.object << encodePairs
|
||||
|
||||
|
||||
encodeWithTag : ( String, String ) -> Category -> Encode.Value
|
||||
encodeWithTag (tagField, tag) model =
|
||||
Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ]
|
||||
|
||||
|
||||
encodePairs : Category -> List (String, Encode.Value)
|
||||
encodePairs model =
|
||||
[ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) )
|
||||
, ( "name", Maybe.withDefault Encode.null (Maybe.map Encode.string model.name) )
|
||||
]
|
||||
|
||||
|
||||
|
||||
toString : Category -> String
|
||||
toString =
|
||||
Encode.encode 0 << encode
|
||||
|
||||
|
||||
|
||||
|
@ -1,59 +0,0 @@
|
||||
{-
|
||||
OpenAPI Petstore
|
||||
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
|
||||
The version of the OpenAPI document: 1.0.0
|
||||
|
||||
NOTE: This file is auto generated by the openapi-generator.
|
||||
https://github.com/openapitools/openapi-generator.git
|
||||
Do not edit this file manually.
|
||||
-}
|
||||
|
||||
|
||||
module Data.InlineObject exposing (InlineObject, decoder, encode, encodeWithTag, toString)
|
||||
|
||||
import Dict exposing (Dict)
|
||||
import Json.Decode as Decode exposing (Decoder)
|
||||
import Json.Decode.Pipeline exposing (optional, required)
|
||||
import Json.Encode as Encode
|
||||
|
||||
|
||||
type alias InlineObject =
|
||||
{ name : Maybe (String)
|
||||
, status : Maybe (String)
|
||||
}
|
||||
|
||||
|
||||
decoder : Decoder InlineObject
|
||||
decoder =
|
||||
Decode.succeed InlineObject
|
||||
|> optional "name" (Decode.nullable Decode.string) Nothing
|
||||
|> optional "status" (Decode.nullable Decode.string) Nothing
|
||||
|
||||
|
||||
|
||||
encode : InlineObject -> Encode.Value
|
||||
encode =
|
||||
Encode.object << encodePairs
|
||||
|
||||
|
||||
encodeWithTag : ( String, String ) -> InlineObject -> Encode.Value
|
||||
encodeWithTag (tagField, tag) model =
|
||||
Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ]
|
||||
|
||||
|
||||
encodePairs : InlineObject -> List (String, Encode.Value)
|
||||
encodePairs model =
|
||||
[ ( "name", Maybe.withDefault Encode.null (Maybe.map Encode.string model.name) )
|
||||
, ( "status", Maybe.withDefault Encode.null (Maybe.map Encode.string model.status) )
|
||||
]
|
||||
|
||||
|
||||
|
||||
toString : InlineObject -> String
|
||||
toString =
|
||||
Encode.encode 0 << encode
|
||||
|
||||
|
||||
|
||||
|
@ -1,59 +0,0 @@
|
||||
{-
|
||||
OpenAPI Petstore
|
||||
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
|
||||
The version of the OpenAPI document: 1.0.0
|
||||
|
||||
NOTE: This file is auto generated by the openapi-generator.
|
||||
https://github.com/openapitools/openapi-generator.git
|
||||
Do not edit this file manually.
|
||||
-}
|
||||
|
||||
|
||||
module Data.InlineObject1 exposing (InlineObject1, decoder, encode, encodeWithTag, toString)
|
||||
|
||||
import Dict exposing (Dict)
|
||||
import Json.Decode as Decode exposing (Decoder)
|
||||
import Json.Decode.Pipeline exposing (optional, required)
|
||||
import Json.Encode as Encode
|
||||
|
||||
|
||||
type alias InlineObject1 =
|
||||
{ additionalMetadata : Maybe (String)
|
||||
, file : Maybe (String)
|
||||
}
|
||||
|
||||
|
||||
decoder : Decoder InlineObject1
|
||||
decoder =
|
||||
Decode.succeed InlineObject1
|
||||
|> optional "additionalMetadata" (Decode.nullable Decode.string) Nothing
|
||||
|> optional "file" (Decode.nullable Decode.string) Nothing
|
||||
|
||||
|
||||
|
||||
encode : InlineObject1 -> Encode.Value
|
||||
encode =
|
||||
Encode.object << encodePairs
|
||||
|
||||
|
||||
encodeWithTag : ( String, String ) -> InlineObject1 -> Encode.Value
|
||||
encodeWithTag (tagField, tag) model =
|
||||
Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ]
|
||||
|
||||
|
||||
encodePairs : InlineObject1 -> List (String, Encode.Value)
|
||||
encodePairs model =
|
||||
[ ( "additionalMetadata", Maybe.withDefault Encode.null (Maybe.map Encode.string model.additionalMetadata) )
|
||||
, ( "file", Maybe.withDefault Encode.null (Maybe.map Encode.string model.file) )
|
||||
]
|
||||
|
||||
|
||||
|
||||
toString : InlineObject1 -> String
|
||||
toString =
|
||||
Encode.encode 0 << encode
|
||||
|
||||
|
||||
|
||||
|
@ -1,117 +0,0 @@
|
||||
{-
|
||||
OpenAPI Petstore
|
||||
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
|
||||
The version of the OpenAPI document: 1.0.0
|
||||
|
||||
NOTE: This file is auto generated by the openapi-generator.
|
||||
https://github.com/openapitools/openapi-generator.git
|
||||
Do not edit this file manually.
|
||||
-}
|
||||
|
||||
|
||||
module Data.Order_ exposing (Order_, Status(..), decoder, encode, encodeWithTag, toString)
|
||||
|
||||
import DateTime exposing (DateTime)
|
||||
import Dict exposing (Dict)
|
||||
import Json.Decode as Decode exposing (Decoder)
|
||||
import Json.Decode.Pipeline exposing (optional, required)
|
||||
import Json.Encode as Encode
|
||||
|
||||
|
||||
{-| An order for a pets from the pet store
|
||||
-}
|
||||
type alias Order_ =
|
||||
{ id : Maybe (Int)
|
||||
, petId : Maybe (Int)
|
||||
, quantity : Maybe (Int)
|
||||
, shipDate : Maybe (DateTime)
|
||||
, status : Maybe (Status)
|
||||
, complete : Maybe (Bool)
|
||||
}
|
||||
|
||||
|
||||
type Status
|
||||
= StatusPlaced
|
||||
| StatusApproved
|
||||
| StatusDelivered
|
||||
|
||||
|
||||
|
||||
decoder : Decoder Order_
|
||||
decoder =
|
||||
Decode.succeed Order_
|
||||
|> optional "id" (Decode.nullable Decode.int) Nothing
|
||||
|> optional "petId" (Decode.nullable Decode.int) Nothing
|
||||
|> optional "quantity" (Decode.nullable Decode.int) Nothing
|
||||
|> optional "shipDate" (Decode.nullable DateTime.decoder) Nothing
|
||||
|> optional "status" (Decode.nullable statusDecoder) Nothing
|
||||
|> optional "complete" (Decode.nullable Decode.bool) (Just False)
|
||||
|
||||
|
||||
|
||||
encode : Order_ -> Encode.Value
|
||||
encode =
|
||||
Encode.object << encodePairs
|
||||
|
||||
|
||||
encodeWithTag : ( String, String ) -> Order_ -> Encode.Value
|
||||
encodeWithTag (tagField, tag) model =
|
||||
Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ]
|
||||
|
||||
|
||||
encodePairs : Order_ -> List (String, Encode.Value)
|
||||
encodePairs model =
|
||||
[ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) )
|
||||
, ( "petId", Maybe.withDefault Encode.null (Maybe.map Encode.int model.petId) )
|
||||
, ( "quantity", Maybe.withDefault Encode.null (Maybe.map Encode.int model.quantity) )
|
||||
, ( "shipDate", Maybe.withDefault Encode.null (Maybe.map DateTime.encode model.shipDate) )
|
||||
, ( "status", Maybe.withDefault Encode.null (Maybe.map encodeStatus model.status) )
|
||||
, ( "complete", Maybe.withDefault Encode.null (Maybe.map Encode.bool model.complete) )
|
||||
]
|
||||
|
||||
|
||||
|
||||
toString : Order_ -> String
|
||||
toString =
|
||||
Encode.encode 0 << encode
|
||||
|
||||
|
||||
|
||||
|
||||
statusDecoder : Decoder Status
|
||||
statusDecoder =
|
||||
Decode.string
|
||||
|> Decode.andThen
|
||||
(\str ->
|
||||
case str of
|
||||
"placed" ->
|
||||
Decode.succeed StatusPlaced
|
||||
|
||||
"approved" ->
|
||||
Decode.succeed StatusApproved
|
||||
|
||||
"delivered" ->
|
||||
Decode.succeed StatusDelivered
|
||||
|
||||
other ->
|
||||
Decode.fail <| "Unknown type: " ++ other
|
||||
)
|
||||
|
||||
|
||||
|
||||
encodeStatus : Status -> Encode.Value
|
||||
encodeStatus model =
|
||||
case model of
|
||||
StatusPlaced ->
|
||||
Encode.string "placed"
|
||||
|
||||
StatusApproved ->
|
||||
Encode.string "approved"
|
||||
|
||||
StatusDelivered ->
|
||||
Encode.string "delivered"
|
||||
|
||||
|
||||
|
||||
|
@ -1,118 +0,0 @@
|
||||
{-
|
||||
OpenAPI Petstore
|
||||
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
|
||||
The version of the OpenAPI document: 1.0.0
|
||||
|
||||
NOTE: This file is auto generated by the openapi-generator.
|
||||
https://github.com/openapitools/openapi-generator.git
|
||||
Do not edit this file manually.
|
||||
-}
|
||||
|
||||
|
||||
module Data.Pet exposing (Pet, Status(..), decoder, encode, encodeWithTag, toString)
|
||||
|
||||
import Data.Category as Category exposing (Category)
|
||||
import Data.Tag as Tag exposing (Tag)
|
||||
import Dict exposing (Dict)
|
||||
import Json.Decode as Decode exposing (Decoder)
|
||||
import Json.Decode.Pipeline exposing (optional, required)
|
||||
import Json.Encode as Encode
|
||||
|
||||
|
||||
{-| A pet for sale in the pet store
|
||||
-}
|
||||
type alias Pet =
|
||||
{ id : Maybe (Int)
|
||||
, category : Maybe (Category)
|
||||
, name : String
|
||||
, photoUrls : (List String)
|
||||
, tags : Maybe ((List Tag))
|
||||
, status : Maybe (Status)
|
||||
}
|
||||
|
||||
|
||||
type Status
|
||||
= StatusAvailable
|
||||
| StatusPending
|
||||
| StatusSold
|
||||
|
||||
|
||||
|
||||
decoder : Decoder Pet
|
||||
decoder =
|
||||
Decode.succeed Pet
|
||||
|> optional "id" (Decode.nullable Decode.int) Nothing
|
||||
|> optional "category" (Decode.nullable Category.decoder) Nothing
|
||||
|> required "name" Decode.string
|
||||
|> required "photoUrls" (Decode.list Decode.string)
|
||||
|> optional "tags" (Decode.nullable (Decode.list Tag.decoder)) Nothing
|
||||
|> optional "status" (Decode.nullable statusDecoder) Nothing
|
||||
|
||||
|
||||
|
||||
encode : Pet -> Encode.Value
|
||||
encode =
|
||||
Encode.object << encodePairs
|
||||
|
||||
|
||||
encodeWithTag : ( String, String ) -> Pet -> Encode.Value
|
||||
encodeWithTag (tagField, tag) model =
|
||||
Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ]
|
||||
|
||||
|
||||
encodePairs : Pet -> List (String, Encode.Value)
|
||||
encodePairs model =
|
||||
[ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) )
|
||||
, ( "category", Maybe.withDefault Encode.null (Maybe.map Category.encode model.category) )
|
||||
, ( "name", Encode.string model.name )
|
||||
, ( "photoUrls", (Encode.list Encode.string) model.photoUrls )
|
||||
, ( "tags", Maybe.withDefault Encode.null (Maybe.map (Encode.list Tag.encode) model.tags) )
|
||||
, ( "status", Maybe.withDefault Encode.null (Maybe.map encodeStatus model.status) )
|
||||
]
|
||||
|
||||
|
||||
|
||||
toString : Pet -> String
|
||||
toString =
|
||||
Encode.encode 0 << encode
|
||||
|
||||
|
||||
|
||||
|
||||
statusDecoder : Decoder Status
|
||||
statusDecoder =
|
||||
Decode.string
|
||||
|> Decode.andThen
|
||||
(\str ->
|
||||
case str of
|
||||
"available" ->
|
||||
Decode.succeed StatusAvailable
|
||||
|
||||
"pending" ->
|
||||
Decode.succeed StatusPending
|
||||
|
||||
"sold" ->
|
||||
Decode.succeed StatusSold
|
||||
|
||||
other ->
|
||||
Decode.fail <| "Unknown type: " ++ other
|
||||
)
|
||||
|
||||
|
||||
|
||||
encodeStatus : Status -> Encode.Value
|
||||
encodeStatus model =
|
||||
case model of
|
||||
StatusAvailable ->
|
||||
Encode.string "available"
|
||||
|
||||
StatusPending ->
|
||||
Encode.string "pending"
|
||||
|
||||
StatusSold ->
|
||||
Encode.string "sold"
|
||||
|
||||
|
||||
|
||||
|
@ -1,61 +0,0 @@
|
||||
{-
|
||||
OpenAPI Petstore
|
||||
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
|
||||
The version of the OpenAPI document: 1.0.0
|
||||
|
||||
NOTE: This file is auto generated by the openapi-generator.
|
||||
https://github.com/openapitools/openapi-generator.git
|
||||
Do not edit this file manually.
|
||||
-}
|
||||
|
||||
|
||||
module Data.Tag exposing (Tag, decoder, encode, encodeWithTag, toString)
|
||||
|
||||
import Dict exposing (Dict)
|
||||
import Json.Decode as Decode exposing (Decoder)
|
||||
import Json.Decode.Pipeline exposing (optional, required)
|
||||
import Json.Encode as Encode
|
||||
|
||||
|
||||
{-| A tag for a pet
|
||||
-}
|
||||
type alias Tag =
|
||||
{ id : Maybe (Int)
|
||||
, name : Maybe (String)
|
||||
}
|
||||
|
||||
|
||||
decoder : Decoder Tag
|
||||
decoder =
|
||||
Decode.succeed Tag
|
||||
|> optional "id" (Decode.nullable Decode.int) Nothing
|
||||
|> optional "name" (Decode.nullable Decode.string) Nothing
|
||||
|
||||
|
||||
|
||||
encode : Tag -> Encode.Value
|
||||
encode =
|
||||
Encode.object << encodePairs
|
||||
|
||||
|
||||
encodeWithTag : ( String, String ) -> Tag -> Encode.Value
|
||||
encodeWithTag (tagField, tag) model =
|
||||
Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ]
|
||||
|
||||
|
||||
encodePairs : Tag -> List (String, Encode.Value)
|
||||
encodePairs model =
|
||||
[ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) )
|
||||
, ( "name", Maybe.withDefault Encode.null (Maybe.map Encode.string model.name) )
|
||||
]
|
||||
|
||||
|
||||
|
||||
toString : Tag -> String
|
||||
toString =
|
||||
Encode.encode 0 << encode
|
||||
|
||||
|
||||
|
||||
|
@ -1,79 +0,0 @@
|
||||
{-
|
||||
OpenAPI Petstore
|
||||
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
|
||||
The version of the OpenAPI document: 1.0.0
|
||||
|
||||
NOTE: This file is auto generated by the openapi-generator.
|
||||
https://github.com/openapitools/openapi-generator.git
|
||||
Do not edit this file manually.
|
||||
-}
|
||||
|
||||
|
||||
module Data.User exposing (User, decoder, encode, encodeWithTag, toString)
|
||||
|
||||
import Dict exposing (Dict)
|
||||
import Json.Decode as Decode exposing (Decoder)
|
||||
import Json.Decode.Pipeline exposing (optional, required)
|
||||
import Json.Encode as Encode
|
||||
|
||||
|
||||
{-| A User who is purchasing from the pet store
|
||||
-}
|
||||
type alias User =
|
||||
{ id : Maybe (Int)
|
||||
, username : Maybe (String)
|
||||
, firstName : Maybe (String)
|
||||
, lastName : Maybe (String)
|
||||
, email : Maybe (String)
|
||||
, password : Maybe (String)
|
||||
, phone : Maybe (String)
|
||||
, userStatus : Maybe (Int)
|
||||
}
|
||||
|
||||
|
||||
decoder : Decoder User
|
||||
decoder =
|
||||
Decode.succeed User
|
||||
|> optional "id" (Decode.nullable Decode.int) Nothing
|
||||
|> optional "username" (Decode.nullable Decode.string) Nothing
|
||||
|> optional "firstName" (Decode.nullable Decode.string) Nothing
|
||||
|> optional "lastName" (Decode.nullable Decode.string) Nothing
|
||||
|> optional "email" (Decode.nullable Decode.string) Nothing
|
||||
|> optional "password" (Decode.nullable Decode.string) Nothing
|
||||
|> optional "phone" (Decode.nullable Decode.string) Nothing
|
||||
|> optional "userStatus" (Decode.nullable Decode.int) Nothing
|
||||
|
||||
|
||||
|
||||
encode : User -> Encode.Value
|
||||
encode =
|
||||
Encode.object << encodePairs
|
||||
|
||||
|
||||
encodeWithTag : ( String, String ) -> User -> Encode.Value
|
||||
encodeWithTag (tagField, tag) model =
|
||||
Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ]
|
||||
|
||||
|
||||
encodePairs : User -> List (String, Encode.Value)
|
||||
encodePairs model =
|
||||
[ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) )
|
||||
, ( "username", Maybe.withDefault Encode.null (Maybe.map Encode.string model.username) )
|
||||
, ( "firstName", Maybe.withDefault Encode.null (Maybe.map Encode.string model.firstName) )
|
||||
, ( "lastName", Maybe.withDefault Encode.null (Maybe.map Encode.string model.lastName) )
|
||||
, ( "email", Maybe.withDefault Encode.null (Maybe.map Encode.string model.email) )
|
||||
, ( "password", Maybe.withDefault Encode.null (Maybe.map Encode.string model.password) )
|
||||
, ( "phone", Maybe.withDefault Encode.null (Maybe.map Encode.string model.phone) )
|
||||
, ( "userStatus", Maybe.withDefault Encode.null (Maybe.map Encode.int model.userStatus) )
|
||||
]
|
||||
|
||||
|
||||
|
||||
toString : User -> String
|
||||
toString =
|
||||
Encode.encode 0 << encode
|
||||
|
||||
|
||||
|
||||
|
@ -1,37 +0,0 @@
|
||||
module DateOnly exposing (DateOnly, decoder, encode, toString)
|
||||
|
||||
import Iso8601
|
||||
import Json.Decode as Decode exposing (Decoder)
|
||||
import Json.Encode as Encode
|
||||
import Result
|
||||
import Time
|
||||
|
||||
|
||||
type alias DateOnly =
|
||||
Time.Posix
|
||||
|
||||
|
||||
decoder : Decoder DateOnly
|
||||
decoder =
|
||||
Decode.string
|
||||
|> Decode.andThen decodeIsoString
|
||||
|
||||
|
||||
encode : DateOnly -> Encode.Value
|
||||
encode =
|
||||
Encode.string << toString
|
||||
|
||||
|
||||
decodeIsoString : String -> Decoder DateOnly
|
||||
decodeIsoString str =
|
||||
case Iso8601.toTime (str ++ "T00:00:00.000Z") of
|
||||
Result.Ok posix ->
|
||||
Decode.succeed posix
|
||||
|
||||
Result.Err _ ->
|
||||
Decode.fail <| "Invalid date: " ++ str
|
||||
|
||||
|
||||
toString : DateOnly -> String
|
||||
toString =
|
||||
String.left 10 << Iso8601.fromTime
|
@ -1,37 +0,0 @@
|
||||
module DateTime exposing (DateTime, decoder, encode, toString)
|
||||
|
||||
import Iso8601
|
||||
import Json.Decode as Decode exposing (Decoder)
|
||||
import Json.Encode as Encode
|
||||
import Result
|
||||
import Time
|
||||
|
||||
|
||||
type alias DateTime =
|
||||
Time.Posix
|
||||
|
||||
|
||||
decoder : Decoder DateTime
|
||||
decoder =
|
||||
Decode.string
|
||||
|> Decode.andThen decodeIsoString
|
||||
|
||||
|
||||
encode : DateTime -> Encode.Value
|
||||
encode =
|
||||
Encode.string << toString
|
||||
|
||||
|
||||
decodeIsoString : String -> Decoder DateTime
|
||||
decodeIsoString str =
|
||||
case Iso8601.toTime str of
|
||||
Result.Ok posix ->
|
||||
Decode.succeed posix
|
||||
|
||||
Result.Err _ ->
|
||||
Decode.fail <| "Invalid date: " ++ str
|
||||
|
||||
|
||||
toString : DateTime -> String
|
||||
toString =
|
||||
Iso8601.fromTime
|
@ -1,238 +0,0 @@
|
||||
{-
|
||||
OpenAPI Petstore
|
||||
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
|
||||
The version of the OpenAPI document: 1.0.0
|
||||
|
||||
NOTE: This file is auto generated by the openapi-generator.
|
||||
https://github.com/openapitools/openapi-generator.git
|
||||
Do not edit this file manually.
|
||||
-}
|
||||
|
||||
|
||||
module Request.Pet exposing (addPet, deletePet, findPetsByStatus, Status(..), findPetsByTags, getPetById, updatePet, updatePetWithForm, uploadFile)
|
||||
|
||||
import Data.Pet as Pet exposing (Pet)
|
||||
import Data.ApiResponse as ApiResponse exposing (ApiResponse)
|
||||
import Dict
|
||||
import Http
|
||||
import Json.Decode as Decode
|
||||
import Url.Builder as Url
|
||||
|
||||
|
||||
type Status
|
||||
= StatusAvailable
|
||||
| StatusPending
|
||||
| StatusSold
|
||||
|
||||
stringifyStatus : Status -> String
|
||||
stringifyStatus value =
|
||||
case value of
|
||||
StatusAvailable ->
|
||||
"available"
|
||||
|
||||
StatusPending ->
|
||||
"pending"
|
||||
|
||||
StatusSold ->
|
||||
"sold"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
basePath : String
|
||||
basePath =
|
||||
"http://petstore.swagger.io/v2"
|
||||
|
||||
|
||||
addPet :
|
||||
{ onSend : Result Http.Error () -> msg
|
||||
|
||||
|
||||
, body : Pet
|
||||
|
||||
|
||||
}
|
||||
-> Cmd msg
|
||||
addPet params =
|
||||
Http.request
|
||||
{ method = "POST"
|
||||
, headers = List.filterMap identity []
|
||||
, url = Url.crossOrigin basePath
|
||||
["pet"]
|
||||
(List.filterMap identity [])
|
||||
, body = Http.jsonBody <| Pet.encode params.body
|
||||
, expect = Http.expectWhatever params.onSend
|
||||
, timeout = Just 30000
|
||||
, tracker = Nothing
|
||||
}
|
||||
|
||||
|
||||
deletePet :
|
||||
{ apiKey : Maybe (String)
|
||||
} ->
|
||||
{ onSend : Result Http.Error () -> msg
|
||||
|
||||
|
||||
|
||||
, petId : Int
|
||||
|
||||
}
|
||||
-> Cmd msg
|
||||
deletePet headers params =
|
||||
Http.request
|
||||
{ method = "DELETE"
|
||||
, headers = List.filterMap identity [Maybe.map (Http.header "api_key" << identity) headers.apiKey]
|
||||
, url = Url.crossOrigin basePath
|
||||
["pet", String.fromInt params.petId]
|
||||
(List.filterMap identity [])
|
||||
, body = Http.emptyBody
|
||||
, expect = Http.expectWhatever params.onSend
|
||||
, timeout = Just 30000
|
||||
, tracker = Nothing
|
||||
}
|
||||
|
||||
|
||||
{-| Multiple status values can be provided with comma separated strings
|
||||
-}
|
||||
findPetsByStatus :
|
||||
{ onSend : Result Http.Error (List Pet) -> msg
|
||||
|
||||
|
||||
|
||||
|
||||
, status : List Status
|
||||
}
|
||||
-> Cmd msg
|
||||
findPetsByStatus params =
|
||||
Http.request
|
||||
{ method = "GET"
|
||||
, headers = List.filterMap identity []
|
||||
, url = Url.crossOrigin basePath
|
||||
["pet", "findByStatus"]
|
||||
(List.filterMap identity [(Just << Url.string "status" << String.join "," << List.map stringifyStatus) params.status])
|
||||
, body = Http.emptyBody
|
||||
, expect = Http.expectJson params.onSend (Decode.list Pet.decoder)
|
||||
, timeout = Just 30000
|
||||
, tracker = Nothing
|
||||
}
|
||||
|
||||
|
||||
{-| Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
||||
-}
|
||||
findPetsByTags :
|
||||
{ onSend : Result Http.Error (List Pet) -> msg
|
||||
|
||||
|
||||
|
||||
|
||||
, tags : List String
|
||||
}
|
||||
-> Cmd msg
|
||||
findPetsByTags params =
|
||||
Http.request
|
||||
{ method = "GET"
|
||||
, headers = List.filterMap identity []
|
||||
, url = Url.crossOrigin basePath
|
||||
["pet", "findByTags"]
|
||||
(List.filterMap identity [(Just << Url.string "tags" << String.join "," << List.map identity) params.tags])
|
||||
, body = Http.emptyBody
|
||||
, expect = Http.expectJson params.onSend (Decode.list Pet.decoder)
|
||||
, timeout = Just 30000
|
||||
, tracker = Nothing
|
||||
}
|
||||
|
||||
|
||||
{-| Returns a single pet
|
||||
-}
|
||||
getPetById :
|
||||
{ onSend : Result Http.Error Pet -> msg
|
||||
|
||||
|
||||
|
||||
, petId : Int
|
||||
|
||||
}
|
||||
-> Cmd msg
|
||||
getPetById params =
|
||||
Http.request
|
||||
{ method = "GET"
|
||||
, headers = List.filterMap identity []
|
||||
, url = Url.crossOrigin basePath
|
||||
["pet", String.fromInt params.petId]
|
||||
(List.filterMap identity [])
|
||||
, body = Http.emptyBody
|
||||
, expect = Http.expectJson params.onSend Pet.decoder
|
||||
, timeout = Just 30000
|
||||
, tracker = Nothing
|
||||
}
|
||||
|
||||
|
||||
updatePet :
|
||||
{ onSend : Result Http.Error () -> msg
|
||||
|
||||
|
||||
, body : Pet
|
||||
|
||||
|
||||
}
|
||||
-> Cmd msg
|
||||
updatePet params =
|
||||
Http.request
|
||||
{ method = "PUT"
|
||||
, headers = List.filterMap identity []
|
||||
, url = Url.crossOrigin basePath
|
||||
["pet"]
|
||||
(List.filterMap identity [])
|
||||
, body = Http.jsonBody <| Pet.encode params.body
|
||||
, expect = Http.expectWhatever params.onSend
|
||||
, timeout = Just 30000
|
||||
, tracker = Nothing
|
||||
}
|
||||
|
||||
|
||||
updatePetWithForm :
|
||||
{ onSend : Result Http.Error () -> msg
|
||||
|
||||
|
||||
|
||||
, petId : Int
|
||||
|
||||
}
|
||||
-> Cmd msg
|
||||
updatePetWithForm params =
|
||||
Http.request
|
||||
{ method = "POST"
|
||||
, headers = List.filterMap identity []
|
||||
, url = Url.crossOrigin basePath
|
||||
["pet", String.fromInt params.petId]
|
||||
(List.filterMap identity [])
|
||||
, body = Http.emptyBody
|
||||
, expect = Http.expectWhatever params.onSend
|
||||
, timeout = Just 30000
|
||||
, tracker = Nothing
|
||||
}
|
||||
|
||||
|
||||
uploadFile :
|
||||
{ onSend : Result Http.Error ApiResponse -> msg
|
||||
|
||||
|
||||
|
||||
, petId : Int
|
||||
|
||||
}
|
||||
-> Cmd msg
|
||||
uploadFile params =
|
||||
Http.request
|
||||
{ method = "POST"
|
||||
, headers = List.filterMap identity []
|
||||
, url = Url.crossOrigin basePath
|
||||
["pet", String.fromInt params.petId, "uploadImage"]
|
||||
(List.filterMap identity [])
|
||||
, body = Http.emptyBody
|
||||
, expect = Http.expectJson params.onSend ApiResponse.decoder
|
||||
, timeout = Just 30000
|
||||
, tracker = Nothing
|
||||
}
|
@ -1,124 +0,0 @@
|
||||
{-
|
||||
OpenAPI Petstore
|
||||
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
|
||||
The version of the OpenAPI document: 1.0.0
|
||||
|
||||
NOTE: This file is auto generated by the openapi-generator.
|
||||
https://github.com/openapitools/openapi-generator.git
|
||||
Do not edit this file manually.
|
||||
-}
|
||||
|
||||
|
||||
module Request.Store exposing (deleteOrder, getInventory, getOrderById, placeOrder)
|
||||
|
||||
import Data.Order_ as Order_ exposing (Order_)
|
||||
import Dict
|
||||
import Http
|
||||
import Json.Decode as Decode
|
||||
import Url.Builder as Url
|
||||
|
||||
|
||||
|
||||
|
||||
basePath : String
|
||||
basePath =
|
||||
"http://petstore.swagger.io/v2"
|
||||
|
||||
|
||||
{-| For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
-}
|
||||
deleteOrder :
|
||||
{ onSend : Result Http.Error () -> msg
|
||||
|
||||
|
||||
|
||||
, orderId : String
|
||||
|
||||
}
|
||||
-> Cmd msg
|
||||
deleteOrder params =
|
||||
Http.request
|
||||
{ method = "DELETE"
|
||||
, headers = List.filterMap identity []
|
||||
, url = Url.crossOrigin basePath
|
||||
["store", "order", identity params.orderId]
|
||||
(List.filterMap identity [])
|
||||
, body = Http.emptyBody
|
||||
, expect = Http.expectWhatever params.onSend
|
||||
, timeout = Just 30000
|
||||
, tracker = Nothing
|
||||
}
|
||||
|
||||
|
||||
{-| Returns a map of status codes to quantities
|
||||
-}
|
||||
getInventory :
|
||||
{ onSend : Result Http.Error (Dict.Dict String Int) -> msg
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
-> Cmd msg
|
||||
getInventory params =
|
||||
Http.request
|
||||
{ method = "GET"
|
||||
, headers = List.filterMap identity []
|
||||
, url = Url.crossOrigin basePath
|
||||
["store", "inventory"]
|
||||
(List.filterMap identity [])
|
||||
, body = Http.emptyBody
|
||||
, expect = Http.expectJson params.onSend (Decode.dict Decode.int)
|
||||
, timeout = Just 30000
|
||||
, tracker = Nothing
|
||||
}
|
||||
|
||||
|
||||
{-| For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions
|
||||
-}
|
||||
getOrderById :
|
||||
{ onSend : Result Http.Error Order_ -> msg
|
||||
|
||||
|
||||
|
||||
, orderId : Int
|
||||
|
||||
}
|
||||
-> Cmd msg
|
||||
getOrderById params =
|
||||
Http.request
|
||||
{ method = "GET"
|
||||
, headers = List.filterMap identity []
|
||||
, url = Url.crossOrigin basePath
|
||||
["store", "order", String.fromInt params.orderId]
|
||||
(List.filterMap identity [])
|
||||
, body = Http.emptyBody
|
||||
, expect = Http.expectJson params.onSend Order_.decoder
|
||||
, timeout = Just 30000
|
||||
, tracker = Nothing
|
||||
}
|
||||
|
||||
|
||||
placeOrder :
|
||||
{ onSend : Result Http.Error Order_ -> msg
|
||||
|
||||
|
||||
, body : Order_
|
||||
|
||||
|
||||
}
|
||||
-> Cmd msg
|
||||
placeOrder params =
|
||||
Http.request
|
||||
{ method = "POST"
|
||||
, headers = List.filterMap identity []
|
||||
, url = Url.crossOrigin basePath
|
||||
["store", "order"]
|
||||
(List.filterMap identity [])
|
||||
, body = Http.jsonBody <| Order_.encode params.body
|
||||
, expect = Http.expectJson params.onSend Order_.decoder
|
||||
, timeout = Just 30000
|
||||
, tracker = Nothing
|
||||
}
|
@ -1,216 +0,0 @@
|
||||
{-
|
||||
OpenAPI Petstore
|
||||
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
|
||||
The version of the OpenAPI document: 1.0.0
|
||||
|
||||
NOTE: This file is auto generated by the openapi-generator.
|
||||
https://github.com/openapitools/openapi-generator.git
|
||||
Do not edit this file manually.
|
||||
-}
|
||||
|
||||
|
||||
module Request.User exposing (createUser, createUsersWithArrayInput, createUsersWithListInput, deleteUser, getUserByName, loginUser, logoutUser, updateUser)
|
||||
|
||||
import Data.User as User exposing (User)
|
||||
import Dict
|
||||
import Http
|
||||
import Json.Decode as Decode
|
||||
import Url.Builder as Url
|
||||
|
||||
|
||||
|
||||
|
||||
basePath : String
|
||||
basePath =
|
||||
"http://petstore.swagger.io/v2"
|
||||
|
||||
|
||||
{-| This can only be done by the logged in user.
|
||||
-}
|
||||
createUser :
|
||||
{ onSend : Result Http.Error () -> msg
|
||||
|
||||
|
||||
, body : User
|
||||
|
||||
|
||||
}
|
||||
-> Cmd msg
|
||||
createUser params =
|
||||
Http.request
|
||||
{ method = "POST"
|
||||
, headers = List.filterMap identity []
|
||||
, url = Url.crossOrigin basePath
|
||||
["user"]
|
||||
(List.filterMap identity [])
|
||||
, body = Http.jsonBody <| User.encode params.body
|
||||
, expect = Http.expectWhatever params.onSend
|
||||
, timeout = Just 30000
|
||||
, tracker = Nothing
|
||||
}
|
||||
|
||||
|
||||
createUsersWithArrayInput :
|
||||
{ onSend : Result Http.Error () -> msg
|
||||
|
||||
|
||||
, body : User
|
||||
|
||||
|
||||
}
|
||||
-> Cmd msg
|
||||
createUsersWithArrayInput params =
|
||||
Http.request
|
||||
{ method = "POST"
|
||||
, headers = List.filterMap identity []
|
||||
, url = Url.crossOrigin basePath
|
||||
["user", "createWithArray"]
|
||||
(List.filterMap identity [])
|
||||
, body = Http.jsonBody <| User.encode params.body
|
||||
, expect = Http.expectWhatever params.onSend
|
||||
, timeout = Just 30000
|
||||
, tracker = Nothing
|
||||
}
|
||||
|
||||
|
||||
createUsersWithListInput :
|
||||
{ onSend : Result Http.Error () -> msg
|
||||
|
||||
|
||||
, body : User
|
||||
|
||||
|
||||
}
|
||||
-> Cmd msg
|
||||
createUsersWithListInput params =
|
||||
Http.request
|
||||
{ method = "POST"
|
||||
, headers = List.filterMap identity []
|
||||
, url = Url.crossOrigin basePath
|
||||
["user", "createWithList"]
|
||||
(List.filterMap identity [])
|
||||
, body = Http.jsonBody <| User.encode params.body
|
||||
, expect = Http.expectWhatever params.onSend
|
||||
, timeout = Just 30000
|
||||
, tracker = Nothing
|
||||
}
|
||||
|
||||
|
||||
{-| This can only be done by the logged in user.
|
||||
-}
|
||||
deleteUser :
|
||||
{ onSend : Result Http.Error () -> msg
|
||||
|
||||
|
||||
|
||||
, username : String
|
||||
|
||||
}
|
||||
-> Cmd msg
|
||||
deleteUser params =
|
||||
Http.request
|
||||
{ method = "DELETE"
|
||||
, headers = List.filterMap identity []
|
||||
, url = Url.crossOrigin basePath
|
||||
["user", identity params.username]
|
||||
(List.filterMap identity [])
|
||||
, body = Http.emptyBody
|
||||
, expect = Http.expectWhatever params.onSend
|
||||
, timeout = Just 30000
|
||||
, tracker = Nothing
|
||||
}
|
||||
|
||||
|
||||
getUserByName :
|
||||
{ onSend : Result Http.Error User -> msg
|
||||
|
||||
|
||||
|
||||
, username : String
|
||||
|
||||
}
|
||||
-> Cmd msg
|
||||
getUserByName params =
|
||||
Http.request
|
||||
{ method = "GET"
|
||||
, headers = List.filterMap identity []
|
||||
, url = Url.crossOrigin basePath
|
||||
["user", identity params.username]
|
||||
(List.filterMap identity [])
|
||||
, body = Http.emptyBody
|
||||
, expect = Http.expectJson params.onSend User.decoder
|
||||
, timeout = Just 30000
|
||||
, tracker = Nothing
|
||||
}
|
||||
|
||||
|
||||
loginUser :
|
||||
{ onSend : Result Http.Error String -> msg
|
||||
|
||||
|
||||
|
||||
|
||||
, username : String , password : String
|
||||
}
|
||||
-> Cmd msg
|
||||
loginUser params =
|
||||
Http.request
|
||||
{ method = "GET"
|
||||
, headers = List.filterMap identity []
|
||||
, url = Url.crossOrigin basePath
|
||||
["user", "login"]
|
||||
(List.filterMap identity [(Just << Url.string "username" << identity) params.username, (Just << Url.string "password" << identity) params.password])
|
||||
, body = Http.emptyBody
|
||||
, expect = Http.expectJson params.onSend Decode.string
|
||||
, timeout = Just 30000
|
||||
, tracker = Nothing
|
||||
}
|
||||
|
||||
|
||||
logoutUser :
|
||||
{ onSend : Result Http.Error () -> msg
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
-> Cmd msg
|
||||
logoutUser params =
|
||||
Http.request
|
||||
{ method = "GET"
|
||||
, headers = List.filterMap identity []
|
||||
, url = Url.crossOrigin basePath
|
||||
["user", "logout"]
|
||||
(List.filterMap identity [])
|
||||
, body = Http.emptyBody
|
||||
, expect = Http.expectWhatever params.onSend
|
||||
, timeout = Just 30000
|
||||
, tracker = Nothing
|
||||
}
|
||||
|
||||
|
||||
{-| This can only be done by the logged in user.
|
||||
-}
|
||||
updateUser :
|
||||
{ onSend : Result Http.Error () -> msg
|
||||
|
||||
|
||||
, body : User
|
||||
, username : String
|
||||
|
||||
}
|
||||
-> Cmd msg
|
||||
updateUser params =
|
||||
Http.request
|
||||
{ method = "PUT"
|
||||
, headers = List.filterMap identity []
|
||||
, url = Url.crossOrigin basePath
|
||||
["user", identity params.username]
|
||||
(List.filterMap identity [])
|
||||
, body = Http.jsonBody <| User.encode params.body
|
||||
, expect = Http.expectWhatever params.onSend
|
||||
, timeout = Just 30000
|
||||
, tracker = Nothing
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user