mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-05-12 20:50:55 +00:00
Elm refactoring (#4891)
* [elm] Remove support for Elm 0.18 * [elm] Drop `Main.elm` * [elm] Put all models in a single file * [elm] Put generated code in `Api` package * [elm] Introduce Request type for operations * [elm] Generate list of enum variants * [elm] Make default Time module * [elm] Small improvements & fixes * [elm] Improve support for allOf * All of types are now nested; * Adding a discriminator creates a custom type wrapping all variants and a 'catch-all' fallback variant. * [elm] Add support for recursive types * [elm] Add catch-all type for allOf * [elm] Drop support for post-processing of files * [elm] Only import required packages * [elm] Handle reserved and unsafe words * [elm] Minor improvements * [elm] Add support for integer enums * [elm] Remove additional slash in path * [elm] Add link to docs * [elm] Update CI test file & scripts
This commit is contained in:
parent
e9459125bb
commit
b62fc1c031
@ -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
|
||||
|
@ -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 -- .
|
||||
|
||||
|
@ -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
|
@ -1,5 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
./bin/elm-0.18-petstore.sh
|
||||
./bin/elm-petstore.sh
|
||||
|
@ -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
|
@ -1,5 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
./bin/openapi3/elm-petstore.sh
|
||||
./bin/openapi3/elm-composition.sh
|
||||
|
@ -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
|
@ -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
|
@ -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"
|
||||
)
|
||||
|
||||
|
@ -5,7 +5,3 @@ sidebar_label: elm
|
||||
|
||||
| Option | Description | Values | Default |
|
||||
| ------ | ----------- | ------ | ------- |
|
||||
|elmVersion|Elm version: 0.18, 0.19|<dl><dt>**0.19**</dt><dd>Elm 0.19</dd><dt>**0.18**</dt><dd>Elm 0.18</dd><dl>|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|
|
||||
|
@ -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<String> customPrimitives = new HashSet<String>();
|
||||
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<String, String> 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<String, Object> postProcessAllModels(Map<String, Object> objs) {
|
||||
// Index all CodegenModels by model name.
|
||||
Map<String, CodegenModel> allModels = new HashMap<>();
|
||||
for (Map.Entry<String, Object> entry : objs.entrySet()) {
|
||||
String modelName = toModelName(entry.getKey());
|
||||
Map<String, Object> inner = (Map<String, Object>) entry.getValue();
|
||||
List<Map<String, Object>> models = (List<Map<String, Object>>) inner.get("models");
|
||||
for (Map<String, Object> mo : models) {
|
||||
CodegenModel cm = (CodegenModel) mo.get("model");
|
||||
allModels.put(modelName, cm);
|
||||
}
|
||||
}
|
||||
// Let parent know about all its children
|
||||
for (CodegenModel cm : allModels.values()) {
|
||||
CodegenModel parent = allModels.get(cm.parent);
|
||||
public Map<String, Object> postProcessAllModels(final Map<String, Object> orgObjs) {
|
||||
final Map<String, Object> 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<CodegenModel>() {
|
||||
@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<String, Object> objects = new HashMap<>();
|
||||
final Map<String, Object> dataObj = objs.values().stream()
|
||||
.map(obj -> (Map<String, Object>) obj)
|
||||
.findFirst()
|
||||
.orElse(new HashMap<>());
|
||||
final List<Map<String, Object>> models = objs.values().stream()
|
||||
.map(obj -> (Map<String, Object>) obj)
|
||||
.flatMap(obj -> ((List<Map<String, Object>>) 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<String, Object> entry : objs.entrySet()) {
|
||||
Map<String, Object> inner = (Map<String, Object>) entry.getValue();
|
||||
List<Map<String, Object>> models = (List<Map<String, Object>>) inner.get("models");
|
||||
for (Map<String, Object> mo : models) {
|
||||
CodegenModel cm = (CodegenModel) mo.get("model");
|
||||
if (cm.isEnum) {
|
||||
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<ElmImport> 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<CodegenProperty> 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<Map<String, Object>> models, final Predicate<CodegenProperty> 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<CodegenOperation> operations, final Predicate<CodegenParameter> 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<CodegenOperation> operations, final Predicate<CodegenResponse> 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<String, Object> postProcessOperationsWithModels(Map<String, Object> operations, List<Object> allModels) {
|
||||
Map<String, Object> objs = (Map<String, Object>) operations.get("operations");
|
||||
List<CodegenOperation> ops = (List<CodegenOperation>) objs.get("operation");
|
||||
|
||||
final Set<String> 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<Object> 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<ElmImport> 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<CodegenParameter> {
|
||||
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<String> 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<String, Object> allowableValues = property.allowableValues;
|
||||
if (allowableValues == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final List<Map<String, Object>> enumVars = (ArrayList<Map<String, Object>>) allowableValues.get("enumVars");
|
||||
if (enumVars == null) {
|
||||
return;
|
||||
}
|
||||
final String prefix = toEnumName(property);
|
||||
for (Map<String, Object> 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<String, Object> 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<String> 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
121
modules/openapi-generator/src/main/resources/elm/Api.mustache
vendored
Normal file
121
modules/openapi-generator/src/main/resources/elm/Api.mustache
vendored
Normal file
@ -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)
|
@ -1,18 +0,0 @@
|
||||
module Byte exposing (Byte, decoder, encode)
|
||||
|
||||
import Json.Decode as Decode exposing (Decoder)
|
||||
import Json.Encode as Encode
|
||||
|
||||
|
||||
type alias Byte =
|
||||
String
|
||||
|
||||
|
||||
decoder : Decoder Byte
|
||||
decoder =
|
||||
Decode.string
|
||||
|
||||
|
||||
encode : Byte -> Encode.Value
|
||||
encode model =
|
||||
Encode.string model
|
@ -1,37 +0,0 @@
|
||||
module DateOnly exposing (DateOnly, decoder, encode, toString)
|
||||
|
||||
import Iso8601
|
||||
import Json.Decode as Decode exposing (Decoder)
|
||||
import Json.Encode as Encode
|
||||
import Result
|
||||
import Time
|
||||
|
||||
|
||||
type alias DateOnly =
|
||||
Time.Posix
|
||||
|
||||
|
||||
decoder : Decoder DateOnly
|
||||
decoder =
|
||||
Decode.string
|
||||
|> Decode.andThen decodeIsoString
|
||||
|
||||
|
||||
encode : DateOnly -> Encode.Value
|
||||
encode =
|
||||
Encode.string << toString
|
||||
|
||||
|
||||
decodeIsoString : String -> Decoder DateOnly
|
||||
decodeIsoString str =
|
||||
case Iso8601.toTime (str ++ "T00:00:00.000Z") of
|
||||
Result.Ok posix ->
|
||||
Decode.succeed posix
|
||||
|
||||
Result.Err _ ->
|
||||
Decode.fail <| "Invalid date: " ++ str
|
||||
|
||||
|
||||
toString : DateOnly -> String
|
||||
toString =
|
||||
String.left 10 << Iso8601.fromTime
|
@ -1,37 +0,0 @@
|
||||
module 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"
|
@ -1,37 +0,0 @@
|
||||
module DateTime exposing (DateTime, decoder, encode, toString)
|
||||
|
||||
import Iso8601
|
||||
import Json.Decode as Decode exposing (Decoder)
|
||||
import Json.Encode as Encode
|
||||
import Result
|
||||
import Time
|
||||
|
||||
|
||||
type alias DateTime =
|
||||
Time.Posix
|
||||
|
||||
|
||||
decoder : Decoder DateTime
|
||||
decoder =
|
||||
Decode.string
|
||||
|> Decode.andThen decodeIsoString
|
||||
|
||||
|
||||
encode : DateTime -> Encode.Value
|
||||
encode =
|
||||
Encode.string << toString
|
||||
|
||||
|
||||
decodeIsoString : String -> Decoder DateTime
|
||||
decodeIsoString str =
|
||||
case Iso8601.toTime str of
|
||||
Result.Ok posix ->
|
||||
Decode.succeed posix
|
||||
|
||||
Result.Err _ ->
|
||||
Decode.fail <| "Invalid date: " ++ str
|
||||
|
||||
|
||||
toString : DateTime -> String
|
||||
toString =
|
||||
Iso8601.fromTime
|
@ -1,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
|
@ -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"
|
70
modules/openapi-generator/src/main/resources/elm/Time.mustache
vendored
Normal file
70
modules/openapi-generator/src/main/resources/elm/Time.mustache
vendored
Normal file
@ -0,0 +1,70 @@
|
||||
module Api.Time exposing
|
||||
( Posix
|
||||
, dateToString
|
||||
, dateTimeToString
|
||||
, encodeDate
|
||||
, encodeDateTime
|
||||
, dateDecoder
|
||||
, dateTimeDecoder
|
||||
)
|
||||
|
||||
import Http
|
||||
import Iso8601
|
||||
import Json.Decode
|
||||
import Json.Encode
|
||||
import Time
|
||||
|
||||
|
||||
type alias Posix = Time.Posix
|
||||
|
||||
|
||||
dateToString : Posix -> String
|
||||
dateToString =
|
||||
String.left 10 << dateTimeToString
|
||||
|
||||
|
||||
dateTimeToString : Posix -> String
|
||||
dateTimeToString =
|
||||
Iso8601.fromTime
|
||||
|
||||
|
||||
encodeDate : Posix -> Json.Encode.Value
|
||||
encodeDate =
|
||||
Json.Encode.string << dateToString
|
||||
|
||||
|
||||
encodeDateTime : Posix -> Json.Encode.Value
|
||||
encodeDateTime =
|
||||
Json.Encode.string << dateTimeToString
|
||||
|
||||
|
||||
dateDecoder : Json.Decode.Decoder Posix
|
||||
dateDecoder =
|
||||
Json.Decode.string
|
||||
|> Json.Decode.andThen decodeDateIsoString
|
||||
|
||||
|
||||
decodeDateIsoString : String -> Json.Decode.Decoder Posix
|
||||
decodeDateIsoString str =
|
||||
case Iso8601.toTime (str ++ "T00:00:00.000Z") of
|
||||
Result.Ok posix ->
|
||||
Json.Decode.succeed posix
|
||||
|
||||
Result.Err _ ->
|
||||
Json.Decode.fail ("Invalid calendar date: " ++ str)
|
||||
|
||||
|
||||
dateTimeDecoder : Json.Decode.Decoder Posix
|
||||
dateTimeDecoder =
|
||||
Json.Decode.string
|
||||
|> Json.Decode.andThen decodeDateTimeIsoString
|
||||
|
||||
|
||||
decodeDateTimeIsoString : String -> Json.Decode.Decoder Posix
|
||||
decodeDateTimeIsoString str =
|
||||
case Iso8601.toTime str of
|
||||
Result.Ok posix ->
|
||||
Json.Decode.succeed posix
|
||||
|
||||
Result.Err _ ->
|
||||
Json.Decode.fail ("Invalid ISO date: " ++ str)
|
@ -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}}
|
@ -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}}
|
@ -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}}
|
||||
{{/allowableValues}}
|
||||
|
||||
|
||||
{{#lambda.camelcase}}{{^paramName}}{{classname}}{{/paramName}}{{enumName}}{{/lambda.camelcase}}Variants =
|
||||
{{#allowableValues}}
|
||||
{{#enumVars}}
|
||||
{{#-first}}[{{/-first}}{{^-first}},{{/-first}} {{^paramName}}{{classname}}{{/paramName}}{{enumName}}{{name}}
|
||||
{{/enumVars}}
|
||||
{{/allowableValues}}
|
||||
]
|
@ -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
|
||||
)
|
@ -1,10 +1,4 @@
|
||||
{{vendorExtensions.elmEncoder}} : {{vendorExtensions.elmCustomType}} -> Encode.Value
|
||||
{{vendorExtensions.elmEncoder}} model =
|
||||
case model of
|
||||
{{#allowableValues}}
|
||||
{{#enumVars}}
|
||||
{{name}} ->
|
||||
Encode.string {{{value}}}
|
||||
|
||||
{{/enumVars}}
|
||||
{{/allowableValues}}
|
||||
{{>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}}
|
15
modules/openapi-generator/src/main/resources/elm/customTypeToString.mustache
vendored
Normal file
15
modules/openapi-generator/src/main/resources/elm/customTypeToString.mustache
vendored
Normal file
@ -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}}
|
4
modules/openapi-generator/src/main/resources/elm/customTypeWithData.mustache
vendored
Normal file
4
modules/openapi-generator/src/main/resources/elm/customTypeWithData.mustache
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
type {{classname}}
|
||||
{{#oneOf}}
|
||||
{{#-first}}={{/-first}}{{^-first}}|{{/-first}} {{classname}}{{.}} {{.}}
|
||||
{{/oneOf}}
|
21
modules/openapi-generator/src/main/resources/elm/customTypeWithDataDecoder.mustache
vendored
Normal file
21
modules/openapi-generator/src/main/resources/elm/customTypeWithDataDecoder.mustache
vendored
Normal file
@ -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}}
|
13
modules/openapi-generator/src/main/resources/elm/customTypeWithDataEncoder.mustache
vendored
Normal file
13
modules/openapi-generator/src/main/resources/elm/customTypeWithDataEncoder.mustache
vendored
Normal file
@ -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}}
|
@ -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"
|
||||
}
|
@ -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",
|
||||
|
1
modules/openapi-generator/src/main/resources/elm/fieldDecoder.mustache
vendored
Normal file
1
modules/openapi-generator/src/main/resources/elm/fieldDecoder.mustache
vendored
Normal file
@ -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}}
|
1
modules/openapi-generator/src/main/resources/elm/fieldEncoder.mustache
vendored
Normal file
1
modules/openapi-generator/src/main/resources/elm/fieldEncoder.mustache
vendored
Normal file
@ -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}}
|
@ -1,3 +0,0 @@
|
||||
{{#elmImports}}
|
||||
import {{moduleName}}{{#as}} as {{as}}{{/as}}{{#hasExposures}} exposing ({{#exposures}}{{^-first}}, {{/-first}}{{.}}{{/exposures}}){{/hasExposures}}
|
||||
{{/elmImports}}
|
@ -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/
|
||||
-}
|
||||
|
@ -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
|
@ -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
|
@ -1,19 +0,0 @@
|
||||
{{>customType}}
|
||||
|
||||
|
||||
{{>customTypeDecoder}}
|
||||
|
||||
|
||||
{{>customTypeEncoder}}
|
||||
|
||||
|
||||
toString : {{classname}} -> String
|
||||
toString model =
|
||||
case model of
|
||||
{{#allowableValues}}
|
||||
{{#enumVars}}
|
||||
{{name}} ->
|
||||
{{{value}}}
|
||||
|
||||
{{/enumVars}}
|
||||
{{/allowableValues}}
|
@ -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
|
@ -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}}
|
@ -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}}
|
46
modules/openapi-generator/src/main/resources/elm/operation.mustache
vendored
Normal file
46
modules/openapi-generator/src/main/resources/elm/operation.mustache
vendored
Normal file
@ -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}}
|
1
modules/openapi-generator/src/main/resources/elm/paramToString.mustache
vendored
Normal file
1
modules/openapi-generator/src/main/resources/elm/paramToString.mustache
vendored
Normal file
@ -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}}
|
24
modules/openapi-generator/src/main/resources/elm/record.mustache
vendored
Normal file
24
modules/openapi-generator/src/main/resources/elm/record.mustache
vendored
Normal file
@ -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}}
|
@ -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}}
|
@ -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}}
|
1
modules/openapi-generator/src/main/resources/elm/recordField.mustache
vendored
Normal file
1
modules/openapi-generator/src/main/resources/elm/recordField.mustache
vendored
Normal file
@ -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}}
|
@ -1 +1 @@
|
||||
{{#required}}required{{/required}}{{^required}}optional{{/required}} "{{baseName}}" {{^required}}{{^isNullable}}(Decode.nullable {{/isNullable}}{{/required}}{{>recordFieldValueDecoder}}{{^required}}{{^isNullable}}) {{{defaultValue}}}{{/isNullable}}{{/required}}
|
||||
{{#required}}decode{{/required}}{{^required}}maybeDecode{{/required}}{{#isNullable}}Nullable{{/isNullable}}{{#isCircularReference}}Lazy {{classname}}{{nameInCamelCase}}{{/isCircularReference}} "{{baseName}}" {{>recordFieldValueDecoder}} {{^required}}{{#defaultValue}}(Just {{{.}}}){{/defaultValue}}{{^defaultValue}}Nothing{{/defaultValue}}{{/required}}
|
@ -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}} )
|
||||
{{#required}}encode{{/required}}{{^required}}maybeEncode{{/required}}{{#isNullable}}Nullable{{/isNullable}} "{{baseName}}" {{>recordFieldValueEncoder}} {{#isCircularReference}}<| unwrap{{classname}}{{nameInCamelCase}} {{/isCircularReference}}model.{{name}}
|
@ -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}}
|
@ -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}}
|
||||
{{#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}}
|
@ -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}}
|
||||
{{#isContainer}}({{#isListContainer}}Json.Encode.list{{/isListContainer}}{{#isMapContainer}}Json.Encode.dict identity{{/isMapContainer}} {{#items}}{{>recordFieldValueEncoder}}{{/items}}{{/isContainer}}{{^isContainer}}{{>fieldEncoder}}{{/isContainer}}{{#isContainer}}){{/isContainer}}
|
@ -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}}
|
@ -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<CodegenOperation> ops = newArrayList(rootOp);
|
||||
|
||||
Map<String, Object> operations = new HashMap<>();
|
||||
operations.put("operations", ImmutableMap
|
||||
.<String, Object>builder()
|
||||
.put("operation", ops)
|
||||
.build());
|
||||
|
||||
// when
|
||||
Map<String, Object> 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 + "\"");
|
||||
}
|
||||
}
|
||||
}
|
@ -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
|
257
modules/openapi-generator/src/test/resources/3_0/elm.yaml
Normal file
257
modules/openapi-generator/src/test/resources/3_0/elm.yaml
Normal file
@ -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
|
||||
|
3
pom.xml
3
pom.xml
@ -1042,7 +1042,6 @@
|
||||
<module>samples/client/petstore/bash</module>
|
||||
<module>samples/client/petstore/c</module>
|
||||
<module>samples/client/petstore/cpp-qt5</module>
|
||||
<!--<module>samples/client/petstore/elm-0.18</module>-->
|
||||
<module>samples/client/petstore/rust</module>
|
||||
<!--<module>samples/client/petstore/perl</module>-->
|
||||
<module>samples/client/petstore/php/OpenAPIClient-php</module>
|
||||
@ -1247,7 +1246,7 @@
|
||||
</activation>
|
||||
<modules>
|
||||
<!-- clients -->
|
||||
<module>samples/client/petstore/elm</module>
|
||||
<module>samples/openapi3/client/elm</module>
|
||||
<module>samples/client/petstore/elixir</module>
|
||||
<module>samples/client/petstore/erlang-client</module>
|
||||
<module>samples/client/petstore/erlang-proper</module>
|
||||
|
@ -1 +0,0 @@
|
||||
5.0.0-SNAPSHOT
|
@ -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
|
@ -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
|
@ -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"
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>Elm018ClientTests</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>Elm 0.18 Petstore Client</name>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>bundle-test</id>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<executable>./elm-0.18-compile-test</executable>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@ -1,18 +0,0 @@
|
||||
module Byte exposing (Byte, decoder, encode)
|
||||
|
||||
import Json.Decode as Decode exposing (Decoder)
|
||||
import Json.Encode as Encode
|
||||
|
||||
|
||||
type alias Byte =
|
||||
String
|
||||
|
||||
|
||||
decoder : Decoder Byte
|
||||
decoder =
|
||||
Decode.string
|
||||
|
||||
|
||||
encode : Byte -> Encode.Value
|
||||
encode model =
|
||||
Encode.string model
|
@ -1,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
|
@ -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
|
@ -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"
|
@ -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"
|
@ -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
|
@ -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
|
@ -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"
|
@ -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
|
@ -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"
|
@ -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
|
@ -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
|
@ -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
|
1
samples/client/petstore/elm/.gitignore
vendored
1
samples/client/petstore/elm/.gitignore
vendored
@ -1 +0,0 @@
|
||||
/elm-stuff
|
@ -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
|
@ -1 +0,0 @@
|
||||
5.0.0-SNAPSHOT
|
@ -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
|
@ -1,18 +0,0 @@
|
||||
module Byte exposing (Byte, decoder, encode)
|
||||
|
||||
import Json.Decode as Decode exposing (Decoder)
|
||||
import Json.Encode as Encode
|
||||
|
||||
|
||||
type alias Byte =
|
||||
String
|
||||
|
||||
|
||||
decoder : Decoder Byte
|
||||
decoder =
|
||||
Decode.string
|
||||
|
||||
|
||||
encode : Byte -> Encode.Value
|
||||
encode model =
|
||||
Encode.string model
|
@ -1,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
|
@ -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
|
@ -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"
|
@ -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"
|
@ -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
|
@ -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
|
@ -1,37 +0,0 @@
|
||||
module DateOnly exposing (DateOnly, decoder, encode, toString)
|
||||
|
||||
import Iso8601
|
||||
import Json.Decode as Decode exposing (Decoder)
|
||||
import Json.Encode as Encode
|
||||
import Result
|
||||
import Time
|
||||
|
||||
|
||||
type alias DateOnly =
|
||||
Time.Posix
|
||||
|
||||
|
||||
decoder : Decoder DateOnly
|
||||
decoder =
|
||||
Decode.string
|
||||
|> Decode.andThen decodeIsoString
|
||||
|
||||
|
||||
encode : DateOnly -> Encode.Value
|
||||
encode =
|
||||
Encode.string << toString
|
||||
|
||||
|
||||
decodeIsoString : String -> Decoder DateOnly
|
||||
decodeIsoString str =
|
||||
case Iso8601.toTime (str ++ "T00:00:00.000Z") of
|
||||
Result.Ok posix ->
|
||||
Decode.succeed posix
|
||||
|
||||
Result.Err _ ->
|
||||
Decode.fail <| "Invalid date: " ++ str
|
||||
|
||||
|
||||
toString : DateOnly -> String
|
||||
toString =
|
||||
String.left 10 << Iso8601.fromTime
|
@ -1,37 +0,0 @@
|
||||
module DateTime exposing (DateTime, decoder, encode, toString)
|
||||
|
||||
import Iso8601
|
||||
import Json.Decode as Decode exposing (Decoder)
|
||||
import Json.Encode as Encode
|
||||
import Result
|
||||
import Time
|
||||
|
||||
|
||||
type alias DateTime =
|
||||
Time.Posix
|
||||
|
||||
|
||||
decoder : Decoder DateTime
|
||||
decoder =
|
||||
Decode.string
|
||||
|> Decode.andThen decodeIsoString
|
||||
|
||||
|
||||
encode : DateTime -> Encode.Value
|
||||
encode =
|
||||
Encode.string << toString
|
||||
|
||||
|
||||
decodeIsoString : String -> Decoder DateTime
|
||||
decodeIsoString str =
|
||||
case Iso8601.toTime str of
|
||||
Result.Ok posix ->
|
||||
Decode.succeed posix
|
||||
|
||||
Result.Err _ ->
|
||||
Decode.fail <| "Invalid date: " ++ str
|
||||
|
||||
|
||||
toString : DateTime -> String
|
||||
toString =
|
||||
Iso8601.fromTime
|
@ -1,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"
|
@ -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
|
||||
}
|
@ -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
|
||||
}
|
@ -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
|
||||
}
|
@ -1 +0,0 @@
|
||||
/elm-stuff
|
@ -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
|
@ -1 +0,0 @@
|
||||
4.2.1-SNAPSHOT
|
@ -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
|
@ -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": {}
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.openapitools</groupId>
|
||||
<artifactId>ElmCompositionTests</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>Elm Composition Client</name>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>bundle-test</id>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<executable>./elm-compile-test</executable>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@ -1,18 +0,0 @@
|
||||
module Byte exposing (Byte, decoder, encode)
|
||||
|
||||
import Json.Decode as Decode exposing (Decoder)
|
||||
import Json.Encode as Encode
|
||||
|
||||
|
||||
type alias Byte =
|
||||
String
|
||||
|
||||
|
||||
decoder : Decoder Byte
|
||||
decoder =
|
||||
Decode.string
|
||||
|
||||
|
||||
encode : Byte -> Encode.Value
|
||||
encode model =
|
||||
Encode.string model
|
@ -1,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
|
@ -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
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user