diff --git a/.travis.yml b/.travis.yml index 8c3abe8a927..01f388d10b2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -62,7 +62,6 @@ before_install: - gem install bundler - npm install -g typescript - npm install -g npm - #- npm install -g elm@0.18.0-exp5 - npm config set registry http://registry.npmjs.org/ # set python 3.6.3 as default - source ~/virtualenv/python3.6/bin/activate diff --git a/CI/circle_parallel.sh b/CI/circle_parallel.sh index b7142b28a9d..a1462d57c36 100755 --- a/CI/circle_parallel.sh +++ b/CI/circle_parallel.sh @@ -21,9 +21,6 @@ elif [ "$NODE_INDEX" = "2" ]; then echo "Running node $NODE_INDEX to test ensure-up-to-date" java -version - # install elm-format - npm install -g elm-format - # clear any changes to the samples git checkout -- . diff --git a/bin/elm-0.18-petstore.sh b/bin/elm-0.18-petstore.sh deleted file mode 100755 index 4ec99604def..00000000000 --- a/bin/elm-0.18-petstore.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/sh - -SCRIPT="$0" -echo "# START SCRIPT: $SCRIPT" - -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/openapi-generator-cli/target/openapi-generator-cli.jar" - -if [ ! -f "$executable" ] -then - mvn -B clean package -fi - -# auto format elm code using elm-format -export ELM_POST_PROCESS_FILE="/usr/bin/env elm-format --elm-version=0.18 --yes" - -# if you've executed sbt assembly previously it will use that instead. -export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g elm -t modules/openapi-generator/src/main/resources/elm -o samples/client/petstore/elm-0.18 --additional-properties elmVersion=0.18 --enable-post-process-file $@" - -java $JAVA_OPTS -jar $executable $ags diff --git a/bin/elm-petstore-all.sh b/bin/elm-petstore-all.sh deleted file mode 100755 index 0d64cf613cf..00000000000 --- a/bin/elm-petstore-all.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -./bin/elm-0.18-petstore.sh -./bin/elm-petstore.sh - diff --git a/bin/elm-petstore.sh b/bin/elm-petstore.sh deleted file mode 100755 index dd4c67f4945..00000000000 --- a/bin/elm-petstore.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/sh - -SCRIPT="$0" -echo "# START SCRIPT: $SCRIPT" - -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/openapi-generator-cli/target/openapi-generator-cli.jar" - -if [ ! -f "$executable" ] -then - mvn -B clean package -fi - -# auto format elm code using elm-format -export ELM_POST_PROCESS_FILE="/usr/bin/env elm-format --elm-version=0.19 --yes" - -# if you've executed sbt assembly previously it will use that instead. -export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g elm -t modules/openapi-generator/src/main/resources/elm -o samples/client/petstore/elm --enable-post-process-file $@" - -java $JAVA_OPTS -jar $executable $ags diff --git a/bin/openapi3/elm-all.sh b/bin/openapi3/elm-all.sh deleted file mode 100755 index 199d1182de2..00000000000 --- a/bin/openapi3/elm-all.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -./bin/openapi3/elm-petstore.sh -./bin/openapi3/elm-composition.sh - diff --git a/bin/openapi3/elm-composition.sh b/bin/openapi3/elm-composition.sh deleted file mode 100755 index 97ad1649502..00000000000 --- a/bin/openapi3/elm-composition.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/sh - -SCRIPT="$0" -echo "# START SCRIPT: $SCRIPT" - -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/openapi-generator-cli/target/openapi-generator-cli.jar" - -if [ ! -f "$executable" ] -then - mvn -B clean package -fi - -# auto format elm code using elm-format -export ELM_POST_PROCESS_FILE="/usr/bin/env elm-format --elm-version=0.19 --yes" - -# if you've executed sbt assembly previously it will use that instead. -export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate -i modules/openapi-generator/src/test/resources/3_0/composition.yaml -g elm -t modules/openapi-generator/src/main/resources/elm -o samples/openapi3/client/composition/elm --enable-post-process-file $@" - -java $JAVA_OPTS -jar $executable $ags diff --git a/bin/openapi3/elm-petstore.sh b/bin/openapi3/elm.sh similarity index 78% rename from bin/openapi3/elm-petstore.sh rename to bin/openapi3/elm.sh index 082678c7bff..9f7eba8ce33 100755 --- a/bin/openapi3/elm-petstore.sh +++ b/bin/openapi3/elm.sh @@ -22,11 +22,11 @@ executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar" if [ ! -f "$executable" ] then - mvn clean package + mvn -B clean package fi # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g elm -t modules/openapi-generator/src/main/resources/elm -o samples/openapi3/client/petstore/elm --additional-properties elmPrefixCustomTypeVariants=true $@" +ags="generate -i modules/openapi-generator/src/test/resources/3_0/elm.yaml -g elm -t modules/openapi-generator/src/main/resources/elm -o samples/openapi3/client/elm $@" java $JAVA_OPTS -jar $executable $ags diff --git a/bin/utils/ensure-up-to-date b/bin/utils/ensure-up-to-date index 561988aa07e..f7d7172d479 100755 --- a/bin/utils/ensure-up-to-date +++ b/bin/utils/ensure-up-to-date @@ -77,7 +77,7 @@ declare -a samples=( "${root}/bin/dart-petstore.sh" "${root}/bin/dart2-petstore.sh" "${root}/bin/java-play-framework-petstore-server-all.sh" -#"${root}/bin/elm-petstore-all.sh" +"${root}/bin/openapi3/elm.sh" "${root}/bin/typescript-redux-query-petstore-with-npm-version.sh" ) diff --git a/docs/generators/elm.md b/docs/generators/elm.md index 922560cd6d3..b9df3d2422e 100644 --- a/docs/generators/elm.md +++ b/docs/generators/elm.md @@ -5,7 +5,3 @@ sidebar_label: elm | Option | Description | Values | Default | | ------ | ----------- | ------ | ------- | -|elmVersion|Elm version: 0.18, 0.19|
**0.19**
Elm 0.19
**0.18**
Elm 0.18
|0.19| -|elmPrefixCustomTypeVariants|Prefix custom type variants| |false| -|elmEnableCustomBasePaths|Enable setting the base path for each request| |false| -|elmEnableHttpRequestTrackers|Enable adding a tracker to each http request| |false| diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElmClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElmClientCodegen.java index 15bfcb01036..29efd452af2 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElmClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElmClientCodegen.java @@ -38,18 +38,6 @@ import static org.openapitools.codegen.utils.StringUtils.camelize; public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig { private static final Logger LOGGER = LoggerFactory.getLogger(ElmClientCodegen.class); - private Set customPrimitives = new HashSet(); - private ElmVersion elmVersion = ElmVersion.ELM_019; - private Boolean elmPrefixCustomTypeVariants = false; - - private static final String ELM_VERSION = "elmVersion"; - private static final String ELM_PREFIX_CUSTOM_TYPE_VARIANTS = "elmPrefixCustomTypeVariants"; - private static final String ELM_ENABLE_CUSTOM_BASE_PATHS = "elmEnableCustomBasePaths"; - private static final String ELM_ENABLE_HTTP_REQUEST_TRACKERS = "elmEnableHttpRequestTrackers"; - private static final String ENCODER = "elmEncoder"; - private static final String DECODER = "elmDecoder"; - private static final String DISCRIMINATOR_NAME = "discriminatorName"; - private static final String CUSTOM_TYPE = "elmCustomType"; protected String packageName = "openapi"; protected String packageVersion = "1.0.0"; @@ -64,14 +52,14 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig { } public String getHelp() { - return "Generates a Elm client library (beta)."; + return "Generates an Elm client library."; } public ElmClientCodegen() { super(); - outputFolder = "generated-code/elm"; - modelTemplateFiles.put("model.mustache", ".elm"); templateDir = "elm"; + apiPackage = "Api.Request"; + modelPackage = "Api"; supportsInheritance = true; @@ -109,14 +97,6 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig { "String") ); - customPrimitives = new HashSet<>( - Arrays.asList( - "Byte", - "DateOnly", - "DateTime", - "Uuid") - ); - instantiationTypes.clear(); instantiationTypes.put("array", "List"); instantiationTypes.put("map", "Dict"); @@ -131,10 +111,10 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig { typeMapping.put("string", "String"); typeMapping.put("array", "List"); typeMapping.put("map", "Dict"); - typeMapping.put("date", "DateOnly"); - typeMapping.put("DateTime", "DateTime"); + typeMapping.put("date", "Posix"); + typeMapping.put("DateTime", "Posix"); typeMapping.put("password", "String"); - typeMapping.put("ByteArray", "Byte"); + typeMapping.put("ByteArray", "String"); typeMapping.put("file", "String"); typeMapping.put("binary", "String"); typeMapping.put("UUID", "Uuid"); @@ -144,80 +124,11 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig { cliOptions.clear(); - final CliOption elmVersion = new CliOption(ELM_VERSION, "Elm version: 0.18, 0.19").defaultValue("0.19"); - final Map supportedVersions = new HashMap<>(); - supportedVersions.put("0.18", "Elm 0.18"); - supportedVersions.put("0.19", "Elm 0.19"); - elmVersion.setEnum(supportedVersions); - cliOptions.add(elmVersion); - final CliOption elmPrefixCustomTypeVariants = CliOption.newBoolean(ELM_PREFIX_CUSTOM_TYPE_VARIANTS, "Prefix custom type variants"); - cliOptions.add(elmPrefixCustomTypeVariants); - final CliOption elmEnableCustomBasePaths = CliOption.newBoolean(ELM_ENABLE_CUSTOM_BASE_PATHS, "Enable setting the base path for each request"); - cliOptions.add(elmEnableCustomBasePaths); - final CliOption elmEnableHttpRequestTrackers = CliOption.newBoolean(ELM_ENABLE_HTTP_REQUEST_TRACKERS, "Enable adding a tracker to each http request"); - cliOptions.add(elmEnableHttpRequestTrackers); - } - - @Override - public void processOpts() { - super.processOpts(); - - if (additionalProperties.containsKey(ELM_VERSION)) { - final String version = (String) additionalProperties.get(ELM_VERSION); - if ("0.18".equals(version)) { - elmVersion = ElmVersion.ELM_018; - } else { - elmVersion = ElmVersion.ELM_019; - } - } - - if (additionalProperties.containsKey(ELM_PREFIX_CUSTOM_TYPE_VARIANTS)) { - elmPrefixCustomTypeVariants = Boolean.TRUE.equals(Boolean.valueOf(additionalProperties.get(ELM_PREFIX_CUSTOM_TYPE_VARIANTS).toString())); - } - - if (additionalProperties.containsKey(ELM_ENABLE_CUSTOM_BASE_PATHS)) { - final boolean enable = Boolean.TRUE.equals(Boolean.valueOf(additionalProperties.get(ELM_ENABLE_CUSTOM_BASE_PATHS).toString())); - additionalProperties.put("enableCustomBasePaths", enable); - } - - if (additionalProperties.containsKey(ELM_ENABLE_HTTP_REQUEST_TRACKERS)) { - final boolean enable = Boolean.TRUE.equals(Boolean.valueOf(additionalProperties.get(ELM_ENABLE_HTTP_REQUEST_TRACKERS).toString())); - additionalProperties.put("enableHttpRequestTrackers", enable); - } - - if (StringUtils.isEmpty(System.getenv("ELM_POST_PROCESS_FILE"))) { - if (elmVersion.equals(ElmVersion.ELM_018)) { // 0.18 - LOGGER.info("Environment variable ELM_POST_PROCESS_FILE not defined so the Elm code may not be properly formatted. To define it, try `export ELM_POST_PROCESS_FILE=\"/usr/local/bin/elm-format --elm-version={} --yes\"` (Linux/Mac)", "0.18"); - } else { // 0.19 - LOGGER.info("Environment variable ELM_POST_PROCESS_FILE not defined so the Elm code may not be properly formatted. To define it, try `export ELM_POST_PROCESS_FILE=\"/usr/local/bin/elm-format --elm-version={} --yes\"` (Linux/Mac)", "0.19"); - } - LOGGER.info("NOTE: To enable file post-processing, 'enablePostProcessFile' must be set to `true` (--enable-post-process-file for CLI)."); - } - - switch (elmVersion) { - case ELM_018: - LOGGER.info("Elm version: 0.18"); - additionalProperties.put("isElm018", true); - apiTemplateFiles.put("api018.mustache", ".elm"); - supportingFiles.add(new SupportingFile("DateOnly018.mustache", "src", "DateOnly.elm")); - supportingFiles.add(new SupportingFile("DateTime018.mustache", "src", "DateTime.elm")); - supportingFiles.add(new SupportingFile("elm-package018.mustache", "", "elm-package.json")); - supportingFiles.add(new SupportingFile("Main018.mustache", "src", "Main.elm")); - break; - case ELM_019: - LOGGER.info("Elm version: 0.19"); - additionalProperties.put("isElm019", true); - apiTemplateFiles.put("api.mustache", ".elm"); - supportingFiles.add(new SupportingFile("DateOnly.mustache", "src", "DateOnly.elm")); - supportingFiles.add(new SupportingFile("DateTime.mustache", "src", "DateTime.elm")); - supportingFiles.add(new SupportingFile("elm.mustache", "", "elm.json")); - supportingFiles.add(new SupportingFile("Main.mustache", "src", "Main.elm")); - break; - default: - throw new RuntimeException("Undefined Elm version"); - } - - supportingFiles.add(new SupportingFile("Byte.mustache", "src", "Byte.elm")); + apiTemplateFiles.put("operation.mustache", ".elm"); + modelTemplateFiles.put("model.mustache", ".elm"); + supportingFiles.add(new SupportingFile("Api.mustache", "", "src" + File.separator + "Api.elm")); + supportingFiles.add(new SupportingFile("Time.mustache", "", "src" + File.separator + "Api" + File.separator + "Time.elm")); + supportingFiles.add(new SupportingFile("elm.mustache", "", "elm.json")); supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore")); supportingFiles.add(new SupportingFile("README.mustache", "", "README.md")); } @@ -246,11 +157,6 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig { return defaultIncludes.contains(modelName) ? modelName + "_" : modelName; } - @Override - public String toModelFilename(String name) { - return toModelName(name); - } - @Override public String toEnumName(CodegenProperty property) { return toModelName(property.name); @@ -258,22 +164,17 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig { @Override public String toVarName(String name) { - final String varName = camelize(name, true); + final String varName = camelize(name.replaceAll("[^a-zA-Z0-9_]", ""), true); return isReservedWord(varName) ? escapeReservedWord(name) : varName; } @Override public String toEnumVarName(String value, String datatype) { String camelized = camelize(value.replace(" ", "_").replace("(", "_").replace(")", "")); // TODO FIXME escape properly - if (camelized.length() == 0) { LOGGER.error("Unable to determine enum variable name (name: {}, datatype: {}) from empty string. Default to UnknownEnumVariableName", value, datatype); camelized = "UnknownEnumVariableName"; } - - if (!Character.isUpperCase(camelized.charAt(0))) { - return "N" + camelized; - } return camelized; } @@ -288,132 +189,100 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig { } } + @Override + public String apiFileFolder() { + return outputFolder + File.separator + "src" + File.separator + apiPackage().replace('.', File.separatorChar); + } + + @Override + public String modelFileFolder() { + return outputFolder + File.separator + "src" + File.separator + modelPackage().replace('.', File.separatorChar); + } + @Override public String escapeReservedWord(String name) { return name + "_"; } @Override - public String apiFileFolder() { - return outputFolder + ("/src/Request/" + apiPackage().replace('.', File.separatorChar)).replace("/", File.separator); - } - - @Override - public String modelFileFolder() { - return outputFolder + ("/src/Data/" + modelPackage().replace('.', File.separatorChar)).replace("/", File.separator); - } - - @Override - public CodegenModel fromModel(String name, Schema schema) { - CodegenModel m = super.fromModel(name, schema); - - if (ModelUtils.isArraySchema(schema)) { - ArraySchema am = (ArraySchema) schema; - CodegenProperty codegenProperty = fromProperty(name, (Schema) am.getItems()); - m.vendorExtensions.putAll(codegenProperty.vendorExtensions); + public void postProcessModelProperty(CodegenModel model, CodegenProperty property) { + if (property.getAllowableValues() != null && !property.getAllowableValues().isEmpty()) { + property.isModel = true; } - - return m; } @SuppressWarnings({"static-method", "unchecked"}) - public Map postProcessAllModels(Map objs) { - // Index all CodegenModels by model name. - Map allModels = new HashMap<>(); - for (Map.Entry entry : objs.entrySet()) { - String modelName = toModelName(entry.getKey()); - Map inner = (Map) entry.getValue(); - List> models = (List>) inner.get("models"); - for (Map 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); + public Map postProcessAllModels(final Map orgObjs) { + final Map objs = super.postProcessAllModels(orgObjs); - if (parent != null) { - if (parent.children == null) { - parent.children = new ArrayList<>(); - parent.hasChildren = true; - } - parent.children.add(cm); - Collections.sort(parent.children, new Comparator() { - @Override - public int compare(CodegenModel cm1, CodegenModel cm2) { - return Collator.getInstance(Locale.ROOT).compare(cm1.classname, cm2.classname); + // put all models in one file + final Map objects = new HashMap<>(); + final Map dataObj = objs.values().stream() + .map(obj -> (Map) obj) + .findFirst() + .orElse(new HashMap<>()); + final List> models = objs.values().stream() + .map(obj -> (Map) obj) + .flatMap(obj -> ((List>) obj.get("models")).stream()) + .flatMap(obj -> { + final CodegenModel model = (CodegenModel) obj.get("model"); + // circular references + model.vars.forEach(var -> { + var.isCircularReference = model.allVars.stream() + .filter(v -> var.baseName.equals(v.baseName)) + .map(v -> v.isCircularReference) + .findAny() + .orElse(false); + CodegenProperty items = var.items; + while (items != null) { + items.isCircularReference = var.isCircularReference; + items.required = true; + items = items.items; } }); - } - } - setCircularReferences(allModels); - for (Map.Entry entry : objs.entrySet()) { - Map inner = (Map) entry.getValue(); - List> models = (List>) inner.get("models"); - for (Map mo : models) { - CodegenModel cm = (CodegenModel) mo.get("model"); - if (cm.isEnum) { - addEncoderAndDecoder(cm.vendorExtensions, cm.classname, DataTypeExposure.EXPOSED); - cm.vendorExtensions.put(CUSTOM_TYPE, cm.classname); - } else if (cm.isAlias) { - addEncoderAndDecoder(cm.vendorExtensions, cm.dataType, DataTypeExposure.EXPOSED); + // discriminators + if (model.discriminator != null && model.getChildren() != null) { + model.getChildren().forEach(child -> { + child.allOf = child.allOf.stream() + .map(v -> model.classname.equals(v) ? "Base" + v : v) + .collect(Collectors.toSet()); + }); } + // remove *AllOf + if (model.classname.endsWith("AllOf")) { + return Stream.empty(); + } else { + model.allOf.removeIf(name -> name.endsWith("AllOf")); + return Stream.of(obj); + } + }) + .collect(Collectors.toList()); - List elmImports = new ArrayList<>(); - for (CodegenProperty property : cm.allVars) { - if (property.complexType != null) { - final ElmImport elmImport = createImport(property.complexType); - elmImports.add(elmImport); - } - } - if (cm.isArrayModel) { - if (cm.arrayModelType != null) { - // add type imports - final ElmImport elmImport = createImport(cm.arrayModelType); - elmImports.add(elmImport); - } - } - if (cm.oneOf != null) { - for (String variant : cm.oneOf) { - final ElmImport elmImport = createImport(variant); - elmImports.add(elmImport); - } - } - if (cm.discriminator != null && cm.children != null) { - for (CodegenModel child : cm.children) { - // add child imports - final ElmImport elmImport = createImport(child.classname); - elmImports.add(elmImport); + final boolean includeTime = anyVarMatches(models, prop -> prop.isDate || prop.isDateTime); + final boolean includeUuid = anyVarMatches(models, prop -> prop.isUuid); - final String propertyName = cm.discriminator.getPropertyName(); - final List allVars = child.allVars.stream() - .filter(var -> !var.baseName.equals(propertyName)) - .collect(Collectors.toList()); - child.allVars.clear(); - child.allVars.addAll(allVars); - - child.vendorExtensions.put(DISCRIMINATOR_NAME, propertyName); - } - } - inner.put("elmImports", elmImports); - } - } - return objs; + dataObj.put("models", models); + dataObj.put("includeTime", includeTime); + dataObj.put("includeUuid", includeUuid); + objects.put("Data", dataObj); + return objects; } - private ElmImport createImport(final String name) { - final ElmImport elmImport = new ElmImport(); - final boolean isData = !customPrimitives.contains(name); - final String modulePrefix = isData ? "Data." : ""; - elmImport.moduleName = modulePrefix + name; - if (isData) { - elmImport.as = name; - } - elmImport.exposures = new TreeSet<>(); - elmImport.exposures.add(name); - elmImport.hasExposures = true; - return elmImport; + private boolean anyVarMatches(final List> models, final Predicate predicate) { + return models.stream() + .map(obj -> (CodegenModel) obj.get("model")) + .flatMap(model -> model.vars.stream()) + .filter(var -> { + CodegenProperty prop = var; + while (prop != null) { + if (predicate.test(prop)) { + return true; + } + prop = prop.items; + } + return false; + }) + .count() > 0; } @Override @@ -423,13 +292,15 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig { private static boolean anyOperationParam(final List operations, final Predicate predicate) { return operations.stream() - .flatMap(operation -> Stream.of( - operation.bodyParams.stream(), - operation.queryParams.stream(), - operation.pathParams.stream(), - operation.headerParams.stream() - )) - .flatMap(a -> a) + .flatMap(operation -> operation.allParams.stream()) + .filter(predicate) + .findAny() + .isPresent(); + } + + private static boolean anyOperationResponse(final List operations, final Predicate predicate) { + return operations.stream() + .flatMap(operation -> operation.responses.stream()) .filter(predicate) .findAny() .isPresent(); @@ -440,187 +311,69 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig { public Map postProcessOperationsWithModels(Map operations, List allModels) { Map objs = (Map) operations.get("operations"); List ops = (List) objs.get("operation"); - - final Set dependencies = new HashSet<>(); - - for (CodegenOperation op : ops) { - if (ElmVersion.ELM_018.equals(elmVersion)) { // elm 0.18 - String path = op.path; - for (CodegenParameter param : op.pathParams) { - final String var = paramToString("params", param, false, null); - path = path.replace("{" + param.baseName + "}", "\" ++ " + var + " ++ \""); + ops.forEach(op -> { + op.allParams = op.allParams.stream().sorted(new ParameterSorter()).collect(Collectors.toList()); + op.responses.forEach(response -> { + if (response.isDefault) { + response.isModel = !response.primitiveType; } - op.path = ("\"" + path + "\"").replaceAll(" \\+\\+ \"\"", ""); - } else { // elm 0.19 or later - final List pathParams = Arrays.asList(op.path.substring(1).split("/")).stream() - .map(str -> { - if (str.startsWith("{") && str.endsWith("}")) { - return op.pathParams.stream().filter(p -> str.equals("{" + p.baseName + "}")).findFirst().orElse(null); - } else { - return "\"" + str + "\""; - } - }) - .collect(Collectors.toList()); - op.vendorExtensions.put("pathParams", pathParams); - } + }); + }); - for (CodegenParameter param : op.allParams) { - if (param.isPrimitiveType || param.isContainer || param.isDate || param.isDateTime || param.isUuid) { - continue; - } - dependencies.add(param.dataType); - } - for (CodegenResponse resp : op.responses) { - if (resp.primitiveType || resp.isMapContainer || resp.isDate || resp.isDateTime || resp.isUuid) { - continue; - } - dependencies.add(resp.dataType); - } - } - - final List elmImports = new ArrayList<>(); - for (String key : dependencies) { - final ElmImport elmImport = new ElmImport(); - elmImport.moduleName = "Data." + key; - elmImport.as = key; - elmImport.exposures = new HashSet<>(); - elmImport.exposures.add(key); - elmImport.hasExposures = true; - elmImports.add(elmImport); - } - final boolean hasDate = anyOperationParam(ops, param -> param.isDate); - if (hasDate) { - final ElmImport elmImport = new ElmImport(); - elmImport.moduleName = "DateOnly"; - elmImport.exposures = new TreeSet<>(); - elmImport.exposures.add("DateOnly"); - elmImport.hasExposures = true; - elmImports.add(elmImport); - } - final boolean hasDateTime = anyOperationParam(ops, param -> param.isDateTime); - if (hasDateTime) { - final ElmImport elmImport = new ElmImport(); - elmImport.moduleName = "DateTime"; - elmImport.exposures = new TreeSet<>(); - elmImport.exposures.add("DateTime"); - elmImport.hasExposures = true; - elmImports.add(elmImport); - } - final boolean hasUuid = anyOperationParam(ops, param -> param.isUuid); - if (hasUuid) { - final ElmImport elmImport = new ElmImport(); - elmImport.moduleName = "Uuid"; - elmImport.exposures = new TreeSet<>(); - elmImport.exposures.add("Uuid"); - elmImport.hasExposures = true; - elmImports.add(elmImport); - } - operations.put("elmImports", elmImports); + final boolean includeTime = + anyOperationResponse(ops, response -> response.isDate || response.isDateTime) || + anyOperationParam(ops, param -> param.isDate || param.isDateTime); + final boolean includeUuid = + anyOperationResponse(ops, response -> response.isUuid) || + anyOperationParam(ops, param -> param.isUuid); + operations.put("includeTime", includeTime); + operations.put("includeUuid", includeUuid); return operations; } + static class ParameterSorter implements Comparator { + public int compare(final CodegenParameter p1, final CodegenParameter p2) { + return index(p1) - index(p2); + } + + private int index(final CodegenParameter p) { + if (p.isPathParam) { + return 1; + } + if (p.isQueryParam) { + return 2; + } + if (p.isHeaderParam) { + return 3; + } + if (p.isBodyParam) { + return 4; + } + return 5; + } + } + @Override public String toDefaultValue(Schema p) { if (ModelUtils.isStringSchema(p)) { if (p.getDefault() != null) { - return toOptionalValue("\"" + p.getDefault().toString() + "\""); + return "\"" + p.getDefault().toString() + "\""; } - return toOptionalValue(null); } else if (ModelUtils.isBooleanSchema(p)) { if (p.getDefault() != null) { - return toOptionalValue(Boolean.valueOf(p.getDefault().toString()) ? "True" : "False"); + return Boolean.valueOf(p.getDefault().toString()) ? "True" : "False"; } - return toOptionalValue(null); - } else if (ModelUtils.isDateSchema(p)) { - return toOptionalValue(null); - } else if (ModelUtils.isDateTimeSchema(p)) { - return toOptionalValue(null); } else if (ModelUtils.isNumberSchema(p)) { if (p.getDefault() != null) { - return toOptionalValue(p.getDefault().toString()); + return p.getDefault().toString(); } - return toOptionalValue(null); } else if (ModelUtils.isIntegerSchema(p)) { if (p.getDefault() != null) { - return toOptionalValue(p.getDefault().toString()); - } - return toOptionalValue(null); - } else { - return toOptionalValue(null); - } - } - - private String toOptionalValue(String value) { - if (value == null) { - return "Nothing"; - } - return "(Just " + value + ")"; - } - - private Optional paramToStringMapper(final String paramName, final CodegenProperty property) { - if (property.isEnum) { - return Optional.of(toVarName(paramName) + "ToString"); - } else if (property.isString || property.isBinary || property.isByteArray) { - return Optional.empty(); - } else if (property.isBoolean) { - return Optional.of("(\\val -> if val then \"true\" else \"false\")"); - } else if (property.isDateTime) { - return Optional.of("DateTime.toString"); - } else if (property.isDate) { - return Optional.of("DateOnly.toString"); - } else if (property.isUuid) { - return Optional.of("Uuid.toString"); - } else if (ElmVersion.ELM_018.equals(elmVersion)) { - return Optional.of("toString"); - } else if (property.isInteger || property.isLong) { - return Optional.of("String.fromInt"); - } else if (property.isFloat || property.isDouble) { - return Optional.of("String.fromFloat"); - } else { - return Optional.of(property.dataType + ".toString"); - } - } - - private CodegenProperty paramToProperty(final CodegenParameter parameter) { - final CodegenProperty property = new CodegenProperty(); - property.dataType = parameter.dataType; - property.isEnum = parameter.isEnum; - property.isString = parameter.isString; - property.isBinary = parameter.isBinary; - property.isByteArray = parameter.isByteArray; - property.isBoolean = parameter.isBoolean; - property.isDateTime = parameter.isDateTime; - property.isDate = parameter.isDate; - property.isUuid = parameter.isUuid; - property.isInteger = parameter.isInteger; - property.isLong = parameter.isLong; - property.isFloat = parameter.isFloat; - property.isDouble = parameter.isDouble; - return property; - } - - private String paramToString(final String prefix, final CodegenParameter param, final boolean useMaybe, final String maybeMapResult) { - final String paramName = (ElmVersion.ELM_018.equals(elmVersion) ? "" : prefix + ".") + param.paramName; - if (!useMaybe) { - param.required = true; - } - - final String mapFn = param.isListContainer - ? "(String.join \",\"" + paramToStringMapper(param.paramName, param.items).map(mapper -> " << List.map " + mapper).orElse("") + ")" - : paramToStringMapper(param.paramName, paramToProperty(param)).orElse(""); - - String mapResult = ""; - if (maybeMapResult != null) { - if ("".equals(mapFn)) { - mapResult = maybeMapResult; - } else { - mapResult = maybeMapResult + (param.required ? " <|" : " <<"); + return p.getDefault().toString(); } } - final String just = useMaybe ? "Just (" : ""; - final String justEnd = useMaybe ? ")" : ""; - return (param.required ? just : "Maybe.map (") + mapResult + " " + mapFn + (param.required ? " " : ") ") + paramName + (param.required ? justEnd : ""); + return null; } @Override @@ -649,146 +402,4 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig { } return super.getTypeDeclaration(p); } - - @Override - public CodegenProperty fromProperty(String name, Schema p) { - final CodegenProperty property = super.fromProperty(name, p); - - if (property.isEnum) { - addEncoderAndDecoder(property.vendorExtensions, property.baseName, DataTypeExposure.INTERNAL); - property.vendorExtensions.put(CUSTOM_TYPE, property.datatypeWithEnum); - } else { - final boolean isPrimitiveType = property.isMapContainer ? isPrimitiveDataType(property.dataType) : property.isPrimitiveType; - addEncoderAndDecoder(property.vendorExtensions, property.dataType, isPrimitiveType ? DataTypeExposure.PRIMITIVE : DataTypeExposure.EXTERNAL); - } - - return property; - } - - @Override - public CodegenResponse fromResponse(String responseCode, ApiResponse resp) { - final CodegenResponse response = super.fromResponse(responseCode, resp); - if (response.dataType != null) { - final boolean isPrimitiveType = response.isMapContainer ? isPrimitiveDataType(response.dataType) : response.primitiveType; - addEncoderAndDecoder(response.vendorExtensions, response.dataType, isPrimitiveType ? DataTypeExposure.PRIMITIVE : DataTypeExposure.EXTERNAL); - } - return response; - } - - @Override - public void postProcessParameter(CodegenParameter parameter) { - final boolean isPrimitiveType = parameter.isMapContainer ? isPrimitiveDataType(parameter.dataType) : parameter.isPrimitiveType; - addEncoderAndDecoder(parameter.vendorExtensions, parameter.dataType, isPrimitiveType ? DataTypeExposure.PRIMITIVE : DataTypeExposure.EXTERNAL); - } - - @Override - public void updateCodegenPropertyEnum(final CodegenProperty property) { - super.updateCodegenPropertyEnum(property); - if (!elmPrefixCustomTypeVariants) { - return; - } - - final Map allowableValues = property.allowableValues; - if (allowableValues == null) { - return; - } - - final List> enumVars = (ArrayList>) allowableValues.get("enumVars"); - if (enumVars == null) { - return; - } - final String prefix = toEnumName(property); - for (Map enumVar : enumVars) { - if (!enumVar.containsKey("_isPrefixed")) { - enumVar.put("name", prefix + enumVar.get("name")); - enumVar.put("_isPrefixed", true); - } - } - } - - private boolean isPrimitiveDataType(String dataType) { - return languageSpecificPrimitives.contains(dataType); - } - - private void addEncoderAndDecoder(final Map vendorExtensions, final String dataType, final DataTypeExposure dataTypeExposure) { - final String baseName = org.openapitools.codegen.utils.StringUtils.camelize(dataType, true); - String encodeName; - String decoderName; - switch (dataTypeExposure) { - case EXPOSED: - decoderName = "decoder"; - encodeName = "encode"; - break; - case INTERNAL: - encodeName = "encode" + StringUtils.capitalize(baseName); - decoderName = baseName + "Decoder"; - break; - case EXTERNAL: - encodeName = dataType + ".encode"; - decoderName = dataType + ".decoder"; - break; - case PRIMITIVE: - encodeName = "Encode." + baseName; - decoderName = "Decode." + baseName; - break; - default: - encodeName = ""; - decoderName = ""; - } - if (!vendorExtensions.containsKey(ENCODER)) { - vendorExtensions.put(ENCODER, encodeName); - } - if (!vendorExtensions.containsKey(DECODER)) { - vendorExtensions.put(DECODER, decoderName); - } - } - - private enum DataTypeExposure { - EXPOSED, - INTERNAL, - EXTERNAL, - PRIMITIVE - } - - private static class ElmImport { - public String moduleName; - public String as; - public Set exposures; - public Boolean hasExposures; - } - - private enum ElmVersion { - ELM_018, - ELM_019 - } - - @Override - public void postProcessFile(File file, String fileType) { - if (file == null) { - return; - } - - String elmPostProcessFile = System.getenv("ELM_POST_PROCESS_FILE"); - if (StringUtils.isEmpty(elmPostProcessFile)) { - return; // skip if ELM_POST_PROCESS_FILE env variable is not defined - } - - // only process files with elm extension - if ("elm".equals(FilenameUtils.getExtension(file.toString()))) { - // e.g. elm-format -w yourcode.elm - String command = elmPostProcessFile + " " + file.toString(); - - try { - Process p = Runtime.getRuntime().exec(command); - int exitValue = p.waitFor(); - if (exitValue != 0) { - LOGGER.error("Error running the command ({}). Exit code: {}", command, exitValue); - } else { - LOGGER.info("Successfully executed: " + command); - } - } catch (Exception e) { - LOGGER.error("Error running the command ({}). Exception: {}", command, e.getMessage()); - } - } - } } diff --git a/modules/openapi-generator/src/main/resources/elm/Api.mustache b/modules/openapi-generator/src/main/resources/elm/Api.mustache new file mode 100644 index 00000000000..ed16f82362c --- /dev/null +++ b/modules/openapi-generator/src/main/resources/elm/Api.mustache @@ -0,0 +1,121 @@ +module Api exposing + ( Request + , request + , send + , map + , withBasePath + , withTimeout + , withTracker + , withHeader + , withHeaders + ) + +import Http +import Json.Decode +import Json.Encode +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 Json.Encode.Value -> Json.Decode.Decoder a -> Request a +request method path pathParams queryParams headerParams body decoder = + Request + { method = method + , headers = headers headerParams + , basePath = "{{basePath}}" + , pathParams = interpolatePath path pathParams + , queryParams = queries queryParams + , body = Maybe.withDefault Http.emptyBody (Maybe.map Http.jsonBody body) + , decoder = decoder + , timeout = Nothing + , tracker = Nothing + } + + +send : (Result Http.Error a -> msg) -> Request a -> Cmd msg +send toMsg (Request req) = + Http.request + { method = req.method + , headers = req.headers + , url = Url.Builder.crossOrigin req.basePath req.pathParams req.queryParams + , body = req.body + , expect = Http.expectJson toMsg req.decoder + , timeout = req.timeout + , tracker = req.tracker + } + + +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 } + + +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) \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/elm/Byte.mustache b/modules/openapi-generator/src/main/resources/elm/Byte.mustache deleted file mode 100644 index d83623d9846..00000000000 --- a/modules/openapi-generator/src/main/resources/elm/Byte.mustache +++ /dev/null @@ -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 diff --git a/modules/openapi-generator/src/main/resources/elm/DateOnly.mustache b/modules/openapi-generator/src/main/resources/elm/DateOnly.mustache deleted file mode 100644 index a31efc88c38..00000000000 --- a/modules/openapi-generator/src/main/resources/elm/DateOnly.mustache +++ /dev/null @@ -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 diff --git a/modules/openapi-generator/src/main/resources/elm/DateOnly018.mustache b/modules/openapi-generator/src/main/resources/elm/DateOnly018.mustache deleted file mode 100644 index 5874cf65d5e..00000000000 --- a/modules/openapi-generator/src/main/resources/elm/DateOnly018.mustache +++ /dev/null @@ -1,37 +0,0 @@ -module DateOnly exposing (DateOnly, decoder, encode, toString) - -import Date -import Date.Extra exposing (fromIsoString, toFormattedString) -import Json.Decode as Decode exposing (Decoder) -import Json.Encode as Encode -import Result - - -type alias DateOnly = - Date.Date - - -decoder : Decoder DateOnly -decoder = - Decode.string - |> Decode.andThen decodeIsoString - - -encode : DateOnly -> Encode.Value -encode = - Encode.string << toString - - -decodeIsoString : String -> Decoder DateOnly -decodeIsoString str = - case fromIsoString str of - Result.Ok date -> - Decode.succeed date - - Result.Err msg -> - Decode.fail msg - - -toString : DateOnly -> String -toString = - toFormattedString "yyyy-MM-dd" diff --git a/modules/openapi-generator/src/main/resources/elm/DateTime.mustache b/modules/openapi-generator/src/main/resources/elm/DateTime.mustache deleted file mode 100644 index 7d4a5c642c1..00000000000 --- a/modules/openapi-generator/src/main/resources/elm/DateTime.mustache +++ /dev/null @@ -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 \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/elm/DateTime018.mustache b/modules/openapi-generator/src/main/resources/elm/DateTime018.mustache deleted file mode 100644 index 6a20f0482a1..00000000000 --- a/modules/openapi-generator/src/main/resources/elm/DateTime018.mustache +++ /dev/null @@ -1,37 +0,0 @@ -module DateTime exposing (DateTime, decoder, encode, toString) - -import Date -import Date.Extra exposing (fromIsoString, toIsoString) -import Json.Decode as Decode exposing (Decoder) -import Json.Encode as Encode -import Result - - -type alias DateTime = - Date.Date - - -decoder : Decoder DateTime -decoder = - Decode.string - |> Decode.andThen decodeIsoString - - -encode : DateTime -> Encode.Value -encode = - Encode.string << toString - - -decodeIsoString : String -> Decoder DateTime -decodeIsoString str = - case fromIsoString str of - Result.Ok date -> - Decode.succeed date - - Result.Err msg -> - Decode.fail msg - - -toString : DateTime -> String -toString = - toIsoString \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/elm/Main018.mustache b/modules/openapi-generator/src/main/resources/elm/Main018.mustache deleted file mode 100644 index 23274d541c1..00000000000 --- a/modules/openapi-generator/src/main/resources/elm/Main018.mustache +++ /dev/null @@ -1,60 +0,0 @@ -module Main exposing (main) - -import Html exposing (Html) - - -main : Program Never Model Msg -main = - Html.program - { init = init - , view = view - , update = update - , subscriptions = subscriptions - } - - - --- MODEL - - -type alias Model = - { value : Int - } - - -init : ( Model, Cmd Msg ) -init = - ( Model 0, Cmd.none ) - - - --- UPDATE - - -type Msg - = NoOp - - -update : Msg -> Model -> ( Model, Cmd Msg ) -update msg model = - case msg of - NoOp -> - ( model, Cmd.none ) - - - --- SUBSCRIPTIONS - - -subscriptions : Model -> Sub Msg -subscriptions _ = - Sub.none - - - --- VIEW - - -view : Model -> Html Msg -view _ = - Html.text "main" diff --git a/modules/openapi-generator/src/main/resources/elm/Time.mustache b/modules/openapi-generator/src/main/resources/elm/Time.mustache new file mode 100644 index 00000000000..a44ce3de772 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/elm/Time.mustache @@ -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) \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/elm/api.mustache b/modules/openapi-generator/src/main/resources/elm/api.mustache deleted file mode 100644 index f07fce45585..00000000000 --- a/modules/openapi-generator/src/main/resources/elm/api.mustache +++ /dev/null @@ -1,72 +0,0 @@ -{{>licenseInfo}} - -module Request.{{classname}} exposing ({{#operations}}{{#operation}}{{^-first}}, {{/-first}}{{operationId}}{{#allParams}}{{#isEnum}}, {{enumName}}(..){{/isEnum}}{{/allParams}}{{/operation}}{{/operations}}) - -{{>imports}}import Dict -import Http -import Json.Decode as Decode -import Url.Builder as Url - - -{{#operations}} -{{#operation}} -{{#allParams}} -{{#isEnum}} -type {{enumName}} -{{#allowableValues.enumVars}} {{#-first}}= {{/-first}}{{^-first}}| {{/-first}}{{name}} -{{/allowableValues.enumVars}} - -stringify{{enumName}} : {{enumName}} -> String -stringify{{enumName}} value = - case value of -{{#allowableValues.enumVars}} {{name}} -> - {{{value}}} - -{{/allowableValues.enumVars}} - - -{{/isEnum}} -{{/allParams}} -{{/operation}} -{{/operations}} - - -{{^enableCustomBasePaths}}basePath : String -basePath = - "{{basePath}}" -{{/enableCustomBasePaths}} -{{#operations}} - {{#operation}} - - -{{#notes}} -{-| {{{notes}}} --} -{{/notes}} -{{operationId}} : -{{#headerParams}} -{{#-first}} { {{/-first}}{{^-first}} , {{/-first}}{{paramName}} : {{^required}}Maybe ({{/required}}{{#isListContainer}}List {{/isListContainer}}{{dataType}}{{^required}}){{/required}} -{{#-last}} } -> {{/-last}} -{{/headerParams}} - { onSend : Result Http.Error {{^responses}}(){{/responses}}{{#responses}}{{#-first}}{{^dataType}}(){{/dataType}}{{#isMapContainer}}(Dict.Dict String {{/isMapContainer}}{{#isListContainer}}(List {{/isListContainer}}{{dataType}}{{#isListContainer}}){{/isListContainer}}{{#isMapContainer}}){{/isMapContainer}}{{/-first}}{{/responses}} -> msg -{{#enableCustomBasePaths}} , basePath : String{{/enableCustomBasePaths}} -{{#enableHttpRequestTrackers}} , tracker : Maybe String{{/enableHttpRequestTrackers}} -{{#bodyParam}} , body : {{^required}}Maybe {{/required}}{{dataType}}{{/bodyParam}} -{{#pathParams}} , {{paramName}} : {{#isListContainer}}List {{/isListContainer}}{{#datatypeWithEnum}}{{datatypeWithEnum}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{dataType}}{{/datatypeWithEnum}}{{/pathParams}} -{{#queryParams}} , {{paramName}} : {{^required}}Maybe ({{/required}}{{#isListContainer}}List {{/isListContainer}}{{#datatypeWithEnum}}{{datatypeWithEnum}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{dataType}}{{/datatypeWithEnum}}{{^required}}){{/required}}{{/queryParams}} - } - -> Cmd msg -{{operationId}} {{#headerParams.0}}headers {{/headerParams.0}}params = - Http.request - { method = "{{httpMethod}}" - , headers = List.filterMap identity [{{#headerParams}}{{#required}}(Just << {{/required}}{{^required}}Maybe.map ({{/required}}Http.header "{{baseName}}" << {{>toString}}) {{^isElm018}}headers.{{/isElm018}}{{paramName}}{{^-last}}, {{/-last}}{{/headerParams}}] - , url = Url.crossOrigin {{#enableCustomBasePaths}}params.{{/enableCustomBasePaths}}basePath - [{{#vendorExtensions.pathParams}}{{#paramName}}{{>toString}} params.{{paramName}}{{/paramName}}{{^paramName}}{{{.}}}{{/paramName}}{{^-last}}, {{/-last}}{{/vendorExtensions.pathParams}}] - (List.filterMap identity [{{#queryParams}}{{#required}}(Just << {{/required}}{{^required}}Maybe.map ({{/required}}Url.string "{{baseName}}" << {{>toString}}) {{^isElm018}}params.{{/isElm018}}{{paramName}}{{^-last}}, {{/-last}}{{/queryParams}}]) - , body = {{#bodyParam}}{{^required}}Maybe.withDefault Http.emptyBody <| Maybe.map ({{/required}}Http.jsonBody {{#required}}<|{{/required}}{{^required}}<<{{/required}} {{vendorExtensions.elmEncoder}}{{^required}}){{/required}} params.body{{/bodyParam}}{{^bodyParam}}Http.emptyBody{{/bodyParam}} - , expect = {{^responses}}Http.expectWhatever params.onSend{{/responses}}{{#responses}}{{#-first}}{{^dataType}}Http.expectWhatever params.onSend{{/dataType}}{{#dataType}}Http.expectJson params.onSend {{#isMapContainer}}(Decode.dict {{/isMapContainer}}{{#isListContainer}}(Decode.list {{/isListContainer}}{{#vendorExtensions}}{{elmDecoder}}{{/vendorExtensions}}{{#isListContainer}}){{/isListContainer}}{{#isMapContainer}}){{/isMapContainer}}{{/dataType}}{{/-first}}{{/responses}} - , timeout = Just 30000 - , tracker = {{#enableHttpRequestTrackers}}params.tracker{{/enableHttpRequestTrackers}}{{^enableHttpRequestTrackers}}Nothing{{/enableHttpRequestTrackers}} - } - {{/operation}} -{{/operations}} diff --git a/modules/openapi-generator/src/main/resources/elm/api018.mustache b/modules/openapi-generator/src/main/resources/elm/api018.mustache deleted file mode 100644 index ebe53eeac93..00000000000 --- a/modules/openapi-generator/src/main/resources/elm/api018.mustache +++ /dev/null @@ -1,33 +0,0 @@ -{{>licenseInfo}} - -module Request.{{classname}} exposing ({{#operations}}{{#operation}}{{^-first}}, {{/-first}}{{operationId}}{{/operation}}{{/operations}}) - -{{>imports}}import Dict -import Http -import Json.Decode as Decode - - -basePath : String -basePath = - "{{basePath}}" -{{#operations}} - {{#operation}} - - -{{#notes}} -{-| {{{notes}}} --} -{{/notes}} -{{operationId}} : {{#pathParams}}{{dataType}} -> {{/pathParams}}{{#bodyParam}}{{dataType}} -> {{/bodyParam}}Http.Request {{^responses}}(){{/responses}}{{#responses}}{{#-first}}{{^dataType}}(){{/dataType}}{{#isMapContainer}}(Dict.Dict String {{/isMapContainer}}{{#isListContainer}}(List {{/isListContainer}}{{dataType}}{{#isListContainer}}){{/isListContainer}}{{#isMapContainer}}){{/isMapContainer}}{{/-first}}{{/responses}} -{{operationId}} {{#pathParams}}{{paramName}} {{/pathParams}}{{#bodyParam}}model {{/bodyParam}}= - { method = "{{httpMethod}}" - , url = basePath ++ {{{path}}} - , headers = [] - , body = {{#bodyParam}}Http.jsonBody <| {{vendorExtensions.elmEncoder}} model{{/bodyParam}}{{^bodyParam}}Http.emptyBody{{/bodyParam}} - , expect = {{^responses}}Http.expectStringResponse (\_ -> Ok ()){{/responses}}{{#responses}}{{#-first}}{{^dataType}}Http.expectStringResponse (\_ -> Ok ()){{/dataType}}{{#dataType}}Http.expectJson {{#isMapContainer}}(Decode.dict {{/isMapContainer}}{{#isListContainer}}(Decode.list {{/isListContainer}}{{#vendorExtensions}}{{elmDecoder}}{{/vendorExtensions}}{{#isListContainer}}){{/isListContainer}}{{#isMapContainer}}){{/isMapContainer}}{{/dataType}}{{/-first}}{{/responses}} - , timeout = Just 30000 - , withCredentials = False - } - |> Http.request - {{/operation}} -{{/operations}} diff --git a/modules/openapi-generator/src/main/resources/elm/customType.mustache b/modules/openapi-generator/src/main/resources/elm/customType.mustache index 282c1808ac4..42a2b12d7f9 100644 --- a/modules/openapi-generator/src/main/resources/elm/customType.mustache +++ b/modules/openapi-generator/src/main/resources/elm/customType.mustache @@ -1,6 +1,15 @@ -type {{#vendorExtensions}}{{elmCustomType}}{{/vendorExtensions}} +type {{^paramName}}{{classname}}{{/paramName}}{{enumName}} {{#allowableValues}} {{#enumVars}} - {{#-first}}={{/-first}}{{^-first}}|{{/-first}} {{name}} + {{#-first}}={{/-first}}{{^-first}}|{{/-first}} {{^paramName}}{{classname}}{{/paramName}}{{enumName}}{{name}} {{/enumVars}} -{{/allowableValues}} \ No newline at end of file +{{/allowableValues}} + + +{{#lambda.camelcase}}{{^paramName}}{{classname}}{{/paramName}}{{enumName}}{{/lambda.camelcase}}Variants = +{{#allowableValues}} + {{#enumVars}} + {{#-first}}[{{/-first}}{{^-first}},{{/-first}} {{^paramName}}{{classname}}{{/paramName}}{{enumName}}{{name}} + {{/enumVars}} +{{/allowableValues}} + ] \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/elm/customTypeDecoder.mustache b/modules/openapi-generator/src/main/resources/elm/customTypeDecoder.mustache index 51847f26233..fa42e3b5f92 100644 --- a/modules/openapi-generator/src/main/resources/elm/customTypeDecoder.mustache +++ b/modules/openapi-generator/src/main/resources/elm/customTypeDecoder.mustache @@ -1,16 +1,16 @@ -{{vendorExtensions.elmDecoder}} : Decoder {{vendorExtensions.elmCustomType}} -{{vendorExtensions.elmDecoder}} = - Decode.string - |> Decode.andThen - (\str -> - case str of +{{#lambda.camelcase}}{{classname}}{{/lambda.camelcase}}{{enumName}}Decoder : Json.Decode.Decoder {{classname}}{{nameInCamelCase}} +{{#lambda.camelcase}}{{classname}}{{/lambda.camelcase}}{{enumName}}Decoder = + Json.Decode.{{#isString}}string{{/isString}}{{^isString}}int{{/isString}} + |> Json.Decode.andThen + (\value -> + case value of {{#allowableValues}} {{#enumVars}} - {{{value}}} -> - Decode.succeed {{name}} + {{#isString}}{{{value}}}{{/isString}}{{^isString}}{{name}}{{/isString}} -> + Json.Decode.succeed {{classname}}{{enumName}}{{name}} {{/enumVars}} {{/allowableValues}} other -> - Decode.fail <| "Unknown type: " ++ other - ) + Json.Decode.fail <| "Unknown type: " ++ {{^isString}}String.fromInt {{/isString}}other + ) \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/elm/customTypeEncoder.mustache b/modules/openapi-generator/src/main/resources/elm/customTypeEncoder.mustache index e5dbfbe02a4..637f3e43312 100644 --- a/modules/openapi-generator/src/main/resources/elm/customTypeEncoder.mustache +++ b/modules/openapi-generator/src/main/resources/elm/customTypeEncoder.mustache @@ -1,10 +1,4 @@ -{{vendorExtensions.elmEncoder}} : {{vendorExtensions.elmCustomType}} -> Encode.Value -{{vendorExtensions.elmEncoder}} model = - case model of -{{#allowableValues}} -{{#enumVars}} - {{name}} -> - Encode.string {{{value}}} - -{{/enumVars}} -{{/allowableValues}} \ No newline at end of file +{{>customTypeToString}} +{{#lambda.camelcase}}encode{{classname}}{{enumName}}{{/lambda.camelcase}} : {{classname}}{{enumName}} -> Json.Encode.Value +{{#lambda.camelcase}}encode{{classname}}{{enumName}}{{/lambda.camelcase}} = +{{#isString}} Json.Encode.string << stringFrom{{classname}}{{enumName}}{{/isString}}{{^isString}} Json.Encode.int << intFrom{{classname}}{{enumName}}{{/isString}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/elm/customTypeToString.mustache b/modules/openapi-generator/src/main/resources/elm/customTypeToString.mustache new file mode 100644 index 00000000000..d233436af7f --- /dev/null +++ b/modules/openapi-generator/src/main/resources/elm/customTypeToString.mustache @@ -0,0 +1,15 @@ +stringFrom{{^paramName}}{{classname}}{{/paramName}}{{enumName}} : {{^paramName}}{{classname}}{{/paramName}}{{enumName}} -> String +stringFrom{{^paramName}}{{classname}}{{/paramName}}{{enumName}}{{#isNumeric}} = + String.fromInt << intFrom{{^paramName}}{{classname}}{{/paramName}}{{enumName}} + + +intFrom{{^paramName}}{{classname}}{{/paramName}}{{enumName}} : {{^paramName}}{{classname}}{{/paramName}}{{enumName}} -> Int +intFrom{{^paramName}}{{classname}}{{/paramName}}{{enumName}}{{/isNumeric}} model = + case model of +{{#allowableValues}} +{{#enumVars}} + {{^paramName}}{{classname}}{{/paramName}}{{enumName}}{{name}} -> + {{#isString}}{{{value}}}{{/isString}}{{^isString}}{{name}}{{/isString}} + +{{/enumVars}} +{{/allowableValues}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/elm/customTypeWithData.mustache b/modules/openapi-generator/src/main/resources/elm/customTypeWithData.mustache new file mode 100644 index 00000000000..68edaa5ffea --- /dev/null +++ b/modules/openapi-generator/src/main/resources/elm/customTypeWithData.mustache @@ -0,0 +1,4 @@ +type {{classname}} +{{#oneOf}} + {{#-first}}={{/-first}}{{^-first}}|{{/-first}} {{classname}}{{.}} {{.}} +{{/oneOf}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/elm/customTypeWithDataDecoder.mustache b/modules/openapi-generator/src/main/resources/elm/customTypeWithDataDecoder.mustache new file mode 100644 index 00000000000..2c462fabe18 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/elm/customTypeWithDataDecoder.mustache @@ -0,0 +1,21 @@ +{{#lambda.camelcase}}{{classname}}{{/lambda.camelcase}}Decoder : Json.Decode.Decoder {{classname}} +{{#lambda.camelcase}}{{classname}}{{/lambda.camelcase}}Decoder ={{^discriminator}} + Json.Decode.oneOf{{#oneOf}} + {{#-first}}[{{/-first}}{{^-first}},{{/-first}} Json.Decode.map {{classname}}{{{.}}} {{#lambda.camelcase}}{{{.}}}{{/lambda.camelcase}}Decoder{{/oneOf}} + ] +{{/discriminator}}{{#discriminator}} + Json.Decode.field "{{{propertyName}}}" Json.Decode.string + |> Json.Decode.andThen {{#lambda.camelcase}}{{classname}}{{/lambda.camelcase}}TagDecoder + + +{{#lambda.camelcase}}{{classname}}{{/lambda.camelcase}}TagDecoder : String -> Json.Decode.Decoder {{classname}} +{{#lambda.camelcase}}{{classname}}{{/lambda.camelcase}}TagDecoder tag = + case tag of +{{#mappedModels}} + "{{mappingName}}" -> + Json.Decode.map {{classname}}{{modelName}} {{#lambda.camelcase}}{{modelName}}{{/lambda.camelcase}}Decoder + +{{/mappedModels}} + _ -> + Json.Decode.fail <| "Trying to decode {{classname}}, but {{{propertyName}}} '" ++ tag ++ "' is not supported." +{{/discriminator}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/elm/customTypeWithDataEncoder.mustache b/modules/openapi-generator/src/main/resources/elm/customTypeWithDataEncoder.mustache new file mode 100644 index 00000000000..d20bef4427a --- /dev/null +++ b/modules/openapi-generator/src/main/resources/elm/customTypeWithDataEncoder.mustache @@ -0,0 +1,13 @@ +encode{{classname}} : {{classname}} -> Json.Encode.Value +encode{{classname}} model = + case model of{{^discriminator}}{{#oneOf}} + {{classname}}{{{.}}} subModel -> + encode{{{.}}} subModel + +{{/oneOf}}{{/discriminator}}{{#discriminator}} +{{#mappedModels}} + {{classname}}{{modelName}} subModel -> + encode{{modelName}}WithTag ("{{discriminatorName}}", "{{mappingName}}") subModel + +{{/mappedModels}} +{{/discriminator}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/elm/elm-package018.mustache b/modules/openapi-generator/src/main/resources/elm/elm-package018.mustache deleted file mode 100644 index 6bd1cd88fa7..00000000000 --- a/modules/openapi-generator/src/main/resources/elm/elm-package018.mustache +++ /dev/null @@ -1,19 +0,0 @@ -{ - "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", - "danyx23/elm-uuid": "2.0.2 <= v < 2.1.1", - "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": "3.0.0 <= v < 4.0.0" - }, - "elm-version": "0.18.0 <= v < 0.19.0" -} diff --git a/modules/openapi-generator/src/main/resources/elm/elm.mustache b/modules/openapi-generator/src/main/resources/elm/elm.mustache index 398da0d2d6d..bf0d1f8f4b6 100644 --- a/modules/openapi-generator/src/main/resources/elm/elm.mustache +++ b/modules/openapi-generator/src/main/resources/elm/elm.mustache @@ -3,10 +3,9 @@ "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", diff --git a/modules/openapi-generator/src/main/resources/elm/fieldDecoder.mustache b/modules/openapi-generator/src/main/resources/elm/fieldDecoder.mustache new file mode 100644 index 00000000000..08364e454a3 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/elm/fieldDecoder.mustache @@ -0,0 +1 @@ +{{#isDateTime}}Api.Time.dateTimeDecoder{{/isDateTime}}{{#isDate}}Api.Time.dateDecoder{{/isDate}}{{#isByteArray}}Json.Decode.string{{/isByteArray}}{{#isBinary}}Json.Decode.string{{/isBinary}}{{#isString}}{{^isEnum}}{{^isUuid}}Json.Decode.string{{/isUuid}}{{/isEnum}}{{/isString}}{{#isInteger}}Json.Decode.int{{/isInteger}}{{#isLong}}Json.Decode.int{{/isLong}}{{#isNumber}}Json.Decode.float{{/isNumber}}{{#isFloat}}Json.Decode.float{{/isFloat}}{{#isDouble}}Json.Decode.float{{/isDouble}}{{#isBoolean}}Json.Decode.bool{{/isBoolean}}{{#isUuid}}Uuid.decoder{{/isUuid}}{{#isModel}}{{#isDefault}}Api.Data.{{/isDefault}}{{#lambda.camelcase}}{{#isEnum}}{{classname}}{{enumName}}{{/isEnum}}{{^isEnum}}{{dataType}}{{/isEnum}}{{/lambda.camelcase}}Decoder{{/isModel}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/elm/fieldEncoder.mustache b/modules/openapi-generator/src/main/resources/elm/fieldEncoder.mustache new file mode 100644 index 00000000000..2644d33c3ad --- /dev/null +++ b/modules/openapi-generator/src/main/resources/elm/fieldEncoder.mustache @@ -0,0 +1 @@ +{{#isDateTime}}Api.Time.encodeDateTime{{/isDateTime}}{{#isDate}}Api.Time.encodeDate{{/isDate}}{{#isByteArray}}Json.Encode.string{{/isByteArray}}{{#isBinary}}Json.Decode.string{{/isBinary}}{{#isString}}{{^isEnum}}{{^isUuid}}Json.Encode.string{{/isUuid}}{{/isEnum}}{{/isString}}{{#isInteger}}Json.Encode.int{{/isInteger}}{{#isLong}}Json.Encode.int{{/isLong}}{{#isNumber}}Json.Encode.float{{/isNumber}}{{#isFloat}}Json.Encode.float{{/isFloat}}{{#isDouble}}Json.Encode.float{{/isDouble}}{{#isBoolean}}Json.Encode.bool{{/isBoolean}}{{#isUuid}}Uuid.encode{{/isUuid}}{{#isModel}}{{#lambda.camelcase}}encode{{#isEnum}}{{classname}}{{enumName}}{{/isEnum}}{{^isEnum}}{{dataType}}{{/isEnum}}{{/lambda.camelcase}}{{/isModel}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/elm/imports.mustache b/modules/openapi-generator/src/main/resources/elm/imports.mustache deleted file mode 100644 index 30350cde7d0..00000000000 --- a/modules/openapi-generator/src/main/resources/elm/imports.mustache +++ /dev/null @@ -1,3 +0,0 @@ -{{#elmImports}} -import {{moduleName}}{{#as}} as {{as}}{{/as}}{{#hasExposures}} exposing ({{#exposures}}{{^-first}}, {{/-first}}{{.}}{{/exposures}}){{/hasExposures}} -{{/elmImports}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/elm/licenseInfo.mustache b/modules/openapi-generator/src/main/resources/elm/licenseInfo.mustache index 49b157e7408..19a72ee6240 100644 --- a/modules/openapi-generator/src/main/resources/elm/licenseInfo.mustache +++ b/modules/openapi-generator/src/main/resources/elm/licenseInfo.mustache @@ -11,5 +11,8 @@ NOTE: This file is auto generated by the openapi-generator. https://github.com/openapitools/openapi-generator.git - Do not edit this file manually. + + DO NOT EDIT THIS FILE MANUALLY. + + For more info on generating Elm code, see https://eriktim.github.io/openapi-elm/ -} diff --git a/modules/openapi-generator/src/main/resources/elm/model.mustache b/modules/openapi-generator/src/main/resources/elm/model.mustache index cba3f3ce242..701ffbf97db 100644 --- a/modules/openapi-generator/src/main/resources/elm/model.mustache +++ b/modules/openapi-generator/src/main/resources/elm/model.mustache @@ -1,20 +1,160 @@ {{>licenseInfo}} -module Data.{{classname}} exposing ({{#models}}{{#model}}{{classname}}{{#hasChildren}}(..){{/hasChildren}}{{#isEnum}}(..){{/isEnum}}{{^isEnum}}{{#vars}}{{#isEnum}}, {{vendorExtensions.elmCustomType}}(..){{/isEnum}}{{/vars}}{{/isEnum}}, decoder, encode{{^isEnum}}{{^discriminator}}{{^oneOf}}, encodeWithTag{{/oneOf}}{{/discriminator}}{{/isEnum}}, toString{{/model}}{{/models}}) +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}} ) + +import Api{{#includeTime}} +import Api.Time exposing (Posix){{/includeTime}} +import Dict +import Json.Decode +import Json.Encode{{#includeUuid}} +import Uuid exposing (Uuid){{/includeUuid}} + + +-- MODEL + -{{>imports}}import Dict exposing (Dict) -import Json.Decode as Decode exposing (Decoder) -import Json.Decode.Pipeline exposing ({{#isElm018}}decode, {{/isElm018}}optional, required) -import Json.Encode as Encode {{#models}} {{#model}} - - {{#description}} -{-| {{{description}}} +{-| {{{.}}} -} {{/description}} -{{#isEnum}}{{>modelTypeCustom}}{{/isEnum}}{{^isEnum}}{{#discriminator}}{{>modelTypeDiscriminator}}{{/discriminator}}{{^discriminator}}{{#oneOf}}{{#-first}}{{>modelTypeDiscriminator}}{{/-first}}{{/oneOf}}{{^oneOf}}{{#isAlias}}{{>modelTypePrimitive}}{{/isAlias}}{{^isAlias}}{{#isArrayModel}}{{>modelTypeArray}}{{/isArrayModel}}{{^isArrayModel}}{{>modelTypeRecord}}{{/isArrayModel}}{{/isAlias}}{{/oneOf}}{{/discriminator}}{{/isEnum}} +{{#isEnum}}{{>customType}}{{/isEnum}}{{^isEnum}}{{#oneOf}}{{#-first}}{{>customTypeWithData}}{{/-first}}{{/oneOf}}{{^oneOf}}{{>record}}{{/oneOf}}{{/isEnum}} + {{/model}} {{/models}} +-- ENCODER + + +{{#models}} +{{#model}} +{{#isEnum}}{{>customTypeEncoder}}{{/isEnum}}{{^isEnum}}{{#oneOf}}{{#-first}}{{>customTypeWithDataEncoder}}{{/-first}}{{/oneOf}}{{^oneOf}}{{>recordEncoder}}{{/oneOf}}{{/isEnum}} + + +{{/model}} +{{/models}} +-- DECODER + + +{{#models}} +{{#model}} +{{#isEnum}}{{>customTypeDecoder}}{{/isEnum}}{{^isEnum}}{{#oneOf}}{{#-first}}{{>customTypeWithDataDecoder}}{{/-first}}{{/oneOf}}{{^oneOf}}{{>recordDecoder}}{{/oneOf}}{{/isEnum}} + + +{{/model}} +{{/models}} + + +-- 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 \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/elm/modelTypeArray.mustache b/modules/openapi-generator/src/main/resources/elm/modelTypeArray.mustache deleted file mode 100644 index 1125af22cd1..00000000000 --- a/modules/openapi-generator/src/main/resources/elm/modelTypeArray.mustache +++ /dev/null @@ -1,17 +0,0 @@ -type alias {{classname}} = - {{parent}} - - -decoder : Decoder {{classname}} -decoder = - Decode.list {{vendorExtensions.elmDecoder}} - - -encode : {{classname}} -> Encode.Value -encode items = - Encode.list {{#isElm018}}(List.map {{/isElm018}}{{vendorExtensions.elmEncoder}} items{{#isElm018}}){{/isElm018}} - - -toString : {{classname}} -> String -toString = - Encode.encode 0 << encode diff --git a/modules/openapi-generator/src/main/resources/elm/modelTypeCustom.mustache b/modules/openapi-generator/src/main/resources/elm/modelTypeCustom.mustache deleted file mode 100644 index dbc2bb22cb8..00000000000 --- a/modules/openapi-generator/src/main/resources/elm/modelTypeCustom.mustache +++ /dev/null @@ -1,19 +0,0 @@ -{{>customType}} - - -{{>customTypeDecoder}} - - -{{>customTypeEncoder}} - - -toString : {{classname}} -> String -toString model = - case model of -{{#allowableValues}} -{{#enumVars}} - {{name}} -> - {{{value}}} - -{{/enumVars}} -{{/allowableValues}} diff --git a/modules/openapi-generator/src/main/resources/elm/modelTypeDiscriminator.mustache b/modules/openapi-generator/src/main/resources/elm/modelTypeDiscriminator.mustache deleted file mode 100644 index 1b9182b7424..00000000000 --- a/modules/openapi-generator/src/main/resources/elm/modelTypeDiscriminator.mustache +++ /dev/null @@ -1,56 +0,0 @@ -type {{classname}} -{{^discriminator}}{{#oneOf}} - {{#-first}}={{/-first}}{{^-first}}|{{/-first}} {{{.}}}Type {{{.}}} -{{/oneOf}}{{/discriminator}} -{{#discriminator}}{{#mappedModels}} - {{#-first}}={{/-first}}{{^-first}}|{{/-first}} {{modelName}}Type {{modelName}} -{{/mappedModels}}{{/discriminator}} - - -decoder : Decoder {{classname}} -decoder = -{{^discriminator}} - Decode.oneOf -{{#oneOf}} - {{#-first}}[{{/-first}}{{^-first}},{{/-first}} Decode.map {{{.}}}Type {{{.}}}.decoder -{{/oneOf}} - ] -{{/discriminator}} -{{#discriminator}} - Decode.field "{{{discriminator.propertyName}}}" Decode.string - |> Decode.andThen {{classVarName}}Decoder - - -{{classVarName}}Decoder : String -> Decoder {{classname}} -{{classVarName}}Decoder tag = - case tag of -{{#mappedModels}} - "{{mappingName}}" -> - Decode.map {{modelName}}Type {{modelName}}.decoder - -{{/mappedModels}} - _ -> - Decode.fail <| "Trying to decode {{classname}}, but {{{discriminatorName}}} '" ++ tag ++ "' is not supported." -{{/discriminator}} - - -encode : {{classname}} -> Encode.Value -encode model = - case model of -{{^discriminator}}{{#oneOf}} - {{{.}}}Type subModel -> - {{{.}}}.encode subModel - -{{/oneOf}}{{/discriminator}} -{{#discriminator}} -{{#mappedModels}} - {{modelName}}Type subModel -> - {{modelName}}.encodeWithTag ("{{discriminatorName}}", "{{mappingName}}") subModel - -{{/mappedModels}} -{{/discriminator}} - - -toString : {{classname}} -> String -toString = - Encode.encode 0 << encode diff --git a/modules/openapi-generator/src/main/resources/elm/modelTypePrimitive.mustache b/modules/openapi-generator/src/main/resources/elm/modelTypePrimitive.mustache deleted file mode 100644 index 376f8fc81d3..00000000000 --- a/modules/openapi-generator/src/main/resources/elm/modelTypePrimitive.mustache +++ /dev/null @@ -1,17 +0,0 @@ -type alias {{classname}} - = {{dataType}} - - -decoder : Decoder {{classname}} -decoder = - {{vendorExtensions.elmDecoder}} - - -encode : {{classname}} -> Encode.Value -encode = - {{vendorExtensions.elmEncoder}} - - -toString : {{classname}} -> String -toString = - {{>toString}} diff --git a/modules/openapi-generator/src/main/resources/elm/modelTypeRecord.mustache b/modules/openapi-generator/src/main/resources/elm/modelTypeRecord.mustache deleted file mode 100644 index e267c46321c..00000000000 --- a/modules/openapi-generator/src/main/resources/elm/modelTypeRecord.mustache +++ /dev/null @@ -1,33 +0,0 @@ -type alias {{classname}} = - { {{#allVars}}{{^-first}} , {{/-first}}{{name}} : {{^required}}{{^isNullable}}Maybe ({{/isNullable}}{{/required}}{{>recordFieldType}}{{^required}}{{^isNullable}}){{/isNullable}}{{/required}} -{{/allVars}} } -{{#vars}} -{{#isEnum}} - - -{{>customType}} -{{/isEnum}} -{{/vars}} - - -{{>recordDecoder}} - - -{{>recordEncoder}} - - -toString : {{classname}} -> String -toString = - Encode.encode 0 << encode - - -{{#vars}} -{{#isEnum}} - - -{{>customTypeDecoder}} - - -{{>customTypeEncoder}} -{{/isEnum}} -{{/vars}} diff --git a/modules/openapi-generator/src/main/resources/elm/operation.mustache b/modules/openapi-generator/src/main/resources/elm/operation.mustache new file mode 100644 index 00000000000..2c8b071c0ef --- /dev/null +++ b/modules/openapi-generator/src/main/resources/elm/operation.mustache @@ -0,0 +1,46 @@ +{{>licenseInfo}} + +module Api.Request.{{classname}} exposing +{{#operations}}{{#operation}} {{#-first}}( {{/-first}}{{^-first}}, {{/-first}}{{operationId}}{{#allParams}}{{#isEnum}}, {{enumName}}(..), {{#lambda.camelcase}}{{enumName}}{{/lambda.camelcase}}Variants{{/isEnum}}{{/allParams}} +{{/operation}}{{/operations}} ) + +import Api +import Api.Data{{#includeTime}} +import Api.Time exposing (Posix){{/includeTime}} +import Dict +import Http +import Json.Decode +import Json.Encode{{#includeUuid}} +import Uuid exposing (Uuid){{/includeUuid}} +{{#operations}} +{{#operation}} +{{#allParams}} +{{#isEnum}} + + +{{>customType}} + + +{{>customTypeToString}} +{{/isEnum}} +{{/allParams}} +{{/operation}} +{{/operations}} +{{#operations}}{{#operation}} + + +{{#notes}} +{-| {{{notes}}} +-} +{{/notes}} +{{operationId}} : {{#allParams}}{{^required}}Maybe {{/required}}{{#isListContainer}}List {{/isListContainer}}{{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{#isModel}}Api.Data.{{/isModel}}{{dataType}}{{/datatypeWithEnum}} -> {{/allParams}}Api.Request {{^responses}}(){{/responses}}{{#responses}}{{#-first}}{{^dataType}}(){{/dataType}}{{#isMapContainer}}(Dict.Dict String {{/isMapContainer}}{{#isListContainer}}(List {{/isListContainer}}{{^primitiveType}}Api.Data.{{/primitiveType}}{{#items}}{{#isModel}}Api.Data.{{/isModel}}{{/items}}{{dataType}}{{#isListContainer}}){{/isListContainer}}{{#isMapContainer}}){{/isMapContainer}}{{/-first}}{{/responses}} +{{operationId}}{{#allParams}} {{paramName}}{{/allParams}} = + Api.request + "{{httpMethod}}" + "{{path}}" + [{{#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}}{{#isDefault}}{{^dataType}}(Json.Decode.succeed ()){{/dataType}}{{#dataType}}{{>recordFieldValueDecoder}}{{/dataType}}{{/isDefault}}{{/responses}} +{{/operation}}{{/operations}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/elm/paramToString.mustache b/modules/openapi-generator/src/main/resources/elm/paramToString.mustache new file mode 100644 index 00000000000..eb8fe145ef4 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/elm/paramToString.mustache @@ -0,0 +1 @@ +{{#isListContainer}}String.join "," << List.map {{#items}}{{>paramToString}}{{/items}}{{/isListContainer}}{{^isListContainer}}{{^isEnum}}{{#isString}}identity{{/isString}}{{#isBinary}}identity{{/isBinary}}{{#isByteArray}}identity{{/isByteArray}}{{/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}}{{/isListContainer}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/elm/record.mustache b/modules/openapi-generator/src/main/resources/elm/record.mustache new file mode 100644 index 00000000000..4039db3fa34 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/elm/record.mustache @@ -0,0 +1,24 @@ +{{#discriminator}} +type {{classname}} + = {{classname}} Base{{classname}} +{{#mappedModels}} | {{classname}}{{modelName}} {{modelName}} +{{/mappedModels}} + + +{{/discriminator}} +type alias {{#discriminator}}Base{{/discriminator}}{{classname}} = +{{#lambda.indented}} + { {{#parent}}{{#allOf}}{{^-first}}, {{/-first}}{{#lambda.camelcase}}{{.}}{{/lambda.camelcase}}: {{.}} +{{/allOf}}, {{/parent}}{{#vars}}{{^-first}}, {{/-first}}{{name}} : {{#isCircularReference}}{{classname}}{{nameInCamelCase}}{{/isCircularReference}}{{^isCircularReference}}{{>recordField}}{{/isCircularReference}} +{{/vars}} +}{{/lambda.indented}}{{#vars}}{{#isCircularReference}} + + +type {{classname}}{{nameInCamelCase}} = {{classname}}{{nameInCamelCase}} ({{>recordField}}) + + +unwrap{{classname}}{{nameInCamelCase}} : {{classname}}{{nameInCamelCase}} -> {{>recordField}} +unwrap{{classname}}{{nameInCamelCase}} ({{classname}}{{nameInCamelCase}} {{name}}) = {{name}}{{/isCircularReference}}{{/vars}}{{#vars}}{{#isEnum}} + + +{{>customType}}{{/isEnum}}{{/vars}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/elm/recordDecoder.mustache b/modules/openapi-generator/src/main/resources/elm/recordDecoder.mustache index f9b2e907615..c787e2fa41a 100644 --- a/modules/openapi-generator/src/main/resources/elm/recordDecoder.mustache +++ b/modules/openapi-generator/src/main/resources/elm/recordDecoder.mustache @@ -1,6 +1,29 @@ -decoder : Decoder {{classname}} -decoder = - {{#isElm018}}decode{{/isElm018}}{{#isElm019}}Decode.succeed{{/isElm019}} {{classname}} -{{#allVars}} - |> {{>recordFieldDecoder}} -{{/allVars}} +{{#discriminator}} +{{#lambda.camelcase}}{{classname}}{{/lambda.camelcase}}Decoder : Json.Decode.Decoder {{classname}} +{{#lambda.camelcase}}{{classname}}{{/lambda.camelcase}}Decoder = + Json.Decode.field "{{{propertyName}}}" Json.Decode.string + |> Json.Decode.andThen {{#lambda.camelcase}}{{classname}}{{/lambda.camelcase}}TagDecoder + + +{{#lambda.camelcase}}{{classname}}{{/lambda.camelcase}}TagDecoder : String -> Json.Decode.Decoder {{classname}} +{{#lambda.camelcase}}{{classname}}{{/lambda.camelcase}}TagDecoder tag = + case tag of +{{#mappedModels}} + "{{mappingName}}" -> + Json.Decode.map {{classname}}{{modelName}} {{#lambda.camelcase}}{{modelName}}{{/lambda.camelcase}}Decoder + +{{/mappedModels}} + _ -> + Json.Decode.map {{classname}} base{{classname}}Decoder + + +{{/discriminator}} +{{#lambda.camelcase}}{{#discriminator}}Base{{/discriminator}}{{classname}}{{/lambda.camelcase}}Decoder : Json.Decode.Decoder {{#discriminator}}Base{{/discriminator}}{{classname}} +{{#lambda.camelcase}}{{#discriminator}}Base{{/discriminator}}{{classname}}{{/lambda.camelcase}}Decoder = + Json.Decode.succeed {{#discriminator}}Base{{/discriminator}}{{classname}}{{#parent}}{{#allOf}} + |> decodeChain {{#lambda.camelcase}}{{.}}{{/lambda.camelcase}}Decoder{{^-last}}, {{/-last}}{{/allOf}}{{/parent}}{{#vars}} + |> {{>recordFieldDecoder}}{{/vars}}{{#vars}}{{#isEnum}} + + +{{>customTypeDecoder}} +{{/isEnum}}{{/vars}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/elm/recordEncoder.mustache b/modules/openapi-generator/src/main/resources/elm/recordEncoder.mustache index 1f626719fa9..a268be8f179 100644 --- a/modules/openapi-generator/src/main/resources/elm/recordEncoder.mustache +++ b/modules/openapi-generator/src/main/resources/elm/recordEncoder.mustache @@ -1,16 +1,35 @@ -encode : {{classname}} -> Encode.Value -encode = - Encode.object << encodePairs +{{#discriminator}} +encode{{classname}} : {{classname}} -> Json.Encode.Value +encode{{classname}} model = + case model of + {{classname}} subModel -> + encodeBase{{classname}} subModel{{#mappedModels}} + + {{classname}}{{modelName}} subModel -> + {{#lambda.camelcase}}encode{{modelName}}WithTag{{/lambda.camelcase}} ("{{discriminatorName}}", "{{mappingName}}") subModel +{{/mappedModels}} -encodeWithTag : ( String, String ) -> {{classname}} -> Encode.Value -encodeWithTag (tagField, tag) model = - Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ] +{{/discriminator}} +{{#lambda.camelcase}}encode{{#discriminator}}Base{{/discriminator}}{{classname}}{{/lambda.camelcase}} : {{#discriminator}}Base{{/discriminator}}{{classname}} -> Json.Encode.Value +{{#lambda.camelcase}}encode{{#discriminator}}Base{{/discriminator}}{{classname}}{{/lambda.camelcase}} = + encodeObject << {{#lambda.camelcase}}encode{{#discriminator}}Base{{/discriminator}}{{classname}}Pairs{{/lambda.camelcase}} -encodePairs : {{classname}} -> List (String, Encode.Value) -encodePairs model = -{{#allVars}} - {{#-first}}[{{/-first}}{{^-first}},{{/-first}} {{>recordFieldEncoder}} -{{/allVars}} - ] +{{#lambda.camelcase}}encode{{#discriminator}}Base{{/discriminator}}{{classname}}WithTag{{/lambda.camelcase}} : ( String, String ) -> {{#discriminator}}Base{{/discriminator}}{{classname}} -> Json.Encode.Value +{{#lambda.camelcase}}encode{{#discriminator}}Base{{/discriminator}}{{classname}}WithTag{{/lambda.camelcase}} (tagField, tag) model = + encodeObject ({{#lambda.camelcase}}encode{{#discriminator}}Base{{/discriminator}}{{classname}}Pairs{{/lambda.camelcase}} model ++ [ encode tagField Json.Encode.string tag ]) + + +{{#lambda.camelcase}}encode{{#discriminator}}Base{{/discriminator}}{{classname}}Pairs{{/lambda.camelcase}} : {{#discriminator}}Base{{/discriminator}}{{classname}} -> List EncodedField +{{#lambda.camelcase}}encode{{#discriminator}}Base{{/discriminator}}{{classname}}Pairs{{/lambda.camelcase}} model = + let + pairs = +{{#vars}} {{#-first}}[{{/-first}}{{^-first}},{{/-first}} {{>recordFieldEncoder}} +{{/vars}} + ] + in + {{#parent}}{{#allOf}}{{#lambda.camelcase}}encode{{.}}Pairs{{/lambda.camelcase}} model.{{#lambda.camelcase}}{{.}}{{/lambda.camelcase}} ++ {{/allOf}}{{/parent}}pairs{{#vars}}{{#isEnum}} + +{{>customTypeEncoder}} +{{/isEnum}}{{/vars}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/elm/recordField.mustache b/modules/openapi-generator/src/main/resources/elm/recordField.mustache new file mode 100644 index 00000000000..78bd5ff0fa3 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/elm/recordField.mustache @@ -0,0 +1 @@ +{{#isNullable}}Maybe {{#isContainer}}({{/isContainer}}{{/isNullable}}{{^isNullable}}{{^required}}Maybe {{#isContainer}}({{/isContainer}}{{/required}}{{/isNullable}}{{#isListContainer}}List {{/isListContainer}}{{#isMapContainer}}Dict.Dict String {{/isMapContainer}}{{#isEnum}}{{classname}}{{enumName}}{{/isEnum}}{{^isEnum}}{{#items}}({{>recordField}}){{/items}}{{^isContainer}}{{dataType}}{{/isContainer}}{{/isEnum}}{{#isContainer}}{{#isNullable}}){{/isNullable}}{{^isNullable}}{{^required}}){{/required}}{{/isNullable}}{{/isContainer}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/elm/recordFieldDecoder.mustache b/modules/openapi-generator/src/main/resources/elm/recordFieldDecoder.mustache index 9a9b7ee0856..13760c0adff 100644 --- a/modules/openapi-generator/src/main/resources/elm/recordFieldDecoder.mustache +++ b/modules/openapi-generator/src/main/resources/elm/recordFieldDecoder.mustache @@ -1 +1 @@ -{{#required}}required{{/required}}{{^required}}optional{{/required}} "{{baseName}}" {{^required}}{{^isNullable}}(Decode.nullable {{/isNullable}}{{/required}}{{>recordFieldValueDecoder}}{{^required}}{{^isNullable}}) {{{defaultValue}}}{{/isNullable}}{{/required}} \ No newline at end of file +{{#required}}decode{{/required}}{{^required}}maybeDecode{{/required}}{{#isNullable}}Nullable{{/isNullable}}{{#isCircularReference}}Lazy {{classname}}{{nameInCamelCase}}{{/isCircularReference}} "{{baseName}}" {{>recordFieldValueDecoder}} {{^required}}{{#defaultValue}}(Just {{{.}}}){{/defaultValue}}{{^defaultValue}}Nothing{{/defaultValue}}{{/required}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/elm/recordFieldEncoder.mustache b/modules/openapi-generator/src/main/resources/elm/recordFieldEncoder.mustache index 2a48bbc31b4..d01a870c65f 100644 --- a/modules/openapi-generator/src/main/resources/elm/recordFieldEncoder.mustache +++ b/modules/openapi-generator/src/main/resources/elm/recordFieldEncoder.mustache @@ -1 +1 @@ -( "{{baseName}}", {{#discriminatorValue}}Encode.string "{{discriminatorValue}}"{{/discriminatorValue}}{{^discriminatorValue}}{{^required}}{{^isNullable}}Maybe.withDefault Encode.null (Maybe.map {{/isNullable}}{{/required}}{{>recordFieldValueEncoder}} model.{{name}}{{#isNullable}}){{/isNullable}}{{^required}}{{^isNullable}}){{/isNullable}}{{/required}}{{/discriminatorValue}} ) \ No newline at end of file +{{#required}}encode{{/required}}{{^required}}maybeEncode{{/required}}{{#isNullable}}Nullable{{/isNullable}} "{{baseName}}" {{>recordFieldValueEncoder}} {{#isCircularReference}}<| unwrap{{classname}}{{nameInCamelCase}} {{/isCircularReference}}model.{{name}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/elm/recordFieldType.mustache b/modules/openapi-generator/src/main/resources/elm/recordFieldType.mustache deleted file mode 100644 index bbfefae18e8..00000000000 --- a/modules/openapi-generator/src/main/resources/elm/recordFieldType.mustache +++ /dev/null @@ -1 +0,0 @@ -{{#isNullable}}(Maybe {{/isNullable}}{{#isContainer}}({{#isListContainer}}List{{/isListContainer}}{{#isMapContainer}}Dict String{{/isMapContainer}} {{#items}}{{>recordFieldType}}{{/items}}){{/isContainer}}{{^isContainer}}{{#isEnum}}{{nameInCamelCase}}{{/isEnum}}{{^isEnum}}{{dataType}}{{/isEnum}}{{/isContainer}}{{#isNullable}}){{/isNullable}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/elm/recordFieldValueDecoder.mustache b/modules/openapi-generator/src/main/resources/elm/recordFieldValueDecoder.mustache index f461987d5c1..f57d5ed5eb8 100644 --- a/modules/openapi-generator/src/main/resources/elm/recordFieldValueDecoder.mustache +++ b/modules/openapi-generator/src/main/resources/elm/recordFieldValueDecoder.mustache @@ -1 +1 @@ -{{#isNullable}}(Decode.nullable {{/isNullable}}{{#isContainer}}({{#isListContainer}}Decode.list{{/isListContainer}}{{#isMapContainer}}Decode.dict{{/isMapContainer}} {{#items}}{{>recordFieldValueDecoder}}{{/items}}){{/isContainer}}{{^isContainer}}{{vendorExtensions.elmDecoder}}{{/isContainer}}{{#isNullable}}){{^required}} {{{defaultValue}}}{{/required}}{{/isNullable}} \ No newline at end of file +{{#isListContainer}}(Json.Decode.list {{/isListContainer}}{{#isMapContainer}}(Json.Decode.dict {{/isMapContainer}}{{#items}}{{>recordFieldValueDecoder}}{{/items}}{{^isContainer}}{{#isCircularReference}}(Json.Decode.lazy (\_ -> {{/isCircularReference}}{{>fieldDecoder}}{{#isCircularReference}})){{/isCircularReference}}{{/isContainer}}{{#isListContainer}}){{/isListContainer}}{{#isMapContainer}}){{/isMapContainer}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/elm/recordFieldValueEncoder.mustache b/modules/openapi-generator/src/main/resources/elm/recordFieldValueEncoder.mustache index ecd856a1a7f..e072d4731c9 100644 --- a/modules/openapi-generator/src/main/resources/elm/recordFieldValueEncoder.mustache +++ b/modules/openapi-generator/src/main/resources/elm/recordFieldValueEncoder.mustache @@ -1 +1 @@ -{{#isNullable}}Maybe.withDefault Encode.null (Maybe.map {{/isNullable}}{{#isContainer}}({{#isListContainer}}Encode.list{{#isElm018}} << List.map{{/isElm018}}{{/isListContainer}}{{#isMapContainer}}Encode.dict identity{{/isMapContainer}} {{#items}}{{>recordFieldValueEncoder}}{{/items}}{{/isContainer}}{{^isContainer}}{{vendorExtensions.elmEncoder}}{{/isContainer}}{{#isContainer}}){{/isContainer}} \ No newline at end of file +{{#isContainer}}({{#isListContainer}}Json.Encode.list{{/isListContainer}}{{#isMapContainer}}Json.Encode.dict identity{{/isMapContainer}} {{#items}}{{>recordFieldValueEncoder}}{{/items}}{{/isContainer}}{{^isContainer}}{{>fieldEncoder}}{{/isContainer}}{{#isContainer}}){{/isContainer}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/elm/toString.mustache b/modules/openapi-generator/src/main/resources/elm/toString.mustache deleted file mode 100644 index c2928dc04d0..00000000000 --- a/modules/openapi-generator/src/main/resources/elm/toString.mustache +++ /dev/null @@ -1 +0,0 @@ -{{#isListContainer}}String.join "," << List.map {{#items}}{{>toString}}{{/items}}{{/isListContainer}}{{^isListContainer}}{{^isEnum}}{{#isString}}identity{{/isString}}{{#isBinary}}identity{{/isBinary}}{{#isByteArray}}identity{{/isByteArray}}{{/isEnum}}{{#isBoolean}}(\val -> if val then "true" else "false"){{/isBoolean}}{{#isDateTime}}DateTime.toString{{/isDateTime}}{{#isDate}}DateOnly.toString{{/isDate}}{{#isElm018}}toString{{/isElm018}}{{^isElm018}}{{#isInteger}}String.fromInt{{/isInteger}}{{#isLong}}String.fromInt{{/isLong}}{{#isFloat}}String.fromFloat{{/isFloat}}{{#isDouble}}String.fromFloat{{/isDouble}}{{#isEnum}}stringify{{enumName}}{{/isEnum}}{{^isEnum}}{{^isString}}{{^isBinary}}{{^isByteArray}}{{^isBoolean}}{{^isDouble}}{{^isFloat}}{{^isLong}}{{^isInteger}}{{dataType}}.toString{{/isInteger}}{{/isLong}}{{/isFloat}}{{/isDouble}}{{/isBoolean}}{{/isByteArray}}{{/isBinary}}{{/isString}}{{/isEnum}}{{/isElm018}}{{/isListContainer}} \ No newline at end of file diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/elm/ElmClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/elm/ElmClientCodegenTest.java deleted file mode 100644 index dd59a7a02b1..00000000000 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/elm/ElmClientCodegenTest.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright 2019 OpenAPI-Generator Contributors (https://openapi-generator.tech) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.openapitools.codegen.elm; - -import static com.google.common.collect.Lists.newArrayList; -import static java.util.Collections.emptyList; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.openapitools.codegen.ClientOptInput; -import org.openapitools.codegen.CodegenOperation; -import org.openapitools.codegen.MockDefaultGenerator; -import org.openapitools.codegen.languages.ElmClientCodegen; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableMap; - -import io.swagger.parser.OpenAPIParser; -import io.swagger.v3.oas.models.OpenAPI; -import io.swagger.v3.parser.core.models.ParseOptions; - -public class ElmClientCodegenTest { - - @Test - public void testPostProcessRootEndpoint() { - // given - final ElmClientCodegen codegen = new ElmClientCodegen(); - - CodegenOperation rootOp = new CodegenOperation() {{ path = "/"; }}; - List ops = newArrayList(rootOp); - - Map operations = new HashMap<>(); - operations.put("operations", ImmutableMap - .builder() - .put("operation", ops) - .build()); - - // when - Map result = codegen.postProcessOperationsWithModels(operations, emptyList()); - - // then - assertEquals(result.size(), 2); - assertTrue(result.containsKey("operations")); - assertTrue(result.containsKey("elmImports")); - - assertEquals(rootOp.path, "/"); - } - - @Test - public void testGenerateRootEndpoint() throws IOException { - // given - File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); - output.deleteOnExit(); - String outputPath = output.getAbsolutePath().replace('\\', '/'); - - final ElmClientCodegen codegen = new ElmClientCodegen(); - codegen.setOutputDir(output.getAbsolutePath()); - - OpenAPI openAPI = new OpenAPIParser() - .readLocation("src/test/resources/3_0/rootOperation.yaml", null, new ParseOptions()) - .getOpenAPI(); - - ClientOptInput input = new ClientOptInput(); - input.setOpenAPI(openAPI); - input.setConfig(codegen); - - // when - MockDefaultGenerator generator = new MockDefaultGenerator(); - generator.opts(input).generate(); - - // then - assertFileContains(generator, outputPath + "/src/Request/Default.elm", "rootGet", "[\"\"]"); - } - - private static void assertFileContains(MockDefaultGenerator generator, String file, String... expected) { - String content = generator.getFiles().get(file); - assertNotNull(content, "The file \"" + file + "\" was not generated"); - for (String line : expected) { - assertTrue(content.contains(line), "The file \"" + file + "\" does not contain \"" + line + "\""); - } - } -} diff --git a/modules/openapi-generator/src/test/resources/3_0/composition.yaml b/modules/openapi-generator/src/test/resources/3_0/composition.yaml deleted file mode 100644 index 0b54cb26d40..00000000000 --- a/modules/openapi-generator/src/test/resources/3_0/composition.yaml +++ /dev/null @@ -1,121 +0,0 @@ -openapi: 3.0.0 -info: - title: Composition and Inheritence (Polymorphism) - version: 1.0.0 -paths: - /oneOf: - post: - summary: One of - responses: - 200: - description: Response - content: - application/json: - schema: - $ref: '#/components/schemas/OneOf' - /oneOfWithDiscriminator: - post: - summary: One of with discriminator - responses: - 200: - description: Response - content: - application/json: - schema: - $ref: '#/components/schemas/OneOfWithDiscriminator' - /oneOfWithAllOfDiscriminator: - post: - summary: One of with discriminator from all of - responses: - 200: - description: Response - content: - application/json: - schema: - $ref: '#/components/schemas/OneOfWithAllOfDiscriminator' - /allOf: - post: - summary: All of - responses: - 200: - description: Response - content: - application/json: - schema: - $ref: '#/components/schemas/AllOf' - /allOfWithDiscriminator: - post: - summary: All of with discriminator - responses: - 200: - description: Response - content: - application/json: - schema: - $ref: '#/components/schemas/BaseObject' -components: - schemas: - OneOf: - oneOf: - - $ref: "#/components/schemas/ObjectA" - - $ref: "#/components/schemas/ObjectB" - OneOfWithDiscriminator: - oneOf: - - $ref: "#/components/schemas/ObjectA" - - $ref: "#/components/schemas/ObjectB" - discriminator: - propertyName: objectType - mapping: - a: "#/components/schemas/ObjectA" - b: "#/components/schemas/ObjectB" - OneOfWithAllOfDiscriminator: - oneOf: - - $ref: "#/components/schemas/SubObjectA" - - $ref: "#/components/schemas/SubObjectB" - AllOf: - allOf: - - $ref: "#/components/schemas/ObjectA" - - $ref: "#/components/schemas/ObjectB" - BaseObject: - required: - - objectType - - value - properties: - objectType: - type: string - value: - type: boolean - discriminator: - propertyName: objectType - ObjectA: - type: object - required: - - objectType - properties: - objectType: - type: string - valueA: - type: string - ObjectB: - type: object - required: - - objectType - properties: - objectType: - type: string - valueB: - type: number - SubObjectA: - allOf: - - $ref: "#/components/schemas/BaseObject" - - type: object - properties: - valueA: - type: string - SubObjectB: - allOf: - - $ref: "#/components/schemas/BaseObject" - - type: object - properties: - valueB: - type: number diff --git a/modules/openapi-generator/src/test/resources/3_0/elm.yaml b/modules/openapi-generator/src/test/resources/3_0/elm.yaml new file mode 100644 index 00000000000..1ad2fe2c92a --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/elm.yaml @@ -0,0 +1,257 @@ +openapi: "3.0.0" +info: + version: 1.0.0 + title: Elm generator test + license: + name: MIT +servers: + - url: http://localhost:9000 +paths: + /data: + post: + tags: + - primitive + operationId: update + requestBody: + description: Request body + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/Primitive" + responses: + "200": + description: Default response + content: + application/json: + schema: + $ref: "#/components/schemas/Primitive" + /header: + post: + parameters: + - name: string + in: header + required: true + schema: + type: string + - name: integer + in: header + schema: + type: integer + - name: headerType + in: header + schema: + type: string + enum: [left, right] + responses: + "200": + description: Default response + content: + application/json: + schema: + type: string + /maybe: + get: + responses: + "200": + description: Default response + content: + application/json: + schema: + $ref: "#/components/schemas/Maybe" + /path/{string}/{integer}/{enumeration}: + get: + parameters: + - name: string + in: path + schema: + type: string + - name: integer + in: path + schema: + type: integer + - name: enumeration + in: path + schema: + type: string + enum: [a, b, c] + responses: + "200": + description: Default response + /query: + get: + parameters: + - name: string + in: query + schema: + type: string + - name: int + in: query + schema: + type: integer + - name: enum + in: query + schema: + type: string + enum: [a, b, c] + responses: + "200": + description: Default response +components: + schemas: + Absent: + description: Model having absent and null values + required: + - required + - requiredNullable + properties: + default: + type: string + required: + type: string + nullable: + type: string + nullable: true + requiredNullable: + type: string + nullable: true + Array: + description: Model with arrays + required: + - array + - arrayOfArray + properties: + array: + type: array + items: + type: string + arrayOfArray: + type: array + items: + type: array + items: + type: string + Composed: + description: Composed model + allOf: + - $ref: "#/components/schemas/ComposedBase" + - type: object + properties: + value: + type: string + ComposedBase: + required: + - base + properties: + base: + type: number + Discriminated: + description: Discriminated model + required: + - kind + properties: + kind: + type: string + discriminator: + propertyName: kind + DiscriminatedA: + allOf: + - $ref: "#/components/schemas/Discriminated" + - type: object + properties: + a: + type: string + DiscriminatedB: + allOf: + - $ref: "#/components/schemas/Discriminated" + - type: object + properties: + b: + type: string + Enum: + type: string + enum: + - foo + - bar + - baz + Enumeric: + type: number + enum: + - 1 + - 2 + - 3 + Maybe: + description: Model using reserved words + properties: + type: + type: string + if: + type: boolean + OneOf: + description: One of two models + oneOf: + - $ref: "#/components/schemas/OneOfA" + - $ref: "#/components/schemas/OneOfB" + OneOfA: + properties: + a: + type: string + OneOfB: + properties: + b: + type: string + Primitive: + description: Model with primitive properties + properties: + string: + type: string + number: + type: number + float: + type: number + format: float + double: + type: number + format: double + integer: + type: integer + short: + type: integer + format: int32 + long: + type: integer + format: int64 + boolean: + type: boolean + Recursion: + properties: + maybe: + $ref: "#/components/schemas/Recursion" + list: + type: array + items: + $ref: "#/components/schemas/Recursion" + ref: + $ref: "#/components/schemas/RecursionLoop" + RecursionLoop: + properties: + ref: + $ref: "#/components/schemas/Recursion" + UnsafeCharacters: + description: Model using unsafe characters + properties: + $prefix: + type: string + suffix$: + type: string + r@nd0m_$t#ff: + type: string + _before: + type: string + after_: + type: string + _both_: + type: string + in_the_middle: + type: string + diff --git a/pom.xml b/pom.xml index 0b0118fdc69..aaa85e48c9c 100644 --- a/pom.xml +++ b/pom.xml @@ -1042,7 +1042,6 @@ samples/client/petstore/bash samples/client/petstore/c samples/client/petstore/cpp-qt5 - samples/client/petstore/rust samples/client/petstore/php/OpenAPIClient-php @@ -1247,7 +1246,7 @@ - samples/client/petstore/elm + samples/openapi3/client/elm samples/client/petstore/elixir samples/client/petstore/erlang-client samples/client/petstore/erlang-proper diff --git a/samples/client/petstore/elm-0.18/.openapi-generator/VERSION b/samples/client/petstore/elm-0.18/.openapi-generator/VERSION deleted file mode 100644 index 71d2eb1c7fc..00000000000 --- a/samples/client/petstore/elm-0.18/.openapi-generator/VERSION +++ /dev/null @@ -1 +0,0 @@ -5.0.0-SNAPSHOT diff --git a/samples/client/petstore/elm-0.18/README.md b/samples/client/petstore/elm-0.18/README.md deleted file mode 100644 index 3f36740911a..00000000000 --- a/samples/client/petstore/elm-0.18/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# Elm API client - -This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. - -## Overview -This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [openapi-spec](https://github.com/OAI/OpenAPI-Specification) from a remote server, you can easily generate an API client. - -- API version: 1.0.0 -- Package version: -- Build package: org.openapitools.codegen.languages.ElmClientCodegen diff --git a/samples/client/petstore/elm-0.18/elm-0.18-compile-test b/samples/client/petstore/elm-0.18/elm-0.18-compile-test deleted file mode 100755 index c6ba0a25f68..00000000000 --- a/samples/client/petstore/elm-0.18/elm-0.18-compile-test +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash -e -# elm 0.18 make all elm files under src - -for ELM in `find src -name "*.elm"` -do - echo "Compiling $ELM" - elm make $ELM --output /dev/null --yes - rc=$? - if [[ $rc != 0 ]] - then - echo "ERROR!! FAILED TO COMPILE $ELM" - exit $rc; - fi -done diff --git a/samples/client/petstore/elm-0.18/elm-package.json b/samples/client/petstore/elm-0.18/elm-package.json deleted file mode 100644 index 6bd1cd88fa7..00000000000 --- a/samples/client/petstore/elm-0.18/elm-package.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "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", - "danyx23/elm-uuid": "2.0.2 <= v < 2.1.1", - "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": "3.0.0 <= v < 4.0.0" - }, - "elm-version": "0.18.0 <= v < 0.19.0" -} diff --git a/samples/client/petstore/elm-0.18/pom.xml b/samples/client/petstore/elm-0.18/pom.xml deleted file mode 100644 index 7ddfe9d49e7..00000000000 --- a/samples/client/petstore/elm-0.18/pom.xml +++ /dev/null @@ -1,43 +0,0 @@ - - 4.0.0 - org.openapitools - Elm018ClientTests - pom - 1.0-SNAPSHOT - Elm 0.18 Petstore Client - - - - maven-dependency-plugin - - - package - - copy-dependencies - - - ${project.build.directory} - - - - - - org.codehaus.mojo - exec-maven-plugin - 1.2.1 - - - bundle-test - integration-test - - exec - - - ./elm-0.18-compile-test - - - - - - - diff --git a/samples/client/petstore/elm-0.18/src/Byte.elm b/samples/client/petstore/elm-0.18/src/Byte.elm deleted file mode 100644 index d83623d9846..00000000000 --- a/samples/client/petstore/elm-0.18/src/Byte.elm +++ /dev/null @@ -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 diff --git a/samples/client/petstore/elm-0.18/src/Data/ApiResponse.elm b/samples/client/petstore/elm-0.18/src/Data/ApiResponse.elm deleted file mode 100644 index 4513a239058..00000000000 --- a/samples/client/petstore/elm-0.18/src/Data/ApiResponse.elm +++ /dev/null @@ -1,58 +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 (decode, 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 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 diff --git a/samples/client/petstore/elm-0.18/src/Data/Category.elm b/samples/client/petstore/elm-0.18/src/Data/Category.elm deleted file mode 100644 index bd3b810819b..00000000000 --- a/samples/client/petstore/elm-0.18/src/Data/Category.elm +++ /dev/null @@ -1,55 +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 (decode, 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 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 diff --git a/samples/client/petstore/elm-0.18/src/Data/Order_.elm b/samples/client/petstore/elm-0.18/src/Data/Order_.elm deleted file mode 100644 index bf2203ec13e..00000000000 --- a/samples/client/petstore/elm-0.18/src/Data/Order_.elm +++ /dev/null @@ -1,107 +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 (decode, 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 - = Placed - | Approved - | Delivered - - -decoder : Decoder Order_ -decoder = - 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 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 Placed - - "approved" -> - Decode.succeed Approved - - "delivered" -> - Decode.succeed Delivered - - other -> - Decode.fail <| "Unknown type: " ++ other - ) - - -encodeStatus : Status -> Encode.Value -encodeStatus model = - case model of - Placed -> - Encode.string "placed" - - Approved -> - Encode.string "approved" - - Delivered -> - Encode.string "delivered" diff --git a/samples/client/petstore/elm-0.18/src/Data/Pet.elm b/samples/client/petstore/elm-0.18/src/Data/Pet.elm deleted file mode 100644 index 166695c26af..00000000000 --- a/samples/client/petstore/elm-0.18/src/Data/Pet.elm +++ /dev/null @@ -1,108 +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 (decode, 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 - = Available - | Pending - | Sold - - -decoder : Decoder Pet -decoder = - decode 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 << List.map Encode.string) model.photoUrls ) - , ( "tags", Maybe.withDefault Encode.null (Maybe.map (Encode.list << List.map 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 Available - - "pending" -> - Decode.succeed Pending - - "sold" -> - Decode.succeed Sold - - other -> - Decode.fail <| "Unknown type: " ++ other - ) - - -encodeStatus : Status -> Encode.Value -encodeStatus model = - case model of - Available -> - Encode.string "available" - - Pending -> - Encode.string "pending" - - Sold -> - Encode.string "sold" diff --git a/samples/client/petstore/elm-0.18/src/Data/Tag.elm b/samples/client/petstore/elm-0.18/src/Data/Tag.elm deleted file mode 100644 index 631119b0416..00000000000 --- a/samples/client/petstore/elm-0.18/src/Data/Tag.elm +++ /dev/null @@ -1,55 +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 (decode, 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 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 diff --git a/samples/client/petstore/elm-0.18/src/Data/User.elm b/samples/client/petstore/elm-0.18/src/Data/User.elm deleted file mode 100644 index ad632f6becc..00000000000 --- a/samples/client/petstore/elm-0.18/src/Data/User.elm +++ /dev/null @@ -1,73 +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 (decode, 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 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 diff --git a/samples/client/petstore/elm-0.18/src/DateOnly.elm b/samples/client/petstore/elm-0.18/src/DateOnly.elm deleted file mode 100644 index 5874cf65d5e..00000000000 --- a/samples/client/petstore/elm-0.18/src/DateOnly.elm +++ /dev/null @@ -1,37 +0,0 @@ -module DateOnly exposing (DateOnly, decoder, encode, toString) - -import Date -import Date.Extra exposing (fromIsoString, toFormattedString) -import Json.Decode as Decode exposing (Decoder) -import Json.Encode as Encode -import Result - - -type alias DateOnly = - Date.Date - - -decoder : Decoder DateOnly -decoder = - Decode.string - |> Decode.andThen decodeIsoString - - -encode : DateOnly -> Encode.Value -encode = - Encode.string << toString - - -decodeIsoString : String -> Decoder DateOnly -decodeIsoString str = - case fromIsoString str of - Result.Ok date -> - Decode.succeed date - - Result.Err msg -> - Decode.fail msg - - -toString : DateOnly -> String -toString = - toFormattedString "yyyy-MM-dd" diff --git a/samples/client/petstore/elm-0.18/src/DateTime.elm b/samples/client/petstore/elm-0.18/src/DateTime.elm deleted file mode 100644 index 7e07312468c..00000000000 --- a/samples/client/petstore/elm-0.18/src/DateTime.elm +++ /dev/null @@ -1,37 +0,0 @@ -module DateTime exposing (DateTime, decoder, encode, toString) - -import Date -import Date.Extra exposing (fromIsoString, toIsoString) -import Json.Decode as Decode exposing (Decoder) -import Json.Encode as Encode -import Result - - -type alias DateTime = - Date.Date - - -decoder : Decoder DateTime -decoder = - Decode.string - |> Decode.andThen decodeIsoString - - -encode : DateTime -> Encode.Value -encode = - Encode.string << toString - - -decodeIsoString : String -> Decoder DateTime -decodeIsoString str = - case fromIsoString str of - Result.Ok date -> - Decode.succeed date - - Result.Err msg -> - Decode.fail msg - - -toString : DateTime -> String -toString = - toIsoString diff --git a/samples/client/petstore/elm-0.18/src/Main.elm b/samples/client/petstore/elm-0.18/src/Main.elm deleted file mode 100644 index 23274d541c1..00000000000 --- a/samples/client/petstore/elm-0.18/src/Main.elm +++ /dev/null @@ -1,60 +0,0 @@ -module Main exposing (main) - -import Html exposing (Html) - - -main : Program Never Model Msg -main = - Html.program - { init = init - , view = view - , update = update - , subscriptions = subscriptions - } - - - --- MODEL - - -type alias Model = - { value : Int - } - - -init : ( Model, Cmd Msg ) -init = - ( Model 0, Cmd.none ) - - - --- UPDATE - - -type Msg - = NoOp - - -update : Msg -> Model -> ( Model, Cmd Msg ) -update msg model = - case msg of - NoOp -> - ( model, Cmd.none ) - - - --- SUBSCRIPTIONS - - -subscriptions : Model -> Sub Msg -subscriptions _ = - Sub.none - - - --- VIEW - - -view : Model -> Html Msg -view _ = - Html.text "main" diff --git a/samples/client/petstore/elm-0.18/src/Request/Pet.elm b/samples/client/petstore/elm-0.18/src/Request/Pet.elm deleted file mode 100644 index a1117a57d5c..00000000000 --- a/samples/client/petstore/elm-0.18/src/Request/Pet.elm +++ /dev/null @@ -1,134 +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, findPetsByTags, getPetById, updatePet, updatePetWithForm, uploadFile) - -import Data.ApiResponse as ApiResponse exposing (ApiResponse) -import Data.Pet as Pet exposing (Pet) -import Dict -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 <| Pet.encode 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 Pet.decoder) - , 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 Pet.decoder) - , 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 Pet.decoder - , timeout = Just 30000 - , withCredentials = False - } - |> Http.request - - -updatePet : Pet -> Http.Request () -updatePet model = - { method = "PUT" - , url = basePath ++ "/pet" - , headers = [] - , body = Http.jsonBody <| Pet.encode 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 ApiResponse.decoder - , timeout = Just 30000 - , withCredentials = False - } - |> Http.request diff --git a/samples/client/petstore/elm-0.18/src/Request/Store.elm b/samples/client/petstore/elm-0.18/src/Request/Store.elm deleted file mode 100644 index 2f44d25c42a..00000000000 --- a/samples/client/petstore/elm-0.18/src/Request/Store.elm +++ /dev/null @@ -1,81 +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 - - -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 : 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 (Dict.Dict String Int) -getInventory = - { method = "GET" - , url = basePath ++ "/store/inventory" - , headers = [] - , body = Http.emptyBody - , expect = Http.expectJson (Decode.dict Decode.int) - , timeout = Just 30000 - , withCredentials = False - } - |> Http.request - - -{-| For valid response try integer IDs with value <= 5 or > 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 Order_.decoder - , timeout = Just 30000 - , withCredentials = False - } - |> Http.request - - -placeOrder : Order_ -> Http.Request Order_ -placeOrder model = - { method = "POST" - , url = basePath ++ "/store/order" - , headers = [] - , body = Http.jsonBody <| Order_.encode model - , expect = Http.expectJson Order_.decoder - , timeout = Just 30000 - , withCredentials = False - } - |> Http.request diff --git a/samples/client/petstore/elm-0.18/src/Request/User.elm b/samples/client/petstore/elm-0.18/src/Request/User.elm deleted file mode 100644 index a7d142cfc0c..00000000000 --- a/samples/client/petstore/elm-0.18/src/Request/User.elm +++ /dev/null @@ -1,133 +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 - - -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 <| User.encode 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 <| User.encode 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 <| User.encode 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 User.decoder - , 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 <| User.encode model - , expect = Http.expectStringResponse (\_ -> Ok ()) - , timeout = Just 30000 - , withCredentials = False - } - |> Http.request diff --git a/samples/client/petstore/elm/.gitignore b/samples/client/petstore/elm/.gitignore deleted file mode 100644 index 8b0d053e4e3..00000000000 --- a/samples/client/petstore/elm/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/elm-stuff \ No newline at end of file diff --git a/samples/client/petstore/elm/.openapi-generator-ignore b/samples/client/petstore/elm/.openapi-generator-ignore deleted file mode 100644 index 7484ee590a3..00000000000 --- a/samples/client/petstore/elm/.openapi-generator-ignore +++ /dev/null @@ -1,23 +0,0 @@ -# OpenAPI Generator Ignore -# Generated by openapi-generator https://github.com/openapitools/openapi-generator - -# 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 OpenAPI Generator 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 diff --git a/samples/client/petstore/elm/.openapi-generator/VERSION b/samples/client/petstore/elm/.openapi-generator/VERSION deleted file mode 100644 index 71d2eb1c7fc..00000000000 --- a/samples/client/petstore/elm/.openapi-generator/VERSION +++ /dev/null @@ -1 +0,0 @@ -5.0.0-SNAPSHOT diff --git a/samples/client/petstore/elm/README.md b/samples/client/petstore/elm/README.md deleted file mode 100644 index 3f36740911a..00000000000 --- a/samples/client/petstore/elm/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# Elm API client - -This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. - -## Overview -This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [openapi-spec](https://github.com/OAI/OpenAPI-Specification) from a remote server, you can easily generate an API client. - -- API version: 1.0.0 -- Package version: -- Build package: org.openapitools.codegen.languages.ElmClientCodegen diff --git a/samples/client/petstore/elm/src/Byte.elm b/samples/client/petstore/elm/src/Byte.elm deleted file mode 100644 index d83623d9846..00000000000 --- a/samples/client/petstore/elm/src/Byte.elm +++ /dev/null @@ -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 diff --git a/samples/client/petstore/elm/src/Data/ApiResponse.elm b/samples/client/petstore/elm/src/Data/ApiResponse.elm deleted file mode 100644 index 36300e78f78..00000000000 --- a/samples/client/petstore/elm/src/Data/ApiResponse.elm +++ /dev/null @@ -1,58 +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 diff --git a/samples/client/petstore/elm/src/Data/Category.elm b/samples/client/petstore/elm/src/Data/Category.elm deleted file mode 100644 index 43d1f5f4185..00000000000 --- a/samples/client/petstore/elm/src/Data/Category.elm +++ /dev/null @@ -1,55 +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 diff --git a/samples/client/petstore/elm/src/Data/Order_.elm b/samples/client/petstore/elm/src/Data/Order_.elm deleted file mode 100644 index 2ae0003257d..00000000000 --- a/samples/client/petstore/elm/src/Data/Order_.elm +++ /dev/null @@ -1,107 +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 - = Placed - | Approved - | Delivered - - -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 Placed - - "approved" -> - Decode.succeed Approved - - "delivered" -> - Decode.succeed Delivered - - other -> - Decode.fail <| "Unknown type: " ++ other - ) - - -encodeStatus : Status -> Encode.Value -encodeStatus model = - case model of - Placed -> - Encode.string "placed" - - Approved -> - Encode.string "approved" - - Delivered -> - Encode.string "delivered" diff --git a/samples/client/petstore/elm/src/Data/Pet.elm b/samples/client/petstore/elm/src/Data/Pet.elm deleted file mode 100644 index 6630115718f..00000000000 --- a/samples/client/petstore/elm/src/Data/Pet.elm +++ /dev/null @@ -1,108 +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 - = Available - | Pending - | Sold - - -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 Available - - "pending" -> - Decode.succeed Pending - - "sold" -> - Decode.succeed Sold - - other -> - Decode.fail <| "Unknown type: " ++ other - ) - - -encodeStatus : Status -> Encode.Value -encodeStatus model = - case model of - Available -> - Encode.string "available" - - Pending -> - Encode.string "pending" - - Sold -> - Encode.string "sold" diff --git a/samples/client/petstore/elm/src/Data/Tag.elm b/samples/client/petstore/elm/src/Data/Tag.elm deleted file mode 100644 index 1a2c9d6b6d7..00000000000 --- a/samples/client/petstore/elm/src/Data/Tag.elm +++ /dev/null @@ -1,55 +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 diff --git a/samples/client/petstore/elm/src/Data/User.elm b/samples/client/petstore/elm/src/Data/User.elm deleted file mode 100644 index 8d56f85052b..00000000000 --- a/samples/client/petstore/elm/src/Data/User.elm +++ /dev/null @@ -1,73 +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 diff --git a/samples/client/petstore/elm/src/DateOnly.elm b/samples/client/petstore/elm/src/DateOnly.elm deleted file mode 100644 index a31efc88c38..00000000000 --- a/samples/client/petstore/elm/src/DateOnly.elm +++ /dev/null @@ -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 diff --git a/samples/client/petstore/elm/src/DateTime.elm b/samples/client/petstore/elm/src/DateTime.elm deleted file mode 100644 index 80b62fb7dec..00000000000 --- a/samples/client/petstore/elm/src/DateTime.elm +++ /dev/null @@ -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 diff --git a/samples/client/petstore/elm/src/Main.elm b/samples/client/petstore/elm/src/Main.elm deleted file mode 100644 index 7c9ddd056d3..00000000000 --- a/samples/client/petstore/elm/src/Main.elm +++ /dev/null @@ -1,61 +0,0 @@ -module Main exposing (main) - -import Browser -import Html exposing (Html) - - -main : Program () Model Msg -main = - Browser.element - { init = init - , view = view - , update = update - , subscriptions = subscriptions - } - - - --- MODEL - - -type alias Model = - { value : Int - } - - -init : () -> ( Model, Cmd Msg ) -init _ = - ( Model 0, Cmd.none ) - - - --- UPDATE - - -type Msg - = NoOp - - -update : Msg -> Model -> ( Model, Cmd Msg ) -update msg model = - case msg of - NoOp -> - ( model, Cmd.none ) - - - --- SUBSCRIPTIONS - - -subscriptions : Model -> Sub Msg -subscriptions _ = - Sub.none - - - --- VIEW - - -view : Model -> Html Msg -view _ = - Html.text "main" diff --git a/samples/client/petstore/elm/src/Request/Pet.elm b/samples/client/petstore/elm/src/Request/Pet.elm deleted file mode 100644 index accf33f896f..00000000000 --- a/samples/client/petstore/elm/src/Request/Pet.elm +++ /dev/null @@ -1,213 +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 (Status(..), addPet, deletePet, findPetsByStatus, findPetsByTags, getPetById, updatePet, updatePetWithForm, uploadFile) - -import Data.ApiResponse as ApiResponse exposing (ApiResponse) -import Data.Pet as Pet exposing (Pet) -import Dict -import Http -import Json.Decode as Decode -import Url.Builder as Url - - -type Status - = Available - | Pending - | Sold - - -stringifyStatus : Status -> String -stringifyStatus value = - case value of - Available -> - "available" - - Pending -> - "pending" - - Sold -> - "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 - } diff --git a/samples/client/petstore/elm/src/Request/Store.elm b/samples/client/petstore/elm/src/Request/Store.elm deleted file mode 100644 index 3800147a77a..00000000000 --- a/samples/client/petstore/elm/src/Request/Store.elm +++ /dev/null @@ -1,109 +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 generated 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 - } diff --git a/samples/client/petstore/elm/src/Request/User.elm b/samples/client/petstore/elm/src/Request/User.elm deleted file mode 100644 index 74bbe8213c0..00000000000 --- a/samples/client/petstore/elm/src/Request/User.elm +++ /dev/null @@ -1,191 +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 - } diff --git a/samples/openapi3/client/composition/elm/.gitignore b/samples/openapi3/client/composition/elm/.gitignore deleted file mode 100644 index 8b0d053e4e3..00000000000 --- a/samples/openapi3/client/composition/elm/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/elm-stuff \ No newline at end of file diff --git a/samples/openapi3/client/composition/elm/.openapi-generator-ignore b/samples/openapi3/client/composition/elm/.openapi-generator-ignore deleted file mode 100644 index 7484ee590a3..00000000000 --- a/samples/openapi3/client/composition/elm/.openapi-generator-ignore +++ /dev/null @@ -1,23 +0,0 @@ -# OpenAPI Generator Ignore -# Generated by openapi-generator https://github.com/openapitools/openapi-generator - -# 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 OpenAPI Generator 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 diff --git a/samples/openapi3/client/composition/elm/.openapi-generator/VERSION b/samples/openapi3/client/composition/elm/.openapi-generator/VERSION deleted file mode 100644 index d168f1d8bda..00000000000 --- a/samples/openapi3/client/composition/elm/.openapi-generator/VERSION +++ /dev/null @@ -1 +0,0 @@ -4.2.1-SNAPSHOT \ No newline at end of file diff --git a/samples/openapi3/client/composition/elm/elm-compile-test b/samples/openapi3/client/composition/elm/elm-compile-test deleted file mode 100755 index 55507cfcad6..00000000000 --- a/samples/openapi3/client/composition/elm/elm-compile-test +++ /dev/null @@ -1,14 +0,0 @@ -#!/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 diff --git a/samples/openapi3/client/composition/elm/elm.json b/samples/openapi3/client/composition/elm/elm.json deleted file mode 100644 index 398da0d2d6d..00000000000 --- a/samples/openapi3/client/composition/elm/elm.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "type": "application", - "source-directories": [ - "src" - ], - "elm-version": "0.19.0", - "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/html": "1.0.0", - "elm/http": "2.0.0", - "elm/json": "1.1.2", - "elm/time": "1.0.0", - "elm/url": "1.0.0", - "rtfeldman/elm-iso8601-date-strings": "1.1.3" - }, - "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", - "elm/virtual-dom": "1.0.2" - } - }, - "test-dependencies": { - "direct": {}, - "indirect": {} - } -} diff --git a/samples/openapi3/client/composition/elm/pom.xml b/samples/openapi3/client/composition/elm/pom.xml deleted file mode 100644 index c70a1f0b874..00000000000 --- a/samples/openapi3/client/composition/elm/pom.xml +++ /dev/null @@ -1,43 +0,0 @@ - - 4.0.0 - org.openapitools - ElmCompositionTests - pom - 1.0-SNAPSHOT - Elm Composition Client - - - - maven-dependency-plugin - - - package - - copy-dependencies - - - ${project.build.directory} - - - - - - org.codehaus.mojo - exec-maven-plugin - 1.2.1 - - - bundle-test - integration-test - - exec - - - ./elm-compile-test - - - - - - - diff --git a/samples/openapi3/client/composition/elm/src/Byte.elm b/samples/openapi3/client/composition/elm/src/Byte.elm deleted file mode 100644 index d83623d9846..00000000000 --- a/samples/openapi3/client/composition/elm/src/Byte.elm +++ /dev/null @@ -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 diff --git a/samples/openapi3/client/composition/elm/src/Data/AllOf.elm b/samples/openapi3/client/composition/elm/src/Data/AllOf.elm deleted file mode 100644 index d5365028afa..00000000000 --- a/samples/openapi3/client/composition/elm/src/Data/AllOf.elm +++ /dev/null @@ -1,56 +0,0 @@ -{- - Composition and Inheritence (Polymorphism) - No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - - 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.AllOf exposing (AllOf, 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 AllOf = - { objectType : String - , valueA : Maybe String - , valueB : Maybe Float - } - - -decoder : Decoder AllOf -decoder = - Decode.succeed AllOf - |> required "objectType" Decode.string - |> optional "valueA" (Decode.nullable Decode.string) Nothing - |> optional "valueB" (Decode.nullable Decode.float) Nothing - - -encode : AllOf -> Encode.Value -encode = - Encode.object << encodePairs - - -encodeWithTag : ( String, String ) -> AllOf -> Encode.Value -encodeWithTag ( tagField, tag ) model = - Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ] - - -encodePairs : AllOf -> List ( String, Encode.Value ) -encodePairs model = - [ ( "objectType", Encode.string model.objectType ) - , ( "valueA", Maybe.withDefault Encode.null (Maybe.map Encode.string model.valueA) ) - , ( "valueB", Maybe.withDefault Encode.null (Maybe.map Encode.float model.valueB) ) - ] - - -toString : AllOf -> String -toString = - Encode.encode 0 << encode diff --git a/samples/openapi3/client/composition/elm/src/Data/BaseObject.elm b/samples/openapi3/client/composition/elm/src/Data/BaseObject.elm deleted file mode 100644 index b81d6f75864..00000000000 --- a/samples/openapi3/client/composition/elm/src/Data/BaseObject.elm +++ /dev/null @@ -1,59 +0,0 @@ -{- - Composition and Inheritence (Polymorphism) - No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - - 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.BaseObject exposing (BaseObject(..), decoder, encode, toString) - -import Data.SubObjectA as SubObjectA exposing (SubObjectA) -import Data.SubObjectB as SubObjectB exposing (SubObjectB) -import Dict exposing (Dict) -import Json.Decode as Decode exposing (Decoder) -import Json.Decode.Pipeline exposing (optional, required) -import Json.Encode as Encode - - -type BaseObject - = SubObjectAType SubObjectA - | SubObjectBType SubObjectB - - -decoder : Decoder BaseObject -decoder = - Decode.field "objectType" Decode.string - |> Decode.andThen baseObjectDecoder - - -baseObjectDecoder : String -> Decoder BaseObject -baseObjectDecoder tag = - case tag of - "SubObjectA" -> - Decode.map SubObjectAType SubObjectA.decoder - - "SubObjectB" -> - Decode.map SubObjectBType SubObjectB.decoder - - _ -> - Decode.fail <| "Trying to decode BaseObject, but objectType '" ++ tag ++ "' is not supported." - - -encode : BaseObject -> Encode.Value -encode model = - case model of - SubObjectAType subModel -> - SubObjectA.encodeWithTag ( "objectType", "SubObjectA" ) subModel - - SubObjectBType subModel -> - SubObjectB.encodeWithTag ( "objectType", "SubObjectB" ) subModel - - -toString : BaseObject -> String -toString = - Encode.encode 0 << encode diff --git a/samples/openapi3/client/composition/elm/src/Data/ObjectA.elm b/samples/openapi3/client/composition/elm/src/Data/ObjectA.elm deleted file mode 100644 index 9a9ba64da51..00000000000 --- a/samples/openapi3/client/composition/elm/src/Data/ObjectA.elm +++ /dev/null @@ -1,53 +0,0 @@ -{- - Composition and Inheritence (Polymorphism) - No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - - 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.ObjectA exposing (ObjectA, 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 ObjectA = - { objectType : String - , valueA : Maybe String - } - - -decoder : Decoder ObjectA -decoder = - Decode.succeed ObjectA - |> required "objectType" Decode.string - |> optional "valueA" (Decode.nullable Decode.string) Nothing - - -encode : ObjectA -> Encode.Value -encode = - Encode.object << encodePairs - - -encodeWithTag : ( String, String ) -> ObjectA -> Encode.Value -encodeWithTag ( tagField, tag ) model = - Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ] - - -encodePairs : ObjectA -> List ( String, Encode.Value ) -encodePairs model = - [ ( "objectType", Encode.string model.objectType ) - , ( "valueA", Maybe.withDefault Encode.null (Maybe.map Encode.string model.valueA) ) - ] - - -toString : ObjectA -> String -toString = - Encode.encode 0 << encode diff --git a/samples/openapi3/client/composition/elm/src/Data/ObjectB.elm b/samples/openapi3/client/composition/elm/src/Data/ObjectB.elm deleted file mode 100644 index 0ffa826106e..00000000000 --- a/samples/openapi3/client/composition/elm/src/Data/ObjectB.elm +++ /dev/null @@ -1,53 +0,0 @@ -{- - Composition and Inheritence (Polymorphism) - No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - - 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.ObjectB exposing (ObjectB, 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 ObjectB = - { objectType : String - , valueB : Maybe Float - } - - -decoder : Decoder ObjectB -decoder = - Decode.succeed ObjectB - |> required "objectType" Decode.string - |> optional "valueB" (Decode.nullable Decode.float) Nothing - - -encode : ObjectB -> Encode.Value -encode = - Encode.object << encodePairs - - -encodeWithTag : ( String, String ) -> ObjectB -> Encode.Value -encodeWithTag ( tagField, tag ) model = - Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ] - - -encodePairs : ObjectB -> List ( String, Encode.Value ) -encodePairs model = - [ ( "objectType", Encode.string model.objectType ) - , ( "valueB", Maybe.withDefault Encode.null (Maybe.map Encode.float model.valueB) ) - ] - - -toString : ObjectB -> String -toString = - Encode.encode 0 << encode diff --git a/samples/openapi3/client/composition/elm/src/Data/OneOf.elm b/samples/openapi3/client/composition/elm/src/Data/OneOf.elm deleted file mode 100644 index 5bd3b463056..00000000000 --- a/samples/openapi3/client/composition/elm/src/Data/OneOf.elm +++ /dev/null @@ -1,48 +0,0 @@ -{- - Composition and Inheritence (Polymorphism) - No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - - 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.OneOf exposing (OneOf, decoder, encode, toString) - -import Data.ObjectA as ObjectA exposing (ObjectA) -import Data.ObjectB as ObjectB exposing (ObjectB) -import Dict exposing (Dict) -import Json.Decode as Decode exposing (Decoder) -import Json.Decode.Pipeline exposing (optional, required) -import Json.Encode as Encode - - -type OneOf - = ObjectAType ObjectA - | ObjectBType ObjectB - - -decoder : Decoder OneOf -decoder = - Decode.oneOf - [ Decode.map ObjectAType ObjectA.decoder - , Decode.map ObjectBType ObjectB.decoder - ] - - -encode : OneOf -> Encode.Value -encode model = - case model of - ObjectAType subModel -> - ObjectA.encode subModel - - ObjectBType subModel -> - ObjectB.encode subModel - - -toString : OneOf -> String -toString = - Encode.encode 0 << encode diff --git a/samples/openapi3/client/composition/elm/src/Data/OneOfWithAllOfDiscriminator.elm b/samples/openapi3/client/composition/elm/src/Data/OneOfWithAllOfDiscriminator.elm deleted file mode 100644 index 6e43730e0f7..00000000000 --- a/samples/openapi3/client/composition/elm/src/Data/OneOfWithAllOfDiscriminator.elm +++ /dev/null @@ -1,48 +0,0 @@ -{- - Composition and Inheritence (Polymorphism) - No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - - 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.OneOfWithAllOfDiscriminator exposing (OneOfWithAllOfDiscriminator, decoder, encode, toString) - -import Data.SubObjectA as SubObjectA exposing (SubObjectA) -import Data.SubObjectB as SubObjectB exposing (SubObjectB) -import Dict exposing (Dict) -import Json.Decode as Decode exposing (Decoder) -import Json.Decode.Pipeline exposing (optional, required) -import Json.Encode as Encode - - -type OneOfWithAllOfDiscriminator - = SubObjectAType SubObjectA - | SubObjectBType SubObjectB - - -decoder : Decoder OneOfWithAllOfDiscriminator -decoder = - Decode.oneOf - [ Decode.map SubObjectAType SubObjectA.decoder - , Decode.map SubObjectBType SubObjectB.decoder - ] - - -encode : OneOfWithAllOfDiscriminator -> Encode.Value -encode model = - case model of - SubObjectAType subModel -> - SubObjectA.encode subModel - - SubObjectBType subModel -> - SubObjectB.encode subModel - - -toString : OneOfWithAllOfDiscriminator -> String -toString = - Encode.encode 0 << encode diff --git a/samples/openapi3/client/composition/elm/src/Data/OneOfWithDiscriminator.elm b/samples/openapi3/client/composition/elm/src/Data/OneOfWithDiscriminator.elm deleted file mode 100644 index a45536791e7..00000000000 --- a/samples/openapi3/client/composition/elm/src/Data/OneOfWithDiscriminator.elm +++ /dev/null @@ -1,59 +0,0 @@ -{- - Composition and Inheritence (Polymorphism) - No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - - 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.OneOfWithDiscriminator exposing (OneOfWithDiscriminator, decoder, encode, toString) - -import Data.ObjectA as ObjectA exposing (ObjectA) -import Data.ObjectB as ObjectB exposing (ObjectB) -import Dict exposing (Dict) -import Json.Decode as Decode exposing (Decoder) -import Json.Decode.Pipeline exposing (optional, required) -import Json.Encode as Encode - - -type OneOfWithDiscriminator - = ObjectAType ObjectA - | ObjectBType ObjectB - - -decoder : Decoder OneOfWithDiscriminator -decoder = - Decode.field "objectType" Decode.string - |> Decode.andThen oneOfWithDiscriminatorDecoder - - -oneOfWithDiscriminatorDecoder : String -> Decoder OneOfWithDiscriminator -oneOfWithDiscriminatorDecoder tag = - case tag of - "a" -> - Decode.map ObjectAType ObjectA.decoder - - "b" -> - Decode.map ObjectBType ObjectB.decoder - - _ -> - Decode.fail <| "Trying to decode OneOfWithDiscriminator, but objectType '" ++ tag ++ "' is not supported." - - -encode : OneOfWithDiscriminator -> Encode.Value -encode model = - case model of - ObjectAType subModel -> - ObjectA.encodeWithTag ( "objectType", "a" ) subModel - - ObjectBType subModel -> - ObjectB.encodeWithTag ( "objectType", "b" ) subModel - - -toString : OneOfWithDiscriminator -> String -toString = - Encode.encode 0 << encode diff --git a/samples/openapi3/client/composition/elm/src/Data/SubObjectA.elm b/samples/openapi3/client/composition/elm/src/Data/SubObjectA.elm deleted file mode 100644 index beb5b335ce0..00000000000 --- a/samples/openapi3/client/composition/elm/src/Data/SubObjectA.elm +++ /dev/null @@ -1,53 +0,0 @@ -{- - Composition and Inheritence (Polymorphism) - No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - - 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.SubObjectA exposing (SubObjectA, 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 SubObjectA = - { value : Bool - , valueA : Maybe String - } - - -decoder : Decoder SubObjectA -decoder = - Decode.succeed SubObjectA - |> required "value" Decode.bool - |> optional "valueA" (Decode.nullable Decode.string) Nothing - - -encode : SubObjectA -> Encode.Value -encode = - Encode.object << encodePairs - - -encodeWithTag : ( String, String ) -> SubObjectA -> Encode.Value -encodeWithTag ( tagField, tag ) model = - Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ] - - -encodePairs : SubObjectA -> List ( String, Encode.Value ) -encodePairs model = - [ ( "value", Encode.bool model.value ) - , ( "valueA", Maybe.withDefault Encode.null (Maybe.map Encode.string model.valueA) ) - ] - - -toString : SubObjectA -> String -toString = - Encode.encode 0 << encode diff --git a/samples/openapi3/client/composition/elm/src/Data/SubObjectAAllOf.elm b/samples/openapi3/client/composition/elm/src/Data/SubObjectAAllOf.elm deleted file mode 100644 index dbebf152361..00000000000 --- a/samples/openapi3/client/composition/elm/src/Data/SubObjectAAllOf.elm +++ /dev/null @@ -1,50 +0,0 @@ -{- - Composition and Inheritence (Polymorphism) - No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - - 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.SubObjectAAllOf exposing (SubObjectAAllOf, 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 SubObjectAAllOf = - { valueA : Maybe String - } - - -decoder : Decoder SubObjectAAllOf -decoder = - Decode.succeed SubObjectAAllOf - |> optional "valueA" (Decode.nullable Decode.string) Nothing - - -encode : SubObjectAAllOf -> Encode.Value -encode = - Encode.object << encodePairs - - -encodeWithTag : ( String, String ) -> SubObjectAAllOf -> Encode.Value -encodeWithTag ( tagField, tag ) model = - Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ] - - -encodePairs : SubObjectAAllOf -> List ( String, Encode.Value ) -encodePairs model = - [ ( "valueA", Maybe.withDefault Encode.null (Maybe.map Encode.string model.valueA) ) - ] - - -toString : SubObjectAAllOf -> String -toString = - Encode.encode 0 << encode diff --git a/samples/openapi3/client/composition/elm/src/Data/SubObjectB.elm b/samples/openapi3/client/composition/elm/src/Data/SubObjectB.elm deleted file mode 100644 index 77c7d9f87ce..00000000000 --- a/samples/openapi3/client/composition/elm/src/Data/SubObjectB.elm +++ /dev/null @@ -1,53 +0,0 @@ -{- - Composition and Inheritence (Polymorphism) - No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - - 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.SubObjectB exposing (SubObjectB, 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 SubObjectB = - { value : Bool - , valueB : Maybe Float - } - - -decoder : Decoder SubObjectB -decoder = - Decode.succeed SubObjectB - |> required "value" Decode.bool - |> optional "valueB" (Decode.nullable Decode.float) Nothing - - -encode : SubObjectB -> Encode.Value -encode = - Encode.object << encodePairs - - -encodeWithTag : ( String, String ) -> SubObjectB -> Encode.Value -encodeWithTag ( tagField, tag ) model = - Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ] - - -encodePairs : SubObjectB -> List ( String, Encode.Value ) -encodePairs model = - [ ( "value", Encode.bool model.value ) - , ( "valueB", Maybe.withDefault Encode.null (Maybe.map Encode.float model.valueB) ) - ] - - -toString : SubObjectB -> String -toString = - Encode.encode 0 << encode diff --git a/samples/openapi3/client/composition/elm/src/Data/SubObjectBAllOf.elm b/samples/openapi3/client/composition/elm/src/Data/SubObjectBAllOf.elm deleted file mode 100644 index 6983e8cbbb3..00000000000 --- a/samples/openapi3/client/composition/elm/src/Data/SubObjectBAllOf.elm +++ /dev/null @@ -1,50 +0,0 @@ -{- - Composition and Inheritence (Polymorphism) - No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - - 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.SubObjectBAllOf exposing (SubObjectBAllOf, 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 SubObjectBAllOf = - { valueB : Maybe Float - } - - -decoder : Decoder SubObjectBAllOf -decoder = - Decode.succeed SubObjectBAllOf - |> optional "valueB" (Decode.nullable Decode.float) Nothing - - -encode : SubObjectBAllOf -> Encode.Value -encode = - Encode.object << encodePairs - - -encodeWithTag : ( String, String ) -> SubObjectBAllOf -> Encode.Value -encodeWithTag ( tagField, tag ) model = - Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ] - - -encodePairs : SubObjectBAllOf -> List ( String, Encode.Value ) -encodePairs model = - [ ( "valueB", Maybe.withDefault Encode.null (Maybe.map Encode.float model.valueB) ) - ] - - -toString : SubObjectBAllOf -> String -toString = - Encode.encode 0 << encode diff --git a/samples/openapi3/client/composition/elm/src/DateOnly.elm b/samples/openapi3/client/composition/elm/src/DateOnly.elm deleted file mode 100644 index a31efc88c38..00000000000 --- a/samples/openapi3/client/composition/elm/src/DateOnly.elm +++ /dev/null @@ -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 diff --git a/samples/openapi3/client/composition/elm/src/DateTime.elm b/samples/openapi3/client/composition/elm/src/DateTime.elm deleted file mode 100644 index 80b62fb7dec..00000000000 --- a/samples/openapi3/client/composition/elm/src/DateTime.elm +++ /dev/null @@ -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 diff --git a/samples/openapi3/client/composition/elm/src/Main.elm b/samples/openapi3/client/composition/elm/src/Main.elm deleted file mode 100644 index 7c9ddd056d3..00000000000 --- a/samples/openapi3/client/composition/elm/src/Main.elm +++ /dev/null @@ -1,61 +0,0 @@ -module Main exposing (main) - -import Browser -import Html exposing (Html) - - -main : Program () Model Msg -main = - Browser.element - { init = init - , view = view - , update = update - , subscriptions = subscriptions - } - - - --- MODEL - - -type alias Model = - { value : Int - } - - -init : () -> ( Model, Cmd Msg ) -init _ = - ( Model 0, Cmd.none ) - - - --- UPDATE - - -type Msg - = NoOp - - -update : Msg -> Model -> ( Model, Cmd Msg ) -update msg model = - case msg of - NoOp -> - ( model, Cmd.none ) - - - --- SUBSCRIPTIONS - - -subscriptions : Model -> Sub Msg -subscriptions _ = - Sub.none - - - --- VIEW - - -view : Model -> Html Msg -view _ = - Html.text "main" diff --git a/samples/openapi3/client/composition/elm/src/Request/Default.elm b/samples/openapi3/client/composition/elm/src/Request/Default.elm deleted file mode 100644 index c4a56ffd524..00000000000 --- a/samples/openapi3/client/composition/elm/src/Request/Default.elm +++ /dev/null @@ -1,123 +0,0 @@ -{- - Composition and Inheritence (Polymorphism) - No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - - 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.Default exposing (allOfPost, allOfWithDiscriminatorPost, oneOfPost, oneOfWithAllOfDiscriminatorPost, oneOfWithDiscriminatorPost) - -import Data.AllOf as AllOf exposing (AllOf) -import Data.BaseObject as BaseObject exposing (BaseObject) -import Data.OneOf as OneOf exposing (OneOf) -import Data.OneOfWithAllOfDiscriminator as OneOfWithAllOfDiscriminator exposing (OneOfWithAllOfDiscriminator) -import Data.OneOfWithDiscriminator as OneOfWithDiscriminator exposing (OneOfWithDiscriminator) -import Dict -import Http -import Json.Decode as Decode -import Url.Builder as Url - - -basePath : String -basePath = - "http://localhost" - - -allOfPost : - { onSend : Result Http.Error AllOf -> msg - } - -> Cmd msg -allOfPost params = - Http.request - { method = "POST" - , headers = List.filterMap identity [] - , url = - Url.crossOrigin basePath - [ "allOf" ] - (List.filterMap identity []) - , body = Http.emptyBody - , expect = Http.expectJson params.onSend AllOf.decoder - , timeout = Just 30000 - , tracker = Nothing - } - - -allOfWithDiscriminatorPost : - { onSend : Result Http.Error BaseObject -> msg - } - -> Cmd msg -allOfWithDiscriminatorPost params = - Http.request - { method = "POST" - , headers = List.filterMap identity [] - , url = - Url.crossOrigin basePath - [ "allOfWithDiscriminator" ] - (List.filterMap identity []) - , body = Http.emptyBody - , expect = Http.expectJson params.onSend BaseObject.decoder - , timeout = Just 30000 - , tracker = Nothing - } - - -oneOfPost : - { onSend : Result Http.Error OneOf -> msg - } - -> Cmd msg -oneOfPost params = - Http.request - { method = "POST" - , headers = List.filterMap identity [] - , url = - Url.crossOrigin basePath - [ "oneOf" ] - (List.filterMap identity []) - , body = Http.emptyBody - , expect = Http.expectJson params.onSend OneOf.decoder - , timeout = Just 30000 - , tracker = Nothing - } - - -oneOfWithAllOfDiscriminatorPost : - { onSend : Result Http.Error OneOfWithAllOfDiscriminator -> msg - } - -> Cmd msg -oneOfWithAllOfDiscriminatorPost params = - Http.request - { method = "POST" - , headers = List.filterMap identity [] - , url = - Url.crossOrigin basePath - [ "oneOfWithAllOfDiscriminator" ] - (List.filterMap identity []) - , body = Http.emptyBody - , expect = Http.expectJson params.onSend OneOfWithAllOfDiscriminator.decoder - , timeout = Just 30000 - , tracker = Nothing - } - - -oneOfWithDiscriminatorPost : - { onSend : Result Http.Error OneOfWithDiscriminator -> msg - } - -> Cmd msg -oneOfWithDiscriminatorPost params = - Http.request - { method = "POST" - , headers = List.filterMap identity [] - , url = - Url.crossOrigin basePath - [ "oneOfWithDiscriminator" ] - (List.filterMap identity []) - , body = Http.emptyBody - , expect = Http.expectJson params.onSend OneOfWithDiscriminator.decoder - , timeout = Just 30000 - , tracker = Nothing - } diff --git a/samples/client/petstore/elm-0.18/.gitignore b/samples/openapi3/client/elm/.gitignore similarity index 100% rename from samples/client/petstore/elm-0.18/.gitignore rename to samples/openapi3/client/elm/.gitignore diff --git a/samples/client/petstore/elm-0.18/.openapi-generator-ignore b/samples/openapi3/client/elm/.openapi-generator-ignore similarity index 100% rename from samples/client/petstore/elm-0.18/.openapi-generator-ignore rename to samples/openapi3/client/elm/.openapi-generator-ignore diff --git a/samples/openapi3/client/elm/.openapi-generator/VERSION b/samples/openapi3/client/elm/.openapi-generator/VERSION new file mode 100644 index 00000000000..d99e7162d01 --- /dev/null +++ b/samples/openapi3/client/elm/.openapi-generator/VERSION @@ -0,0 +1 @@ +5.0.0-SNAPSHOT \ No newline at end of file diff --git a/samples/openapi3/client/composition/elm/README.md b/samples/openapi3/client/elm/README.md similarity index 100% rename from samples/openapi3/client/composition/elm/README.md rename to samples/openapi3/client/elm/README.md diff --git a/samples/client/petstore/elm/elm-compile-test b/samples/openapi3/client/elm/elm-compile-test similarity index 100% rename from samples/client/petstore/elm/elm-compile-test rename to samples/openapi3/client/elm/elm-compile-test diff --git a/samples/client/petstore/elm/elm.json b/samples/openapi3/client/elm/elm.json similarity index 90% rename from samples/client/petstore/elm/elm.json rename to samples/openapi3/client/elm/elm.json index 398da0d2d6d..bf0d1f8f4b6 100644 --- a/samples/client/petstore/elm/elm.json +++ b/samples/openapi3/client/elm/elm.json @@ -3,10 +3,9 @@ "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", diff --git a/samples/client/petstore/elm/pom.xml b/samples/openapi3/client/elm/pom.xml similarity index 94% rename from samples/client/petstore/elm/pom.xml rename to samples/openapi3/client/elm/pom.xml index abedbfae9c5..1088d3744c5 100644 --- a/samples/client/petstore/elm/pom.xml +++ b/samples/openapi3/client/elm/pom.xml @@ -1,10 +1,10 @@ 4.0.0 org.openapitools - ElmClientTests + ElmTests pom 1.0-SNAPSHOT - Elm Petstore Client + Elm Client diff --git a/samples/openapi3/client/elm/src/Api.elm b/samples/openapi3/client/elm/src/Api.elm new file mode 100644 index 00000000000..841cca9d762 --- /dev/null +++ b/samples/openapi3/client/elm/src/Api.elm @@ -0,0 +1,121 @@ +module Api exposing + ( Request + , request + , send + , map + , withBasePath + , withTimeout + , withTracker + , withHeader + , withHeaders + ) + +import Http +import Json.Decode +import Json.Encode +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 Json.Encode.Value -> Json.Decode.Decoder a -> Request a +request method path pathParams queryParams headerParams body decoder = + Request + { method = method + , headers = headers headerParams + , basePath = "http://localhost:9000" + , pathParams = interpolatePath path pathParams + , queryParams = queries queryParams + , body = Maybe.withDefault Http.emptyBody (Maybe.map Http.jsonBody body) + , decoder = decoder + , timeout = Nothing + , tracker = Nothing + } + + +send : (Result Http.Error a -> msg) -> Request a -> Cmd msg +send toMsg (Request req) = + Http.request + { method = req.method + , headers = req.headers + , url = Url.Builder.crossOrigin req.basePath req.pathParams req.queryParams + , body = req.body + , expect = Http.expectJson toMsg req.decoder + , timeout = req.timeout + , tracker = req.tracker + } + + +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 } + + +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) \ No newline at end of file diff --git a/samples/openapi3/client/elm/src/Api/Data.elm b/samples/openapi3/client/elm/src/Api/Data.elm new file mode 100644 index 00000000000..d3f0996776b --- /dev/null +++ b/samples/openapi3/client/elm/src/Api/Data.elm @@ -0,0 +1,913 @@ +{- + Elm generator test + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + 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 + ( Absent + , Array + , Composed + , ComposedBase + , Discriminated(..) + , DiscriminatedA + , DiscriminatedB + , Enum(..), enumVariants + , Enumeric(..), enumericVariants + , Maybe_ + , OneOf(..) + , OneOfA + , OneOfB + , Primitive + , Recursion, RecursionMaybe(..), RecursionList(..), RecursionRef(..) + , RecursionLoop, RecursionLoopRef(..) + , UnsafeCharacters + , encodeAbsent + , encodeArray + , encodeComposed + , encodeComposedBase + , encodeDiscriminated + , encodeDiscriminatedA + , encodeDiscriminatedB + , encodeEnum + , encodeEnumeric + , encodeMaybe + , encodeOneOf + , encodeOneOfA + , encodeOneOfB + , encodePrimitive + , encodeRecursion + , encodeRecursionLoop + , encodeUnsafeCharacters + , absentDecoder + , arrayDecoder + , composedDecoder + , composedBaseDecoder + , discriminatedDecoder + , discriminatedADecoder + , discriminatedBDecoder + , enumDecoder + , enumericDecoder + , maybeDecoder + , oneOfDecoder + , oneOfADecoder + , oneOfBDecoder + , primitiveDecoder + , recursionDecoder + , recursionLoopDecoder + , unsafeCharactersDecoder + ) + +import Api +import Dict +import Json.Decode +import Json.Encode + + +-- MODEL + + +{-| Model having absent and null values +-} +type alias Absent = + { default : Maybe String + , required : String + , nullable : Maybe String + , requiredNullable : Maybe String + } + + +{-| Model with arrays +-} +type alias Array = + { array : List (String) + , arrayOfArray : List (List (String)) + } + + +{-| Composed model +-} +type alias Composed = + { base : Float + , value : Maybe String + } + + +type alias ComposedBase = + { base : Float + } + + +{-| Discriminated model +-} +type Discriminated + = Discriminated BaseDiscriminated + | DiscriminatedDiscriminatedA DiscriminatedA + | DiscriminatedDiscriminatedB DiscriminatedB + + +type alias BaseDiscriminated = + { kind : String + } + + +type alias DiscriminatedA = + { baseDiscriminated: BaseDiscriminated + , a : Maybe String + } + + +type alias DiscriminatedB = + { baseDiscriminated: BaseDiscriminated + , b : Maybe String + } + + +type Enum + = EnumFoo + | EnumBar + | EnumBaz + + +enumVariants = + [ EnumFoo + , EnumBar + , EnumBaz + ] + + +type Enumeric + = Enumeric1 + | Enumeric2 + | Enumeric3 + + +enumericVariants = + [ Enumeric1 + , Enumeric2 + , Enumeric3 + ] + + +{-| Model using reserved words +-} +type alias Maybe_ = + { type_ : Maybe String + , if_ : Maybe Bool + } + + +{-| One of two models +-} +type OneOf + = OneOfOneOfA OneOfA + | OneOfOneOfB OneOfB + + + +type alias OneOfA = + { a : Maybe String + } + + +type alias OneOfB = + { b : Maybe String + } + + +{-| Model with primitive properties +-} +type alias Primitive = + { string : Maybe String + , number : Maybe Float + , float : Maybe Float + , double : Maybe Float + , integer : Maybe Int + , short : Maybe Int + , long : Maybe Int + , boolean : Maybe Bool + } + + +type alias Recursion = + { maybe : RecursionMaybe + , list : RecursionList + , ref : RecursionRef + } + + +type RecursionMaybe = RecursionMaybe (Maybe Recursion) + + +unwrapRecursionMaybe : RecursionMaybe -> Maybe Recursion +unwrapRecursionMaybe (RecursionMaybe maybe) = maybe + + +type RecursionList = RecursionList (Maybe (List (Recursion))) + + +unwrapRecursionList : RecursionList -> Maybe (List (Recursion)) +unwrapRecursionList (RecursionList list) = list + + +type RecursionRef = RecursionRef (Maybe RecursionLoop) + + +unwrapRecursionRef : RecursionRef -> Maybe RecursionLoop +unwrapRecursionRef (RecursionRef ref) = ref + + +type alias RecursionLoop = + { ref : RecursionLoopRef + } + + +type RecursionLoopRef = RecursionLoopRef (Maybe Recursion) + + +unwrapRecursionLoopRef : RecursionLoopRef -> Maybe Recursion +unwrapRecursionLoopRef (RecursionLoopRef ref) = ref + + +{-| Model using unsafe characters +-} +type alias UnsafeCharacters = + { prefix : Maybe String + , suffix : Maybe String + , rnd0mTff : Maybe String + , before : Maybe String + , after : Maybe String + , both : Maybe String + , inTheMiddle : Maybe String + } + + +-- ENCODER + + +encodeAbsent : Absent -> Json.Encode.Value +encodeAbsent = + encodeObject << encodeAbsentPairs + + +encodeAbsentWithTag : ( String, String ) -> Absent -> Json.Encode.Value +encodeAbsentWithTag (tagField, tag) model = + encodeObject (encodeAbsentPairs model ++ [ encode tagField Json.Encode.string tag ]) + + +encodeAbsentPairs : Absent -> List EncodedField +encodeAbsentPairs model = + let + pairs = + [ maybeEncode "default" Json.Encode.string model.default + , encode "required" Json.Encode.string model.required + , maybeEncodeNullable "nullable" Json.Encode.string model.nullable + , encodeNullable "requiredNullable" Json.Encode.string model.requiredNullable + ] + in + pairs + + +encodeArray : Array -> Json.Encode.Value +encodeArray = + encodeObject << encodeArrayPairs + + +encodeArrayWithTag : ( String, String ) -> Array -> Json.Encode.Value +encodeArrayWithTag (tagField, tag) model = + encodeObject (encodeArrayPairs model ++ [ encode tagField Json.Encode.string tag ]) + + +encodeArrayPairs : Array -> List EncodedField +encodeArrayPairs model = + let + pairs = + [ encode "array" (Json.Encode.list Json.Encode.string) model.array + , encode "arrayOfArray" (Json.Encode.list (Json.Encode.list Json.Encode.string)) model.arrayOfArray + ] + in + pairs + + +encodeComposed : Composed -> Json.Encode.Value +encodeComposed = + encodeObject << encodeComposedPairs + + +encodeComposedWithTag : ( String, String ) -> Composed -> Json.Encode.Value +encodeComposedWithTag (tagField, tag) model = + encodeObject (encodeComposedPairs model ++ [ encode tagField Json.Encode.string tag ]) + + +encodeComposedPairs : Composed -> List EncodedField +encodeComposedPairs model = + let + pairs = + [ encode "base" Json.Encode.float model.base + , maybeEncode "value" Json.Encode.string model.value + ] + in + pairs + + +encodeComposedBase : ComposedBase -> Json.Encode.Value +encodeComposedBase = + encodeObject << encodeComposedBasePairs + + +encodeComposedBaseWithTag : ( String, String ) -> ComposedBase -> Json.Encode.Value +encodeComposedBaseWithTag (tagField, tag) model = + encodeObject (encodeComposedBasePairs model ++ [ encode tagField Json.Encode.string tag ]) + + +encodeComposedBasePairs : ComposedBase -> List EncodedField +encodeComposedBasePairs model = + let + pairs = + [ encode "base" Json.Encode.float model.base + ] + in + pairs + + +encodeDiscriminated : Discriminated -> Json.Encode.Value +encodeDiscriminated model = + case model of + Discriminated subModel -> + encodeBaseDiscriminated subModel + + DiscriminatedDiscriminatedA subModel -> + encodeDiscriminatedAWithTag ("kind", "DiscriminatedA") subModel + + + DiscriminatedDiscriminatedB subModel -> + encodeDiscriminatedBWithTag ("kind", "DiscriminatedB") subModel + + +encodeBaseDiscriminated : BaseDiscriminated -> Json.Encode.Value +encodeBaseDiscriminated = + encodeObject << encodeBaseDiscriminatedPairs + + +encodeBaseDiscriminatedWithTag : ( String, String ) -> BaseDiscriminated -> Json.Encode.Value +encodeBaseDiscriminatedWithTag (tagField, tag) model = + encodeObject (encodeBaseDiscriminatedPairs model ++ [ encode tagField Json.Encode.string tag ]) + + +encodeBaseDiscriminatedPairs : BaseDiscriminated -> List EncodedField +encodeBaseDiscriminatedPairs model = + let + pairs = + [ encode "kind" Json.Encode.string model.kind + ] + in + pairs + + +encodeDiscriminatedA : DiscriminatedA -> Json.Encode.Value +encodeDiscriminatedA = + encodeObject << encodeDiscriminatedAPairs + + +encodeDiscriminatedAWithTag : ( String, String ) -> DiscriminatedA -> Json.Encode.Value +encodeDiscriminatedAWithTag (tagField, tag) model = + encodeObject (encodeDiscriminatedAPairs model ++ [ encode tagField Json.Encode.string tag ]) + + +encodeDiscriminatedAPairs : DiscriminatedA -> List EncodedField +encodeDiscriminatedAPairs model = + let + pairs = + [ maybeEncode "a" Json.Encode.string model.a + ] + in + encodeBaseDiscriminatedPairs model.baseDiscriminated ++ pairs + + +encodeDiscriminatedB : DiscriminatedB -> Json.Encode.Value +encodeDiscriminatedB = + encodeObject << encodeDiscriminatedBPairs + + +encodeDiscriminatedBWithTag : ( String, String ) -> DiscriminatedB -> Json.Encode.Value +encodeDiscriminatedBWithTag (tagField, tag) model = + encodeObject (encodeDiscriminatedBPairs model ++ [ encode tagField Json.Encode.string tag ]) + + +encodeDiscriminatedBPairs : DiscriminatedB -> List EncodedField +encodeDiscriminatedBPairs model = + let + pairs = + [ maybeEncode "b" Json.Encode.string model.b + ] + in + encodeBaseDiscriminatedPairs model.baseDiscriminated ++ pairs + + +stringFromEnum : Enum -> String +stringFromEnum model = + case model of + EnumFoo -> + "foo" + + EnumBar -> + "bar" + + EnumBaz -> + "baz" + + +encodeEnum : Enum -> Json.Encode.Value +encodeEnum = + Json.Encode.string << stringFromEnum + + +stringFromEnumeric : Enumeric -> String +stringFromEnumeric = + String.fromInt << intFromEnumeric + + +intFromEnumeric : Enumeric -> Int +intFromEnumeric model = + case model of + Enumeric1 -> + 1 + + Enumeric2 -> + 2 + + Enumeric3 -> + 3 + + +encodeEnumeric : Enumeric -> Json.Encode.Value +encodeEnumeric = + Json.Encode.int << intFromEnumeric + + +encodeMaybe : Maybe_ -> Json.Encode.Value +encodeMaybe = + encodeObject << encodeMaybePairs + + +encodeMaybeWithTag : ( String, String ) -> Maybe_ -> Json.Encode.Value +encodeMaybeWithTag (tagField, tag) model = + encodeObject (encodeMaybePairs model ++ [ encode tagField Json.Encode.string tag ]) + + +encodeMaybePairs : Maybe_ -> List EncodedField +encodeMaybePairs model = + let + pairs = + [ maybeEncode "type" Json.Encode.string model.type_ + , maybeEncode "if" Json.Encode.bool model.if_ + ] + in + pairs + + +encodeOneOf : OneOf -> Json.Encode.Value +encodeOneOf model = + case model of + OneOfOneOfA subModel -> + encodeOneOfA subModel + + + OneOfOneOfB subModel -> + encodeOneOfB subModel + + + + +encodeOneOfA : OneOfA -> Json.Encode.Value +encodeOneOfA = + encodeObject << encodeOneOfAPairs + + +encodeOneOfAWithTag : ( String, String ) -> OneOfA -> Json.Encode.Value +encodeOneOfAWithTag (tagField, tag) model = + encodeObject (encodeOneOfAPairs model ++ [ encode tagField Json.Encode.string tag ]) + + +encodeOneOfAPairs : OneOfA -> List EncodedField +encodeOneOfAPairs model = + let + pairs = + [ maybeEncode "a" Json.Encode.string model.a + ] + in + pairs + + +encodeOneOfB : OneOfB -> Json.Encode.Value +encodeOneOfB = + encodeObject << encodeOneOfBPairs + + +encodeOneOfBWithTag : ( String, String ) -> OneOfB -> Json.Encode.Value +encodeOneOfBWithTag (tagField, tag) model = + encodeObject (encodeOneOfBPairs model ++ [ encode tagField Json.Encode.string tag ]) + + +encodeOneOfBPairs : OneOfB -> List EncodedField +encodeOneOfBPairs model = + let + pairs = + [ maybeEncode "b" Json.Encode.string model.b + ] + in + pairs + + +encodePrimitive : Primitive -> Json.Encode.Value +encodePrimitive = + encodeObject << encodePrimitivePairs + + +encodePrimitiveWithTag : ( String, String ) -> Primitive -> Json.Encode.Value +encodePrimitiveWithTag (tagField, tag) model = + encodeObject (encodePrimitivePairs model ++ [ encode tagField Json.Encode.string tag ]) + + +encodePrimitivePairs : Primitive -> List EncodedField +encodePrimitivePairs model = + let + pairs = + [ maybeEncode "string" Json.Encode.string model.string + , maybeEncode "number" Json.Encode.float model.number + , maybeEncode "float" Json.Encode.float model.float + , maybeEncode "double" Json.Encode.float model.double + , maybeEncode "integer" Json.Encode.int model.integer + , maybeEncode "short" Json.Encode.int model.short + , maybeEncode "long" Json.Encode.int model.long + , maybeEncode "boolean" Json.Encode.bool model.boolean + ] + in + pairs + + +encodeRecursion : Recursion -> Json.Encode.Value +encodeRecursion = + encodeObject << encodeRecursionPairs + + +encodeRecursionWithTag : ( String, String ) -> Recursion -> Json.Encode.Value +encodeRecursionWithTag (tagField, tag) model = + encodeObject (encodeRecursionPairs model ++ [ encode tagField Json.Encode.string tag ]) + + +encodeRecursionPairs : Recursion -> List EncodedField +encodeRecursionPairs model = + let + pairs = + [ maybeEncode "maybe" encodeRecursion <| unwrapRecursionMaybe model.maybe + , maybeEncode "list" (Json.Encode.list encodeRecursion) <| unwrapRecursionList model.list + , maybeEncode "ref" encodeRecursionLoop <| unwrapRecursionRef model.ref + ] + in + pairs + + +encodeRecursionLoop : RecursionLoop -> Json.Encode.Value +encodeRecursionLoop = + encodeObject << encodeRecursionLoopPairs + + +encodeRecursionLoopWithTag : ( String, String ) -> RecursionLoop -> Json.Encode.Value +encodeRecursionLoopWithTag (tagField, tag) model = + encodeObject (encodeRecursionLoopPairs model ++ [ encode tagField Json.Encode.string tag ]) + + +encodeRecursionLoopPairs : RecursionLoop -> List EncodedField +encodeRecursionLoopPairs model = + let + pairs = + [ maybeEncode "ref" encodeRecursion <| unwrapRecursionLoopRef model.ref + ] + in + pairs + + +encodeUnsafeCharacters : UnsafeCharacters -> Json.Encode.Value +encodeUnsafeCharacters = + encodeObject << encodeUnsafeCharactersPairs + + +encodeUnsafeCharactersWithTag : ( String, String ) -> UnsafeCharacters -> Json.Encode.Value +encodeUnsafeCharactersWithTag (tagField, tag) model = + encodeObject (encodeUnsafeCharactersPairs model ++ [ encode tagField Json.Encode.string tag ]) + + +encodeUnsafeCharactersPairs : UnsafeCharacters -> List EncodedField +encodeUnsafeCharactersPairs model = + let + pairs = + [ maybeEncode "$prefix" Json.Encode.string model.prefix + , maybeEncode "suffix$" Json.Encode.string model.suffix + , maybeEncode "r@nd0m_$t#ff" Json.Encode.string model.rnd0mTff + , maybeEncode "_before" Json.Encode.string model.before + , maybeEncode "after_" Json.Encode.string model.after + , maybeEncode "_both_" Json.Encode.string model.both + , maybeEncode "in_the_middle" Json.Encode.string model.inTheMiddle + ] + in + pairs + + +-- DECODER + + +absentDecoder : Json.Decode.Decoder Absent +absentDecoder = + Json.Decode.succeed Absent + |> maybeDecode "default" Json.Decode.string Nothing + |> decode "required" Json.Decode.string + |> maybeDecodeNullable "nullable" Json.Decode.string Nothing + |> decodeNullable "requiredNullable" Json.Decode.string + + +arrayDecoder : Json.Decode.Decoder Array +arrayDecoder = + Json.Decode.succeed Array + |> decode "array" (Json.Decode.list Json.Decode.string) + |> decode "arrayOfArray" (Json.Decode.list (Json.Decode.list Json.Decode.string)) + + +composedDecoder : Json.Decode.Decoder Composed +composedDecoder = + Json.Decode.succeed Composed + |> decode "base" Json.Decode.float + |> maybeDecode "value" Json.Decode.string Nothing + + +composedBaseDecoder : Json.Decode.Decoder ComposedBase +composedBaseDecoder = + Json.Decode.succeed ComposedBase + |> decode "base" Json.Decode.float + + +discriminatedDecoder : Json.Decode.Decoder Discriminated +discriminatedDecoder = + Json.Decode.field "kind" Json.Decode.string + |> Json.Decode.andThen discriminatedTagDecoder + + +discriminatedTagDecoder : String -> Json.Decode.Decoder Discriminated +discriminatedTagDecoder tag = + case tag of + "DiscriminatedA" -> + Json.Decode.map DiscriminatedDiscriminatedA discriminatedADecoder + + "DiscriminatedB" -> + Json.Decode.map DiscriminatedDiscriminatedB discriminatedBDecoder + + _ -> + Json.Decode.map Discriminated baseDiscriminatedDecoder + + +baseDiscriminatedDecoder : Json.Decode.Decoder BaseDiscriminated +baseDiscriminatedDecoder = + Json.Decode.succeed BaseDiscriminated + |> decode "kind" Json.Decode.string + + +discriminatedADecoder : Json.Decode.Decoder DiscriminatedA +discriminatedADecoder = + Json.Decode.succeed DiscriminatedA + |> decodeChain baseDiscriminatedDecoder + |> maybeDecode "a" Json.Decode.string Nothing + + +discriminatedBDecoder : Json.Decode.Decoder DiscriminatedB +discriminatedBDecoder = + Json.Decode.succeed DiscriminatedB + |> decodeChain baseDiscriminatedDecoder + |> maybeDecode "b" Json.Decode.string Nothing + + +enumDecoder : Json.Decode.Decoder Enum +enumDecoder = + Json.Decode.string + |> Json.Decode.andThen + (\value -> + case value of + "foo" -> + Json.Decode.succeed EnumFoo + + "bar" -> + Json.Decode.succeed EnumBar + + "baz" -> + Json.Decode.succeed EnumBaz + + other -> + Json.Decode.fail <| "Unknown type: " ++ other + ) + + +enumericDecoder : Json.Decode.Decoder Enumeric +enumericDecoder = + Json.Decode.int + |> Json.Decode.andThen + (\value -> + case value of + 1 -> + Json.Decode.succeed Enumeric1 + + 2 -> + Json.Decode.succeed Enumeric2 + + 3 -> + Json.Decode.succeed Enumeric3 + + other -> + Json.Decode.fail <| "Unknown type: " ++ String.fromInt other + ) + + +maybeDecoder : Json.Decode.Decoder Maybe_ +maybeDecoder = + Json.Decode.succeed Maybe_ + |> maybeDecode "type" Json.Decode.string Nothing + |> maybeDecode "if" Json.Decode.bool Nothing + + +oneOfDecoder : Json.Decode.Decoder OneOf +oneOfDecoder = + Json.Decode.oneOf + [ Json.Decode.map OneOfOneOfA oneOfADecoder + , Json.Decode.map OneOfOneOfB oneOfBDecoder + ] + + + +oneOfADecoder : Json.Decode.Decoder OneOfA +oneOfADecoder = + Json.Decode.succeed OneOfA + |> maybeDecode "a" Json.Decode.string Nothing + + +oneOfBDecoder : Json.Decode.Decoder OneOfB +oneOfBDecoder = + Json.Decode.succeed OneOfB + |> maybeDecode "b" Json.Decode.string Nothing + + +primitiveDecoder : Json.Decode.Decoder Primitive +primitiveDecoder = + Json.Decode.succeed Primitive + |> maybeDecode "string" Json.Decode.string Nothing + |> maybeDecode "number" Json.Decode.float Nothing + |> maybeDecode "float" Json.Decode.float Nothing + |> maybeDecode "double" Json.Decode.float Nothing + |> maybeDecode "integer" Json.Decode.int Nothing + |> maybeDecode "short" Json.Decode.int Nothing + |> maybeDecode "long" Json.Decode.int Nothing + |> maybeDecode "boolean" Json.Decode.bool Nothing + + +recursionDecoder : Json.Decode.Decoder Recursion +recursionDecoder = + Json.Decode.succeed Recursion + |> maybeDecodeLazy RecursionMaybe "maybe" (Json.Decode.lazy (\_ -> recursionDecoder)) Nothing + |> maybeDecodeLazy RecursionList "list" (Json.Decode.list (Json.Decode.lazy (\_ -> recursionDecoder))) Nothing + |> maybeDecodeLazy RecursionRef "ref" (Json.Decode.lazy (\_ -> recursionLoopDecoder)) Nothing + + +recursionLoopDecoder : Json.Decode.Decoder RecursionLoop +recursionLoopDecoder = + Json.Decode.succeed RecursionLoop + |> maybeDecodeLazy RecursionLoopRef "ref" (Json.Decode.lazy (\_ -> recursionDecoder)) Nothing + + +unsafeCharactersDecoder : Json.Decode.Decoder UnsafeCharacters +unsafeCharactersDecoder = + Json.Decode.succeed UnsafeCharacters + |> maybeDecode "$prefix" Json.Decode.string Nothing + |> maybeDecode "suffix$" Json.Decode.string Nothing + |> maybeDecode "r@nd0m_$t#ff" Json.Decode.string Nothing + |> maybeDecode "_before" Json.Decode.string Nothing + |> maybeDecode "after_" Json.Decode.string Nothing + |> maybeDecode "_both_" Json.Decode.string Nothing + |> maybeDecode "in_the_middle" Json.Decode.string 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 \ No newline at end of file diff --git a/samples/openapi3/client/elm/src/Api/Request/Default.elm b/samples/openapi3/client/elm/src/Api/Request/Default.elm new file mode 100644 index 00000000000..75f381aa201 --- /dev/null +++ b/samples/openapi3/client/elm/src/Api/Request/Default.elm @@ -0,0 +1,159 @@ +{- + Elm generator test + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + 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.Default exposing + ( headerPost, HeaderType(..), headerTypeVariants + , maybeGet + , pathStringIntegerEnumerationGet, Enumeration(..), enumerationVariants + , queryGet, Enum(..), enumVariants + ) + +import Api +import Api.Data +import Dict +import Http +import Json.Decode +import Json.Encode + + +type HeaderType + = HeaderTypeLeft + | HeaderTypeRight + + +headerTypeVariants = + [ HeaderTypeLeft + , HeaderTypeRight + ] + + +stringFromHeaderType : HeaderType -> String +stringFromHeaderType model = + case model of + HeaderTypeLeft -> + "left" + + HeaderTypeRight -> + "right" + + + + +type Enumeration + = EnumerationA + | EnumerationB + | EnumerationC + + +enumerationVariants = + [ EnumerationA + , EnumerationB + , EnumerationC + ] + + +stringFromEnumeration : Enumeration -> String +stringFromEnumeration model = + case model of + EnumerationA -> + "a" + + EnumerationB -> + "b" + + EnumerationC -> + "c" + + + + +type Enum + = EnumA + | EnumB + | EnumC + + +enumVariants = + [ EnumA + , EnumB + , EnumC + ] + + +stringFromEnum : Enum -> String +stringFromEnum model = + case model of + EnumA -> + "a" + + EnumB -> + "b" + + EnumC -> + "c" + + + + + +headerPost : String -> Maybe Int -> Maybe HeaderType -> Api.Request String +headerPost string integer headerType = + Api.request + "POST" + "/header" + [] + [] + [ ( "string", Just <| identity string ), ( "integer", Maybe.map String.fromInt integer ), ( "headerType", Maybe.map stringFromHeaderType headerType ) ] + Nothing + Json.Decode.string + + + +maybeGet : Api.Request Api.Data.Maybe_ +maybeGet = + Api.request + "GET" + "/maybe" + [] + [] + [] + Nothing + Api.Data.maybeDecoder + + + +pathStringIntegerEnumerationGet : String -> Int -> Enumeration -> Api.Request () +pathStringIntegerEnumerationGet string integer enumeration = + Api.request + "GET" + "/path/{string}/{integer}/{enumeration}" + [ ( "string", identity string ), ( "integer", String.fromInt integer ), ( "enumeration", stringFromEnumeration enumeration ) ] + [] + [] + Nothing + (Json.Decode.succeed ()) + + + +queryGet : Maybe String -> Maybe Int -> Maybe Enum -> Api.Request () +queryGet string int enum = + Api.request + "GET" + "/query" + [] + [ ( "string", Maybe.map identity string ), ( "int", Maybe.map String.fromInt int ), ( "enum", Maybe.map stringFromEnum enum ) ] + [] + Nothing + (Json.Decode.succeed ()) diff --git a/samples/openapi3/client/elm/src/Api/Request/Primitive.elm b/samples/openapi3/client/elm/src/Api/Request/Primitive.elm new file mode 100644 index 00000000000..f9e59dce68d --- /dev/null +++ b/samples/openapi3/client/elm/src/Api/Request/Primitive.elm @@ -0,0 +1,38 @@ +{- + Elm generator test + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + 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.Primitive exposing + ( update + ) + +import Api +import Api.Data +import Dict +import Http +import Json.Decode +import Json.Encode + + + +update : Api.Data.Primitive -> Api.Request Api.Data.Primitive +update primitive = + Api.request + "POST" + "/data" + [] + [] + [] + (Just (Api.Data.encodePrimitive primitive)) + Api.Data.primitiveDecoder diff --git a/samples/openapi3/client/elm/src/Api/Time.elm b/samples/openapi3/client/elm/src/Api/Time.elm new file mode 100644 index 00000000000..a44ce3de772 --- /dev/null +++ b/samples/openapi3/client/elm/src/Api/Time.elm @@ -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) \ No newline at end of file diff --git a/samples/openapi3/client/petstore/elm/.openapi-generator/VERSION b/samples/openapi3/client/petstore/elm/.openapi-generator/VERSION index d168f1d8bda..d99e7162d01 100644 --- a/samples/openapi3/client/petstore/elm/.openapi-generator/VERSION +++ b/samples/openapi3/client/petstore/elm/.openapi-generator/VERSION @@ -1 +1 @@ -4.2.1-SNAPSHOT \ No newline at end of file +5.0.0-SNAPSHOT \ No newline at end of file diff --git a/samples/openapi3/client/petstore/elm/src/Main.elm b/samples/openapi3/client/petstore/elm/src/Main.elm deleted file mode 100644 index 7c9ddd056d3..00000000000 --- a/samples/openapi3/client/petstore/elm/src/Main.elm +++ /dev/null @@ -1,61 +0,0 @@ -module Main exposing (main) - -import Browser -import Html exposing (Html) - - -main : Program () Model Msg -main = - Browser.element - { init = init - , view = view - , update = update - , subscriptions = subscriptions - } - - - --- MODEL - - -type alias Model = - { value : Int - } - - -init : () -> ( Model, Cmd Msg ) -init _ = - ( Model 0, Cmd.none ) - - - --- UPDATE - - -type Msg - = NoOp - - -update : Msg -> Model -> ( Model, Cmd Msg ) -update msg model = - case msg of - NoOp -> - ( model, Cmd.none ) - - - --- SUBSCRIPTIONS - - -subscriptions : Model -> Sub Msg -subscriptions _ = - Sub.none - - - --- VIEW - - -view : Model -> Html Msg -view _ = - Html.text "main" diff --git a/shippable.yml b/shippable.yml index fe67ed0ea62..d2b96f13632 100644 --- a/shippable.yml +++ b/shippable.yml @@ -30,7 +30,8 @@ build: - sudo apt-get update - sudo apt-get install elixir # install elm - - curl -SL https://github.com/elm/compiler/releases/download/0.19.0/binaries-for-linux.tar.gz | tar xzv -C /usr/local/bin + - curl -SL https://github.com/elm/compiler/releases/download/0.19.1/binary-for-linux-64-bit.gz | zcat > /usr/local/bin/elm + - chmod +x /usr/local/bin/elm # install rebar3 - wget https://s3.amazonaws.com/rebar3/rebar3 && chmod +x rebar3 && cp rebar3 /usr/bin # install php