From 7a86c36c94483acc3a538088922220d75d0d3390 Mon Sep 17 00:00:00 2001 From: Erik Timmers Date: Sat, 29 Sep 2018 21:11:01 +0200 Subject: [PATCH 1/2] WIP --- bin/elm-petstore-all.sh | 1 + bin/openapi3/elm-petstore.sh | 4 +- .../codegen/languages/ElmClientCodegen.java | 63 +++++- .../src/main/resources/elm/Byte.mustache | 10 +- .../src/main/resources/elm/api.mustache | 1 + .../openapi3/client/petstore/elm/.gitignore | 1 + .../petstore/elm/.openapi-generator-ignore | 23 +++ .../petstore/elm/.openapi-generator/VERSION | 1 + .../openapi3/client/petstore/elm/README.md | 10 + .../client/petstore/elm/elm-compile-test | 14 ++ samples/openapi3/client/petstore/elm/elm.json | 28 +++ samples/openapi3/client/petstore/elm/pom.xml | 43 ++++ .../openapi3/client/petstore/elm/src/Byte.elm | 18 ++ .../src/Data/AdditionalPropertiesClass.elm | 39 ++++ .../client/petstore/elm/src/Data/Animal.elm | 53 +++++ .../petstore/elm/src/Data/AnimalFarm.elm | 32 +++ .../petstore/elm/src/Data/ApiResponse.elm | 41 ++++ .../elm/src/Data/ArrayOfArrayOfNumberOnly.elm | 36 ++++ .../elm/src/Data/ArrayOfNumberOnly.elm | 35 ++++ .../petstore/elm/src/Data/ArrayTest.elm | 42 ++++ .../client/petstore/elm/src/Data/Body.elm | 38 ++++ .../client/petstore/elm/src/Data/Body1.elm | 38 ++++ .../client/petstore/elm/src/Data/Body2.elm | 109 ++++++++++ .../client/petstore/elm/src/Data/Body3.elm | 77 +++++++ .../client/petstore/elm/src/Data/Body4.elm | 38 ++++ .../client/petstore/elm/src/Data/Body5.elm | 38 ++++ .../petstore/elm/src/Data/Capitalization.elm | 50 +++++ .../client/petstore/elm/src/Data/Cat.elm | 39 ++++ .../client/petstore/elm/src/Data/Category.elm | 38 ++++ .../petstore/elm/src/Data/ClassModel.elm | 37 ++++ .../client/petstore/elm/src/Data/Client.elm | 35 ++++ .../client/petstore/elm/src/Data/Dog.elm | 39 ++++ .../petstore/elm/src/Data/EnumArrays.elm | 102 ++++++++++ .../petstore/elm/src/Data/EnumClass.elm | 56 ++++++ .../client/petstore/elm/src/Data/EnumTest.elm | 190 ++++++++++++++++++ .../client/petstore/elm/src/Data/File.elm | 37 ++++ .../elm/src/Data/FileSchemaTestClass.elm | 39 ++++ .../petstore/elm/src/Data/FormatTest.elm | 74 +++++++ .../petstore/elm/src/Data/HasOnlyReadOnly.elm | 38 ++++ .../client/petstore/elm/src/Data/List_.elm | 35 ++++ .../client/petstore/elm/src/Data/MapTest.elm | 77 +++++++ ...PropertiesAndAdditionalPropertiesClass.elm | 43 ++++ .../petstore/elm/src/Data/N200Response.elm | 40 ++++ .../client/petstore/elm/src/Data/Name.elm | 46 +++++ .../petstore/elm/src/Data/NumberOnly.elm | 35 ++++ .../client/petstore/elm/src/Data/Order_.elm | 90 +++++++++ .../petstore/elm/src/Data/OuterComposite.elm | 41 ++++ .../petstore/elm/src/Data/OuterEnum.elm | 56 ++++++ .../client/petstore/elm/src/Data/Pet.elm | 91 +++++++++ .../petstore/elm/src/Data/ReadOnlyFirst.elm | 38 ++++ .../client/petstore/elm/src/Data/Return.elm | 37 ++++ .../elm/src/Data/SpecialModelName.elm | 35 ++++ .../elm/src/Data/StringBooleanMap.elm | 36 ++++ .../client/petstore/elm/src/Data/Tag.elm | 38 ++++ .../client/petstore/elm/src/Data/User.elm | 56 ++++++ .../client/petstore/elm/src/DateOnly.elm | 34 ++++ .../client/petstore/elm/src/DateTime.elm | 32 +++ .../openapi3/client/petstore/elm/src/Main.elm | 61 ++++++ .../petstore/elm/src/Request/AnotherFake.elm | 39 ++++ .../client/petstore/elm/src/Request/Fake.elm | 186 +++++++++++++++++ .../elm/src/Request/FakeClassnameTags123.elm | 39 ++++ .../client/petstore/elm/src/Request/Pet.elm | 148 ++++++++++++++ .../client/petstore/elm/src/Request/Store.elm | 82 ++++++++ .../client/petstore/elm/src/Request/User.elm | 134 ++++++++++++ 64 files changed, 3143 insertions(+), 13 deletions(-) create mode 100644 samples/openapi3/client/petstore/elm/.gitignore create mode 100644 samples/openapi3/client/petstore/elm/.openapi-generator-ignore create mode 100644 samples/openapi3/client/petstore/elm/.openapi-generator/VERSION create mode 100644 samples/openapi3/client/petstore/elm/README.md create mode 100755 samples/openapi3/client/petstore/elm/elm-compile-test create mode 100644 samples/openapi3/client/petstore/elm/elm.json create mode 100644 samples/openapi3/client/petstore/elm/pom.xml create mode 100644 samples/openapi3/client/petstore/elm/src/Byte.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Data/AdditionalPropertiesClass.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Data/Animal.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Data/AnimalFarm.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Data/ApiResponse.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Data/ArrayOfArrayOfNumberOnly.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Data/ArrayOfNumberOnly.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Data/ArrayTest.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Data/Body.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Data/Body1.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Data/Body2.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Data/Body3.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Data/Body4.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Data/Body5.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Data/Capitalization.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Data/Cat.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Data/Category.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Data/ClassModel.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Data/Client.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Data/Dog.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Data/EnumArrays.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Data/EnumClass.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Data/EnumTest.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Data/File.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Data/FileSchemaTestClass.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Data/FormatTest.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Data/HasOnlyReadOnly.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Data/List_.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Data/MapTest.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Data/MixedPropertiesAndAdditionalPropertiesClass.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Data/N200Response.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Data/Name.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Data/NumberOnly.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Data/Order_.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Data/OuterComposite.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Data/OuterEnum.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Data/Pet.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Data/ReadOnlyFirst.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Data/Return.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Data/SpecialModelName.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Data/StringBooleanMap.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Data/Tag.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Data/User.elm create mode 100644 samples/openapi3/client/petstore/elm/src/DateOnly.elm create mode 100644 samples/openapi3/client/petstore/elm/src/DateTime.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Main.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Request/AnotherFake.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Request/Fake.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Request/FakeClassnameTags123.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Request/Pet.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Request/Store.elm create mode 100644 samples/openapi3/client/petstore/elm/src/Request/User.elm diff --git a/bin/elm-petstore-all.sh b/bin/elm-petstore-all.sh index 0d64cf613cf7..a678f2da8668 100755 --- a/bin/elm-petstore-all.sh +++ b/bin/elm-petstore-all.sh @@ -2,4 +2,5 @@ ./bin/elm-0.18-petstore.sh ./bin/elm-petstore.sh +./bin/openapi3/elm-petstore.sh diff --git a/bin/openapi3/elm-petstore.sh b/bin/openapi3/elm-petstore.sh index 9090d50a87fb..1c033e7362b4 100755 --- a/bin/openapi3/elm-petstore.sh +++ b/bin/openapi3/elm-petstore.sh @@ -22,11 +22,11 @@ executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar" if [ ! -f "$executable" ] then - mvn clean package + mvn -B clean package fi # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g elm -o samples/client/petstore/elm $@" +ags="generate -i modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml -g elm -t modules/openapi-generator/src/main/resources/elm -o samples/openapi3/client/petstore/elm $@" java $JAVA_OPTS -jar $executable $ags diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElmClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElmClientCodegen.java index 8d94006be503..67a40ef4c0ac 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElmClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElmClientCodegen.java @@ -58,6 +58,7 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig { private static final Logger LOGGER = LoggerFactory.getLogger(ElmClientCodegen.class); private Set customPrimitives = new HashSet(); + private Map reservedCharacters = new HashMap<>(); private ElmVersion elmVersion = ElmVersion.ELM_019; private static final String ELM_VERSION = "elmVersion"; @@ -146,11 +147,36 @@ public ElmClientCodegen() { typeMapping.put("date", "DateOnly"); typeMapping.put("DateTime", "DateTime"); typeMapping.put("password", "String"); + typeMapping.put("UUID", "String"); typeMapping.put("file", "String"); typeMapping.put("ByteArray", "Byte"); typeMapping.put("binary", "String"); + reservedCharacters.clear(); + reservedCharacters.put(";", "Semicolon"); + reservedCharacters.put("/", "Slash"); + reservedCharacters.put("?", "QuestionMark"); + reservedCharacters.put(":", "Colon"); + reservedCharacters.put("@", "At"); + reservedCharacters.put("&", "Ampersand"); + reservedCharacters.put("=;", "Equal"); + reservedCharacters.put("+", "Plus"); + reservedCharacters.put("$", "Dollar"); + reservedCharacters.put(",", "Comma"); + reservedCharacters.put("_", "_"); + reservedCharacters.put(".", "Dot"); + reservedCharacters.put("!", "ExclamationMark"); + reservedCharacters.put("~", "Tilde"); + reservedCharacters.put("*", "Asterisk"); + reservedCharacters.put("(", ""); + reservedCharacters.put(")", ""); + reservedCharacters.put("[", ""); + reservedCharacters.put("]", ""); + reservedCharacters.put("<", "LessThan"); + reservedCharacters.put(">", "GreaterThan"); + importMapping.clear(); + // TODO DateTime, DateOnly, Byte ??? cliOptions.clear(); @@ -220,6 +246,20 @@ public String escapeQuotationMark(String input) { return input.replace("\"", ""); } + @Override + public String removeNonNameElementToCamelCase(final String name) { + if (StringUtils.isEmpty(name)) { + return ""; + } + String prefixed; + if (Character.isLetter(name.charAt(0))) { + prefixed = name; + } else { + prefixed = "N" + name; + } + return removeNonNameElementToCamelCase(prefixed.replace('.', '_').replace('-', '_').replace('[', '_').replace(']', '_'), "[:;&#$@%(){}<>=-]"); + } + @Override public String toApiName(String name) { if (name.length() == 0) { @@ -231,6 +271,9 @@ public String toApiName(String name) { @Override public String toModelName(String name) { final String modelName = org.openapitools.codegen.utils.StringUtils.camelize(name); + if (!Character.isUpperCase(modelName.charAt(0))) { + return "N" + modelName; + } return defaultIncludes.contains(modelName) ? modelName + "_" : modelName; } @@ -246,17 +289,25 @@ public String toEnumName(CodegenProperty property) { @Override public String toVarName(String name) { - final String varName = org.openapitools.codegen.utils.StringUtils.camelize(name, true); - return isReservedWord(varName) ? escapeReservedWord(name) : varName; + final String escaped = name == null ? "" : removeNonNameElementToCamelCase(name); + if ("".equals(escaped)) { + return ""; + } + final String varName = escaped.substring(0, 1).toLowerCase(Locale.ROOT) + (escaped.length() > 1 ? escaped.substring(1) : ""); + return isReservedWord(varName) ? escapeReservedWord(varName) : varName; } @Override public String toEnumVarName(String value, String datatype) { - final String camelized = org.openapitools.codegen.utils.StringUtils.camelize(value.replace(" ", "_").replace("(", "_").replace(")", "")); // TODO FIXME escape properly - if (!Character.isUpperCase(camelized.charAt(0))) { - return "N" + camelized; + String name = value; + for (Map.Entry entry : reservedCharacters.entrySet()) { + name = name.replace(entry.getKey(), entry.getValue()); + } + final String varName = toVarName(name); + if ("".equals(varName)) { + return "Empty"; } - return camelized; + return varName.substring(0, 1).toUpperCase(Locale.ROOT) + (varName.length() > 1 ? varName.substring(1) : ""); } @Override diff --git a/modules/openapi-generator/src/main/resources/elm/Byte.mustache b/modules/openapi-generator/src/main/resources/elm/Byte.mustache index da078742947b..6c80664aba10 100644 --- a/modules/openapi-generator/src/main/resources/elm/Byte.mustache +++ b/modules/openapi-generator/src/main/resources/elm/Byte.mustache @@ -1,4 +1,4 @@ -module Byte exposing (Byte, byteDecoder, byteEncoder) +module Byte exposing (Byte, decoder, encoder) import Json.Decode as Decode exposing (Decoder) import Json.Encode as Encode @@ -8,11 +8,11 @@ type alias Byte = String -byteDecoder : Decoder Byte -byteDecoder = +decoder : Decoder Byte +decoder = Decode.string -byteEncoder : Byte -> Encode.Value -byteEncoder model = +encoder : Byte -> Encode.Value +encoder model = Encode.string model diff --git a/modules/openapi-generator/src/main/resources/elm/api.mustache b/modules/openapi-generator/src/main/resources/elm/api.mustache index ebe53eeac930..cf10313adbe9 100644 --- a/modules/openapi-generator/src/main/resources/elm/api.mustache +++ b/modules/openapi-generator/src/main/resources/elm/api.mustache @@ -5,6 +5,7 @@ module Request.{{classname}} exposing ({{#operations}}{{#operation}}{{^-first}}, {{>imports}}import Dict import Http import Json.Decode as Decode +import Json.Encode as Encode basePath : String diff --git a/samples/openapi3/client/petstore/elm/.gitignore b/samples/openapi3/client/petstore/elm/.gitignore new file mode 100644 index 000000000000..8b0d053e4e35 --- /dev/null +++ b/samples/openapi3/client/petstore/elm/.gitignore @@ -0,0 +1 @@ +/elm-stuff \ No newline at end of file diff --git a/samples/openapi3/client/petstore/elm/.openapi-generator-ignore b/samples/openapi3/client/petstore/elm/.openapi-generator-ignore new file mode 100644 index 000000000000..7484ee590a38 --- /dev/null +++ b/samples/openapi3/client/petstore/elm/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/samples/openapi3/client/petstore/elm/.openapi-generator/VERSION b/samples/openapi3/client/petstore/elm/.openapi-generator/VERSION new file mode 100644 index 000000000000..6d94c9c2e12a --- /dev/null +++ b/samples/openapi3/client/petstore/elm/.openapi-generator/VERSION @@ -0,0 +1 @@ +3.3.0-SNAPSHOT \ No newline at end of file diff --git a/samples/openapi3/client/petstore/elm/README.md b/samples/openapi3/client/petstore/elm/README.md new file mode 100644 index 000000000000..d912d35e56f0 --- /dev/null +++ b/samples/openapi3/client/petstore/elm/README.md @@ -0,0 +1,10 @@ +# Elm API client + +This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + +## Overview +This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [openapi-spec](https://github.com/OAI/OpenAPI-Specification) from a remote server, you can easily generate an API client. + +- API version: 1.0.0 +- Package version: +- Build package: org.openapitools.codegen.languages.ElmClientCodegen diff --git a/samples/openapi3/client/petstore/elm/elm-compile-test b/samples/openapi3/client/petstore/elm/elm-compile-test new file mode 100755 index 000000000000..55507cfcad61 --- /dev/null +++ b/samples/openapi3/client/petstore/elm/elm-compile-test @@ -0,0 +1,14 @@ +#!/bin/bash -e +# elm make all elm files under src + +for ELM in `find src -name "*.elm"` +do + echo "Compiling $ELM" + elm make $ELM --output /dev/null + rc=$? + if [[ $rc != 0 ]] + then + echo "ERROR!! FAILED TO COMPILE $ELM" + exit $rc; + fi +done diff --git a/samples/openapi3/client/petstore/elm/elm.json b/samples/openapi3/client/petstore/elm/elm.json new file mode 100644 index 000000000000..6028a740feb8 --- /dev/null +++ b/samples/openapi3/client/petstore/elm/elm.json @@ -0,0 +1,28 @@ +{ + "type": "application", + "source-directories": [ + "src" + ], + "elm-version": "0.19.0", + "dependencies": { + "direct": { + "NoRedInk/elm-json-decode-pipeline": "1.0.0", + "elm/browser": "1.0.0", + "elm/core": "1.0.0", + "elm/html": "1.0.0", + "elm/http": "1.0.0", + "elm/json": "1.0.0", + "elm/time": "1.0.0", + "rtfeldman/elm-iso8601-date-strings": "1.0.0" + }, + "indirect": { + "elm/parser": "1.0.0", + "elm/url": "1.0.0", + "elm/virtual-dom": "1.0.0" + } + }, + "test-dependencies": { + "direct": {}, + "indirect": {} + } +} diff --git a/samples/openapi3/client/petstore/elm/pom.xml b/samples/openapi3/client/petstore/elm/pom.xml new file mode 100644 index 000000000000..5e2bddbecddc --- /dev/null +++ b/samples/openapi3/client/petstore/elm/pom.xml @@ -0,0 +1,43 @@ + + 4.0.0 + org.openapitools + ElmClientTests + pom + 1.0-SNAPSHOT + Elm AllOf Client + + + + maven-dependency-plugin + + + package + + copy-dependencies + + + ${project.build.directory} + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.2.1 + + + bundle-test + integration-test + + exec + + + ./elm-compile-test + + + + + + + diff --git a/samples/openapi3/client/petstore/elm/src/Byte.elm b/samples/openapi3/client/petstore/elm/src/Byte.elm new file mode 100644 index 000000000000..6c80664aba10 --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Byte.elm @@ -0,0 +1,18 @@ +module Byte exposing (Byte, decoder, encoder) + +import Json.Decode as Decode exposing (Decoder) +import Json.Encode as Encode + + +type alias Byte = + String + + +decoder : Decoder Byte +decoder = + Decode.string + + +encoder : Byte -> Encode.Value +encoder model = + Encode.string model diff --git a/samples/openapi3/client/petstore/elm/src/Data/AdditionalPropertiesClass.elm b/samples/openapi3/client/petstore/elm/src/Data/AdditionalPropertiesClass.elm new file mode 100644 index 000000000000..19e3732c145c --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Data/AdditionalPropertiesClass.elm @@ -0,0 +1,39 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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.AdditionalPropertiesClass exposing (AdditionalPropertiesClass, decoder, encoder) + +import Data.Map as Map exposing (Map) +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +type alias AdditionalPropertiesClass = + { map_property : Maybe (List String) + , map_of_map_property : Maybe (List String) + } + + +decoder : Decoder AdditionalPropertiesClass +decoder = + Decode.succeed AdditionalPropertiesClass + |> optional "map_property" (Decode.nullable (Decode.list Decode.string)) Nothing + |> optional "map_of_map_property" (Decode.nullable (Decode.list Decode.string)) Nothing + + +encoder : AdditionalPropertiesClass -> Encode.Value +encoder model = + Encode.object + [ ( "map_property", Maybe.withDefault Encode.null (Maybe.map (Encode.list Encode.string) model.map_property) ) + , ( "map_of_map_property", Maybe.withDefault Encode.null (Maybe.map (Encode.list Encode.string) model.map_of_map_property) ) + ] diff --git a/samples/openapi3/client/petstore/elm/src/Data/Animal.elm b/samples/openapi3/client/petstore/elm/src/Data/Animal.elm new file mode 100644 index 000000000000..6454bf2c9ecb --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Data/Animal.elm @@ -0,0 +1,53 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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.Animal exposing (Animal(..), decoder, encoder) + +import Data.Cat as Cat exposing (Cat) +import Data.Dog as Dog exposing (Dog) +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +type Animal + = DogType Dog + | CatType Cat + + +decoder : Decoder Animal +decoder = + Decode.field "className" Decode.string + |> Decode.andThen animalDecoder + + +animalDecoder : String -> Decoder Animal +animalDecoder tag = + case tag of + "Dog" -> + Decode.map DogType Dog.decoder + + "Cat" -> + Decode.map CatType Cat.decoder + + _ -> + Decode.fail <| "Trying to decode Animal, but className " ++ tag ++ " is not supported." + + +encoder : Animal -> Encode.Value +encoder model = + case model of + DogType subModel -> + Dog.encoder "Dog" subModel + + CatType subModel -> + Cat.encoder "Cat" subModel diff --git a/samples/openapi3/client/petstore/elm/src/Data/AnimalFarm.elm b/samples/openapi3/client/petstore/elm/src/Data/AnimalFarm.elm new file mode 100644 index 000000000000..c46a1895c9a1 --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Data/AnimalFarm.elm @@ -0,0 +1,32 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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.AnimalFarm exposing (AnimalFarm, decoder, encoder) + +import Data.Animal as Animal exposing (Animal) +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +type alias AnimalFarm = + List Animal + + +decoder : Decoder AnimalFarm +decoder = + Decode.list Animal.decoder + + +encoder : AnimalFarm -> Encode.Value +encoder items = + Encode.list Animal.encoder items diff --git a/samples/openapi3/client/petstore/elm/src/Data/ApiResponse.elm b/samples/openapi3/client/petstore/elm/src/Data/ApiResponse.elm new file mode 100644 index 000000000000..b9761cb80771 --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Data/ApiResponse.elm @@ -0,0 +1,41 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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, encoder) + +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +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 + + +encoder : ApiResponse -> Encode.Value +encoder model = + Encode.object + [ ( "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) ) + ] diff --git a/samples/openapi3/client/petstore/elm/src/Data/ArrayOfArrayOfNumberOnly.elm b/samples/openapi3/client/petstore/elm/src/Data/ArrayOfArrayOfNumberOnly.elm new file mode 100644 index 000000000000..4f60830a1e04 --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Data/ArrayOfArrayOfNumberOnly.elm @@ -0,0 +1,36 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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.ArrayOfArrayOfNumberOnly exposing (ArrayOfArrayOfNumberOnly, decoder, encoder) + +import Data.List_ as List_ exposing (List_) +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +type alias ArrayOfArrayOfNumberOnly = + { arrayArrayNumber : Maybe (List Float) + } + + +decoder : Decoder ArrayOfArrayOfNumberOnly +decoder = + Decode.succeed ArrayOfArrayOfNumberOnly + |> optional "ArrayArrayNumber" (Decode.nullable (Decode.list Float.decoder)) Nothing + + +encoder : ArrayOfArrayOfNumberOnly -> Encode.Value +encoder model = + Encode.object + [ ( "ArrayArrayNumber", Maybe.withDefault Encode.null (Maybe.map (Encode.list Float.encoder) model.arrayArrayNumber) ) + ] diff --git a/samples/openapi3/client/petstore/elm/src/Data/ArrayOfNumberOnly.elm b/samples/openapi3/client/petstore/elm/src/Data/ArrayOfNumberOnly.elm new file mode 100644 index 000000000000..fb4b9b786f7b --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Data/ArrayOfNumberOnly.elm @@ -0,0 +1,35 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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.ArrayOfNumberOnly exposing (ArrayOfNumberOnly, decoder, encoder) + +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +type alias ArrayOfNumberOnly = + { arrayNumber : Maybe (List Float) + } + + +decoder : Decoder ArrayOfNumberOnly +decoder = + Decode.succeed ArrayOfNumberOnly + |> optional "ArrayNumber" (Decode.nullable (Decode.list Decode.float)) Nothing + + +encoder : ArrayOfNumberOnly -> Encode.Value +encoder model = + Encode.object + [ ( "ArrayNumber", Maybe.withDefault Encode.null (Maybe.map (Encode.list Encode.float) model.arrayNumber) ) + ] diff --git a/samples/openapi3/client/petstore/elm/src/Data/ArrayTest.elm b/samples/openapi3/client/petstore/elm/src/Data/ArrayTest.elm new file mode 100644 index 000000000000..762429cbae07 --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Data/ArrayTest.elm @@ -0,0 +1,42 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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.ArrayTest exposing (ArrayTest, decoder, encoder) + +import Data.List_ as List_ exposing (List_) +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +type alias ArrayTest = + { array_of_string : Maybe (List String) + , array_array_of_integer : Maybe (List Int) + , array_array_of_model : Maybe (List ReadOnlyFirst) + } + + +decoder : Decoder ArrayTest +decoder = + Decode.succeed ArrayTest + |> optional "array_of_string" (Decode.nullable (Decode.list Decode.string)) Nothing + |> optional "array_array_of_integer" (Decode.nullable (Decode.list Int.decoder)) Nothing + |> optional "array_array_of_model" (Decode.nullable (Decode.list ReadOnlyFirst.decoder)) Nothing + + +encoder : ArrayTest -> Encode.Value +encoder model = + Encode.object + [ ( "array_of_string", Maybe.withDefault Encode.null (Maybe.map (Encode.list Encode.string) model.array_of_string) ) + , ( "array_array_of_integer", Maybe.withDefault Encode.null (Maybe.map (Encode.list Int.encoder) model.array_array_of_integer) ) + , ( "array_array_of_model", Maybe.withDefault Encode.null (Maybe.map (Encode.list ReadOnlyFirst.encoder) model.array_array_of_model) ) + ] diff --git a/samples/openapi3/client/petstore/elm/src/Data/Body.elm b/samples/openapi3/client/petstore/elm/src/Data/Body.elm new file mode 100644 index 000000000000..1f7ecafa60a7 --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Data/Body.elm @@ -0,0 +1,38 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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.Body exposing (Body, decoder, encoder) + +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +type alias Body = + { name : Maybe String + , status : Maybe String + } + + +decoder : Decoder Body +decoder = + Decode.succeed Body + |> optional "name" (Decode.nullable Decode.string) Nothing + |> optional "status" (Decode.nullable Decode.string) Nothing + + +encoder : Body -> Encode.Value +encoder model = + Encode.object + [ ( "name", Maybe.withDefault Encode.null (Maybe.map Encode.string model.name) ) + , ( "status", Maybe.withDefault Encode.null (Maybe.map Encode.string model.status) ) + ] diff --git a/samples/openapi3/client/petstore/elm/src/Data/Body1.elm b/samples/openapi3/client/petstore/elm/src/Data/Body1.elm new file mode 100644 index 000000000000..20a88b730449 --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Data/Body1.elm @@ -0,0 +1,38 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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.Body1 exposing (Body1, decoder, encoder) + +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +type alias Body1 = + { additionalMetadata : Maybe String + , file : Maybe String + } + + +decoder : Decoder Body1 +decoder = + Decode.succeed Body1 + |> optional "additionalMetadata" (Decode.nullable Decode.string) Nothing + |> optional "file" (Decode.nullable Decode.string) Nothing + + +encoder : Body1 -> Encode.Value +encoder model = + Encode.object + [ ( "additionalMetadata", Maybe.withDefault Encode.null (Maybe.map Encode.string model.additionalMetadata) ) + , ( "file", Maybe.withDefault Encode.null (Maybe.map Encode.string model.file) ) + ] diff --git a/samples/openapi3/client/petstore/elm/src/Data/Body2.elm b/samples/openapi3/client/petstore/elm/src/Data/Body2.elm new file mode 100644 index 000000000000..b1ead65dfe3c --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Data/Body2.elm @@ -0,0 +1,109 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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.Body2 exposing (Body2, EnumFormString(..), EnumFormStringArray(..), decoder, encoder) + +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +type alias Body2 = + { enum_form_string_array : Maybe (List EnumFormStringArray) + , enum_form_string : Maybe EnumFormString + } + + +type EnumFormStringArray + = GreaterThan + | Dollar + + +type EnumFormString + = N_abc + | N_efg + | Xyz + + +decoder : Decoder Body2 +decoder = + Decode.succeed Body2 + |> optional "enum_form_string_array" (Decode.nullable (Decode.list enumFormStringArrayDecoder)) Nothing + |> optional "enum_form_string" (Decode.nullable enumFormStringDecoder) (Just "-efg") + + +encoder : Body2 -> Encode.Value +encoder model = + Encode.object + [ ( "enum_form_string_array", Maybe.withDefault Encode.null (Maybe.map (Encode.list enumFormStringArrayEncoder) model.enum_form_string_array) ) + , ( "enum_form_string", Maybe.withDefault Encode.null (Maybe.map enumFormStringEncoder model.enum_form_string) ) + ] + + +enumFormStringArrayDecoder : Decoder EnumFormStringArray +enumFormStringArrayDecoder = + Decode.string + |> Decode.andThen + (\str -> + case str of + ">" -> + Decode.succeed GreaterThan + + "$" -> + Decode.succeed Dollar + + other -> + Decode.fail <| "Unknown type: " ++ other + ) + + +enumFormStringArrayEncoder : EnumFormStringArray -> Encode.Value +enumFormStringArrayEncoder model = + case model of + GreaterThan -> + Encode.string ">" + + Dollar -> + Encode.string "$" + + +enumFormStringDecoder : Decoder EnumFormString +enumFormStringDecoder = + Decode.string + |> Decode.andThen + (\str -> + case str of + "_abc" -> + Decode.succeed N_abc + + "-efg" -> + Decode.succeed N_efg + + "(xyz)" -> + Decode.succeed Xyz + + other -> + Decode.fail <| "Unknown type: " ++ other + ) + + +enumFormStringEncoder : EnumFormString -> Encode.Value +enumFormStringEncoder model = + case model of + N_abc -> + Encode.string "_abc" + + N_efg -> + Encode.string "-efg" + + Xyz -> + Encode.string "(xyz)" diff --git a/samples/openapi3/client/petstore/elm/src/Data/Body3.elm b/samples/openapi3/client/petstore/elm/src/Data/Body3.elm new file mode 100644 index 000000000000..03d20aa43455 --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Data/Body3.elm @@ -0,0 +1,77 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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.Body3 exposing (Body3, decoder, encoder) + +import Byte exposing (Byte) +import DateOnly exposing (DateOnly) +import DateTime exposing (DateTime) +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +type alias Body3 = + { integer : Maybe Int + , int32 : Maybe Int + , int64 : Maybe Int + , number : Float + , float : Maybe Float + , double : Float + , string : Maybe String + , pattern_without_delimiter : String + , byte : Byte + , binary : Maybe String + , date : Maybe DateOnly + , dateTime : Maybe DateTime + , password : Maybe String + , callback : Maybe String + } + + +decoder : Decoder Body3 +decoder = + Decode.succeed Body3 + |> optional "integer" (Decode.nullable Decode.int) Nothing + |> optional "int32" (Decode.nullable Decode.int) Nothing + |> optional "int64" (Decode.nullable Decode.int) Nothing + |> required "number" Decode.float + |> optional "float" (Decode.nullable Decode.float) Nothing + |> required "double" Decode.float + |> optional "string" (Decode.nullable Decode.string) Nothing + |> required "pattern_without_delimiter" Decode.string + |> required "byte" Byte.decoder + |> optional "binary" (Decode.nullable Decode.string) Nothing + |> optional "date" (Decode.nullable DateOnly.decoder) Nothing + |> optional "dateTime" (Decode.nullable DateTime.decoder) Nothing + |> optional "password" (Decode.nullable Decode.string) Nothing + |> optional "callback" (Decode.nullable Decode.string) Nothing + + +encoder : Body3 -> Encode.Value +encoder model = + Encode.object + [ ( "integer", Maybe.withDefault Encode.null (Maybe.map Encode.int model.integer) ) + , ( "int32", Maybe.withDefault Encode.null (Maybe.map Encode.int model.int32) ) + , ( "int64", Maybe.withDefault Encode.null (Maybe.map Encode.int model.int64) ) + , ( "number", Encode.float model.number ) + , ( "float", Maybe.withDefault Encode.null (Maybe.map Encode.float model.float) ) + , ( "double", Encode.float model.double ) + , ( "string", Maybe.withDefault Encode.null (Maybe.map Encode.string model.string) ) + , ( "pattern_without_delimiter", Encode.string model.pattern_without_delimiter ) + , ( "byte", Byte.encoder model.byte ) + , ( "binary", Maybe.withDefault Encode.null (Maybe.map Encode.string model.binary) ) + , ( "date", Maybe.withDefault Encode.null (Maybe.map DateOnly.encoder model.date) ) + , ( "dateTime", Maybe.withDefault Encode.null (Maybe.map DateTime.encoder model.dateTime) ) + , ( "password", Maybe.withDefault Encode.null (Maybe.map Encode.string model.password) ) + , ( "callback", Maybe.withDefault Encode.null (Maybe.map Encode.string model.callback) ) + ] diff --git a/samples/openapi3/client/petstore/elm/src/Data/Body4.elm b/samples/openapi3/client/petstore/elm/src/Data/Body4.elm new file mode 100644 index 000000000000..c35c62ff2a3f --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Data/Body4.elm @@ -0,0 +1,38 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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.Body4 exposing (Body4, decoder, encoder) + +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +type alias Body4 = + { param : String + , param2 : String + } + + +decoder : Decoder Body4 +decoder = + Decode.succeed Body4 + |> required "param" Decode.string + |> required "param2" Decode.string + + +encoder : Body4 -> Encode.Value +encoder model = + Encode.object + [ ( "param", Encode.string model.param ) + , ( "param2", Encode.string model.param2 ) + ] diff --git a/samples/openapi3/client/petstore/elm/src/Data/Body5.elm b/samples/openapi3/client/petstore/elm/src/Data/Body5.elm new file mode 100644 index 000000000000..bf2e9032f534 --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Data/Body5.elm @@ -0,0 +1,38 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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.Body5 exposing (Body5, decoder, encoder) + +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +type alias Body5 = + { additionalMetadata : Maybe String + , requiredFile : String + } + + +decoder : Decoder Body5 +decoder = + Decode.succeed Body5 + |> optional "additionalMetadata" (Decode.nullable Decode.string) Nothing + |> required "requiredFile" Decode.string + + +encoder : Body5 -> Encode.Value +encoder model = + Encode.object + [ ( "additionalMetadata", Maybe.withDefault Encode.null (Maybe.map Encode.string model.additionalMetadata) ) + , ( "requiredFile", Encode.string model.requiredFile ) + ] diff --git a/samples/openapi3/client/petstore/elm/src/Data/Capitalization.elm b/samples/openapi3/client/petstore/elm/src/Data/Capitalization.elm new file mode 100644 index 000000000000..73cde56feaa4 --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Data/Capitalization.elm @@ -0,0 +1,50 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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.Capitalization exposing (Capitalization, decoder, encoder) + +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +type alias Capitalization = + { smallCamel : Maybe String + , capitalCamel : Maybe String + , small_Snake : Maybe String + , capital_Snake : Maybe String + , sCA_ETH_Flow_Points : Maybe String + , aTT_NAME : Maybe String + } + + +decoder : Decoder Capitalization +decoder = + Decode.succeed Capitalization + |> optional "smallCamel" (Decode.nullable Decode.string) Nothing + |> optional "CapitalCamel" (Decode.nullable Decode.string) Nothing + |> optional "small_Snake" (Decode.nullable Decode.string) Nothing + |> optional "Capital_Snake" (Decode.nullable Decode.string) Nothing + |> optional "SCA_ETH_Flow_Points" (Decode.nullable Decode.string) Nothing + |> optional "ATT_NAME" (Decode.nullable Decode.string) Nothing + + +encoder : Capitalization -> Encode.Value +encoder model = + Encode.object + [ ( "smallCamel", Maybe.withDefault Encode.null (Maybe.map Encode.string model.smallCamel) ) + , ( "CapitalCamel", Maybe.withDefault Encode.null (Maybe.map Encode.string model.capitalCamel) ) + , ( "small_Snake", Maybe.withDefault Encode.null (Maybe.map Encode.string model.small_Snake) ) + , ( "Capital_Snake", Maybe.withDefault Encode.null (Maybe.map Encode.string model.capital_Snake) ) + , ( "SCA_ETH_Flow_Points", Maybe.withDefault Encode.null (Maybe.map Encode.string model.sCA_ETH_Flow_Points) ) + , ( "ATT_NAME", Maybe.withDefault Encode.null (Maybe.map Encode.string model.aTT_NAME) ) + ] diff --git a/samples/openapi3/client/petstore/elm/src/Data/Cat.elm b/samples/openapi3/client/petstore/elm/src/Data/Cat.elm new file mode 100644 index 000000000000..f8328cfb6576 --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Data/Cat.elm @@ -0,0 +1,39 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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.Cat exposing (Cat, decoder, encoder) + +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +type alias Cat = + { color : Maybe String + , declawed : Maybe Bool + } + + +decoder : Decoder Cat +decoder = + Decode.succeed Cat + |> optional "color" (Decode.nullable Decode.string) (Just "red") + |> optional "declawed" (Decode.nullable Decode.bool) Nothing + + +encoder : String -> Cat -> Encode.Value +encoder tag model = + Encode.object + [ ( "color", Maybe.withDefault Encode.null (Maybe.map Encode.string model.color) ) + , ( "declawed", Maybe.withDefault Encode.null (Maybe.map Encode.bool model.declawed) ) + , ( "className", Encode.string tag ) + ] diff --git a/samples/openapi3/client/petstore/elm/src/Data/Category.elm b/samples/openapi3/client/petstore/elm/src/Data/Category.elm new file mode 100644 index 000000000000..c7285f39a597 --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Data/Category.elm @@ -0,0 +1,38 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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, encoder) + +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +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 + + +encoder : Category -> Encode.Value +encoder model = + Encode.object + [ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) ) + , ( "name", Maybe.withDefault Encode.null (Maybe.map Encode.string model.name) ) + ] diff --git a/samples/openapi3/client/petstore/elm/src/Data/ClassModel.elm b/samples/openapi3/client/petstore/elm/src/Data/ClassModel.elm new file mode 100644 index 000000000000..2cab25f3d974 --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Data/ClassModel.elm @@ -0,0 +1,37 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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.ClassModel exposing (ClassModel, decoder, encoder) + +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +{-| Model for testing model with "\_class" property +-} +type alias ClassModel = + { n_class : Maybe String + } + + +decoder : Decoder ClassModel +decoder = + Decode.succeed ClassModel + |> optional "_class" (Decode.nullable Decode.string) Nothing + + +encoder : ClassModel -> Encode.Value +encoder model = + Encode.object + [ ( "_class", Maybe.withDefault Encode.null (Maybe.map Encode.string model.n_class) ) + ] diff --git a/samples/openapi3/client/petstore/elm/src/Data/Client.elm b/samples/openapi3/client/petstore/elm/src/Data/Client.elm new file mode 100644 index 000000000000..909488bd9539 --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Data/Client.elm @@ -0,0 +1,35 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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.Client exposing (Client, decoder, encoder) + +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +type alias Client = + { client : Maybe String + } + + +decoder : Decoder Client +decoder = + Decode.succeed Client + |> optional "client" (Decode.nullable Decode.string) Nothing + + +encoder : Client -> Encode.Value +encoder model = + Encode.object + [ ( "client", Maybe.withDefault Encode.null (Maybe.map Encode.string model.client) ) + ] diff --git a/samples/openapi3/client/petstore/elm/src/Data/Dog.elm b/samples/openapi3/client/petstore/elm/src/Data/Dog.elm new file mode 100644 index 000000000000..61dc7654ec5a --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Data/Dog.elm @@ -0,0 +1,39 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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.Dog exposing (Dog, decoder, encoder) + +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +type alias Dog = + { color : Maybe String + , breed : Maybe String + } + + +decoder : Decoder Dog +decoder = + Decode.succeed Dog + |> optional "color" (Decode.nullable Decode.string) (Just "red") + |> optional "breed" (Decode.nullable Decode.string) Nothing + + +encoder : String -> Dog -> Encode.Value +encoder tag model = + Encode.object + [ ( "color", Maybe.withDefault Encode.null (Maybe.map Encode.string model.color) ) + , ( "breed", Maybe.withDefault Encode.null (Maybe.map Encode.string model.breed) ) + , ( "className", Encode.string tag ) + ] diff --git a/samples/openapi3/client/petstore/elm/src/Data/EnumArrays.elm b/samples/openapi3/client/petstore/elm/src/Data/EnumArrays.elm new file mode 100644 index 000000000000..ad6e8e186030 --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Data/EnumArrays.elm @@ -0,0 +1,102 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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.EnumArrays exposing (ArrayEnum(..), EnumArrays, JustSymbol(..), decoder, encoder) + +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +type alias EnumArrays = + { just_symbol : Maybe JustSymbol + , array_enum : Maybe (List ArrayEnum) + } + + +type JustSymbol + = GreaterThan + | Dollar + + +type ArrayEnum + = Fish + | Crab + + +decoder : Decoder EnumArrays +decoder = + Decode.succeed EnumArrays + |> optional "just_symbol" (Decode.nullable justSymbolDecoder) Nothing + |> optional "array_enum" (Decode.nullable (Decode.list arrayEnumDecoder)) Nothing + + +encoder : EnumArrays -> Encode.Value +encoder model = + Encode.object + [ ( "just_symbol", Maybe.withDefault Encode.null (Maybe.map justSymbolEncoder model.just_symbol) ) + , ( "array_enum", Maybe.withDefault Encode.null (Maybe.map (Encode.list arrayEnumEncoder) model.array_enum) ) + ] + + +justSymbolDecoder : Decoder JustSymbol +justSymbolDecoder = + Decode.string + |> Decode.andThen + (\str -> + case str of + ">=" -> + Decode.succeed GreaterThan + + "$" -> + Decode.succeed Dollar + + other -> + Decode.fail <| "Unknown type: " ++ other + ) + + +justSymbolEncoder : JustSymbol -> Encode.Value +justSymbolEncoder model = + case model of + GreaterThan -> + Encode.string ">=" + + Dollar -> + Encode.string "$" + + +arrayEnumDecoder : Decoder ArrayEnum +arrayEnumDecoder = + Decode.string + |> Decode.andThen + (\str -> + case str of + "fish" -> + Decode.succeed Fish + + "crab" -> + Decode.succeed Crab + + other -> + Decode.fail <| "Unknown type: " ++ other + ) + + +arrayEnumEncoder : ArrayEnum -> Encode.Value +arrayEnumEncoder model = + case model of + Fish -> + Encode.string "fish" + + Crab -> + Encode.string "crab" diff --git a/samples/openapi3/client/petstore/elm/src/Data/EnumClass.elm b/samples/openapi3/client/petstore/elm/src/Data/EnumClass.elm new file mode 100644 index 000000000000..32c786e06f0f --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Data/EnumClass.elm @@ -0,0 +1,56 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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.EnumClass exposing (EnumClass(..), decoder, encoder) + +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +type EnumClass + = N_abc + | N_efg + | Xyz + + +decoder : Decoder EnumClass +decoder = + Decode.string + |> Decode.andThen + (\str -> + case str of + "_abc" -> + Decode.succeed N_abc + + "-efg" -> + Decode.succeed N_efg + + "(xyz)" -> + Decode.succeed Xyz + + other -> + Decode.fail <| "Unknown type: " ++ other + ) + + +encoder : EnumClass -> Encode.Value +encoder model = + case model of + N_abc -> + Encode.string "_abc" + + N_efg -> + Encode.string "-efg" + + Xyz -> + Encode.string "(xyz)" diff --git a/samples/openapi3/client/petstore/elm/src/Data/EnumTest.elm b/samples/openapi3/client/petstore/elm/src/Data/EnumTest.elm new file mode 100644 index 000000000000..1df4a1e57d20 --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Data/EnumTest.elm @@ -0,0 +1,190 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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.EnumTest exposing (EnumInteger(..), EnumNumber(..), EnumString(..), EnumStringRequired(..), EnumTest, decoder, encoder) + +import Data.OuterEnum as OuterEnum exposing (OuterEnum) +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +type alias EnumTest = + { enum_string : Maybe EnumString + , enum_string_required : EnumStringRequired + , enum_integer : Maybe EnumInteger + , enum_number : Maybe EnumNumber + , outerEnum : Maybe OuterEnum + } + + +type EnumString + = UPPER + | Lower + | Empty + + +type EnumStringRequired + = UPPER + | Lower + | Empty + + +type EnumInteger + = N1 + | N_1 + + +type EnumNumber + = N1Dot1 + | N_1Dot2 + + +decoder : Decoder EnumTest +decoder = + Decode.succeed EnumTest + |> optional "enum_string" (Decode.nullable enumStringDecoder) Nothing + |> required "enum_string_required" enumStringRequiredDecoder + |> optional "enum_integer" (Decode.nullable enumIntegerDecoder) Nothing + |> optional "enum_number" (Decode.nullable enumNumberDecoder) Nothing + |> optional "outerEnum" (Decode.nullable OuterEnum.decoder) Nothing + + +encoder : EnumTest -> Encode.Value +encoder model = + Encode.object + [ ( "enum_string", Maybe.withDefault Encode.null (Maybe.map enumStringEncoder model.enum_string) ) + , ( "enum_string_required", enumStringRequiredEncoder model.enum_string_required ) + , ( "enum_integer", Maybe.withDefault Encode.null (Maybe.map enumIntegerEncoder model.enum_integer) ) + , ( "enum_number", Maybe.withDefault Encode.null (Maybe.map enumNumberEncoder model.enum_number) ) + , ( "outerEnum", Maybe.withDefault Encode.null (Maybe.map OuterEnum.encoder model.outerEnum) ) + ] + + +enumStringDecoder : Decoder EnumString +enumStringDecoder = + Decode.string + |> Decode.andThen + (\str -> + case str of + "UPPER" -> + Decode.succeed UPPER + + "lower" -> + Decode.succeed Lower + + "" -> + Decode.succeed Empty + + other -> + Decode.fail <| "Unknown type: " ++ other + ) + + +enumStringEncoder : EnumString -> Encode.Value +enumStringEncoder model = + case model of + UPPER -> + Encode.string "UPPER" + + Lower -> + Encode.string "lower" + + Empty -> + Encode.string "" + + +enumStringRequiredDecoder : Decoder EnumStringRequired +enumStringRequiredDecoder = + Decode.string + |> Decode.andThen + (\str -> + case str of + "UPPER" -> + Decode.succeed UPPER + + "lower" -> + Decode.succeed Lower + + "" -> + Decode.succeed Empty + + other -> + Decode.fail <| "Unknown type: " ++ other + ) + + +enumStringRequiredEncoder : EnumStringRequired -> Encode.Value +enumStringRequiredEncoder model = + case model of + UPPER -> + Encode.string "UPPER" + + Lower -> + Encode.string "lower" + + Empty -> + Encode.string "" + + +enumIntegerDecoder : Decoder EnumInteger +enumIntegerDecoder = + Decode.string + |> Decode.andThen + (\str -> + case str of + "1" -> + Decode.succeed N1 + + "-1" -> + Decode.succeed N_1 + + other -> + Decode.fail <| "Unknown type: " ++ other + ) + + +enumIntegerEncoder : EnumInteger -> Encode.Value +enumIntegerEncoder model = + case model of + N1 -> + Encode.string "1" + + N_1 -> + Encode.string "-1" + + +enumNumberDecoder : Decoder EnumNumber +enumNumberDecoder = + Decode.string + |> Decode.andThen + (\str -> + case str of + "1.1" -> + Decode.succeed N1Dot1 + + "-1.2" -> + Decode.succeed N_1Dot2 + + other -> + Decode.fail <| "Unknown type: " ++ other + ) + + +enumNumberEncoder : EnumNumber -> Encode.Value +enumNumberEncoder model = + case model of + N1Dot1 -> + Encode.string "1.1" + + N_1Dot2 -> + Encode.string "-1.2" diff --git a/samples/openapi3/client/petstore/elm/src/Data/File.elm b/samples/openapi3/client/petstore/elm/src/Data/File.elm new file mode 100644 index 000000000000..3472ca06ab47 --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Data/File.elm @@ -0,0 +1,37 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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.File exposing (File, decoder, encoder) + +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +{-| Must be named `File` for test. +-} +type alias File = + { sourceURI : Maybe String + } + + +decoder : Decoder File +decoder = + Decode.succeed File + |> optional "sourceURI" (Decode.nullable Decode.string) Nothing + + +encoder : File -> Encode.Value +encoder model = + Encode.object + [ ( "sourceURI", Maybe.withDefault Encode.null (Maybe.map Encode.string model.sourceURI) ) + ] diff --git a/samples/openapi3/client/petstore/elm/src/Data/FileSchemaTestClass.elm b/samples/openapi3/client/petstore/elm/src/Data/FileSchemaTestClass.elm new file mode 100644 index 000000000000..5052ce8abddc --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Data/FileSchemaTestClass.elm @@ -0,0 +1,39 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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.FileSchemaTestClass exposing (FileSchemaTestClass, decoder, encoder) + +import Data.File as File exposing (File) +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +type alias FileSchemaTestClass = + { file : Maybe File + , files : Maybe (List File) + } + + +decoder : Decoder FileSchemaTestClass +decoder = + Decode.succeed FileSchemaTestClass + |> optional "file" (Decode.nullable File.decoder) Nothing + |> optional "files" (Decode.nullable (Decode.list File.decoder)) Nothing + + +encoder : FileSchemaTestClass -> Encode.Value +encoder model = + Encode.object + [ ( "file", Maybe.withDefault Encode.null (Maybe.map File.encoder model.file) ) + , ( "files", Maybe.withDefault Encode.null (Maybe.map (Encode.list File.encoder) model.files) ) + ] diff --git a/samples/openapi3/client/petstore/elm/src/Data/FormatTest.elm b/samples/openapi3/client/petstore/elm/src/Data/FormatTest.elm new file mode 100644 index 000000000000..0b5826aab135 --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Data/FormatTest.elm @@ -0,0 +1,74 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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.FormatTest exposing (FormatTest, decoder, encoder) + +import Byte exposing (Byte) +import DateOnly exposing (DateOnly) +import DateTime exposing (DateTime) +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +type alias FormatTest = + { integer : Maybe Int + , int32 : Maybe Int + , int64 : Maybe Int + , number : Float + , float : Maybe Float + , double : Maybe Float + , string : Maybe String + , byte : Byte + , binary : Maybe String + , date : DateOnly + , dateTime : Maybe DateTime + , uuid : Maybe String + , password : String + } + + +decoder : Decoder FormatTest +decoder = + Decode.succeed FormatTest + |> optional "integer" (Decode.nullable Decode.int) Nothing + |> optional "int32" (Decode.nullable Decode.int) Nothing + |> optional "int64" (Decode.nullable Decode.int) Nothing + |> required "number" Decode.float + |> optional "float" (Decode.nullable Decode.float) Nothing + |> optional "double" (Decode.nullable Decode.float) Nothing + |> optional "string" (Decode.nullable Decode.string) Nothing + |> required "byte" Byte.decoder + |> optional "binary" (Decode.nullable Decode.string) Nothing + |> required "date" DateOnly.decoder + |> optional "dateTime" (Decode.nullable DateTime.decoder) Nothing + |> optional "uuid" (Decode.nullable Decode.string) Nothing + |> required "password" Decode.string + + +encoder : FormatTest -> Encode.Value +encoder model = + Encode.object + [ ( "integer", Maybe.withDefault Encode.null (Maybe.map Encode.int model.integer) ) + , ( "int32", Maybe.withDefault Encode.null (Maybe.map Encode.int model.int32) ) + , ( "int64", Maybe.withDefault Encode.null (Maybe.map Encode.int model.int64) ) + , ( "number", Encode.float model.number ) + , ( "float", Maybe.withDefault Encode.null (Maybe.map Encode.float model.float) ) + , ( "double", Maybe.withDefault Encode.null (Maybe.map Encode.float model.double) ) + , ( "string", Maybe.withDefault Encode.null (Maybe.map Encode.string model.string) ) + , ( "byte", Byte.encoder model.byte ) + , ( "binary", Maybe.withDefault Encode.null (Maybe.map Encode.string model.binary) ) + , ( "date", DateOnly.encoder model.date ) + , ( "dateTime", Maybe.withDefault Encode.null (Maybe.map DateTime.encoder model.dateTime) ) + , ( "uuid", Maybe.withDefault Encode.null (Maybe.map Encode.string model.uuid) ) + , ( "password", Encode.string model.password ) + ] diff --git a/samples/openapi3/client/petstore/elm/src/Data/HasOnlyReadOnly.elm b/samples/openapi3/client/petstore/elm/src/Data/HasOnlyReadOnly.elm new file mode 100644 index 000000000000..33d65aad6683 --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Data/HasOnlyReadOnly.elm @@ -0,0 +1,38 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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.HasOnlyReadOnly exposing (HasOnlyReadOnly, decoder, encoder) + +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +type alias HasOnlyReadOnly = + { bar : Maybe String + , foo : Maybe String + } + + +decoder : Decoder HasOnlyReadOnly +decoder = + Decode.succeed HasOnlyReadOnly + |> optional "bar" (Decode.nullable Decode.string) Nothing + |> optional "foo" (Decode.nullable Decode.string) Nothing + + +encoder : HasOnlyReadOnly -> Encode.Value +encoder model = + Encode.object + [ ( "bar", Maybe.withDefault Encode.null (Maybe.map Encode.string model.bar) ) + , ( "foo", Maybe.withDefault Encode.null (Maybe.map Encode.string model.foo) ) + ] diff --git a/samples/openapi3/client/petstore/elm/src/Data/List_.elm b/samples/openapi3/client/petstore/elm/src/Data/List_.elm new file mode 100644 index 000000000000..78b4fbfb3e8e --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Data/List_.elm @@ -0,0 +1,35 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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.List_ exposing (List_, decoder, encoder) + +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +type alias List_ = + { n123_list : Maybe String + } + + +decoder : Decoder List_ +decoder = + Decode.succeed List_ + |> optional "123-list" (Decode.nullable Decode.string) Nothing + + +encoder : List_ -> Encode.Value +encoder model = + Encode.object + [ ( "123-list", Maybe.withDefault Encode.null (Maybe.map Encode.string model.n123_list) ) + ] diff --git a/samples/openapi3/client/petstore/elm/src/Data/MapTest.elm b/samples/openapi3/client/petstore/elm/src/Data/MapTest.elm new file mode 100644 index 000000000000..c5a4790c93d1 --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Data/MapTest.elm @@ -0,0 +1,77 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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.MapTest exposing (MapTest, String(..), decoder, encoder) + +import Data.Map as Map exposing (Map) +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +type alias MapTest = + { map_map_of_string : Maybe (List String) + , map_of_enum_string : Maybe (List MapOfEnumString) + , direct_map : Maybe (List Bool) + , indirect_map : Maybe (List Bool) + } + + +type String + = UPPER + | Lower + + +decoder : Decoder MapTest +decoder = + Decode.succeed MapTest + |> optional "map_map_of_string" (Decode.nullable (Decode.list Decode.string)) Nothing + |> optional "map_of_enum_string" (Decode.nullable (Decode.list mapOfEnumStringDecoder)) Nothing + |> optional "direct_map" (Decode.nullable (Decode.list Decode.bool)) Nothing + |> optional "indirect_map" (Decode.nullable (Decode.list Decode.bool)) Nothing + + +encoder : MapTest -> Encode.Value +encoder model = + Encode.object + [ ( "map_map_of_string", Maybe.withDefault Encode.null (Maybe.map (Encode.list Encode.string) model.map_map_of_string) ) + , ( "map_of_enum_string", Maybe.withDefault Encode.null (Maybe.map (Encode.list mapOfEnumStringEncoder) model.map_of_enum_string) ) + , ( "direct_map", Maybe.withDefault Encode.null (Maybe.map (Encode.list Encode.bool) model.direct_map) ) + , ( "indirect_map", Maybe.withDefault Encode.null (Maybe.map (Encode.list Encode.bool) model.indirect_map) ) + ] + + +mapOfEnumStringDecoder : Decoder String +mapOfEnumStringDecoder = + Decode.string + |> Decode.andThen + (\str -> + case str of + "UPPER" -> + Decode.succeed UPPER + + "lower" -> + Decode.succeed Lower + + other -> + Decode.fail <| "Unknown type: " ++ other + ) + + +mapOfEnumStringEncoder : String -> Encode.Value +mapOfEnumStringEncoder model = + case model of + UPPER -> + Encode.string "UPPER" + + Lower -> + Encode.string "lower" diff --git a/samples/openapi3/client/petstore/elm/src/Data/MixedPropertiesAndAdditionalPropertiesClass.elm b/samples/openapi3/client/petstore/elm/src/Data/MixedPropertiesAndAdditionalPropertiesClass.elm new file mode 100644 index 000000000000..dbc02fcd3b00 --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Data/MixedPropertiesAndAdditionalPropertiesClass.elm @@ -0,0 +1,43 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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.MixedPropertiesAndAdditionalPropertiesClass exposing (MixedPropertiesAndAdditionalPropertiesClass, decoder, encoder) + +import Data.Animal as Animal exposing (Animal) +import DateTime exposing (DateTime) +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +type alias MixedPropertiesAndAdditionalPropertiesClass = + { uuid : Maybe String + , dateTime : Maybe DateTime + , map : Maybe (List Animal) + } + + +decoder : Decoder MixedPropertiesAndAdditionalPropertiesClass +decoder = + Decode.succeed MixedPropertiesAndAdditionalPropertiesClass + |> optional "uuid" (Decode.nullable Decode.string) Nothing + |> optional "dateTime" (Decode.nullable DateTime.decoder) Nothing + |> optional "map" (Decode.nullable (Decode.list Animal.decoder)) Nothing + + +encoder : MixedPropertiesAndAdditionalPropertiesClass -> Encode.Value +encoder model = + Encode.object + [ ( "uuid", Maybe.withDefault Encode.null (Maybe.map Encode.string model.uuid) ) + , ( "dateTime", Maybe.withDefault Encode.null (Maybe.map DateTime.encoder model.dateTime) ) + , ( "map", Maybe.withDefault Encode.null (Maybe.map (Encode.list Animal.encoder) model.map) ) + ] diff --git a/samples/openapi3/client/petstore/elm/src/Data/N200Response.elm b/samples/openapi3/client/petstore/elm/src/Data/N200Response.elm new file mode 100644 index 000000000000..1663a5e3395a --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Data/N200Response.elm @@ -0,0 +1,40 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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.N200Response exposing (N200Response, decoder, encoder) + +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +{-| Model for testing model name starting with number +-} +type alias N200Response = + { name : Maybe Int + , class : Maybe String + } + + +decoder : Decoder N200Response +decoder = + Decode.succeed N200Response + |> optional "name" (Decode.nullable Decode.int) Nothing + |> optional "class" (Decode.nullable Decode.string) Nothing + + +encoder : N200Response -> Encode.Value +encoder model = + Encode.object + [ ( "name", Maybe.withDefault Encode.null (Maybe.map Encode.int model.name) ) + , ( "class", Maybe.withDefault Encode.null (Maybe.map Encode.string model.class) ) + ] diff --git a/samples/openapi3/client/petstore/elm/src/Data/Name.elm b/samples/openapi3/client/petstore/elm/src/Data/Name.elm new file mode 100644 index 000000000000..91b90ceffef6 --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Data/Name.elm @@ -0,0 +1,46 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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.Name exposing (Name, decoder, encoder) + +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +{-| Model for testing model name same as property name +-} +type alias Name = + { name : Int + , snake_case : Maybe Int + , property : Maybe String + , n123Number : Maybe Int + } + + +decoder : Decoder Name +decoder = + Decode.succeed Name + |> required "name" Decode.int + |> optional "snake_case" (Decode.nullable Decode.int) Nothing + |> optional "property" (Decode.nullable Decode.string) Nothing + |> optional "123Number" (Decode.nullable Decode.int) Nothing + + +encoder : Name -> Encode.Value +encoder model = + Encode.object + [ ( "name", Encode.int model.name ) + , ( "snake_case", Maybe.withDefault Encode.null (Maybe.map Encode.int model.snake_case) ) + , ( "property", Maybe.withDefault Encode.null (Maybe.map Encode.string model.property) ) + , ( "123Number", Maybe.withDefault Encode.null (Maybe.map Encode.int model.n123Number) ) + ] diff --git a/samples/openapi3/client/petstore/elm/src/Data/NumberOnly.elm b/samples/openapi3/client/petstore/elm/src/Data/NumberOnly.elm new file mode 100644 index 000000000000..a3f2c2ad1524 --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Data/NumberOnly.elm @@ -0,0 +1,35 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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.NumberOnly exposing (NumberOnly, decoder, encoder) + +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +type alias NumberOnly = + { justNumber : Maybe Float + } + + +decoder : Decoder NumberOnly +decoder = + Decode.succeed NumberOnly + |> optional "JustNumber" (Decode.nullable Decode.float) Nothing + + +encoder : NumberOnly -> Encode.Value +encoder model = + Encode.object + [ ( "JustNumber", Maybe.withDefault Encode.null (Maybe.map Encode.float model.justNumber) ) + ] diff --git a/samples/openapi3/client/petstore/elm/src/Data/Order_.elm b/samples/openapi3/client/petstore/elm/src/Data/Order_.elm new file mode 100644 index 000000000000..9a0c31ce58f3 --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Data/Order_.elm @@ -0,0 +1,90 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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, encoder) + +import DateTime exposing (DateTime) +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +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) + + +encoder : Order_ -> Encode.Value +encoder model = + Encode.object + [ ( "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.encoder model.shipDate) ) + , ( "status", Maybe.withDefault Encode.null (Maybe.map statusEncoder model.status) ) + , ( "complete", Maybe.withDefault Encode.null (Maybe.map Encode.bool model.complete) ) + ] + + +statusDecoder : Decoder Status +statusDecoder = + Decode.string + |> Decode.andThen + (\str -> + case str of + "placed" -> + Decode.succeed Placed + + "approved" -> + Decode.succeed Approved + + "delivered" -> + Decode.succeed Delivered + + other -> + Decode.fail <| "Unknown type: " ++ other + ) + + +statusEncoder : Status -> Encode.Value +statusEncoder model = + case model of + Placed -> + Encode.string "placed" + + Approved -> + Encode.string "approved" + + Delivered -> + Encode.string "delivered" diff --git a/samples/openapi3/client/petstore/elm/src/Data/OuterComposite.elm b/samples/openapi3/client/petstore/elm/src/Data/OuterComposite.elm new file mode 100644 index 000000000000..e60097d3cc5d --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Data/OuterComposite.elm @@ -0,0 +1,41 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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.OuterComposite exposing (OuterComposite, decoder, encoder) + +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +type alias OuterComposite = + { my_number : Maybe Float + , my_string : Maybe String + , my_boolean : Maybe Bool + } + + +decoder : Decoder OuterComposite +decoder = + Decode.succeed OuterComposite + |> optional "my_number" (Decode.nullable Decode.float) Nothing + |> optional "my_string" (Decode.nullable Decode.string) Nothing + |> optional "my_boolean" (Decode.nullable Decode.bool) Nothing + + +encoder : OuterComposite -> Encode.Value +encoder model = + Encode.object + [ ( "my_number", Maybe.withDefault Encode.null (Maybe.map Encode.float model.my_number) ) + , ( "my_string", Maybe.withDefault Encode.null (Maybe.map Encode.string model.my_string) ) + , ( "my_boolean", Maybe.withDefault Encode.null (Maybe.map Encode.bool model.my_boolean) ) + ] diff --git a/samples/openapi3/client/petstore/elm/src/Data/OuterEnum.elm b/samples/openapi3/client/petstore/elm/src/Data/OuterEnum.elm new file mode 100644 index 000000000000..997419a37981 --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Data/OuterEnum.elm @@ -0,0 +1,56 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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.OuterEnum exposing (OuterEnum(..), decoder, encoder) + +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +type OuterEnum + = Placed + | Approved + | Delivered + + +decoder : Decoder OuterEnum +decoder = + 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 + ) + + +encoder : OuterEnum -> Encode.Value +encoder model = + case model of + Placed -> + Encode.string "placed" + + Approved -> + Encode.string "approved" + + Delivered -> + Encode.string "delivered" diff --git a/samples/openapi3/client/petstore/elm/src/Data/Pet.elm b/samples/openapi3/client/petstore/elm/src/Data/Pet.elm new file mode 100644 index 000000000000..11313514540e --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Data/Pet.elm @@ -0,0 +1,91 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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, encoder) + +import Data.Category as Category exposing (Category) +import Data.Tag as Tag exposing (Tag) +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +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 + + +encoder : Pet -> Encode.Value +encoder model = + Encode.object + [ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) ) + , ( "category", Maybe.withDefault Encode.null (Maybe.map Category.encoder model.category) ) + , ( "name", Encode.string model.name ) + , ( "photoUrls", Encode.list Encode.string model.photoUrls ) + , ( "tags", Maybe.withDefault Encode.null (Maybe.map (Encode.list Tag.encoder) model.tags) ) + , ( "status", Maybe.withDefault Encode.null (Maybe.map statusEncoder model.status) ) + ] + + +statusDecoder : Decoder Status +statusDecoder = + Decode.string + |> Decode.andThen + (\str -> + case str of + "available" -> + Decode.succeed Available + + "pending" -> + Decode.succeed Pending + + "sold" -> + Decode.succeed Sold + + other -> + Decode.fail <| "Unknown type: " ++ other + ) + + +statusEncoder : Status -> Encode.Value +statusEncoder model = + case model of + Available -> + Encode.string "available" + + Pending -> + Encode.string "pending" + + Sold -> + Encode.string "sold" diff --git a/samples/openapi3/client/petstore/elm/src/Data/ReadOnlyFirst.elm b/samples/openapi3/client/petstore/elm/src/Data/ReadOnlyFirst.elm new file mode 100644 index 000000000000..b96500edc90e --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Data/ReadOnlyFirst.elm @@ -0,0 +1,38 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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.ReadOnlyFirst exposing (ReadOnlyFirst, decoder, encoder) + +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +type alias ReadOnlyFirst = + { bar : Maybe String + , baz : Maybe String + } + + +decoder : Decoder ReadOnlyFirst +decoder = + Decode.succeed ReadOnlyFirst + |> optional "bar" (Decode.nullable Decode.string) Nothing + |> optional "baz" (Decode.nullable Decode.string) Nothing + + +encoder : ReadOnlyFirst -> Encode.Value +encoder model = + Encode.object + [ ( "bar", Maybe.withDefault Encode.null (Maybe.map Encode.string model.bar) ) + , ( "baz", Maybe.withDefault Encode.null (Maybe.map Encode.string model.baz) ) + ] diff --git a/samples/openapi3/client/petstore/elm/src/Data/Return.elm b/samples/openapi3/client/petstore/elm/src/Data/Return.elm new file mode 100644 index 000000000000..195b700f29ce --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Data/Return.elm @@ -0,0 +1,37 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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.Return exposing (Return, decoder, encoder) + +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +{-| Model for testing reserved words +-} +type alias Return = + { return : Maybe Int + } + + +decoder : Decoder Return +decoder = + Decode.succeed Return + |> optional "return" (Decode.nullable Decode.int) Nothing + + +encoder : Return -> Encode.Value +encoder model = + Encode.object + [ ( "return", Maybe.withDefault Encode.null (Maybe.map Encode.int model.return) ) + ] diff --git a/samples/openapi3/client/petstore/elm/src/Data/SpecialModelName.elm b/samples/openapi3/client/petstore/elm/src/Data/SpecialModelName.elm new file mode 100644 index 000000000000..ae03d56442a7 --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Data/SpecialModelName.elm @@ -0,0 +1,35 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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.SpecialModelName exposing (SpecialModelName, decoder, encoder) + +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +type alias SpecialModelName = + { nSpecial_property_name_ : Maybe Int + } + + +decoder : Decoder SpecialModelName +decoder = + Decode.succeed SpecialModelName + |> optional "$special[property.name]" (Decode.nullable Decode.int) Nothing + + +encoder : SpecialModelName -> Encode.Value +encoder model = + Encode.object + [ ( "$special[property.name]", Maybe.withDefault Encode.null (Maybe.map Encode.int model.nSpecial_property_name_) ) + ] diff --git a/samples/openapi3/client/petstore/elm/src/Data/StringBooleanMap.elm b/samples/openapi3/client/petstore/elm/src/Data/StringBooleanMap.elm new file mode 100644 index 000000000000..ea75f3b512ca --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Data/StringBooleanMap.elm @@ -0,0 +1,36 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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.StringBooleanMap exposing (StringBooleanMap, decoder, encoder) + +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +type alias StringBooleanMap = + { } + + +decoder : Decoder StringBooleanMap +decoder = + Decode.succeed StringBooleanMap + + + +encoder : StringBooleanMap -> Encode.Value +encoder model = + Encode.object + + ] + + diff --git a/samples/openapi3/client/petstore/elm/src/Data/Tag.elm b/samples/openapi3/client/petstore/elm/src/Data/Tag.elm new file mode 100644 index 000000000000..7d45e32ad236 --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Data/Tag.elm @@ -0,0 +1,38 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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, encoder) + +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +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 + + +encoder : Tag -> Encode.Value +encoder model = + Encode.object + [ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) ) + , ( "name", Maybe.withDefault Encode.null (Maybe.map Encode.string model.name) ) + ] diff --git a/samples/openapi3/client/petstore/elm/src/Data/User.elm b/samples/openapi3/client/petstore/elm/src/Data/User.elm new file mode 100644 index 000000000000..a68fe4e07ef4 --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Data/User.elm @@ -0,0 +1,56 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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, encoder) + +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +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 + + +encoder : User -> Encode.Value +encoder model = + Encode.object + [ ( "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) ) + ] diff --git a/samples/openapi3/client/petstore/elm/src/DateOnly.elm b/samples/openapi3/client/petstore/elm/src/DateOnly.elm new file mode 100644 index 000000000000..df5e681bc3fd --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/DateOnly.elm @@ -0,0 +1,34 @@ +module DateOnly exposing (DateOnly, decoder, encoder) + +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 + + +encoder : DateOnly -> Encode.Value +encoder model = + Iso8601.fromTime model + |> String.left 10 + |> Encode.string + + +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 diff --git a/samples/openapi3/client/petstore/elm/src/DateTime.elm b/samples/openapi3/client/petstore/elm/src/DateTime.elm new file mode 100644 index 000000000000..f7ad4ba814e9 --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/DateTime.elm @@ -0,0 +1,32 @@ +module DateTime exposing (DateTime, decoder, encoder) + +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 + + +encoder : DateTime -> Encode.Value +encoder model = + Encode.string <| Iso8601.fromTime model + + +decodeIsoString : String -> Decoder DateTime +decodeIsoString str = + case Iso8601.toTime str of + Result.Ok posix -> + Decode.succeed posix + + Result.Err _ -> + Decode.fail <| "Invalid date: " ++ str diff --git a/samples/openapi3/client/petstore/elm/src/Main.elm b/samples/openapi3/client/petstore/elm/src/Main.elm new file mode 100644 index 000000000000..7c9ddd056d38 --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Main.elm @@ -0,0 +1,61 @@ +module Main exposing (main) + +import Browser +import Html exposing (Html) + + +main : Program () Model Msg +main = + Browser.element + { init = init + , view = view + , update = update + , subscriptions = subscriptions + } + + + +-- MODEL + + +type alias Model = + { value : Int + } + + +init : () -> ( Model, Cmd Msg ) +init _ = + ( Model 0, Cmd.none ) + + + +-- UPDATE + + +type Msg + = NoOp + + +update : Msg -> Model -> ( Model, Cmd Msg ) +update msg model = + case msg of + NoOp -> + ( model, Cmd.none ) + + + +-- SUBSCRIPTIONS + + +subscriptions : Model -> Sub Msg +subscriptions _ = + Sub.none + + + +-- VIEW + + +view : Model -> Html Msg +view _ = + Html.text "main" diff --git a/samples/openapi3/client/petstore/elm/src/Request/AnotherFake.elm b/samples/openapi3/client/petstore/elm/src/Request/AnotherFake.elm new file mode 100644 index 000000000000..7ea89a7ab4d9 --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Request/AnotherFake.elm @@ -0,0 +1,39 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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.AnotherFake exposing (n123_test__special_tags) + +import Data.Client as Client exposing (Client) +import Dict +import Http +import Json.Decode as Decode +import Json.Encode as Encode + + +basePath : String +basePath = + "http://petstore.swagger.io:80/v2" + + +{-| To test special tags and operation ID starting with number +-} +n123_test__special_tags : Client -> Http.Request Client +n123_test__special_tags model = + { method = "PATCH" + , url = basePath ++ "/another-fake/dummy" + , headers = [] + , body = Http.jsonBody <| Client.encoder model + , expect = Http.expectJson Client.decoder + , timeout = Just 30000 + , withCredentials = False + } + |> Http.request diff --git a/samples/openapi3/client/petstore/elm/src/Request/Fake.elm b/samples/openapi3/client/petstore/elm/src/Request/Fake.elm new file mode 100644 index 000000000000..93f0cb4120bc --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Request/Fake.elm @@ -0,0 +1,186 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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.Fake exposing (fakeOuterBooleanSerialize, fakeOuterCompositeSerialize, fakeOuterNumberSerialize, fakeOuterStringSerialize, testBodyWithFileSchema, testBodyWithQueryParams, testClientModel, testEndpointParameters, testEnumParameters, testInlineAdditionalProperties, testJsonFormData) + +import Data.Client as Client exposing (Client) +import Data.FileSchemaTestClass as FileSchemaTestClass exposing (FileSchemaTestClass) +import Data.OuterComposite as OuterComposite exposing (OuterComposite) +import Data.User as User exposing (User) +import Dict +import Http +import Json.Decode as Decode +import Json.Encode as Encode + + +basePath : String +basePath = + "http://petstore.swagger.io:80/v2" + + +{-| Test serialization of outer boolean types +-} +fakeOuterBooleanSerialize : Bool -> Http.Request Bool +fakeOuterBooleanSerialize model = + { method = "POST" + , url = basePath ++ "/fake/outer/boolean" + , headers = [] + , body = Http.jsonBody <| Encode.bool model + , expect = Http.expectJson Decode.bool + , timeout = Just 30000 + , withCredentials = False + } + |> Http.request + + +{-| Test serialization of object with outer number type +-} +fakeOuterCompositeSerialize : OuterComposite -> Http.Request OuterComposite +fakeOuterCompositeSerialize model = + { method = "POST" + , url = basePath ++ "/fake/outer/composite" + , headers = [] + , body = Http.jsonBody <| OuterComposite.encoder model + , expect = Http.expectJson OuterComposite.decoder + , timeout = Just 30000 + , withCredentials = False + } + |> Http.request + + +{-| Test serialization of outer number types +-} +fakeOuterNumberSerialize : Float -> Http.Request Float +fakeOuterNumberSerialize model = + { method = "POST" + , url = basePath ++ "/fake/outer/number" + , headers = [] + , body = Http.jsonBody <| Encode.float model + , expect = Http.expectJson Decode.float + , timeout = Just 30000 + , withCredentials = False + } + |> Http.request + + +{-| Test serialization of outer string types +-} +fakeOuterStringSerialize : String -> Http.Request String +fakeOuterStringSerialize model = + { method = "POST" + , url = basePath ++ "/fake/outer/string" + , headers = [] + , body = Http.jsonBody <| Encode.string model + , expect = Http.expectJson Decode.string + , timeout = Just 30000 + , withCredentials = False + } + |> Http.request + + +{-| For this test, the body for this request much reference a schema named `File`. +-} +testBodyWithFileSchema : FileSchemaTestClass -> Http.Request () +testBodyWithFileSchema model = + { method = "PUT" + , url = basePath ++ "/fake/body-with-file-schema" + , headers = [] + , body = Http.jsonBody <| FileSchemaTestClass.encoder model + , expect = Http.expectStringResponse (\_ -> Ok ()) + , timeout = Just 30000 + , withCredentials = False + } + |> Http.request + + +testBodyWithQueryParams : User -> Http.Request () +testBodyWithQueryParams model = + { method = "PUT" + , url = basePath ++ "/fake/body-with-query-params" + , headers = [] + , body = Http.jsonBody <| User.encoder model + , expect = Http.expectStringResponse (\_ -> Ok ()) + , timeout = Just 30000 + , withCredentials = False + } + |> Http.request + + +{-| To test "client" model +-} +testClientModel : Client -> Http.Request Client +testClientModel model = + { method = "PATCH" + , url = basePath ++ "/fake" + , headers = [] + , body = Http.jsonBody <| Client.encoder model + , expect = Http.expectJson Client.decoder + , timeout = Just 30000 + , withCredentials = False + } + |> Http.request + + +{-| Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 +-} +testEndpointParameters : Http.Request () +testEndpointParameters = + { method = "POST" + , url = basePath ++ "/fake" + , headers = [] + , body = Http.emptyBody + , expect = Http.expectStringResponse (\_ -> Ok ()) + , timeout = Just 30000 + , withCredentials = False + } + |> Http.request + + +{-| To test enum parameters +-} +testEnumParameters : Http.Request () +testEnumParameters = + { method = "GET" + , url = basePath ++ "/fake" + , headers = [] + , body = Http.emptyBody + , expect = Http.expectStringResponse (\_ -> Ok ()) + , timeout = Just 30000 + , withCredentials = False + } + |> Http.request + + +testInlineAdditionalProperties : String -> Http.Request () +testInlineAdditionalProperties model = + { method = "POST" + , url = basePath ++ "/fake/inline-additionalProperties" + , headers = [] + , body = Http.jsonBody <| Encode.string model + , expect = Http.expectStringResponse (\_ -> Ok ()) + , timeout = Just 30000 + , withCredentials = False + } + |> Http.request + + +testJsonFormData : Http.Request () +testJsonFormData = + { method = "GET" + , url = basePath ++ "/fake/jsonFormData" + , headers = [] + , body = Http.emptyBody + , expect = Http.expectStringResponse (\_ -> Ok ()) + , timeout = Just 30000 + , withCredentials = False + } + |> Http.request diff --git a/samples/openapi3/client/petstore/elm/src/Request/FakeClassnameTags123.elm b/samples/openapi3/client/petstore/elm/src/Request/FakeClassnameTags123.elm new file mode 100644 index 000000000000..a63e07742505 --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Request/FakeClassnameTags123.elm @@ -0,0 +1,39 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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.FakeClassnameTags123 exposing (testClassname) + +import Data.Client as Client exposing (Client) +import Dict +import Http +import Json.Decode as Decode +import Json.Encode as Encode + + +basePath : String +basePath = + "http://petstore.swagger.io:80/v2" + + +{-| To test class name in snake case +-} +testClassname : Client -> Http.Request Client +testClassname model = + { method = "PATCH" + , url = basePath ++ "/fake_classname_test" + , headers = [] + , body = Http.jsonBody <| Client.encoder model + , expect = Http.expectJson Client.decoder + , timeout = Just 30000 + , withCredentials = False + } + |> Http.request diff --git a/samples/openapi3/client/petstore/elm/src/Request/Pet.elm b/samples/openapi3/client/petstore/elm/src/Request/Pet.elm new file mode 100644 index 000000000000..d61cdb1e5961 --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Request/Pet.elm @@ -0,0 +1,148 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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, uploadFileWithRequiredFile) + +import Data.ApiResponse as ApiResponse exposing (ApiResponse) +import Data.Pet as Pet exposing (Pet) +import Dict +import Http +import Json.Decode as Decode +import Json.Encode as Encode + + +basePath : String +basePath = + "http://petstore.swagger.io:80/v2" + + +addPet : Pet -> Http.Request () +addPet model = + { method = "POST" + , url = basePath ++ "/pet" + , headers = [] + , body = Http.jsonBody <| Pet.encoder model + , expect = Http.expectStringResponse (\_ -> Ok ()) + , timeout = Just 30000 + , withCredentials = False + } + |> Http.request + + +deletePet : Int -> Http.Request () +deletePet petId = + { method = "DELETE" + , url = basePath ++ "/pet/" ++ String.fromInt 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/" ++ String.fromInt 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.encoder model + , expect = Http.expectStringResponse (\_ -> Ok ()) + , timeout = Just 30000 + , withCredentials = False + } + |> Http.request + + +updatePetWithForm : Int -> Http.Request () +updatePetWithForm petId = + { method = "POST" + , url = basePath ++ "/pet/" ++ String.fromInt 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/" ++ String.fromInt petId ++ "/uploadImage" + , headers = [] + , body = Http.emptyBody + , expect = Http.expectJson ApiResponse.decoder + , timeout = Just 30000 + , withCredentials = False + } + |> Http.request + + +uploadFileWithRequiredFile : Int -> Http.Request ApiResponse +uploadFileWithRequiredFile petId = + { method = "POST" + , url = basePath ++ "/fake/" ++ String.fromInt petId ++ "/uploadImageWithRequiredFile" + , headers = [] + , body = Http.emptyBody + , expect = Http.expectJson ApiResponse.decoder + , timeout = Just 30000 + , withCredentials = False + } + |> Http.request diff --git a/samples/openapi3/client/petstore/elm/src/Request/Store.elm b/samples/openapi3/client/petstore/elm/src/Request/Store.elm new file mode 100644 index 000000000000..b855ed360a9f --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Request/Store.elm @@ -0,0 +1,82 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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 Json.Encode as Encode + + +basePath : String +basePath = + "http://petstore.swagger.io:80/v2" + + +{-| For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors +-} +deleteOrder : String -> Http.Request () +deleteOrder orderUnderscoreid = + { method = "DELETE" + , url = basePath ++ "/store/order/{order_id}" + , 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 orderUnderscoreid = + { method = "GET" + , url = basePath ++ "/store/order/{order_id}" + , 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_.encoder model + , expect = Http.expectJson Order_.decoder + , timeout = Just 30000 + , withCredentials = False + } + |> Http.request diff --git a/samples/openapi3/client/petstore/elm/src/Request/User.elm b/samples/openapi3/client/petstore/elm/src/Request/User.elm new file mode 100644 index 000000000000..aa508a08f9ae --- /dev/null +++ b/samples/openapi3/client/petstore/elm/src/Request/User.elm @@ -0,0 +1,134 @@ +{- + OpenAPI Petstore + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + + OpenAPI spec version: 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 Json.Encode as Encode + + +basePath : String +basePath = + "http://petstore.swagger.io:80/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.encoder 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.encoder 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.encoder 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.encoder model + , expect = Http.expectStringResponse (\_ -> Ok ()) + , timeout = Just 30000 + , withCredentials = False + } + |> Http.request From c2c25f7b6e076056fdb00683631fe75fd4c48f89 Mon Sep 17 00:00:00 2001 From: Erik Timmers Date: Wed, 17 Oct 2018 21:30:13 +0200 Subject: [PATCH 2/2] WIP - custom type variant prefix --- bin/openapi3/elm-petstore.sh | 2 +- .../codegen/languages/ElmClientCodegen.java | 25 ++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/bin/openapi3/elm-petstore.sh b/bin/openapi3/elm-petstore.sh index 1c033e7362b4..00876917cec6 100755 --- a/bin/openapi3/elm-petstore.sh +++ b/bin/openapi3/elm-petstore.sh @@ -27,6 +27,6 @@ fi # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate -i modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml -g elm -t modules/openapi-generator/src/main/resources/elm -o samples/openapi3/client/petstore/elm $@" +ags="generate -i modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml -g elm -t modules/openapi-generator/src/main/resources/elm -o samples/openapi3/client/petstore/elm --additional-properties prefixCustomTypeVariants=true $@" java $JAVA_OPTS -jar $executable $ags diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElmClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElmClientCodegen.java index 67a40ef4c0ac..7d9ffcdae33e 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElmClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElmClientCodegen.java @@ -62,6 +62,7 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig { private ElmVersion elmVersion = ElmVersion.ELM_019; private static final String ELM_VERSION = "elmVersion"; + private static final String PREFIX_CUSTOM_TYPE_VARIANTS = "prefixCustomTypeVariants"; private static final String ENCODER = "elmEncoder"; private static final String DECODER = "elmDecoder"; private static final String DISCRIMINATOR_NAME = "discriminatorName"; @@ -69,6 +70,7 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig { protected String packageName = "openapi"; protected String packageVersion = "1.0.0"; + protected Boolean prefixCustomTypeVariants = false; public CodegenType getTag() { return CodegenType.CLIENT; @@ -186,13 +188,14 @@ public ElmClientCodegen() { supportedVersions.put("0.19", "Elm 0.19"); elmVersion.setEnum(supportedVersions); cliOptions.add(elmVersion); + final CliOption prefixCustomTypeVariants = CliOption.newBoolean(PREFIX_CUSTOM_TYPE_VARIANTS, "Prefix custom type variants"); + cliOptions.add(prefixCustomTypeVariants); } @Override public void processOpts() { super.processOpts(); - if (additionalProperties.containsKey(ELM_VERSION)) { final String version = (String) additionalProperties.get(ELM_VERSION); if ("0.18".equals(version)) { @@ -202,6 +205,10 @@ public void processOpts() { } } + if (additionalProperties.containsKey(PREFIX_CUSTOM_TYPE_VARIANTS)) { + prefixCustomTypeVariants = "true".equals(additionalProperties.get(PREFIX_CUSTOM_TYPE_VARIANTS)); + } + 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"); @@ -388,6 +395,9 @@ public int compare(CodegenModel cm1, CodegenModel cm2) { if (cm.isEnum) { addEncoderAndDecoder(cm.vendorExtensions, cm.classname, DataTypeExposure.EXPOSED); cm.vendorExtensions.put(UNION_TYPE, cm.classname); + if (prefixCustomTypeVariants) { + addCustomTypeVariantsPrefix(cm.classname, cm.allowableValues); + } } else if (cm.isAlias) { addEncoderAndDecoder(cm.vendorExtensions, cm.dataType, DataTypeExposure.EXPOSED); } @@ -590,6 +600,9 @@ public CodegenProperty fromProperty(String name, Schema p) { if (property.isEnum) { addEncoderAndDecoder(property.vendorExtensions, property.baseName, DataTypeExposure.INTERNAL); property.vendorExtensions.put(UNION_TYPE, property.datatypeWithEnum); + if (prefixCustomTypeVariants) { + addCustomTypeVariantsPrefix(property.datatypeWithEnum, property.allowableValues); + } } else { final boolean isPrimitiveType = property.isMapContainer ? isPrimitiveDataType(property.dataType) : property.isPrimitiveType; addEncoderAndDecoder(property.vendorExtensions, property.dataType, isPrimitiveType ? DataTypeExposure.PRIMITIVE : DataTypeExposure.EXTERNAL); @@ -614,6 +627,16 @@ public void postProcessParameter(CodegenParameter parameter) { addEncoderAndDecoder(parameter.vendorExtensions, parameter.dataType, isPrimitiveType ? DataTypeExposure.PRIMITIVE : DataTypeExposure.EXTERNAL); } + private void addCustomTypeVariantsPrefix(final String prefix, final Map allowableValues) { + List> enumVars = (ArrayList>) allowableValues.get("enumVars"); + if (enumVars == null) { + return; + } + for (Map enumVar : enumVars) { + enumVar.put("name", prefix + enumVar.get("name")); + } + } + private boolean isPrimitiveDataType(String dataType) { return languageSpecificPrimitives.contains(dataType); }