Add Elm language - BETA (#6947)

This is the initial Codegen for Elm 0.18.
Please try it out and provide feedback.

Not yet supported:

* path variables;
* additionalProperties;
* authentication;
* recursive types.
This commit is contained in:
Erik Timmers 2017-12-20 15:26:46 +01:00 committed by William Cheng
parent 538f28e568
commit d6539ba3c8
46 changed files with 1933 additions and 0 deletions

31
bin/elm-petstore.sh Executable file
View File

@ -0,0 +1,31 @@
#!/bin/sh
SCRIPT="$0"
while [ -h "$SCRIPT" ] ; do
ls=`ls -ld "$SCRIPT"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
SCRIPT="$link"
else
SCRIPT=`dirname "$SCRIPT"`/"$link"
fi
done
if [ ! -d "${APP_DIR}" ]; then
APP_DIR=`dirname "$SCRIPT"`/..
APP_DIR=`cd "${APP_DIR}"; pwd`
fi
executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"
if [ ! -f "$executable" ]
then
mvn clean package
fi
# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l elm -o samples/client/petstore/elm"
java $JAVA_OPTS -jar $executable $ags

10
bin/windows/elm-petstore.bat Executable file
View File

@ -0,0 +1,10 @@
set executable=.\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar
If Not Exist %executable% (
mvn clean package
)
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
set ags=generate -i modules\swagger-codegen\src\test\resources\2_0\petstore.yaml -l elm -o samples\client\petstore\elm
java %JAVA_OPTS% -jar %executable% %ags%

View File

@ -49,6 +49,7 @@ public class CodegenProperty implements Cloneable {
public Map<String, Object> vendorExtensions;
public boolean hasValidation; // true if pattern, maximum, etc are set (only used in the mustache template)
public boolean isInherited;
public String discriminatorValue;
public String nameInCamelCase; // property name in camel case
// enum name based on the property name, usually use as a prefix (e.g. VAR_NAME) for enum name (e.g. VAR_NAME_VALUE1)
public String enumName;
@ -131,6 +132,7 @@ public class CodegenProperty implements Cloneable {
result = prime * result + ((isMapContainer ? 13:31));
result = prime * result + ((isListContainer ? 13:31));
result = prime * result + Objects.hashCode(isInherited);
result = prime * result + Objects.hashCode(discriminatorValue);
result = prime * result + Objects.hashCode(nameInCamelCase);
result = prime * result + Objects.hashCode(enumName);
result = prime * result + ((maxItems == null) ? 0 : maxItems.hashCode());
@ -312,6 +314,9 @@ public class CodegenProperty implements Cloneable {
if (!Objects.equals(this.isInherited, other.isInherited)) {
return false;
}
if (!Objects.equals(this.discriminatorValue, other.discriminatorValue)) {
return false;
}
if (!Objects.equals(this.nameInCamelCase, other.nameInCamelCase)) {
return false;
}

View File

@ -0,0 +1,511 @@
package io.swagger.codegen.languages;
import io.swagger.codegen.CodegenConfig;
import io.swagger.codegen.CodegenModel;
import io.swagger.codegen.CodegenOperation;
import io.swagger.codegen.CodegenParameter;
import io.swagger.codegen.CodegenProperty;
import io.swagger.codegen.CodegenResponse;
import io.swagger.codegen.CodegenType;
import io.swagger.codegen.DefaultCodegen;
import io.swagger.codegen.SupportingFile;
import io.swagger.models.Response;
import io.swagger.models.parameters.Parameter;
import io.swagger.models.properties.ArrayProperty;
import io.swagger.models.properties.BooleanProperty;
import io.swagger.models.properties.DateProperty;
import io.swagger.models.properties.DateTimeProperty;
import io.swagger.models.properties.DoubleProperty;
import io.swagger.models.properties.FloatProperty;
import io.swagger.models.properties.IntegerProperty;
import io.swagger.models.properties.LongProperty;
import io.swagger.models.properties.MapProperty;
import io.swagger.models.properties.Property;
import io.swagger.models.properties.StringProperty;
import java.io.File;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
private static final String X_ENCODER = "x-encoder";
private static final String X_DECODER = "x-decoder";
private static final String X_DISCRIMINATOR_TYPE = "x-discriminator-value";
private static final String X_UNION_TYPE = "x-union-type";
private Set<String> customPrimitives = new HashSet<String>();
protected String packageName = "swagger";
protected String packageVersion = "1.0.0";
public CodegenType getTag() {
return CodegenType.CLIENT;
}
@Override
public String getName() {
return "elm";
}
public String getHelp() {
return "Generates a Elm client library (beta).";
}
public ElmClientCodegen() {
super();
outputFolder = "generated-code/elm";
modelTemplateFiles.put("model.mustache", ".elm");
apiTemplateFiles.put("api.mustache", ".elm");
templateDir = "elm";
supportsInheritance = true;
reservedWords = new HashSet<>(
Arrays.asList(
"if", "then", "else",
"case", "of",
"let", "in",
"type",
"module", "where",
"import", "exposing",
"as",
"port")
);
defaultIncludes = new HashSet<>(
Arrays.asList(
"List")
);
languageSpecificPrimitives = new HashSet<>(
Arrays.asList(
"Bool",
"Dict",
"Float",
"Int",
"String")
);
customPrimitives = new HashSet<>(
Arrays.asList(
"Byte",
"DateOnly",
"DateTime")
);
instantiationTypes.clear();
typeMapping.clear();
typeMapping.put("integer", "Int");
typeMapping.put("long", "Int");
typeMapping.put("number", "Float");
typeMapping.put("float", "Float");
typeMapping.put("double", "Float");
typeMapping.put("boolean", "Bool");
typeMapping.put("string", "String");
typeMapping.put("array", "List");
typeMapping.put("date", "DateOnly");
typeMapping.put("DateTime", "DateTime");
typeMapping.put("password", "String");
typeMapping.put("file", "String");
typeMapping.put("ByteArray", "Byte");
typeMapping.put("binary", "String");
importMapping.clear();
cliOptions.clear();
supportingFiles.add(new SupportingFile("Byte.mustache", "src", "Byte.elm"));
supportingFiles.add(new SupportingFile("DateOnly.mustache", "src", "DateOnly.elm"));
supportingFiles.add(new SupportingFile("DateTime.mustache", "src", "DateTime.elm"));
supportingFiles.add(new SupportingFile("Main.mustache", "src", "Main.elm"));
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
supportingFiles.add(new SupportingFile("elm-package.mustache", "", "elm-package.json"));
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
}
@Override
public String escapeUnsafeCharacters(String input) {
return input.replace("*/", "*_/").replace("/*", "/_*");
}
@Override
public String escapeQuotationMark(String input) {
return input.replace("\"", "");
}
@Override
public String toApiName(String name) {
if (name.length() == 0) {
return "Default";
}
return initialCaps(name);
}
@Override
public String toModelName(String name) {
return camelize(name);
}
@Override
public String toModelFilename(String name) {
return toModelName(name);
}
@Override
public String toEnumName(CodegenProperty property) {
return toModelName(property.name);
}
@Override
public String toVarName(String name) {
final String varName = camelize(name, true);
return isReservedWord(varName) ? escapeReservedWord(name) : varName;
}
@Override
public String toEnumVarName(String value, String datatype) {
final String camelized = camelize(value.replace(" ", "_").replace("(", "_").replace(")", "")); // TODO FIXME escape properly
if (!Character.isUpperCase(camelized.charAt(0))) {
return "N" + camelized;
}
return camelized;
}
@Override
public String escapeReservedWord(String name) {
return name + "_";
}
@Override
public String apiFileFolder() {
return outputFolder + "/src/Request/" + apiPackage().replace('.', File.separatorChar);
}
@Override
public String modelFileFolder() {
return outputFolder + "/src/Data/" + modelPackage().replace('.', File.separatorChar);
}
@SuppressWarnings({ "static-method", "unchecked" })
public Map<String, Object> postProcessAllModels(Map<String, Object> objs) {
// Index all CodegenModels by model name.
Map<String, CodegenModel> allModels = new HashMap<>();
for (Map.Entry<String, Object> entry : objs.entrySet()) {
String modelName = toModelName(entry.getKey());
Map<String, Object> inner = (Map<String, Object>) entry.getValue();
List<Map<String, Object>> models = (List<Map<String, Object>>) inner.get("models");
for (Map<String, Object> mo : models) {
CodegenModel cm = (CodegenModel) mo.get("model");
allModels.put(modelName, cm);
}
}
// Let parent know about all its children
for (CodegenModel cm : allModels.values()) {
CodegenModel parent = allModels.get(cm.parent);
if (parent != null) {
if (parent.children == null) {
parent.children = new ArrayList<>();
parent.hasChildren = true;
}
parent.children.add(cm);
Collections.sort(parent.children, new Comparator<CodegenModel>() {
@Override
public int compare(CodegenModel cm1, CodegenModel cm2) {
return Collator.getInstance().compare(cm1.classname, cm2.classname);
}
});
}
}
for (Map.Entry<String, Object> entry : objs.entrySet()) {
Map<String, Object> inner = (Map<String, Object>) entry.getValue();
List<Map<String, Object>> models = (List<Map<String, Object>>) inner.get("models");
for (Map<String, Object> mo : models) {
CodegenModel cm = (CodegenModel) mo.get("model");
if (cm.isEnum) {
this.addEncoderAndDecoder(cm.vendorExtensions, cm.classname, false);
cm.vendorExtensions.put(X_UNION_TYPE, cm.classname);
} else if (cm.isAlias) {
this.addEncoderAndDecoder(cm.vendorExtensions, cm.dataType, true);
}
List<ElmImport> elmImports = new ArrayList<>();
for (CodegenProperty property : cm.allVars) {
if (property.complexType != null) {
elmImports.add(createPropertyImport(property));
}
}
if (cm.discriminator != null) {
for (CodegenModel child : cm.children) {
// add child imports
final ElmImport elmImport = new ElmImport();
final String modulePrefix = customPrimitives.contains(child.classname) ? "" : "Data.";
elmImport.moduleName = modulePrefix + child.classname;
elmImport.exposures = new TreeSet<>();
elmImport.exposures.add(child.classname);
elmImport.exposures.add(child.classVarName + "Decoder");
elmImport.exposures.add(child.classVarName + "Encoder");
elmImport.hasExposures = true;
elmImports.add(elmImport);
// set discriminator value to all children (recursively)
this.setDiscriminatorValue(child, cm.discriminator, this.getDiscriminatorValue(child));
// add all non-discriminator vars
int index = 0;
for (CodegenProperty property : cm.vars) {
if (!cm.discriminator.equals(property.baseName)) {
child.vars.add(index++, property);
}
}
}
}
inner.put("elmImports", elmImports);
}
}
return objs;
}
private void setDiscriminatorValue(CodegenModel model, String baseName, String value) {
for (CodegenProperty prop : model.vars) {
if (prop.baseName.equals(baseName)) {
prop.discriminatorValue = value;
}
}
for (CodegenProperty prop : model.allVars) {
if (prop.baseName.equals(baseName)) {
prop.discriminatorValue = value;
}
}
if (model.children != null) {
final boolean newDiscriminator = model.discriminator != null;
for (CodegenModel child : model.children) {
this.setDiscriminatorValue(child, baseName, newDiscriminator ? value : this.getDiscriminatorValue(child));
}
}
}
private String getDiscriminatorValue(CodegenModel model) {
return model.vendorExtensions.containsKey(X_DISCRIMINATOR_TYPE) ?
(String) model.vendorExtensions.get(X_DISCRIMINATOR_TYPE) : model.classname;
}
private ElmImport createPropertyImport(final CodegenProperty property) {
final ElmImport elmImport = new ElmImport();
final String modulePrefix = customPrimitives.contains(property.complexType) ? "" : "Data.";
elmImport.moduleName = modulePrefix + property.complexType;
elmImport.exposures = new TreeSet<>();
elmImport.exposures.add(property.complexType);
if (property.vendorExtensions.containsKey(X_DECODER)) {
elmImport.exposures.add((String) property.vendorExtensions.get(X_DECODER));
}
if (property.vendorExtensions.containsKey(X_ENCODER)) {
elmImport.exposures.add((String) property.vendorExtensions.get(X_ENCODER));
}
elmImport.hasExposures = true;
return elmImport;
}
@Override
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
return postProcessModelsEnum(objs);
}
@Override
@SuppressWarnings({ "static-method", "unchecked" })
public Map<String, Object> postProcessOperations(Map<String, Object> operations) {
Map<String, Object> objs = (Map<String, Object>) operations.get("operations");
List<CodegenOperation> ops = (List<CodegenOperation>) objs.get("operation");
Map<String, Set<String>> dependencies = new HashMap<>();
for (CodegenOperation op : ops) {
String path = op.path;
for (CodegenParameter param : op.pathParams) {
final String var = param.isString ? param.paramName : "toString " + param.paramName;
path = path.replace("{" + param.paramName + "}", "\" ++ " + var + " ++ \"");
}
op.path = ("\"" + path + "\"").replaceAll(" \\+\\+ \"\"", "");
if (op.bodyParam != null) {
final String encoder = (String) op.bodyParam.vendorExtensions.get(X_ENCODER);
if (encoder != null) {
if (!dependencies.containsKey(op.bodyParam.dataType)) {
dependencies.put(op.bodyParam.dataType, new TreeSet<String>());
}
dependencies.get(op.bodyParam.dataType).add(encoder);
}
}
for (CodegenResponse resp : op.responses) {
final String decoder = (String) resp.vendorExtensions.get(X_DECODER);
if (decoder != null) {
if (!dependencies.containsKey(resp.dataType)) {
dependencies.put(resp.dataType, new TreeSet<String>());
}
dependencies.get(resp.dataType).add(decoder);
}
}
}
List<ElmImport> elmImports = new ArrayList<>();
for (Map.Entry<String, Set<String>> entry : dependencies.entrySet()) {
final ElmImport elmImport = new ElmImport();
final String key = entry.getKey();
elmImport.moduleName = "Data." + key;
elmImport.exposures = entry.getValue();
elmImport.exposures.add(key);
elmImport.hasExposures = true;
elmImports.add(elmImport);
}
operations.put("elmImports", elmImports);
return operations;
}
@Override
public String toDefaultValue(Property p) {
if (p instanceof StringProperty) {
StringProperty sp = (StringProperty) p;
if (sp.getDefault() != null) {
return toOptionalValue("\"" + sp.getDefault().toString() + "\"");
}
return toOptionalValue(null);
} else if (p instanceof BooleanProperty) {
BooleanProperty bp = (BooleanProperty) p;
if (bp.getDefault() != null) {
return toOptionalValue(bp.getDefault() ? "True" : "False");
}
return toOptionalValue(null);
} else if (p instanceof DateProperty) {
return toOptionalValue(null);
} else if (p instanceof DateTimeProperty) {
return toOptionalValue(null);
} else if (p instanceof DoubleProperty) {
DoubleProperty dp = (DoubleProperty) p;
if (dp.getDefault() != null) {
return toOptionalValue(dp.getDefault().toString());
}
return toOptionalValue(null);
} else if (p instanceof FloatProperty) {
FloatProperty fp = (FloatProperty) p;
if (fp.getDefault() != null) {
return toOptionalValue(fp.getDefault().toString());
}
return toOptionalValue(null);
} else if (p instanceof IntegerProperty) {
IntegerProperty ip = (IntegerProperty) p;
if (ip.getDefault() != null) {
return toOptionalValue(ip.getDefault().toString());
}
return toOptionalValue(null);
} else if (p instanceof LongProperty) {
LongProperty lp = (LongProperty) p;
if (lp.getDefault() != null) {
return toOptionalValue(lp.getDefault().toString());
}
return toOptionalValue(null);
} else {
return toOptionalValue(null);
}
}
private String toOptionalValue(String value) {
if (value == null) {
return "Nothing";
}
return "(Just " + value + ")";
}
@Override
public String getSwaggerType(Property p) {
String swaggerType = super.getSwaggerType(p);
String type;
if (typeMapping.containsKey(swaggerType)) {
type = typeMapping.get(swaggerType);
if (languageSpecificPrimitives.contains(type)) {
return type;
}
} else
type = swaggerType;
return toModelName(type);
}
@Override
public String getTypeDeclaration(Property p) {
if (p instanceof ArrayProperty) {
ArrayProperty ap = (ArrayProperty) p;
Property inner = ap.getItems();
return getTypeDeclaration(inner);
} else if (p instanceof MapProperty) {
MapProperty mp = (MapProperty) p;
Property inner = mp.getAdditionalProperties();
return getTypeDeclaration(inner);
}
return super.getTypeDeclaration(p);
}
@Override
public CodegenProperty fromProperty(String name, Property p) {
final CodegenProperty property = super.fromProperty(name, p);
final String dataType = property.isEnum ? property.baseName : property.datatype;
addEncoderAndDecoder(property.vendorExtensions, dataType, property.isPrimitiveType && !property.isEnum);
if (property.isEnum) {
property.vendorExtensions.put(X_UNION_TYPE, property.datatypeWithEnum);
}
return property;
}
@Override
public CodegenResponse fromResponse(String responseCode, Response resp) {
final CodegenResponse response = super.fromResponse(responseCode, resp);
if (response.dataType != null) {
addEncoderAndDecoder(response.vendorExtensions, response.dataType, response.primitiveType);
}
return response;
}
@Override
public CodegenParameter fromParameter(Parameter param, Set<String> imports) {
final CodegenParameter parameter = super.fromParameter(param, imports);
addEncoderAndDecoder(parameter.vendorExtensions, parameter.dataType, parameter.isPrimitiveType);
return parameter;
}
private void addEncoderAndDecoder(Map<String, Object> vendorExtensions, String dataType, Boolean isPrimitiveType) {
final String baseName = camelize(dataType, true);
String encoderName;
String decoderName;
if (isPrimitiveType) {
encoderName = "Encode." + baseName;
decoderName = "Decode." + baseName;
} else {
encoderName = baseName + "Encoder";
decoderName = baseName + "Decoder";
}
if (!vendorExtensions.containsKey(X_ENCODER)) {
vendorExtensions.put(X_ENCODER, encoderName);
}
if (!vendorExtensions.containsKey(X_DECODER)) {
vendorExtensions.put(X_DECODER, decoderName);
}
}
private static class ElmImport {
public String moduleName;
public String as;
public Set<String> exposures;
public Boolean hasExposures;
}
}

View File

@ -12,6 +12,7 @@ io.swagger.codegen.languages.CppRestClientCodegen
io.swagger.codegen.languages.CsharpDotNet2ClientCodegen
io.swagger.codegen.languages.DartClientCodegen
io.swagger.codegen.languages.ElixirClientCodegen
io.swagger.codegen.languages.ElmClientCodegen
io.swagger.codegen.languages.EiffelClientCodegen
io.swagger.codegen.languages.ErlangClientCodegen
io.swagger.codegen.languages.ErlangServerCodegen

View File

@ -0,0 +1,18 @@
module Byte exposing (Byte, byteDecoder, byteEncoder)
import Json.Decode as Decode exposing (Decoder)
import Json.Encode as Encode
type alias Byte = String
byteDecoder : Decoder Byte
byteDecoder =
Decode.string
byteEncoder : Byte -> Encode.Value
byteEncoder model =
Encode.string model

View File

@ -0,0 +1,34 @@
module DateOnly exposing (DateOnly, dateOnlyDecoder, dateOnlyEncoder)
import Date
import Date.Extra exposing (fromIsoString, toFormattedString)
import Json.Decode as Decode exposing (Decoder)
import Json.Encode as Encode
type alias DateOnly =
Date.Date
dateOnlyDecoder : Decoder DateOnly
dateOnlyDecoder =
Decode.string
|> Decode.andThen decodeIsoString
dateOnlyEncoder : DateOnly -> Encode.Value
dateOnlyEncoder model =
Encode.string <| toFormattedString "yyyy-MM-dd" model
decodeIsoString : String -> Decoder DateOnly
decodeIsoString str =
case fromIsoString str of
Just date ->
Decode.succeed date
Nothing ->
Decode.fail <|
"Cannot convert "
++ str
++ " to DateOnly"

View File

@ -0,0 +1,34 @@
module DateTime exposing (DateTime, dateTimeDecoder, dateTimeEncoder)
import Date
import Date.Extra exposing (fromIsoString, toIsoString)
import Json.Decode as Decode exposing (Decoder)
import Json.Encode as Encode
type alias DateTime =
Date.Date
dateTimeDecoder : Decoder DateTime
dateTimeDecoder =
Decode.string
|> Decode.andThen decodeIsoString
dateTimeEncoder : DateTime -> Encode.Value
dateTimeEncoder model =
Encode.string <| toIsoString model
decodeIsoString : String -> Decoder DateTime
decodeIsoString str =
case fromIsoString str of
Just date ->
Decode.succeed date
Nothing ->
Decode.fail <|
"Cannot convert "
++ str
++ " to DateTime"

View File

@ -0,0 +1,43 @@
module Main exposing (..)
import Json.Decode as Decode
import Html exposing (Html, button, div, text)
import Html.Events exposing (onClick)
import Http
main : Program Never Model Msg
main =
Html.program
{ init = init
, view = view
, update = update
, subscriptions = subscriptions
}
type alias Model =
{ status : Maybe Int
}
init : (Model, Cmd Msg)
init =
( Model Nothing, Cmd.none )
type Msg
= NoOp
update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
case msg of
NoOp
( model, Cmd.none )
view : Model -> Html Msg
view model =
Html.text "main"
subscriptions : Model -> Sub Msg
subscriptions model =
Sub.none

View File

@ -0,0 +1,18 @@
# Elm API client
{{#appDescription}}
{{{appDescription}}}
{{/appDescription}}
## Overview
This API client was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the [swagger-spec](https://github.com/swagger-api/swagger-spec) from a remote server, you can easily generate an API client.
- API version: {{appVersion}}
- Package version: {{packageVersion}}
{{^hideGenerationTimestamp}}
- Build date: {{generatedDate}}
{{/hideGenerationTimestamp}}
- Build package: {{generatorClass}}
{{#infoUrl}}
For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
{{/infoUrl}}

View File

@ -0,0 +1,5 @@
{{classVarName}}Decoder : Decoder {{classname}}
{{classVarName}}Decoder =
decode {{classname}}
{{#allVars}}{{^discriminatorValue}} |> {{>fieldDecoder}}
{{/discriminatorValue}}{{/allVars}}

View File

@ -0,0 +1,7 @@
{{classVarName}}Encoder : {{classname}} -> Encode.Value
{{classVarName}}Encoder model =
Encode.object
{{#allVars}}
{{#-first}}[{{/-first}}{{^-first}},{{/-first}} {{>fieldEncoder}}
{{/allVars}}
]

View File

@ -0,0 +1,33 @@
{{>licenseInfo}}
module Request.{{classname}} exposing ({{#operations}}{{#operation}}{{^-first}}, {{/-first}}{{operationId}}{{/operation}}{{/operations}})
{{>imports}}import Http
import Json.Decode as Decode
basePath : String
basePath =
"{{basePath}}"
{{#operations}}
{{#operation}}
{-
{{notes}}
-}
{{operationId}} : {{#pathParams}}{{dataType}} -> {{/pathParams}}{{#bodyParam}}{{dataType}} -> {{/bodyParam}}Http.Request {{#responses}}{{#-first}}{{^dataType}}(){{/dataType}}{{#isListContainer}}(List {{/isListContainer}}{{dataType}}{{#isListContainer}}){{/isListContainer}}{{/-first}}{{/responses}}
{{operationId}} {{#pathParams}}{{paramName}} {{/pathParams}}{{#bodyParam}}model {{/bodyParam}}=
{ method = "{{httpMethod}}"
, url = basePath ++ {{{path}}}
, headers = []
, body = {{#bodyParam}}Http.jsonBody <| {{vendorExtensions.x-encoder}} model{{/bodyParam}}{{^bodyParam}}Http.emptyBody{{/bodyParam}}
, expect = {{#responses}}{{#-first}}{{^dataType}}Http.expectStringResponse (\_ -> Ok ()){{/dataType}}{{#dataType}}Http.expectJson {{#isListContainer}}(Decode.list {{/isListContainer}}{{#vendorExtensions}}{{x-decoder}}{{/vendorExtensions}}{{#isListContainer}}){{/isListContainer}}{{/dataType}}{{/-first}}{{/responses}}
, timeout = Just 30000
, withCredentials = False
}
|> Http.request
{{/operation}}
{{/operations}}

View File

@ -0,0 +1,18 @@
{
"version": "1.0.0",
"summary": "helpful summary of your project, less than 80 characters",
"repository": "https://github.com/user/project.git",
"license": "BSD3",
"source-directories": [
"src"
],
"exposed-modules": [],
"dependencies": {
"NoRedInk/elm-decode-pipeline": "3.0.0 <= v < 4.0.0",
"elm-lang/core": "5.1.1 <= v < 6.0.0",
"elm-lang/html": "2.0.0 <= v < 3.0.0",
"elm-lang/http": "1.0.0 <= v < 2.0.0",
"justinmimbs/elm-date-extra": "2.0.3 <= v < 3.0.0"
},
"elm-version": "0.18.0 <= v < 0.19.0"
}

View File

@ -0,0 +1 @@
{{#required}}required{{/required}}{{^required}}optional{{/required}} "{{baseName}}" {{^required}}(Decode.nullable {{/required}}{{#isContainer}}(Decode.list {{/isContainer}}{{vendorExtensions.x-decoder}}{{#isContainer}}){{/isContainer}}{{^required}}){{/required}}{{^required}} {{{defaultValue}}}{{/required}}

View File

@ -0,0 +1 @@
( "{{baseName}}", {{#discriminatorValue}}Encode.string "{{discriminatorValue}}"{{/discriminatorValue}}{{^discriminatorValue}}{{^required}}withDefault Encode.null (map {{/required}}{{#isContainer}}(Encode.list << List.map {{/isContainer}}{{vendorExtensions.x-encoder}}{{#isContainer}}){{/isContainer}} model.{{name}}{{^required}}){{/required}}{{/discriminatorValue}} )

View File

@ -0,0 +1 @@
/elm-stuff

View File

@ -0,0 +1,3 @@
{{#elmImports}}
import {{moduleName}}{{#as}} as {{as}}{{/as}}{{#hasExposures}} exposing ({{#exposures}}{{^-first}}, {{/-first}}{{.}}{{/exposures}}){{/hasExposures}}
{{/elmImports}}

View File

@ -0,0 +1,11 @@
{-
{{{appName}}}
{{{appDescription}}}
{{#version}}OpenAPI spec version: {{{version}}}{{/version}}
{{#infoEmail}}Contact: {{{infoEmail}}}{{/infoEmail}}
NOTE: This file is auto generated by the swagger code generator program.
https://github.com/swagger-api/swagger-codegen.git
Do not edit this file manually.
-}

View File

@ -0,0 +1,24 @@
{{>licenseInfo}}
module Data.{{classname}} exposing ({{#models}}{{#model}}{{classname}}{{#hasChildren}}(..){{/hasChildren}}{{#isEnum}}(..){{/isEnum}}{{^isEnum}}{{#vars}}{{#isEnum}}, {{vendorExtensions.x-union-type}}(..){{/isEnum}}{{/vars}}{{/isEnum}}, {{classVarName}}Decoder, {{classVarName}}Encoder{{/model}}{{/models}})
{{>imports}}import Json.Decode as Decode exposing (Decoder)
import Json.Decode.Pipeline exposing (decode, optional, required)
import Json.Encode as Encode
import Maybe exposing (map, withDefault)
{{#models}}
{{#model}}
{{#description}}
{-
{{{description}}}
-}
{{/description}}
{{#isEnum}}{{>modelTypeUnion}}{{/isEnum}}{{^isEnum}}{{#hasChildren}}{{>modelTypeDiscriminator}}{{/hasChildren}}{{^hasChildren}}{{#isAlias}}{{>modelTypePrimitive}}{{/isAlias}}{{^isAlias}}{{>modelTypeAlias}}{{/isAlias}}{{/hasChildren}}{{/isEnum}}
{{/model}}
{{^-last}}
{{/-last}}
{{/models}}

View File

@ -0,0 +1,28 @@
type alias {{classname}} =
{ {{#vars}}{{^-first}} , {{/-first}}{{name}} : {{^required}}Maybe {{/required}}{{#isContainer}}(List {{/isContainer}}{{#isEnum}}{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{datatype}}{{/isEnum}}{{#isContainer}}){{/isContainer}}
{{/vars}} }
{{#vars}}
{{#isEnum}}
{{>union}}
{{/isEnum}}
{{/vars}}
{{>aliasDecoder}}
{{>aliasEncoder}}
{{#vars}}
{{#isEnum}}
{{>unionDecoder}}
{{>unionEncoder}}
{{/isEnum}}
{{/vars}}

View File

@ -0,0 +1,34 @@
type {{classname}}
{{#children}}
{{#-first}}={{/-first}}{{^-first}}|{{/-first}} {{classname}}Type {{classname}}
{{/children}}
{{classVarName}}Decoder : Decoder {{classname}}
{{classVarName}}Decoder =
Decode.field "{{discriminator}}" Decode.string
|> Decode.andThen {{classVarName}}TypeDecoder
{{classVarName}}TypeDecoder : String -> Decoder {{classname}}
{{classVarName}}TypeDecoder {{discriminator}} =
case {{discriminator}} of
{{#children}}
"{{vendorExtensions.x-discriminator-value}}" ->
Decode.map {{classname}}Type {{classVarName}}Decoder
{{/children}}
_ ->
Decode.fail <|
"Trying to decode {{classname}}, but {{discriminator}} "
++ toString {{discriminator}} ++ " is not supported."
{{classVarName}}Encoder : {{classname}} -> Encode.Value
{{classVarName}}Encoder model =
case model of
{{#children}}
{{classname}}Type subModel ->
{{classVarName}}Encoder subModel
{{/children}}

View File

@ -0,0 +1,14 @@
type alias {{classname}}
= {{dataType}}
{{classVarName}}Decoder : Decoder {{classname}}
{{classVarName}}Decoder =
{{vendorExtensions.x-decoder}}
{{classVarName}}Encoder : {{classname}} -> Encode.Value
{{classVarName}}Encoder =
{{vendorExtensions.x-encoder}}

View File

@ -0,0 +1,7 @@
{{>union}}
{{>unionDecoder}}
{{>unionEncoder}}

View File

@ -0,0 +1,6 @@
type {{#vendorExtensions}}{{x-union-type}}{{/vendorExtensions}}
{{#allowableValues}}
{{#enumVars}}
{{#-first}}={{/-first}}{{^-first}}|{{/-first}} {{name}}
{{/enumVars}}
{{/allowableValues}}

View File

@ -0,0 +1,15 @@
{{vendorExtensions.x-decoder}} : Decoder {{vendorExtensions.x-union-type}}
{{vendorExtensions.x-decoder}} =
Decode.string
|> Decode.andThen (\str ->
case str of
{{#allowableValues}}
{{#enumVars}}
{{{value}}} ->
Decode.succeed {{name}}
{{/enumVars}}
{{/allowableValues}}
other ->
Decode.fail <| "Unknown type: " ++ other
)

View File

@ -0,0 +1,10 @@
{{vendorExtensions.x-encoder}} : {{vendorExtensions.x-union-type}} -> Encode.Value
{{vendorExtensions.x-encoder}} model =
case model of
{{#allowableValues}}
{{#enumVars}}
{{name}} ->
Encode.string {{{value}}}
{{/enumVars}}
{{/allowableValues}}

View File

@ -0,0 +1 @@
/elm-stuff

View File

@ -0,0 +1,23 @@
# Swagger Codegen Ignore
# Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen
# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.
# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line:
#ApiClient.cs
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md

View File

@ -0,0 +1 @@
2.3.0-SNAPSHOT

View File

@ -0,0 +1,11 @@
# Elm API client
This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
## Overview
This API client was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the [swagger-spec](https://github.com/swagger-api/swagger-spec) from a remote server, you can easily generate an API client.
- API version: 1.0.0
- Package version:
- Build date: 2017-12-20T12:18:55.677+01:00
- Build package: io.swagger.codegen.languages.ElmClientCodegen

View File

@ -0,0 +1,18 @@
{
"version": "1.0.0",
"summary": "helpful summary of your project, less than 80 characters",
"repository": "https://github.com/user/project.git",
"license": "BSD3",
"source-directories": [
"src"
],
"exposed-modules": [],
"dependencies": {
"NoRedInk/elm-decode-pipeline": "3.0.0 <= v < 4.0.0",
"elm-lang/core": "5.1.1 <= v < 6.0.0",
"elm-lang/html": "2.0.0 <= v < 3.0.0",
"elm-lang/http": "1.0.0 <= v < 2.0.0",
"justinmimbs/elm-date-extra": "2.0.3 <= v < 3.0.0"
},
"elm-version": "0.18.0 <= v < 0.19.0"
}

View File

@ -0,0 +1,11 @@
{-
* {{{appName}}}
* {{{appDescription}}}
*
* {{#version}}OpenAPI spec version: {{{version}}}{{/version}}
* {{#infoEmail}}Contact: {{{infoEmail}}}{{/infoEmail}}
*
* NOTE: This file is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit manually.
-}

View File

@ -0,0 +1,18 @@
module Byte exposing (Byte, byteDecoder, byteEncoder)
import Json.Decode as Decode exposing (Decoder)
import Json.Encode as Encode
type alias Byte = String
byteDecoder : Decoder Byte
byteDecoder =
Decode.string
byteEncoder : Byte -> Encode.Value
byteEncoder model =
Encode.string model

View File

@ -0,0 +1,51 @@
{-
Swagger Petstore
This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
OpenAPI spec version: 1.0.0
Contact: apiteam@swagger.io
NOTE: This file is auto generated by the swagger code generator program.
https://github.com/swagger-api/swagger-codegen.git
Do not edit this file manually.
-}
module Data.ApiResponse exposing (ApiResponse, apiResponseDecoder, apiResponseEncoder)
import Json.Decode as Decode exposing (Decoder)
import Json.Decode.Pipeline exposing (decode, optional, required)
import Json.Encode as Encode
import Maybe exposing (map, withDefault)
{-
Describes the result of uploading an image resource
-}
type alias ApiResponse =
{ code : Maybe Int
, type_ : Maybe String
, message : Maybe String
}
apiResponseDecoder : Decoder ApiResponse
apiResponseDecoder =
decode ApiResponse
|> optional "code" (Decode.nullable Decode.int) Nothing
|> optional "type" (Decode.nullable Decode.string) Nothing
|> optional "message" (Decode.nullable Decode.string) Nothing
apiResponseEncoder : ApiResponse -> Encode.Value
apiResponseEncoder model =
Encode.object
[ ( "code", withDefault Encode.null (map Encode.int model.code) )
, ( "type", withDefault Encode.null (map Encode.string model.type_) )
, ( "message", withDefault Encode.null (map Encode.string model.message) )
]

View File

@ -0,0 +1,48 @@
{-
Swagger Petstore
This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
OpenAPI spec version: 1.0.0
Contact: apiteam@swagger.io
NOTE: This file is auto generated by the swagger code generator program.
https://github.com/swagger-api/swagger-codegen.git
Do not edit this file manually.
-}
module Data.Category exposing (Category, categoryDecoder, categoryEncoder)
import Json.Decode as Decode exposing (Decoder)
import Json.Decode.Pipeline exposing (decode, optional, required)
import Json.Encode as Encode
import Maybe exposing (map, withDefault)
{-
A category for a pet
-}
type alias Category =
{ id : Maybe Int
, name : Maybe String
}
categoryDecoder : Decoder Category
categoryDecoder =
decode Category
|> optional "id" (Decode.nullable Decode.int) Nothing
|> optional "name" (Decode.nullable Decode.string) Nothing
categoryEncoder : Category -> Encode.Value
categoryEncoder model =
Encode.object
[ ( "id", withDefault Encode.null (map Encode.int model.id) )
, ( "name", withDefault Encode.null (map Encode.string model.name) )
]

View File

@ -0,0 +1,102 @@
{-
Swagger Petstore
This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
OpenAPI spec version: 1.0.0
Contact: apiteam@swagger.io
NOTE: This file is auto generated by the swagger code generator program.
https://github.com/swagger-api/swagger-codegen.git
Do not edit this file manually.
-}
module Data.Order exposing (Order, Status(..), orderDecoder, orderEncoder)
import DateTime exposing (DateTime, dateTimeDecoder, dateTimeEncoder)
import Json.Decode as Decode exposing (Decoder)
import Json.Decode.Pipeline exposing (decode, optional, required)
import Json.Encode as Encode
import Maybe exposing (map, withDefault)
{-
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
= Placed
| Approved
| Delivered
orderDecoder : Decoder Order
orderDecoder =
decode 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 dateTimeDecoder) Nothing
|> optional "status" (Decode.nullable statusDecoder) Nothing
|> optional "complete" (Decode.nullable Decode.bool) (Just False)
orderEncoder : Order -> Encode.Value
orderEncoder model =
Encode.object
[ ( "id", withDefault Encode.null (map Encode.int model.id) )
, ( "petId", withDefault Encode.null (map Encode.int model.petId) )
, ( "quantity", withDefault Encode.null (map Encode.int model.quantity) )
, ( "shipDate", withDefault Encode.null (map dateTimeEncoder model.shipDate) )
, ( "status", withDefault Encode.null (map statusEncoder model.status) )
, ( "complete", withDefault Encode.null (map Encode.bool model.complete) )
]
statusDecoder : Decoder Status
statusDecoder =
Decode.string
|> Decode.andThen (\str ->
case str of
"placed" ->
Decode.succeed Placed
"approved" ->
Decode.succeed Approved
"delivered" ->
Decode.succeed Delivered
other ->
Decode.fail <| "Unknown type: " ++ other
)
statusEncoder : Status -> Encode.Value
statusEncoder model =
case model of
Placed ->
Encode.string "placed"
Approved ->
Encode.string "approved"
Delivered ->
Encode.string "delivered"

View File

@ -0,0 +1,103 @@
{-
Swagger Petstore
This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
OpenAPI spec version: 1.0.0
Contact: apiteam@swagger.io
NOTE: This file is auto generated by the swagger code generator program.
https://github.com/swagger-api/swagger-codegen.git
Do not edit this file manually.
-}
module Data.Pet exposing (Pet, Status(..), petDecoder, petEncoder)
import Data.Category exposing (Category, categoryDecoder, categoryEncoder)
import Data.Tag exposing (Tag, tagDecoder, tagEncoder)
import Json.Decode as Decode exposing (Decoder)
import Json.Decode.Pipeline exposing (decode, optional, required)
import Json.Encode as Encode
import Maybe exposing (map, withDefault)
{-
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
= Available
| Pending
| Sold
petDecoder : Decoder Pet
petDecoder =
decode Pet
|> optional "id" (Decode.nullable Decode.int) Nothing
|> optional "category" (Decode.nullable categoryDecoder) Nothing
|> required "name" Decode.string
|> required "photoUrls" (Decode.list Decode.string)
|> optional "tags" (Decode.nullable (Decode.list tagDecoder)) Nothing
|> optional "status" (Decode.nullable statusDecoder) Nothing
petEncoder : Pet -> Encode.Value
petEncoder model =
Encode.object
[ ( "id", withDefault Encode.null (map Encode.int model.id) )
, ( "category", withDefault Encode.null (map categoryEncoder model.category) )
, ( "name", Encode.string model.name )
, ( "photoUrls", (Encode.list << List.map Encode.string) model.photoUrls )
, ( "tags", withDefault Encode.null (map (Encode.list << List.map tagEncoder) model.tags) )
, ( "status", withDefault Encode.null (map statusEncoder model.status) )
]
statusDecoder : Decoder Status
statusDecoder =
Decode.string
|> Decode.andThen (\str ->
case str of
"available" ->
Decode.succeed Available
"pending" ->
Decode.succeed Pending
"sold" ->
Decode.succeed Sold
other ->
Decode.fail <| "Unknown type: " ++ other
)
statusEncoder : Status -> Encode.Value
statusEncoder model =
case model of
Available ->
Encode.string "available"
Pending ->
Encode.string "pending"
Sold ->
Encode.string "sold"

View File

@ -0,0 +1,48 @@
{-
Swagger Petstore
This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
OpenAPI spec version: 1.0.0
Contact: apiteam@swagger.io
NOTE: This file is auto generated by the swagger code generator program.
https://github.com/swagger-api/swagger-codegen.git
Do not edit this file manually.
-}
module Data.Tag exposing (Tag, tagDecoder, tagEncoder)
import Json.Decode as Decode exposing (Decoder)
import Json.Decode.Pipeline exposing (decode, optional, required)
import Json.Encode as Encode
import Maybe exposing (map, withDefault)
{-
A tag for a pet
-}
type alias Tag =
{ id : Maybe Int
, name : Maybe String
}
tagDecoder : Decoder Tag
tagDecoder =
decode Tag
|> optional "id" (Decode.nullable Decode.int) Nothing
|> optional "name" (Decode.nullable Decode.string) Nothing
tagEncoder : Tag -> Encode.Value
tagEncoder model =
Encode.object
[ ( "id", withDefault Encode.null (map Encode.int model.id) )
, ( "name", withDefault Encode.null (map Encode.string model.name) )
]

View File

@ -0,0 +1,66 @@
{-
Swagger Petstore
This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
OpenAPI spec version: 1.0.0
Contact: apiteam@swagger.io
NOTE: This file is auto generated by the swagger code generator program.
https://github.com/swagger-api/swagger-codegen.git
Do not edit this file manually.
-}
module Data.User exposing (User, userDecoder, userEncoder)
import Json.Decode as Decode exposing (Decoder)
import Json.Decode.Pipeline exposing (decode, optional, required)
import Json.Encode as Encode
import Maybe exposing (map, withDefault)
{-
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
}
userDecoder : Decoder User
userDecoder =
decode 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
userEncoder : User -> Encode.Value
userEncoder model =
Encode.object
[ ( "id", withDefault Encode.null (map Encode.int model.id) )
, ( "username", withDefault Encode.null (map Encode.string model.username) )
, ( "firstName", withDefault Encode.null (map Encode.string model.firstName) )
, ( "lastName", withDefault Encode.null (map Encode.string model.lastName) )
, ( "email", withDefault Encode.null (map Encode.string model.email) )
, ( "password", withDefault Encode.null (map Encode.string model.password) )
, ( "phone", withDefault Encode.null (map Encode.string model.phone) )
, ( "userStatus", withDefault Encode.null (map Encode.int model.userStatus) )
]

View File

@ -0,0 +1,34 @@
module DateOnly exposing (DateOnly, dateOnlyDecoder, dateOnlyEncoder)
import Date
import Date.Extra exposing (fromIsoString, toFormattedString)
import Json.Decode as Decode exposing (Decoder)
import Json.Encode as Encode
type alias DateOnly =
Date.Date
dateOnlyDecoder : Decoder DateOnly
dateOnlyDecoder =
Decode.string
|> Decode.andThen decodeIsoString
dateOnlyEncoder : DateOnly -> Encode.Value
dateOnlyEncoder model =
Encode.string <| toFormattedString "yyyy-MM-dd" model
decodeIsoString : String -> Decoder DateOnly
decodeIsoString str =
case fromIsoString str of
Just date ->
Decode.succeed date
Nothing ->
Decode.fail <|
"Cannot convert "
++ str
++ " to DateOnly"

View File

@ -0,0 +1,34 @@
module DateTime exposing (DateTime, dateTimeDecoder, dateTimeEncoder)
import Date
import Date.Extra exposing (fromIsoString, toIsoString)
import Json.Decode as Decode exposing (Decoder)
import Json.Encode as Encode
type alias DateTime =
Date.Date
dateTimeDecoder : Decoder DateTime
dateTimeDecoder =
Decode.string
|> Decode.andThen decodeIsoString
dateTimeEncoder : DateTime -> Encode.Value
dateTimeEncoder model =
Encode.string <| toIsoString model
decodeIsoString : String -> Decoder DateTime
decodeIsoString str =
case fromIsoString str of
Just date ->
Decode.succeed date
Nothing ->
Decode.fail <|
"Cannot convert "
++ str
++ " to DateTime"

View File

@ -0,0 +1,43 @@
module Main exposing (..)
import Json.Decode as Decode
import Html exposing (Html, button, div, text)
import Html.Events exposing (onClick)
import Http
main : Program Never Model Msg
main =
Html.program
{ init = init
, view = view
, update = update
, subscriptions = subscriptions
}
type alias Model =
{ status : Maybe Int
}
init : (Model, Cmd Msg)
init =
( Model Nothing, Cmd.none )
type Msg
= NoOp
update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
case msg of
NoOp
( model, Cmd.none )
view : Model -> Html Msg
view model =
Html.text "main"
subscriptions : Model -> Sub Msg
subscriptions model =
Sub.none

View File

@ -0,0 +1,154 @@
{-
Swagger Petstore
This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
OpenAPI spec version: 1.0.0
Contact: apiteam@swagger.io
NOTE: This file is auto generated by the swagger code generator program.
https://github.com/swagger-api/swagger-codegen.git
Do not edit this file manually.
-}
module Request.Pet exposing (addPet, deletePet, findPetsByStatus, findPetsByTags, getPetById, updatePet, updatePetWithForm, uploadFile)
import Data.Pet exposing (Pet, petDecoder, petEncoder)
import Data.ApiResponse exposing (ApiResponse, apiResponseDecoder)
import Http
import Json.Decode as Decode
basePath : String
basePath =
"http://petstore.swagger.io/v2"
{-
-}
addPet : Pet -> Http.Request ()
addPet model =
{ method = "POST"
, url = basePath ++ "/pet"
, headers = []
, body = Http.jsonBody <| petEncoder model
, expect = Http.expectStringResponse (\_ -> Ok ())
, timeout = Just 30000
, withCredentials = False
}
|> Http.request
{-
-}
deletePet : Int -> Http.Request ()
deletePet petId =
{ method = "DELETE"
, url = basePath ++ "/pet/" ++ toString petId
, headers = []
, body = Http.emptyBody
, expect = Http.expectStringResponse (\_ -> Ok ())
, timeout = Just 30000
, withCredentials = False
}
|> Http.request
{-
Multiple status values can be provided with comma separated strings
-}
findPetsByStatus : Http.Request (List Pet)
findPetsByStatus =
{ method = "GET"
, url = basePath ++ "/pet/findByStatus"
, headers = []
, body = Http.emptyBody
, expect = Http.expectJson (Decode.list petDecoder)
, timeout = Just 30000
, withCredentials = False
}
|> Http.request
{-
Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
-}
findPetsByTags : Http.Request (List Pet)
findPetsByTags =
{ method = "GET"
, url = basePath ++ "/pet/findByTags"
, headers = []
, body = Http.emptyBody
, expect = Http.expectJson (Decode.list petDecoder)
, timeout = Just 30000
, withCredentials = False
}
|> Http.request
{-
Returns a single pet
-}
getPetById : Int -> Http.Request Pet
getPetById petId =
{ method = "GET"
, url = basePath ++ "/pet/" ++ toString petId
, headers = []
, body = Http.emptyBody
, expect = Http.expectJson petDecoder
, timeout = Just 30000
, withCredentials = False
}
|> Http.request
{-
-}
updatePet : Pet -> Http.Request ()
updatePet model =
{ method = "PUT"
, url = basePath ++ "/pet"
, headers = []
, body = Http.jsonBody <| petEncoder model
, expect = Http.expectStringResponse (\_ -> Ok ())
, timeout = Just 30000
, withCredentials = False
}
|> Http.request
{-
-}
updatePetWithForm : Int -> Http.Request ()
updatePetWithForm petId =
{ method = "POST"
, url = basePath ++ "/pet/" ++ toString petId
, headers = []
, body = Http.emptyBody
, expect = Http.expectStringResponse (\_ -> Ok ())
, timeout = Just 30000
, withCredentials = False
}
|> Http.request
{-
-}
uploadFile : Int -> Http.Request ApiResponse
uploadFile petId =
{ method = "POST"
, url = basePath ++ "/pet/" ++ toString petId ++ "/uploadImage"
, headers = []
, body = Http.emptyBody
, expect = Http.expectJson apiResponseDecoder
, timeout = Just 30000
, withCredentials = False
}
|> Http.request

View File

@ -0,0 +1,90 @@
{-
Swagger Petstore
This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
OpenAPI spec version: 1.0.0
Contact: apiteam@swagger.io
NOTE: This file is auto generated by the swagger code generator program.
https://github.com/swagger-api/swagger-codegen.git
Do not edit this file manually.
-}
module Request.Store exposing (deleteOrder, getInventory, getOrderById, placeOrder)
import Data.Order exposing (Order, orderDecoder, orderEncoder)
import Data.Int exposing (Int, intDecoder)
import Http
import Json.Decode as Decode
basePath : String
basePath =
"http://petstore.swagger.io/v2"
{-
For valid response try integer IDs with value &lt; 1000. Anything above 1000 or nonintegers will generate API errors
-}
deleteOrder : String -> Http.Request ()
deleteOrder orderId =
{ method = "DELETE"
, url = basePath ++ "/store/order/" ++ orderId
, headers = []
, body = Http.emptyBody
, expect = Http.expectStringResponse (\_ -> Ok ())
, timeout = Just 30000
, withCredentials = False
}
|> Http.request
{-
Returns a map of status codes to quantities
-}
getInventory : Http.Request Int
getInventory =
{ method = "GET"
, url = basePath ++ "/store/inventory"
, headers = []
, body = Http.emptyBody
, expect = Http.expectJson intDecoder
, timeout = Just 30000
, withCredentials = False
}
|> Http.request
{-
For valid response try integer IDs with value &lt;&#x3D; 5 or &gt; 10. Other values will generated exceptions
-}
getOrderById : Int -> Http.Request Order
getOrderById orderId =
{ method = "GET"
, url = basePath ++ "/store/order/" ++ toString orderId
, headers = []
, body = Http.emptyBody
, expect = Http.expectJson orderDecoder
, timeout = Just 30000
, withCredentials = False
}
|> Http.request
{-
-}
placeOrder : Order -> Http.Request Order
placeOrder model =
{ method = "POST"
, url = basePath ++ "/store/order"
, headers = []
, body = Http.jsonBody <| orderEncoder model
, expect = Http.expectJson orderDecoder
, timeout = Just 30000
, withCredentials = False
}
|> Http.request

View File

@ -0,0 +1,154 @@
{-
Swagger Petstore
This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
OpenAPI spec version: 1.0.0
Contact: apiteam@swagger.io
NOTE: This file is auto generated by the swagger code generator program.
https://github.com/swagger-api/swagger-codegen.git
Do not edit this file manually.
-}
module Request.User exposing (createUser, createUsersWithArrayInput, createUsersWithListInput, deleteUser, getUserByName, loginUser, logoutUser, updateUser)
import Data.User exposing (User, userDecoder, userEncoder)
import Data.String exposing (Decode.string, String)
import Http
import Json.Decode as Decode
basePath : String
basePath =
"http://petstore.swagger.io/v2"
{-
This can only be done by the logged in user.
-}
createUser : User -> Http.Request ()
createUser model =
{ method = "POST"
, url = basePath ++ "/user"
, headers = []
, body = Http.jsonBody <| userEncoder model
, expect = Http.expectStringResponse (\_ -> Ok ())
, timeout = Just 30000
, withCredentials = False
}
|> Http.request
{-
-}
createUsersWithArrayInput : User -> Http.Request ()
createUsersWithArrayInput model =
{ method = "POST"
, url = basePath ++ "/user/createWithArray"
, headers = []
, body = Http.jsonBody <| userEncoder model
, expect = Http.expectStringResponse (\_ -> Ok ())
, timeout = Just 30000
, withCredentials = False
}
|> Http.request
{-
-}
createUsersWithListInput : User -> Http.Request ()
createUsersWithListInput model =
{ method = "POST"
, url = basePath ++ "/user/createWithList"
, headers = []
, body = Http.jsonBody <| userEncoder model
, expect = Http.expectStringResponse (\_ -> Ok ())
, timeout = Just 30000
, withCredentials = False
}
|> Http.request
{-
This can only be done by the logged in user.
-}
deleteUser : String -> Http.Request ()
deleteUser username =
{ method = "DELETE"
, url = basePath ++ "/user/" ++ username
, headers = []
, body = Http.emptyBody
, expect = Http.expectStringResponse (\_ -> Ok ())
, timeout = Just 30000
, withCredentials = False
}
|> Http.request
{-
-}
getUserByName : String -> Http.Request User
getUserByName username =
{ method = "GET"
, url = basePath ++ "/user/" ++ username
, headers = []
, body = Http.emptyBody
, expect = Http.expectJson userDecoder
, timeout = Just 30000
, withCredentials = False
}
|> Http.request
{-
-}
loginUser : Http.Request String
loginUser =
{ method = "GET"
, url = basePath ++ "/user/login"
, headers = []
, body = Http.emptyBody
, expect = Http.expectJson Decode.string
, timeout = Just 30000
, withCredentials = False
}
|> Http.request
{-
-}
logoutUser : Http.Request ()
logoutUser =
{ method = "GET"
, url = basePath ++ "/user/logout"
, headers = []
, body = Http.emptyBody
, expect = Http.expectStringResponse (\_ -> Ok ())
, timeout = Just 30000
, withCredentials = False
}
|> Http.request
{-
This can only be done by the logged in user.
-}
updateUser : String -> User -> Http.Request ()
updateUser username model =
{ method = "PUT"
, url = basePath ++ "/user/" ++ username
, headers = []
, body = Http.jsonBody <| userEncoder model
, expect = Http.expectStringResponse (\_ -> Ok ())
, timeout = Just 30000
, withCredentials = False
}
|> Http.request