diff --git a/bin/openapi3/elm-all.sh b/bin/openapi3/elm-all.sh new file mode 100755 index 00000000000..199d1182de2 --- /dev/null +++ b/bin/openapi3/elm-all.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +./bin/openapi3/elm-petstore.sh +./bin/openapi3/elm-composition.sh + diff --git a/bin/openapi3/elm-composition.sh b/bin/openapi3/elm-composition.sh new file mode 100755 index 00000000000..97ad1649502 --- /dev/null +++ b/bin/openapi3/elm-composition.sh @@ -0,0 +1,35 @@ +#!/bin/sh + +SCRIPT="$0" +echo "# START SCRIPT: $SCRIPT" + +while [ -h "$SCRIPT" ] ; do + ls=`ls -ld "$SCRIPT"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + SCRIPT="$link" + else + SCRIPT=`dirname "$SCRIPT"`/"$link" + fi +done + +if [ ! -d "${APP_DIR}" ]; then + APP_DIR=`dirname "$SCRIPT"`/.. + APP_DIR=`cd "${APP_DIR}"; pwd` +fi + +executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar" + +if [ ! -f "$executable" ] +then + mvn -B clean package +fi + +# auto format elm code using elm-format +export ELM_POST_PROCESS_FILE="/usr/bin/env elm-format --elm-version=0.19 --yes" + +# if you've executed sbt assembly previously it will use that instead. +export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" +ags="generate -i modules/openapi-generator/src/test/resources/3_0/composition.yaml -g elm -t modules/openapi-generator/src/main/resources/elm -o samples/openapi3/client/composition/elm --enable-post-process-file $@" + +java $JAVA_OPTS -jar $executable $ags diff --git a/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 3f08e337fa4..d192dd80010 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 @@ -373,7 +373,13 @@ public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig { elmImports.add(elmImport); } } - if (cm.discriminator != null) { + if (cm.oneOf != null) { + for (String variant : cm.oneOf) { + final ElmImport elmImport = createImport(variant); + elmImports.add(elmImport); + } + } + if (cm.discriminator != null && cm.children != null) { for (CodegenModel child : cm.children) { // add child imports final ElmImport elmImport = createImport(child.classname); diff --git a/modules/openapi-generator/src/main/resources/elm/model.mustache b/modules/openapi-generator/src/main/resources/elm/model.mustache index 9ac8a6c445b..cba3f3ce242 100644 --- a/modules/openapi-generator/src/main/resources/elm/model.mustache +++ b/modules/openapi-generator/src/main/resources/elm/model.mustache @@ -1,6 +1,6 @@ {{>licenseInfo}} -module Data.{{classname}} exposing ({{#models}}{{#model}}{{classname}}{{#hasChildren}}(..){{/hasChildren}}{{#isEnum}}(..){{/isEnum}}{{^isEnum}}{{#vars}}{{#isEnum}}, {{vendorExtensions.elmCustomType}}(..){{/isEnum}}{{/vars}}{{/isEnum}}, decoder, encode, toString{{/model}}{{/models}}) +module Data.{{classname}} exposing ({{#models}}{{#model}}{{classname}}{{#hasChildren}}(..){{/hasChildren}}{{#isEnum}}(..){{/isEnum}}{{^isEnum}}{{#vars}}{{#isEnum}}, {{vendorExtensions.elmCustomType}}(..){{/isEnum}}{{/vars}}{{/isEnum}}, decoder, encode{{^isEnum}}{{^discriminator}}{{^oneOf}}, encodeWithTag{{/oneOf}}{{/discriminator}}{{/isEnum}}, toString{{/model}}{{/models}}) {{>imports}}import Dict exposing (Dict) import Json.Decode as Decode exposing (Decoder) @@ -14,7 +14,7 @@ import Json.Encode as Encode {-| {{{description}}} -} {{/description}} -{{#isEnum}}{{>modelTypeCustom}}{{/isEnum}}{{^isEnum}}{{#discriminator}}{{>modelTypeDiscriminator}}{{/discriminator}}{{^discriminator}}{{#isAlias}}{{>modelTypePrimitive}}{{/isAlias}}{{^isAlias}}{{#isArrayModel}}{{>modelTypeArray}}{{/isArrayModel}}{{^isArrayModel}}{{>modelTypeRecord}}{{/isArrayModel}}{{/isAlias}}{{/discriminator}}{{/isEnum}} +{{#isEnum}}{{>modelTypeCustom}}{{/isEnum}}{{^isEnum}}{{#discriminator}}{{>modelTypeDiscriminator}}{{/discriminator}}{{^discriminator}}{{#oneOf}}{{#-first}}{{>modelTypeDiscriminator}}{{/-first}}{{/oneOf}}{{^oneOf}}{{#isAlias}}{{>modelTypePrimitive}}{{/isAlias}}{{^isAlias}}{{#isArrayModel}}{{>modelTypeArray}}{{/isArrayModel}}{{^isArrayModel}}{{>modelTypeRecord}}{{/isArrayModel}}{{/isAlias}}{{/oneOf}}{{/discriminator}}{{/isEnum}} {{/model}} {{/models}} diff --git a/modules/openapi-generator/src/main/resources/elm/modelTypeDiscriminator.mustache b/modules/openapi-generator/src/main/resources/elm/modelTypeDiscriminator.mustache index 0284323476c..1b9182b7424 100644 --- a/modules/openapi-generator/src/main/resources/elm/modelTypeDiscriminator.mustache +++ b/modules/openapi-generator/src/main/resources/elm/modelTypeDiscriminator.mustache @@ -1,11 +1,22 @@ type {{classname}} -{{#mappedModels}} +{{^discriminator}}{{#oneOf}} + {{#-first}}={{/-first}}{{^-first}}|{{/-first}} {{{.}}}Type {{{.}}} +{{/oneOf}}{{/discriminator}} +{{#discriminator}}{{#mappedModels}} {{#-first}}={{/-first}}{{^-first}}|{{/-first}} {{modelName}}Type {{modelName}} -{{/mappedModels}} +{{/mappedModels}}{{/discriminator}} decoder : Decoder {{classname}} decoder = +{{^discriminator}} + Decode.oneOf +{{#oneOf}} + {{#-first}}[{{/-first}}{{^-first}},{{/-first}} Decode.map {{{.}}}Type {{{.}}}.decoder +{{/oneOf}} + ] +{{/discriminator}} +{{#discriminator}} Decode.field "{{{discriminator.propertyName}}}" Decode.string |> Decode.andThen {{classVarName}}Decoder @@ -19,17 +30,25 @@ decoder = {{/mappedModels}} _ -> - Decode.fail <| "Trying to decode {{classname}}, but {{{discriminatorName}}} " ++ tag ++ " is not supported." + Decode.fail <| "Trying to decode {{classname}}, but {{{discriminatorName}}} '" ++ tag ++ "' is not supported." +{{/discriminator}} encode : {{classname}} -> Encode.Value encode model = case model of +{{^discriminator}}{{#oneOf}} + {{{.}}}Type subModel -> + {{{.}}}.encode subModel + +{{/oneOf}}{{/discriminator}} +{{#discriminator}} {{#mappedModels}} {{modelName}}Type subModel -> - {{modelName}}.encode "{{mappingName}}" subModel + {{modelName}}.encodeWithTag ("{{discriminatorName}}", "{{mappingName}}") subModel {{/mappedModels}} +{{/discriminator}} toString : {{classname}} -> String diff --git a/modules/openapi-generator/src/main/resources/elm/modelTypeRecord.mustache b/modules/openapi-generator/src/main/resources/elm/modelTypeRecord.mustache index bbe185a36ac..e267c46321c 100644 --- a/modules/openapi-generator/src/main/resources/elm/modelTypeRecord.mustache +++ b/modules/openapi-generator/src/main/resources/elm/modelTypeRecord.mustache @@ -18,7 +18,7 @@ type alias {{classname}} = toString : {{classname}} -> String toString = - Encode.encode 0 << encode{{#vendorExtensions.discriminatorName}} ""{{/vendorExtensions.discriminatorName}} + Encode.encode 0 << encode {{#vars}} diff --git a/modules/openapi-generator/src/main/resources/elm/recordEncoder.mustache b/modules/openapi-generator/src/main/resources/elm/recordEncoder.mustache index a30933a59d7..1f626719fa9 100644 --- a/modules/openapi-generator/src/main/resources/elm/recordEncoder.mustache +++ b/modules/openapi-generator/src/main/resources/elm/recordEncoder.mustache @@ -1,7 +1,16 @@ -encode : {{#vendorExtensions.discriminatorName}}String -> {{/vendorExtensions.discriminatorName}}{{classname}} -> Encode.Value -encode {{#vendorExtensions.discriminatorName}}tag {{/vendorExtensions.discriminatorName}}model = - Encode.object +encode : {{classname}} -> Encode.Value +encode = + Encode.object << encodePairs + + +encodeWithTag : ( String, String ) -> {{classname}} -> Encode.Value +encodeWithTag (tagField, tag) model = + Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ] + + +encodePairs : {{classname}} -> List (String, Encode.Value) +encodePairs model = {{#allVars}} - {{#-first}}[{{/-first}}{{^-first}},{{/-first}} {{>recordFieldEncoder}} -{{/allVars}}{{#vendorExtensions.discriminatorName}} , ( "{{{vendorExtensions.discriminatorName}}}", Encode.string tag ){{/vendorExtensions.discriminatorName}} - ] + {{#-first}}[{{/-first}}{{^-first}},{{/-first}} {{>recordFieldEncoder}} +{{/allVars}} + ] diff --git a/modules/openapi-generator/src/test/resources/3_0/composition.yaml b/modules/openapi-generator/src/test/resources/3_0/composition.yaml new file mode 100644 index 00000000000..0b54cb26d40 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/composition.yaml @@ -0,0 +1,121 @@ +openapi: 3.0.0 +info: + title: Composition and Inheritence (Polymorphism) + version: 1.0.0 +paths: + /oneOf: + post: + summary: One of + responses: + 200: + description: Response + content: + application/json: + schema: + $ref: '#/components/schemas/OneOf' + /oneOfWithDiscriminator: + post: + summary: One of with discriminator + responses: + 200: + description: Response + content: + application/json: + schema: + $ref: '#/components/schemas/OneOfWithDiscriminator' + /oneOfWithAllOfDiscriminator: + post: + summary: One of with discriminator from all of + responses: + 200: + description: Response + content: + application/json: + schema: + $ref: '#/components/schemas/OneOfWithAllOfDiscriminator' + /allOf: + post: + summary: All of + responses: + 200: + description: Response + content: + application/json: + schema: + $ref: '#/components/schemas/AllOf' + /allOfWithDiscriminator: + post: + summary: All of with discriminator + responses: + 200: + description: Response + content: + application/json: + schema: + $ref: '#/components/schemas/BaseObject' +components: + schemas: + OneOf: + oneOf: + - $ref: "#/components/schemas/ObjectA" + - $ref: "#/components/schemas/ObjectB" + OneOfWithDiscriminator: + oneOf: + - $ref: "#/components/schemas/ObjectA" + - $ref: "#/components/schemas/ObjectB" + discriminator: + propertyName: objectType + mapping: + a: "#/components/schemas/ObjectA" + b: "#/components/schemas/ObjectB" + OneOfWithAllOfDiscriminator: + oneOf: + - $ref: "#/components/schemas/SubObjectA" + - $ref: "#/components/schemas/SubObjectB" + AllOf: + allOf: + - $ref: "#/components/schemas/ObjectA" + - $ref: "#/components/schemas/ObjectB" + BaseObject: + required: + - objectType + - value + properties: + objectType: + type: string + value: + type: boolean + discriminator: + propertyName: objectType + ObjectA: + type: object + required: + - objectType + properties: + objectType: + type: string + valueA: + type: string + ObjectB: + type: object + required: + - objectType + properties: + objectType: + type: string + valueB: + type: number + SubObjectA: + allOf: + - $ref: "#/components/schemas/BaseObject" + - type: object + properties: + valueA: + type: string + SubObjectB: + allOf: + - $ref: "#/components/schemas/BaseObject" + - type: object + properties: + valueB: + type: number diff --git a/samples/client/petstore/elm-0.18/src/Data/ApiResponse.elm b/samples/client/petstore/elm-0.18/src/Data/ApiResponse.elm index 1e5d44b7941..4513a239058 100644 --- a/samples/client/petstore/elm-0.18/src/Data/ApiResponse.elm +++ b/samples/client/petstore/elm-0.18/src/Data/ApiResponse.elm @@ -10,7 +10,7 @@ -} -module Data.ApiResponse exposing (ApiResponse, decoder, encode, toString) +module Data.ApiResponse exposing (ApiResponse, decoder, encode, encodeWithTag, toString) import Dict exposing (Dict) import Json.Decode as Decode exposing (Decoder) @@ -36,12 +36,21 @@ decoder = encode : ApiResponse -> Encode.Value -encode 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) ) - ] +encode = + Encode.object << encodePairs + + +encodeWithTag : ( String, String ) -> ApiResponse -> Encode.Value +encodeWithTag ( tagField, tag ) model = + Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ] + + +encodePairs : ApiResponse -> List ( String, Encode.Value ) +encodePairs model = + [ ( "code", Maybe.withDefault Encode.null (Maybe.map Encode.int model.code) ) + , ( "type", Maybe.withDefault Encode.null (Maybe.map Encode.string model.type_) ) + , ( "message", Maybe.withDefault Encode.null (Maybe.map Encode.string model.message) ) + ] toString : ApiResponse -> String diff --git a/samples/client/petstore/elm-0.18/src/Data/Category.elm b/samples/client/petstore/elm-0.18/src/Data/Category.elm index f8e5a7fb31d..bd3b810819b 100644 --- a/samples/client/petstore/elm-0.18/src/Data/Category.elm +++ b/samples/client/petstore/elm-0.18/src/Data/Category.elm @@ -10,7 +10,7 @@ -} -module Data.Category exposing (Category, decoder, encode, toString) +module Data.Category exposing (Category, decoder, encode, encodeWithTag, toString) import Dict exposing (Dict) import Json.Decode as Decode exposing (Decoder) @@ -34,11 +34,20 @@ decoder = encode : Category -> Encode.Value -encode 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) ) - ] +encode = + Encode.object << encodePairs + + +encodeWithTag : ( String, String ) -> Category -> Encode.Value +encodeWithTag ( tagField, tag ) model = + Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ] + + +encodePairs : Category -> List ( String, Encode.Value ) +encodePairs model = + [ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) ) + , ( "name", Maybe.withDefault Encode.null (Maybe.map Encode.string model.name) ) + ] toString : Category -> String diff --git a/samples/client/petstore/elm-0.18/src/Data/Order_.elm b/samples/client/petstore/elm-0.18/src/Data/Order_.elm index 0d8e8781098..bf2203ec13e 100644 --- a/samples/client/petstore/elm-0.18/src/Data/Order_.elm +++ b/samples/client/petstore/elm-0.18/src/Data/Order_.elm @@ -10,7 +10,7 @@ -} -module Data.Order_ exposing (Order_, Status(..), decoder, encode, toString) +module Data.Order_ exposing (Order_, Status(..), decoder, encode, encodeWithTag, toString) import DateTime exposing (DateTime) import Dict exposing (Dict) @@ -49,15 +49,24 @@ decoder = encode : Order_ -> Encode.Value -encode 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.encode model.shipDate) ) - , ( "status", Maybe.withDefault Encode.null (Maybe.map encodeStatus model.status) ) - , ( "complete", Maybe.withDefault Encode.null (Maybe.map Encode.bool model.complete) ) - ] +encode = + Encode.object << encodePairs + + +encodeWithTag : ( String, String ) -> Order_ -> Encode.Value +encodeWithTag ( tagField, tag ) model = + Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ] + + +encodePairs : Order_ -> List ( String, Encode.Value ) +encodePairs model = + [ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) ) + , ( "petId", Maybe.withDefault Encode.null (Maybe.map Encode.int model.petId) ) + , ( "quantity", Maybe.withDefault Encode.null (Maybe.map Encode.int model.quantity) ) + , ( "shipDate", Maybe.withDefault Encode.null (Maybe.map DateTime.encode model.shipDate) ) + , ( "status", Maybe.withDefault Encode.null (Maybe.map encodeStatus model.status) ) + , ( "complete", Maybe.withDefault Encode.null (Maybe.map Encode.bool model.complete) ) + ] toString : Order_ -> String diff --git a/samples/client/petstore/elm-0.18/src/Data/Pet.elm b/samples/client/petstore/elm-0.18/src/Data/Pet.elm index 50f39279e10..166695c26af 100644 --- a/samples/client/petstore/elm-0.18/src/Data/Pet.elm +++ b/samples/client/petstore/elm-0.18/src/Data/Pet.elm @@ -10,7 +10,7 @@ -} -module Data.Pet exposing (Pet, Status(..), decoder, encode, toString) +module Data.Pet exposing (Pet, Status(..), decoder, encode, encodeWithTag, toString) import Data.Category as Category exposing (Category) import Data.Tag as Tag exposing (Tag) @@ -50,15 +50,24 @@ decoder = encode : Pet -> Encode.Value -encode model = - Encode.object - [ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) ) - , ( "category", Maybe.withDefault Encode.null (Maybe.map Category.encode model.category) ) - , ( "name", Encode.string model.name ) - , ( "photoUrls", (Encode.list << List.map Encode.string) model.photoUrls ) - , ( "tags", Maybe.withDefault Encode.null (Maybe.map (Encode.list << List.map Tag.encode) model.tags) ) - , ( "status", Maybe.withDefault Encode.null (Maybe.map encodeStatus model.status) ) - ] +encode = + Encode.object << encodePairs + + +encodeWithTag : ( String, String ) -> Pet -> Encode.Value +encodeWithTag ( tagField, tag ) model = + Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ] + + +encodePairs : Pet -> List ( String, Encode.Value ) +encodePairs model = + [ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) ) + , ( "category", Maybe.withDefault Encode.null (Maybe.map Category.encode model.category) ) + , ( "name", Encode.string model.name ) + , ( "photoUrls", (Encode.list << List.map Encode.string) model.photoUrls ) + , ( "tags", Maybe.withDefault Encode.null (Maybe.map (Encode.list << List.map Tag.encode) model.tags) ) + , ( "status", Maybe.withDefault Encode.null (Maybe.map encodeStatus model.status) ) + ] toString : Pet -> String diff --git a/samples/client/petstore/elm-0.18/src/Data/Tag.elm b/samples/client/petstore/elm-0.18/src/Data/Tag.elm index 81b9407409b..631119b0416 100644 --- a/samples/client/petstore/elm-0.18/src/Data/Tag.elm +++ b/samples/client/petstore/elm-0.18/src/Data/Tag.elm @@ -10,7 +10,7 @@ -} -module Data.Tag exposing (Tag, decoder, encode, toString) +module Data.Tag exposing (Tag, decoder, encode, encodeWithTag, toString) import Dict exposing (Dict) import Json.Decode as Decode exposing (Decoder) @@ -34,11 +34,20 @@ decoder = encode : Tag -> Encode.Value -encode 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) ) - ] +encode = + Encode.object << encodePairs + + +encodeWithTag : ( String, String ) -> Tag -> Encode.Value +encodeWithTag ( tagField, tag ) model = + Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ] + + +encodePairs : Tag -> List ( String, Encode.Value ) +encodePairs model = + [ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) ) + , ( "name", Maybe.withDefault Encode.null (Maybe.map Encode.string model.name) ) + ] toString : Tag -> String diff --git a/samples/client/petstore/elm-0.18/src/Data/User.elm b/samples/client/petstore/elm-0.18/src/Data/User.elm index 5b27dc8e183..ad632f6becc 100644 --- a/samples/client/petstore/elm-0.18/src/Data/User.elm +++ b/samples/client/petstore/elm-0.18/src/Data/User.elm @@ -10,7 +10,7 @@ -} -module Data.User exposing (User, decoder, encode, toString) +module Data.User exposing (User, decoder, encode, encodeWithTag, toString) import Dict exposing (Dict) import Json.Decode as Decode exposing (Decoder) @@ -46,17 +46,26 @@ decoder = encode : User -> Encode.Value -encode 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) ) - ] +encode = + Encode.object << encodePairs + + +encodeWithTag : ( String, String ) -> User -> Encode.Value +encodeWithTag ( tagField, tag ) model = + Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ] + + +encodePairs : User -> List ( String, Encode.Value ) +encodePairs model = + [ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) ) + , ( "username", Maybe.withDefault Encode.null (Maybe.map Encode.string model.username) ) + , ( "firstName", Maybe.withDefault Encode.null (Maybe.map Encode.string model.firstName) ) + , ( "lastName", Maybe.withDefault Encode.null (Maybe.map Encode.string model.lastName) ) + , ( "email", Maybe.withDefault Encode.null (Maybe.map Encode.string model.email) ) + , ( "password", Maybe.withDefault Encode.null (Maybe.map Encode.string model.password) ) + , ( "phone", Maybe.withDefault Encode.null (Maybe.map Encode.string model.phone) ) + , ( "userStatus", Maybe.withDefault Encode.null (Maybe.map Encode.int model.userStatus) ) + ] toString : User -> String diff --git a/samples/client/petstore/elm/src/Data/ApiResponse.elm b/samples/client/petstore/elm/src/Data/ApiResponse.elm index 08199cab32f..36300e78f78 100644 --- a/samples/client/petstore/elm/src/Data/ApiResponse.elm +++ b/samples/client/petstore/elm/src/Data/ApiResponse.elm @@ -10,7 +10,7 @@ -} -module Data.ApiResponse exposing (ApiResponse, decoder, encode, toString) +module Data.ApiResponse exposing (ApiResponse, decoder, encode, encodeWithTag, toString) import Dict exposing (Dict) import Json.Decode as Decode exposing (Decoder) @@ -36,12 +36,21 @@ decoder = encode : ApiResponse -> Encode.Value -encode 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) ) - ] +encode = + Encode.object << encodePairs + + +encodeWithTag : ( String, String ) -> ApiResponse -> Encode.Value +encodeWithTag ( tagField, tag ) model = + Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ] + + +encodePairs : ApiResponse -> List ( String, Encode.Value ) +encodePairs model = + [ ( "code", Maybe.withDefault Encode.null (Maybe.map Encode.int model.code) ) + , ( "type", Maybe.withDefault Encode.null (Maybe.map Encode.string model.type_) ) + , ( "message", Maybe.withDefault Encode.null (Maybe.map Encode.string model.message) ) + ] toString : ApiResponse -> String diff --git a/samples/client/petstore/elm/src/Data/Category.elm b/samples/client/petstore/elm/src/Data/Category.elm index cd1778b8703..43d1f5f4185 100644 --- a/samples/client/petstore/elm/src/Data/Category.elm +++ b/samples/client/petstore/elm/src/Data/Category.elm @@ -10,7 +10,7 @@ -} -module Data.Category exposing (Category, decoder, encode, toString) +module Data.Category exposing (Category, decoder, encode, encodeWithTag, toString) import Dict exposing (Dict) import Json.Decode as Decode exposing (Decoder) @@ -34,11 +34,20 @@ decoder = encode : Category -> Encode.Value -encode 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) ) - ] +encode = + Encode.object << encodePairs + + +encodeWithTag : ( String, String ) -> Category -> Encode.Value +encodeWithTag ( tagField, tag ) model = + Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ] + + +encodePairs : Category -> List ( String, Encode.Value ) +encodePairs model = + [ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) ) + , ( "name", Maybe.withDefault Encode.null (Maybe.map Encode.string model.name) ) + ] toString : Category -> String diff --git a/samples/client/petstore/elm/src/Data/Order_.elm b/samples/client/petstore/elm/src/Data/Order_.elm index aff082a6f67..2ae0003257d 100644 --- a/samples/client/petstore/elm/src/Data/Order_.elm +++ b/samples/client/petstore/elm/src/Data/Order_.elm @@ -10,7 +10,7 @@ -} -module Data.Order_ exposing (Order_, Status(..), decoder, encode, toString) +module Data.Order_ exposing (Order_, Status(..), decoder, encode, encodeWithTag, toString) import DateTime exposing (DateTime) import Dict exposing (Dict) @@ -49,15 +49,24 @@ decoder = encode : Order_ -> Encode.Value -encode 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.encode model.shipDate) ) - , ( "status", Maybe.withDefault Encode.null (Maybe.map encodeStatus model.status) ) - , ( "complete", Maybe.withDefault Encode.null (Maybe.map Encode.bool model.complete) ) - ] +encode = + Encode.object << encodePairs + + +encodeWithTag : ( String, String ) -> Order_ -> Encode.Value +encodeWithTag ( tagField, tag ) model = + Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ] + + +encodePairs : Order_ -> List ( String, Encode.Value ) +encodePairs model = + [ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) ) + , ( "petId", Maybe.withDefault Encode.null (Maybe.map Encode.int model.petId) ) + , ( "quantity", Maybe.withDefault Encode.null (Maybe.map Encode.int model.quantity) ) + , ( "shipDate", Maybe.withDefault Encode.null (Maybe.map DateTime.encode model.shipDate) ) + , ( "status", Maybe.withDefault Encode.null (Maybe.map encodeStatus model.status) ) + , ( "complete", Maybe.withDefault Encode.null (Maybe.map Encode.bool model.complete) ) + ] toString : Order_ -> String diff --git a/samples/client/petstore/elm/src/Data/Pet.elm b/samples/client/petstore/elm/src/Data/Pet.elm index f024b79c80f..6630115718f 100644 --- a/samples/client/petstore/elm/src/Data/Pet.elm +++ b/samples/client/petstore/elm/src/Data/Pet.elm @@ -10,7 +10,7 @@ -} -module Data.Pet exposing (Pet, Status(..), decoder, encode, toString) +module Data.Pet exposing (Pet, Status(..), decoder, encode, encodeWithTag, toString) import Data.Category as Category exposing (Category) import Data.Tag as Tag exposing (Tag) @@ -50,15 +50,24 @@ decoder = encode : Pet -> Encode.Value -encode model = - Encode.object - [ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) ) - , ( "category", Maybe.withDefault Encode.null (Maybe.map Category.encode model.category) ) - , ( "name", Encode.string model.name ) - , ( "photoUrls", Encode.list Encode.string model.photoUrls ) - , ( "tags", Maybe.withDefault Encode.null (Maybe.map (Encode.list Tag.encode) model.tags) ) - , ( "status", Maybe.withDefault Encode.null (Maybe.map encodeStatus model.status) ) - ] +encode = + Encode.object << encodePairs + + +encodeWithTag : ( String, String ) -> Pet -> Encode.Value +encodeWithTag ( tagField, tag ) model = + Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ] + + +encodePairs : Pet -> List ( String, Encode.Value ) +encodePairs model = + [ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) ) + , ( "category", Maybe.withDefault Encode.null (Maybe.map Category.encode model.category) ) + , ( "name", Encode.string model.name ) + , ( "photoUrls", Encode.list Encode.string model.photoUrls ) + , ( "tags", Maybe.withDefault Encode.null (Maybe.map (Encode.list Tag.encode) model.tags) ) + , ( "status", Maybe.withDefault Encode.null (Maybe.map encodeStatus model.status) ) + ] toString : Pet -> String diff --git a/samples/client/petstore/elm/src/Data/Tag.elm b/samples/client/petstore/elm/src/Data/Tag.elm index 052a4197b28..1a2c9d6b6d7 100644 --- a/samples/client/petstore/elm/src/Data/Tag.elm +++ b/samples/client/petstore/elm/src/Data/Tag.elm @@ -10,7 +10,7 @@ -} -module Data.Tag exposing (Tag, decoder, encode, toString) +module Data.Tag exposing (Tag, decoder, encode, encodeWithTag, toString) import Dict exposing (Dict) import Json.Decode as Decode exposing (Decoder) @@ -34,11 +34,20 @@ decoder = encode : Tag -> Encode.Value -encode 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) ) - ] +encode = + Encode.object << encodePairs + + +encodeWithTag : ( String, String ) -> Tag -> Encode.Value +encodeWithTag ( tagField, tag ) model = + Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ] + + +encodePairs : Tag -> List ( String, Encode.Value ) +encodePairs model = + [ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) ) + , ( "name", Maybe.withDefault Encode.null (Maybe.map Encode.string model.name) ) + ] toString : Tag -> String diff --git a/samples/client/petstore/elm/src/Data/User.elm b/samples/client/petstore/elm/src/Data/User.elm index c4b2e3db9cc..8d56f85052b 100644 --- a/samples/client/petstore/elm/src/Data/User.elm +++ b/samples/client/petstore/elm/src/Data/User.elm @@ -10,7 +10,7 @@ -} -module Data.User exposing (User, decoder, encode, toString) +module Data.User exposing (User, decoder, encode, encodeWithTag, toString) import Dict exposing (Dict) import Json.Decode as Decode exposing (Decoder) @@ -46,17 +46,26 @@ decoder = encode : User -> Encode.Value -encode 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) ) - ] +encode = + Encode.object << encodePairs + + +encodeWithTag : ( String, String ) -> User -> Encode.Value +encodeWithTag ( tagField, tag ) model = + Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ] + + +encodePairs : User -> List ( String, Encode.Value ) +encodePairs model = + [ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) ) + , ( "username", Maybe.withDefault Encode.null (Maybe.map Encode.string model.username) ) + , ( "firstName", Maybe.withDefault Encode.null (Maybe.map Encode.string model.firstName) ) + , ( "lastName", Maybe.withDefault Encode.null (Maybe.map Encode.string model.lastName) ) + , ( "email", Maybe.withDefault Encode.null (Maybe.map Encode.string model.email) ) + , ( "password", Maybe.withDefault Encode.null (Maybe.map Encode.string model.password) ) + , ( "phone", Maybe.withDefault Encode.null (Maybe.map Encode.string model.phone) ) + , ( "userStatus", Maybe.withDefault Encode.null (Maybe.map Encode.int model.userStatus) ) + ] toString : User -> String diff --git a/samples/openapi3/client/composition/elm/.gitignore b/samples/openapi3/client/composition/elm/.gitignore new file mode 100644 index 00000000000..8b0d053e4e3 --- /dev/null +++ b/samples/openapi3/client/composition/elm/.gitignore @@ -0,0 +1 @@ +/elm-stuff \ No newline at end of file diff --git a/samples/openapi3/client/composition/elm/.openapi-generator-ignore b/samples/openapi3/client/composition/elm/.openapi-generator-ignore new file mode 100644 index 00000000000..7484ee590a3 --- /dev/null +++ b/samples/openapi3/client/composition/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/composition/elm/.openapi-generator/VERSION b/samples/openapi3/client/composition/elm/.openapi-generator/VERSION new file mode 100644 index 00000000000..d168f1d8bda --- /dev/null +++ b/samples/openapi3/client/composition/elm/.openapi-generator/VERSION @@ -0,0 +1 @@ +4.2.1-SNAPSHOT \ No newline at end of file diff --git a/samples/openapi3/client/composition/elm/README.md b/samples/openapi3/client/composition/elm/README.md new file mode 100644 index 00000000000..c088cadbea3 --- /dev/null +++ b/samples/openapi3/client/composition/elm/README.md @@ -0,0 +1,10 @@ +# Elm API client + +No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + +## 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/composition/elm/elm-compile-test b/samples/openapi3/client/composition/elm/elm-compile-test new file mode 100755 index 00000000000..55507cfcad6 --- /dev/null +++ b/samples/openapi3/client/composition/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/composition/elm/elm.json b/samples/openapi3/client/composition/elm/elm.json new file mode 100644 index 00000000000..398da0d2d6d --- /dev/null +++ b/samples/openapi3/client/composition/elm/elm.json @@ -0,0 +1,33 @@ +{ + "type": "application", + "source-directories": [ + "src" + ], + "elm-version": "0.19.0", + "dependencies": { + "direct": { + "NoRedInk/elm-json-decode-pipeline": "1.0.0", + "danyx23/elm-uuid": "2.1.2", + "elm/browser": "1.0.1", + "elm/core": "1.0.2", + "elm/html": "1.0.0", + "elm/http": "2.0.0", + "elm/json": "1.1.2", + "elm/time": "1.0.0", + "elm/url": "1.0.0", + "rtfeldman/elm-iso8601-date-strings": "1.1.3" + }, + "indirect": { + "elm/bytes": "1.0.5", + "elm/file": "1.0.1", + "elm/parser": "1.1.0", + "elm/random": "1.0.0", + "elm/regex": "1.0.0", + "elm/virtual-dom": "1.0.2" + } + }, + "test-dependencies": { + "direct": {}, + "indirect": {} + } +} diff --git a/samples/openapi3/client/composition/elm/pom.xml b/samples/openapi3/client/composition/elm/pom.xml new file mode 100644 index 00000000000..c70a1f0b874 --- /dev/null +++ b/samples/openapi3/client/composition/elm/pom.xml @@ -0,0 +1,43 @@ + + 4.0.0 + org.openapitools + ElmCompositionTests + pom + 1.0-SNAPSHOT + Elm Composition Client + + + + maven-dependency-plugin + + + package + + copy-dependencies + + + ${project.build.directory} + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.2.1 + + + bundle-test + integration-test + + exec + + + ./elm-compile-test + + + + + + + diff --git a/samples/openapi3/client/composition/elm/src/Byte.elm b/samples/openapi3/client/composition/elm/src/Byte.elm new file mode 100644 index 00000000000..d83623d9846 --- /dev/null +++ b/samples/openapi3/client/composition/elm/src/Byte.elm @@ -0,0 +1,18 @@ +module Byte exposing (Byte, decoder, encode) + +import Json.Decode as Decode exposing (Decoder) +import Json.Encode as Encode + + +type alias Byte = + String + + +decoder : Decoder Byte +decoder = + Decode.string + + +encode : Byte -> Encode.Value +encode model = + Encode.string model diff --git a/samples/openapi3/client/composition/elm/src/Data/AllOf.elm b/samples/openapi3/client/composition/elm/src/Data/AllOf.elm new file mode 100644 index 00000000000..d5365028afa --- /dev/null +++ b/samples/openapi3/client/composition/elm/src/Data/AllOf.elm @@ -0,0 +1,56 @@ +{- + Composition and Inheritence (Polymorphism) + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + The version of the OpenAPI document: 1.0.0 + + NOTE: This file is auto generated by the openapi-generator. + https://github.com/openapitools/openapi-generator.git + Do not edit this file manually. +-} + + +module Data.AllOf exposing (AllOf, decoder, encode, encodeWithTag, toString) + +import Dict exposing (Dict) +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +type alias AllOf = + { objectType : String + , valueA : Maybe String + , valueB : Maybe Float + } + + +decoder : Decoder AllOf +decoder = + Decode.succeed AllOf + |> required "objectType" Decode.string + |> optional "valueA" (Decode.nullable Decode.string) Nothing + |> optional "valueB" (Decode.nullable Decode.float) Nothing + + +encode : AllOf -> Encode.Value +encode = + Encode.object << encodePairs + + +encodeWithTag : ( String, String ) -> AllOf -> Encode.Value +encodeWithTag ( tagField, tag ) model = + Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ] + + +encodePairs : AllOf -> List ( String, Encode.Value ) +encodePairs model = + [ ( "objectType", Encode.string model.objectType ) + , ( "valueA", Maybe.withDefault Encode.null (Maybe.map Encode.string model.valueA) ) + , ( "valueB", Maybe.withDefault Encode.null (Maybe.map Encode.float model.valueB) ) + ] + + +toString : AllOf -> String +toString = + Encode.encode 0 << encode diff --git a/samples/openapi3/client/composition/elm/src/Data/BaseObject.elm b/samples/openapi3/client/composition/elm/src/Data/BaseObject.elm new file mode 100644 index 00000000000..b81d6f75864 --- /dev/null +++ b/samples/openapi3/client/composition/elm/src/Data/BaseObject.elm @@ -0,0 +1,59 @@ +{- + Composition and Inheritence (Polymorphism) + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + The version of the OpenAPI document: 1.0.0 + + NOTE: This file is auto generated by the openapi-generator. + https://github.com/openapitools/openapi-generator.git + Do not edit this file manually. +-} + + +module Data.BaseObject exposing (BaseObject(..), decoder, encode, toString) + +import Data.SubObjectA as SubObjectA exposing (SubObjectA) +import Data.SubObjectB as SubObjectB exposing (SubObjectB) +import Dict exposing (Dict) +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +type BaseObject + = SubObjectAType SubObjectA + | SubObjectBType SubObjectB + + +decoder : Decoder BaseObject +decoder = + Decode.field "objectType" Decode.string + |> Decode.andThen baseObjectDecoder + + +baseObjectDecoder : String -> Decoder BaseObject +baseObjectDecoder tag = + case tag of + "SubObjectA" -> + Decode.map SubObjectAType SubObjectA.decoder + + "SubObjectB" -> + Decode.map SubObjectBType SubObjectB.decoder + + _ -> + Decode.fail <| "Trying to decode BaseObject, but objectType '" ++ tag ++ "' is not supported." + + +encode : BaseObject -> Encode.Value +encode model = + case model of + SubObjectAType subModel -> + SubObjectA.encodeWithTag ( "objectType", "SubObjectA" ) subModel + + SubObjectBType subModel -> + SubObjectB.encodeWithTag ( "objectType", "SubObjectB" ) subModel + + +toString : BaseObject -> String +toString = + Encode.encode 0 << encode diff --git a/samples/openapi3/client/composition/elm/src/Data/ObjectA.elm b/samples/openapi3/client/composition/elm/src/Data/ObjectA.elm new file mode 100644 index 00000000000..9a9ba64da51 --- /dev/null +++ b/samples/openapi3/client/composition/elm/src/Data/ObjectA.elm @@ -0,0 +1,53 @@ +{- + Composition and Inheritence (Polymorphism) + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + The version of the OpenAPI document: 1.0.0 + + NOTE: This file is auto generated by the openapi-generator. + https://github.com/openapitools/openapi-generator.git + Do not edit this file manually. +-} + + +module Data.ObjectA exposing (ObjectA, decoder, encode, encodeWithTag, toString) + +import Dict exposing (Dict) +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +type alias ObjectA = + { objectType : String + , valueA : Maybe String + } + + +decoder : Decoder ObjectA +decoder = + Decode.succeed ObjectA + |> required "objectType" Decode.string + |> optional "valueA" (Decode.nullable Decode.string) Nothing + + +encode : ObjectA -> Encode.Value +encode = + Encode.object << encodePairs + + +encodeWithTag : ( String, String ) -> ObjectA -> Encode.Value +encodeWithTag ( tagField, tag ) model = + Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ] + + +encodePairs : ObjectA -> List ( String, Encode.Value ) +encodePairs model = + [ ( "objectType", Encode.string model.objectType ) + , ( "valueA", Maybe.withDefault Encode.null (Maybe.map Encode.string model.valueA) ) + ] + + +toString : ObjectA -> String +toString = + Encode.encode 0 << encode diff --git a/samples/openapi3/client/composition/elm/src/Data/ObjectB.elm b/samples/openapi3/client/composition/elm/src/Data/ObjectB.elm new file mode 100644 index 00000000000..0ffa826106e --- /dev/null +++ b/samples/openapi3/client/composition/elm/src/Data/ObjectB.elm @@ -0,0 +1,53 @@ +{- + Composition and Inheritence (Polymorphism) + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + The version of the OpenAPI document: 1.0.0 + + NOTE: This file is auto generated by the openapi-generator. + https://github.com/openapitools/openapi-generator.git + Do not edit this file manually. +-} + + +module Data.ObjectB exposing (ObjectB, decoder, encode, encodeWithTag, toString) + +import Dict exposing (Dict) +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +type alias ObjectB = + { objectType : String + , valueB : Maybe Float + } + + +decoder : Decoder ObjectB +decoder = + Decode.succeed ObjectB + |> required "objectType" Decode.string + |> optional "valueB" (Decode.nullable Decode.float) Nothing + + +encode : ObjectB -> Encode.Value +encode = + Encode.object << encodePairs + + +encodeWithTag : ( String, String ) -> ObjectB -> Encode.Value +encodeWithTag ( tagField, tag ) model = + Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ] + + +encodePairs : ObjectB -> List ( String, Encode.Value ) +encodePairs model = + [ ( "objectType", Encode.string model.objectType ) + , ( "valueB", Maybe.withDefault Encode.null (Maybe.map Encode.float model.valueB) ) + ] + + +toString : ObjectB -> String +toString = + Encode.encode 0 << encode diff --git a/samples/openapi3/client/composition/elm/src/Data/OneOf.elm b/samples/openapi3/client/composition/elm/src/Data/OneOf.elm new file mode 100644 index 00000000000..5bd3b463056 --- /dev/null +++ b/samples/openapi3/client/composition/elm/src/Data/OneOf.elm @@ -0,0 +1,48 @@ +{- + Composition and Inheritence (Polymorphism) + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + The version of the OpenAPI document: 1.0.0 + + NOTE: This file is auto generated by the openapi-generator. + https://github.com/openapitools/openapi-generator.git + Do not edit this file manually. +-} + + +module Data.OneOf exposing (OneOf, decoder, encode, toString) + +import Data.ObjectA as ObjectA exposing (ObjectA) +import Data.ObjectB as ObjectB exposing (ObjectB) +import Dict exposing (Dict) +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +type OneOf + = ObjectAType ObjectA + | ObjectBType ObjectB + + +decoder : Decoder OneOf +decoder = + Decode.oneOf + [ Decode.map ObjectAType ObjectA.decoder + , Decode.map ObjectBType ObjectB.decoder + ] + + +encode : OneOf -> Encode.Value +encode model = + case model of + ObjectAType subModel -> + ObjectA.encode subModel + + ObjectBType subModel -> + ObjectB.encode subModel + + +toString : OneOf -> String +toString = + Encode.encode 0 << encode diff --git a/samples/openapi3/client/composition/elm/src/Data/OneOfWithAllOfDiscriminator.elm b/samples/openapi3/client/composition/elm/src/Data/OneOfWithAllOfDiscriminator.elm new file mode 100644 index 00000000000..6e43730e0f7 --- /dev/null +++ b/samples/openapi3/client/composition/elm/src/Data/OneOfWithAllOfDiscriminator.elm @@ -0,0 +1,48 @@ +{- + Composition and Inheritence (Polymorphism) + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + The version of the OpenAPI document: 1.0.0 + + NOTE: This file is auto generated by the openapi-generator. + https://github.com/openapitools/openapi-generator.git + Do not edit this file manually. +-} + + +module Data.OneOfWithAllOfDiscriminator exposing (OneOfWithAllOfDiscriminator, decoder, encode, toString) + +import Data.SubObjectA as SubObjectA exposing (SubObjectA) +import Data.SubObjectB as SubObjectB exposing (SubObjectB) +import Dict exposing (Dict) +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +type OneOfWithAllOfDiscriminator + = SubObjectAType SubObjectA + | SubObjectBType SubObjectB + + +decoder : Decoder OneOfWithAllOfDiscriminator +decoder = + Decode.oneOf + [ Decode.map SubObjectAType SubObjectA.decoder + , Decode.map SubObjectBType SubObjectB.decoder + ] + + +encode : OneOfWithAllOfDiscriminator -> Encode.Value +encode model = + case model of + SubObjectAType subModel -> + SubObjectA.encode subModel + + SubObjectBType subModel -> + SubObjectB.encode subModel + + +toString : OneOfWithAllOfDiscriminator -> String +toString = + Encode.encode 0 << encode diff --git a/samples/openapi3/client/composition/elm/src/Data/OneOfWithDiscriminator.elm b/samples/openapi3/client/composition/elm/src/Data/OneOfWithDiscriminator.elm new file mode 100644 index 00000000000..a45536791e7 --- /dev/null +++ b/samples/openapi3/client/composition/elm/src/Data/OneOfWithDiscriminator.elm @@ -0,0 +1,59 @@ +{- + Composition and Inheritence (Polymorphism) + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + The version of the OpenAPI document: 1.0.0 + + NOTE: This file is auto generated by the openapi-generator. + https://github.com/openapitools/openapi-generator.git + Do not edit this file manually. +-} + + +module Data.OneOfWithDiscriminator exposing (OneOfWithDiscriminator, decoder, encode, toString) + +import Data.ObjectA as ObjectA exposing (ObjectA) +import Data.ObjectB as ObjectB exposing (ObjectB) +import Dict exposing (Dict) +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +type OneOfWithDiscriminator + = ObjectAType ObjectA + | ObjectBType ObjectB + + +decoder : Decoder OneOfWithDiscriminator +decoder = + Decode.field "objectType" Decode.string + |> Decode.andThen oneOfWithDiscriminatorDecoder + + +oneOfWithDiscriminatorDecoder : String -> Decoder OneOfWithDiscriminator +oneOfWithDiscriminatorDecoder tag = + case tag of + "a" -> + Decode.map ObjectAType ObjectA.decoder + + "b" -> + Decode.map ObjectBType ObjectB.decoder + + _ -> + Decode.fail <| "Trying to decode OneOfWithDiscriminator, but objectType '" ++ tag ++ "' is not supported." + + +encode : OneOfWithDiscriminator -> Encode.Value +encode model = + case model of + ObjectAType subModel -> + ObjectA.encodeWithTag ( "objectType", "a" ) subModel + + ObjectBType subModel -> + ObjectB.encodeWithTag ( "objectType", "b" ) subModel + + +toString : OneOfWithDiscriminator -> String +toString = + Encode.encode 0 << encode diff --git a/samples/openapi3/client/composition/elm/src/Data/SubObjectA.elm b/samples/openapi3/client/composition/elm/src/Data/SubObjectA.elm new file mode 100644 index 00000000000..beb5b335ce0 --- /dev/null +++ b/samples/openapi3/client/composition/elm/src/Data/SubObjectA.elm @@ -0,0 +1,53 @@ +{- + Composition and Inheritence (Polymorphism) + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + The version of the OpenAPI document: 1.0.0 + + NOTE: This file is auto generated by the openapi-generator. + https://github.com/openapitools/openapi-generator.git + Do not edit this file manually. +-} + + +module Data.SubObjectA exposing (SubObjectA, decoder, encode, encodeWithTag, toString) + +import Dict exposing (Dict) +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +type alias SubObjectA = + { value : Bool + , valueA : Maybe String + } + + +decoder : Decoder SubObjectA +decoder = + Decode.succeed SubObjectA + |> required "value" Decode.bool + |> optional "valueA" (Decode.nullable Decode.string) Nothing + + +encode : SubObjectA -> Encode.Value +encode = + Encode.object << encodePairs + + +encodeWithTag : ( String, String ) -> SubObjectA -> Encode.Value +encodeWithTag ( tagField, tag ) model = + Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ] + + +encodePairs : SubObjectA -> List ( String, Encode.Value ) +encodePairs model = + [ ( "value", Encode.bool model.value ) + , ( "valueA", Maybe.withDefault Encode.null (Maybe.map Encode.string model.valueA) ) + ] + + +toString : SubObjectA -> String +toString = + Encode.encode 0 << encode diff --git a/samples/openapi3/client/composition/elm/src/Data/SubObjectAAllOf.elm b/samples/openapi3/client/composition/elm/src/Data/SubObjectAAllOf.elm new file mode 100644 index 00000000000..dbebf152361 --- /dev/null +++ b/samples/openapi3/client/composition/elm/src/Data/SubObjectAAllOf.elm @@ -0,0 +1,50 @@ +{- + Composition and Inheritence (Polymorphism) + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + The version of the OpenAPI document: 1.0.0 + + NOTE: This file is auto generated by the openapi-generator. + https://github.com/openapitools/openapi-generator.git + Do not edit this file manually. +-} + + +module Data.SubObjectAAllOf exposing (SubObjectAAllOf, decoder, encode, encodeWithTag, toString) + +import Dict exposing (Dict) +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +type alias SubObjectAAllOf = + { valueA : Maybe String + } + + +decoder : Decoder SubObjectAAllOf +decoder = + Decode.succeed SubObjectAAllOf + |> optional "valueA" (Decode.nullable Decode.string) Nothing + + +encode : SubObjectAAllOf -> Encode.Value +encode = + Encode.object << encodePairs + + +encodeWithTag : ( String, String ) -> SubObjectAAllOf -> Encode.Value +encodeWithTag ( tagField, tag ) model = + Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ] + + +encodePairs : SubObjectAAllOf -> List ( String, Encode.Value ) +encodePairs model = + [ ( "valueA", Maybe.withDefault Encode.null (Maybe.map Encode.string model.valueA) ) + ] + + +toString : SubObjectAAllOf -> String +toString = + Encode.encode 0 << encode diff --git a/samples/openapi3/client/composition/elm/src/Data/SubObjectB.elm b/samples/openapi3/client/composition/elm/src/Data/SubObjectB.elm new file mode 100644 index 00000000000..77c7d9f87ce --- /dev/null +++ b/samples/openapi3/client/composition/elm/src/Data/SubObjectB.elm @@ -0,0 +1,53 @@ +{- + Composition and Inheritence (Polymorphism) + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + The version of the OpenAPI document: 1.0.0 + + NOTE: This file is auto generated by the openapi-generator. + https://github.com/openapitools/openapi-generator.git + Do not edit this file manually. +-} + + +module Data.SubObjectB exposing (SubObjectB, decoder, encode, encodeWithTag, toString) + +import Dict exposing (Dict) +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +type alias SubObjectB = + { value : Bool + , valueB : Maybe Float + } + + +decoder : Decoder SubObjectB +decoder = + Decode.succeed SubObjectB + |> required "value" Decode.bool + |> optional "valueB" (Decode.nullable Decode.float) Nothing + + +encode : SubObjectB -> Encode.Value +encode = + Encode.object << encodePairs + + +encodeWithTag : ( String, String ) -> SubObjectB -> Encode.Value +encodeWithTag ( tagField, tag ) model = + Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ] + + +encodePairs : SubObjectB -> List ( String, Encode.Value ) +encodePairs model = + [ ( "value", Encode.bool model.value ) + , ( "valueB", Maybe.withDefault Encode.null (Maybe.map Encode.float model.valueB) ) + ] + + +toString : SubObjectB -> String +toString = + Encode.encode 0 << encode diff --git a/samples/openapi3/client/composition/elm/src/Data/SubObjectBAllOf.elm b/samples/openapi3/client/composition/elm/src/Data/SubObjectBAllOf.elm new file mode 100644 index 00000000000..6983e8cbbb3 --- /dev/null +++ b/samples/openapi3/client/composition/elm/src/Data/SubObjectBAllOf.elm @@ -0,0 +1,50 @@ +{- + Composition and Inheritence (Polymorphism) + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + The version of the OpenAPI document: 1.0.0 + + NOTE: This file is auto generated by the openapi-generator. + https://github.com/openapitools/openapi-generator.git + Do not edit this file manually. +-} + + +module Data.SubObjectBAllOf exposing (SubObjectBAllOf, decoder, encode, encodeWithTag, toString) + +import Dict exposing (Dict) +import Json.Decode as Decode exposing (Decoder) +import Json.Decode.Pipeline exposing (optional, required) +import Json.Encode as Encode + + +type alias SubObjectBAllOf = + { valueB : Maybe Float + } + + +decoder : Decoder SubObjectBAllOf +decoder = + Decode.succeed SubObjectBAllOf + |> optional "valueB" (Decode.nullable Decode.float) Nothing + + +encode : SubObjectBAllOf -> Encode.Value +encode = + Encode.object << encodePairs + + +encodeWithTag : ( String, String ) -> SubObjectBAllOf -> Encode.Value +encodeWithTag ( tagField, tag ) model = + Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ] + + +encodePairs : SubObjectBAllOf -> List ( String, Encode.Value ) +encodePairs model = + [ ( "valueB", Maybe.withDefault Encode.null (Maybe.map Encode.float model.valueB) ) + ] + + +toString : SubObjectBAllOf -> String +toString = + Encode.encode 0 << encode diff --git a/samples/openapi3/client/composition/elm/src/DateOnly.elm b/samples/openapi3/client/composition/elm/src/DateOnly.elm new file mode 100644 index 00000000000..a31efc88c38 --- /dev/null +++ b/samples/openapi3/client/composition/elm/src/DateOnly.elm @@ -0,0 +1,37 @@ +module DateOnly exposing (DateOnly, decoder, encode, toString) + +import Iso8601 +import Json.Decode as Decode exposing (Decoder) +import Json.Encode as Encode +import Result +import Time + + +type alias DateOnly = + Time.Posix + + +decoder : Decoder DateOnly +decoder = + Decode.string + |> Decode.andThen decodeIsoString + + +encode : DateOnly -> Encode.Value +encode = + Encode.string << toString + + +decodeIsoString : String -> Decoder DateOnly +decodeIsoString str = + case Iso8601.toTime (str ++ "T00:00:00.000Z") of + Result.Ok posix -> + Decode.succeed posix + + Result.Err _ -> + Decode.fail <| "Invalid date: " ++ str + + +toString : DateOnly -> String +toString = + String.left 10 << Iso8601.fromTime diff --git a/samples/openapi3/client/composition/elm/src/DateTime.elm b/samples/openapi3/client/composition/elm/src/DateTime.elm new file mode 100644 index 00000000000..80b62fb7dec --- /dev/null +++ b/samples/openapi3/client/composition/elm/src/DateTime.elm @@ -0,0 +1,37 @@ +module DateTime exposing (DateTime, decoder, encode, toString) + +import Iso8601 +import Json.Decode as Decode exposing (Decoder) +import Json.Encode as Encode +import Result +import Time + + +type alias DateTime = + Time.Posix + + +decoder : Decoder DateTime +decoder = + Decode.string + |> Decode.andThen decodeIsoString + + +encode : DateTime -> Encode.Value +encode = + Encode.string << toString + + +decodeIsoString : String -> Decoder DateTime +decodeIsoString str = + case Iso8601.toTime str of + Result.Ok posix -> + Decode.succeed posix + + Result.Err _ -> + Decode.fail <| "Invalid date: " ++ str + + +toString : DateTime -> String +toString = + Iso8601.fromTime diff --git a/samples/openapi3/client/composition/elm/src/Main.elm b/samples/openapi3/client/composition/elm/src/Main.elm new file mode 100644 index 00000000000..7c9ddd056d3 --- /dev/null +++ b/samples/openapi3/client/composition/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/composition/elm/src/Request/Default.elm b/samples/openapi3/client/composition/elm/src/Request/Default.elm new file mode 100644 index 00000000000..c4a56ffd524 --- /dev/null +++ b/samples/openapi3/client/composition/elm/src/Request/Default.elm @@ -0,0 +1,123 @@ +{- + Composition and Inheritence (Polymorphism) + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + The version of the OpenAPI document: 1.0.0 + + NOTE: This file is auto generated by the openapi-generator. + https://github.com/openapitools/openapi-generator.git + Do not edit this file manually. +-} + + +module Request.Default exposing (allOfPost, allOfWithDiscriminatorPost, oneOfPost, oneOfWithAllOfDiscriminatorPost, oneOfWithDiscriminatorPost) + +import Data.AllOf as AllOf exposing (AllOf) +import Data.BaseObject as BaseObject exposing (BaseObject) +import Data.OneOf as OneOf exposing (OneOf) +import Data.OneOfWithAllOfDiscriminator as OneOfWithAllOfDiscriminator exposing (OneOfWithAllOfDiscriminator) +import Data.OneOfWithDiscriminator as OneOfWithDiscriminator exposing (OneOfWithDiscriminator) +import Dict +import Http +import Json.Decode as Decode +import Url.Builder as Url + + +basePath : String +basePath = + "http://localhost" + + +allOfPost : + { onSend : Result Http.Error AllOf -> msg + } + -> Cmd msg +allOfPost params = + Http.request + { method = "POST" + , headers = List.filterMap identity [] + , url = + Url.crossOrigin basePath + [ "allOf" ] + (List.filterMap identity []) + , body = Http.emptyBody + , expect = Http.expectJson params.onSend AllOf.decoder + , timeout = Just 30000 + , tracker = Nothing + } + + +allOfWithDiscriminatorPost : + { onSend : Result Http.Error BaseObject -> msg + } + -> Cmd msg +allOfWithDiscriminatorPost params = + Http.request + { method = "POST" + , headers = List.filterMap identity [] + , url = + Url.crossOrigin basePath + [ "allOfWithDiscriminator" ] + (List.filterMap identity []) + , body = Http.emptyBody + , expect = Http.expectJson params.onSend BaseObject.decoder + , timeout = Just 30000 + , tracker = Nothing + } + + +oneOfPost : + { onSend : Result Http.Error OneOf -> msg + } + -> Cmd msg +oneOfPost params = + Http.request + { method = "POST" + , headers = List.filterMap identity [] + , url = + Url.crossOrigin basePath + [ "oneOf" ] + (List.filterMap identity []) + , body = Http.emptyBody + , expect = Http.expectJson params.onSend OneOf.decoder + , timeout = Just 30000 + , tracker = Nothing + } + + +oneOfWithAllOfDiscriminatorPost : + { onSend : Result Http.Error OneOfWithAllOfDiscriminator -> msg + } + -> Cmd msg +oneOfWithAllOfDiscriminatorPost params = + Http.request + { method = "POST" + , headers = List.filterMap identity [] + , url = + Url.crossOrigin basePath + [ "oneOfWithAllOfDiscriminator" ] + (List.filterMap identity []) + , body = Http.emptyBody + , expect = Http.expectJson params.onSend OneOfWithAllOfDiscriminator.decoder + , timeout = Just 30000 + , tracker = Nothing + } + + +oneOfWithDiscriminatorPost : + { onSend : Result Http.Error OneOfWithDiscriminator -> msg + } + -> Cmd msg +oneOfWithDiscriminatorPost params = + Http.request + { method = "POST" + , headers = List.filterMap identity [] + , url = + Url.crossOrigin basePath + [ "oneOfWithDiscriminator" ] + (List.filterMap identity []) + , body = Http.emptyBody + , expect = Http.expectJson params.onSend OneOfWithDiscriminator.decoder + , timeout = Just 30000 + , tracker = Nothing + } diff --git a/samples/openapi3/client/petstore/elm/.openapi-generator/VERSION b/samples/openapi3/client/petstore/elm/.openapi-generator/VERSION index 479c313e87b..d168f1d8bda 100644 --- a/samples/openapi3/client/petstore/elm/.openapi-generator/VERSION +++ b/samples/openapi3/client/petstore/elm/.openapi-generator/VERSION @@ -1 +1 @@ -4.0.3-SNAPSHOT \ No newline at end of file +4.2.1-SNAPSHOT \ No newline at end of file diff --git a/samples/openapi3/client/petstore/elm/src/Data/ApiResponse.elm b/samples/openapi3/client/petstore/elm/src/Data/ApiResponse.elm index 3559c4f3fe8..7fbf5de80e7 100644 --- a/samples/openapi3/client/petstore/elm/src/Data/ApiResponse.elm +++ b/samples/openapi3/client/petstore/elm/src/Data/ApiResponse.elm @@ -10,7 +10,7 @@ -} -module Data.ApiResponse exposing (ApiResponse, decoder, encode) +module Data.ApiResponse exposing (ApiResponse, decoder, encode, encodeWithTag, toString) import Dict exposing (Dict) import Json.Decode as Decode exposing (Decoder) @@ -37,12 +37,28 @@ decoder = encode : ApiResponse -> Encode.Value -encode 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) ) - - ] +encode = + Encode.object << encodePairs + + +encodeWithTag : ( String, String ) -> ApiResponse -> Encode.Value +encodeWithTag (tagField, tag) model = + Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ] + + +encodePairs : ApiResponse -> List (String, Encode.Value) +encodePairs model = + [ ( "code", Maybe.withDefault Encode.null (Maybe.map Encode.int model.code) ) + , ( "type", Maybe.withDefault Encode.null (Maybe.map Encode.string model.type_) ) + , ( "message", Maybe.withDefault Encode.null (Maybe.map Encode.string model.message) ) + ] + + + +toString : ApiResponse -> String +toString = + Encode.encode 0 << encode + + diff --git a/samples/openapi3/client/petstore/elm/src/Data/Category.elm b/samples/openapi3/client/petstore/elm/src/Data/Category.elm index 9a5803626d9..d0b29b295da 100644 --- a/samples/openapi3/client/petstore/elm/src/Data/Category.elm +++ b/samples/openapi3/client/petstore/elm/src/Data/Category.elm @@ -10,7 +10,7 @@ -} -module Data.Category exposing (Category, decoder, encode) +module Data.Category exposing (Category, decoder, encode, encodeWithTag, toString) import Dict exposing (Dict) import Json.Decode as Decode exposing (Decoder) @@ -35,11 +35,27 @@ decoder = encode : Category -> Encode.Value -encode 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) ) - - ] +encode = + Encode.object << encodePairs + + +encodeWithTag : ( String, String ) -> Category -> Encode.Value +encodeWithTag (tagField, tag) model = + Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ] + + +encodePairs : Category -> List (String, Encode.Value) +encodePairs model = + [ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) ) + , ( "name", Maybe.withDefault Encode.null (Maybe.map Encode.string model.name) ) + ] + + + +toString : Category -> String +toString = + Encode.encode 0 << encode + + diff --git a/samples/openapi3/client/petstore/elm/src/Data/InlineObject.elm b/samples/openapi3/client/petstore/elm/src/Data/InlineObject.elm index 0fda842c6c7..cac10db9769 100644 --- a/samples/openapi3/client/petstore/elm/src/Data/InlineObject.elm +++ b/samples/openapi3/client/petstore/elm/src/Data/InlineObject.elm @@ -10,7 +10,7 @@ -} -module Data.InlineObject exposing (InlineObject, decoder, encode) +module Data.InlineObject exposing (InlineObject, decoder, encode, encodeWithTag, toString) import Dict exposing (Dict) import Json.Decode as Decode exposing (Decoder) @@ -33,11 +33,27 @@ decoder = encode : InlineObject -> Encode.Value -encode 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) ) - - ] +encode = + Encode.object << encodePairs + + +encodeWithTag : ( String, String ) -> InlineObject -> Encode.Value +encodeWithTag (tagField, tag) model = + Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ] + + +encodePairs : InlineObject -> List (String, Encode.Value) +encodePairs model = + [ ( "name", Maybe.withDefault Encode.null (Maybe.map Encode.string model.name) ) + , ( "status", Maybe.withDefault Encode.null (Maybe.map Encode.string model.status) ) + ] + + + +toString : InlineObject -> String +toString = + Encode.encode 0 << encode + + diff --git a/samples/openapi3/client/petstore/elm/src/Data/InlineObject1.elm b/samples/openapi3/client/petstore/elm/src/Data/InlineObject1.elm index 8ec67406c35..ac64e3132f3 100644 --- a/samples/openapi3/client/petstore/elm/src/Data/InlineObject1.elm +++ b/samples/openapi3/client/petstore/elm/src/Data/InlineObject1.elm @@ -10,7 +10,7 @@ -} -module Data.InlineObject1 exposing (InlineObject1, decoder, encode) +module Data.InlineObject1 exposing (InlineObject1, decoder, encode, encodeWithTag, toString) import Dict exposing (Dict) import Json.Decode as Decode exposing (Decoder) @@ -33,11 +33,27 @@ decoder = encode : InlineObject1 -> Encode.Value -encode 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) ) - - ] +encode = + Encode.object << encodePairs + + +encodeWithTag : ( String, String ) -> InlineObject1 -> Encode.Value +encodeWithTag (tagField, tag) model = + Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ] + + +encodePairs : InlineObject1 -> List (String, Encode.Value) +encodePairs model = + [ ( "additionalMetadata", Maybe.withDefault Encode.null (Maybe.map Encode.string model.additionalMetadata) ) + , ( "file", Maybe.withDefault Encode.null (Maybe.map Encode.string model.file) ) + ] + + + +toString : InlineObject1 -> String +toString = + Encode.encode 0 << encode + + diff --git a/samples/openapi3/client/petstore/elm/src/Data/Order_.elm b/samples/openapi3/client/petstore/elm/src/Data/Order_.elm index f1a620a19f1..7a7325592ad 100644 --- a/samples/openapi3/client/petstore/elm/src/Data/Order_.elm +++ b/samples/openapi3/client/petstore/elm/src/Data/Order_.elm @@ -10,7 +10,7 @@ -} -module Data.Order_ exposing (Order_, Status(..), decoder, encode) +module Data.Order_ exposing (Order_, Status(..), decoder, encode, encodeWithTag, toString) import DateTime exposing (DateTime) import Dict exposing (Dict) @@ -51,16 +51,31 @@ decoder = encode : Order_ -> Encode.Value -encode 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.encode model.shipDate) ) - , ( "status", Maybe.withDefault Encode.null (Maybe.map encodeStatus model.status) ) - , ( "complete", Maybe.withDefault Encode.null (Maybe.map Encode.bool model.complete) ) +encode = + Encode.object << encodePairs + + +encodeWithTag : ( String, String ) -> Order_ -> Encode.Value +encodeWithTag (tagField, tag) model = + Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ] + + +encodePairs : Order_ -> List (String, Encode.Value) +encodePairs model = + [ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) ) + , ( "petId", Maybe.withDefault Encode.null (Maybe.map Encode.int model.petId) ) + , ( "quantity", Maybe.withDefault Encode.null (Maybe.map Encode.int model.quantity) ) + , ( "shipDate", Maybe.withDefault Encode.null (Maybe.map DateTime.encode model.shipDate) ) + , ( "status", Maybe.withDefault Encode.null (Maybe.map encodeStatus model.status) ) + , ( "complete", Maybe.withDefault Encode.null (Maybe.map Encode.bool model.complete) ) + ] + + + +toString : Order_ -> String +toString = + Encode.encode 0 << encode - ] @@ -99,3 +114,4 @@ encodeStatus model = + diff --git a/samples/openapi3/client/petstore/elm/src/Data/Pet.elm b/samples/openapi3/client/petstore/elm/src/Data/Pet.elm index 4eaf5a47938..3267cfc059e 100644 --- a/samples/openapi3/client/petstore/elm/src/Data/Pet.elm +++ b/samples/openapi3/client/petstore/elm/src/Data/Pet.elm @@ -10,7 +10,7 @@ -} -module Data.Pet exposing (Pet, Status(..), decoder, encode) +module Data.Pet exposing (Pet, Status(..), decoder, encode, encodeWithTag, toString) import Data.Category as Category exposing (Category) import Data.Tag as Tag exposing (Tag) @@ -52,16 +52,31 @@ decoder = encode : Pet -> Encode.Value -encode model = - Encode.object - [ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) ) - , ( "category", Maybe.withDefault Encode.null (Maybe.map Category.encode model.category) ) - , ( "name", Encode.string model.name ) - , ( "photoUrls", (Encode.list Encode.string) model.photoUrls ) - , ( "tags", Maybe.withDefault Encode.null (Maybe.map (Encode.list Tag.encode) model.tags) ) - , ( "status", Maybe.withDefault Encode.null (Maybe.map encodeStatus model.status) ) +encode = + Encode.object << encodePairs + + +encodeWithTag : ( String, String ) -> Pet -> Encode.Value +encodeWithTag (tagField, tag) model = + Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ] + + +encodePairs : Pet -> List (String, Encode.Value) +encodePairs model = + [ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) ) + , ( "category", Maybe.withDefault Encode.null (Maybe.map Category.encode model.category) ) + , ( "name", Encode.string model.name ) + , ( "photoUrls", (Encode.list Encode.string) model.photoUrls ) + , ( "tags", Maybe.withDefault Encode.null (Maybe.map (Encode.list Tag.encode) model.tags) ) + , ( "status", Maybe.withDefault Encode.null (Maybe.map encodeStatus model.status) ) + ] + + + +toString : Pet -> String +toString = + Encode.encode 0 << encode - ] @@ -100,3 +115,4 @@ encodeStatus model = + diff --git a/samples/openapi3/client/petstore/elm/src/Data/Tag.elm b/samples/openapi3/client/petstore/elm/src/Data/Tag.elm index 16118b9b80b..2fbd439fe97 100644 --- a/samples/openapi3/client/petstore/elm/src/Data/Tag.elm +++ b/samples/openapi3/client/petstore/elm/src/Data/Tag.elm @@ -10,7 +10,7 @@ -} -module Data.Tag exposing (Tag, decoder, encode) +module Data.Tag exposing (Tag, decoder, encode, encodeWithTag, toString) import Dict exposing (Dict) import Json.Decode as Decode exposing (Decoder) @@ -35,11 +35,27 @@ decoder = encode : Tag -> Encode.Value -encode 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) ) - - ] +encode = + Encode.object << encodePairs + + +encodeWithTag : ( String, String ) -> Tag -> Encode.Value +encodeWithTag (tagField, tag) model = + Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ] + + +encodePairs : Tag -> List (String, Encode.Value) +encodePairs model = + [ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) ) + , ( "name", Maybe.withDefault Encode.null (Maybe.map Encode.string model.name) ) + ] + + + +toString : Tag -> String +toString = + Encode.encode 0 << encode + + diff --git a/samples/openapi3/client/petstore/elm/src/Data/User.elm b/samples/openapi3/client/petstore/elm/src/Data/User.elm index 0b0cba12cc4..819857888dc 100644 --- a/samples/openapi3/client/petstore/elm/src/Data/User.elm +++ b/samples/openapi3/client/petstore/elm/src/Data/User.elm @@ -10,7 +10,7 @@ -} -module Data.User exposing (User, decoder, encode) +module Data.User exposing (User, decoder, encode, encodeWithTag, toString) import Dict exposing (Dict) import Json.Decode as Decode exposing (Decoder) @@ -47,17 +47,33 @@ decoder = encode : User -> Encode.Value -encode 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) ) - - ] +encode = + Encode.object << encodePairs + + +encodeWithTag : ( String, String ) -> User -> Encode.Value +encodeWithTag (tagField, tag) model = + Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ] + + +encodePairs : User -> List (String, Encode.Value) +encodePairs model = + [ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) ) + , ( "username", Maybe.withDefault Encode.null (Maybe.map Encode.string model.username) ) + , ( "firstName", Maybe.withDefault Encode.null (Maybe.map Encode.string model.firstName) ) + , ( "lastName", Maybe.withDefault Encode.null (Maybe.map Encode.string model.lastName) ) + , ( "email", Maybe.withDefault Encode.null (Maybe.map Encode.string model.email) ) + , ( "password", Maybe.withDefault Encode.null (Maybe.map Encode.string model.password) ) + , ( "phone", Maybe.withDefault Encode.null (Maybe.map Encode.string model.phone) ) + , ( "userStatus", Maybe.withDefault Encode.null (Maybe.map Encode.int model.userStatus) ) + ] + + + +toString : User -> String +toString = + Encode.encode 0 << encode + + diff --git a/samples/openapi3/client/petstore/elm/src/Request/Pet.elm b/samples/openapi3/client/petstore/elm/src/Request/Pet.elm index af5b1654eca..a7a77529477 100644 --- a/samples/openapi3/client/petstore/elm/src/Request/Pet.elm +++ b/samples/openapi3/client/petstore/elm/src/Request/Pet.elm @@ -25,8 +25,8 @@ type Status | StatusPending | StatusSold -statusToString : Status -> String -statusToString value = +stringifyStatus : Status -> String +stringifyStatus value = case value of StatusAvailable -> "available" @@ -58,10 +58,10 @@ addPet : addPet params = Http.request { method = "POST" - , headers = [] + , headers = List.filterMap identity [] , url = Url.crossOrigin basePath ["pet"] - [] + (List.filterMap identity []) , body = Http.jsonBody <| Pet.encode params.body , expect = Http.expectWhatever params.onSend , timeout = Just 30000 @@ -83,10 +83,10 @@ deletePet : deletePet headers params = Http.request { method = "DELETE" - , headers = List.filterMap identity [Maybe.map (Http.header "api_key" ) headers.apiKey] + , headers = List.filterMap identity [Maybe.map (Http.header "api_key" << identity) headers.apiKey] , url = Url.crossOrigin basePath - ["pet", String.fromInt params.petId] - [] + ["pet", String.fromInt params.petId] + (List.filterMap identity []) , body = Http.emptyBody , expect = Http.expectWhatever params.onSend , timeout = Just 30000 @@ -108,10 +108,10 @@ findPetsByStatus : findPetsByStatus params = Http.request { method = "GET" - , headers = [] + , headers = List.filterMap identity [] , url = Url.crossOrigin basePath ["pet", "findByStatus"] - (List.filterMap identity [Just (Url.string "status" <| (String.join "," << List.map statusToString) params.status)]) + (List.filterMap identity [(Just << Url.string "status" << String.join "," << List.map stringifyStatus) params.status]) , body = Http.emptyBody , expect = Http.expectJson params.onSend (Decode.list Pet.decoder) , timeout = Just 30000 @@ -127,16 +127,16 @@ findPetsByTags : - , tags : List String , maxCount : Maybe (Int) + , tags : List String } -> Cmd msg findPetsByTags params = Http.request { method = "GET" - , headers = [] + , headers = List.filterMap identity [] , url = Url.crossOrigin basePath ["pet", "findByTags"] - (List.filterMap identity [Just (Url.string "tags" <| (String.join ",") params.tags), Maybe.map (Url.string "maxCount" << String.fromInt) params.maxCount]) + (List.filterMap identity [(Just << Url.string "tags" << String.join "," << List.map identity) params.tags]) , body = Http.emptyBody , expect = Http.expectJson params.onSend (Decode.list Pet.decoder) , timeout = Just 30000 @@ -158,10 +158,10 @@ getPetById : getPetById params = Http.request { method = "GET" - , headers = [] + , headers = List.filterMap identity [] , url = Url.crossOrigin basePath - ["pet", String.fromInt params.petId] - [] + ["pet", String.fromInt params.petId] + (List.filterMap identity []) , body = Http.emptyBody , expect = Http.expectJson params.onSend Pet.decoder , timeout = Just 30000 @@ -181,10 +181,10 @@ updatePet : updatePet params = Http.request { method = "PUT" - , headers = [] + , headers = List.filterMap identity [] , url = Url.crossOrigin basePath ["pet"] - [] + (List.filterMap identity []) , body = Http.jsonBody <| Pet.encode params.body , expect = Http.expectWhatever params.onSend , timeout = Just 30000 @@ -204,10 +204,10 @@ updatePetWithForm : updatePetWithForm params = Http.request { method = "POST" - , headers = [] + , headers = List.filterMap identity [] , url = Url.crossOrigin basePath - ["pet", String.fromInt params.petId] - [] + ["pet", String.fromInt params.petId] + (List.filterMap identity []) , body = Http.emptyBody , expect = Http.expectWhatever params.onSend , timeout = Just 30000 @@ -227,10 +227,10 @@ uploadFile : uploadFile params = Http.request { method = "POST" - , headers = [] + , headers = List.filterMap identity [] , url = Url.crossOrigin basePath - ["pet", String.fromInt params.petId, "uploadImage"] - [] + ["pet", String.fromInt params.petId, "uploadImage"] + (List.filterMap identity []) , body = Http.emptyBody , expect = Http.expectJson params.onSend ApiResponse.decoder , timeout = Just 30000 diff --git a/samples/openapi3/client/petstore/elm/src/Request/Store.elm b/samples/openapi3/client/petstore/elm/src/Request/Store.elm index 7ac926fe41e..e2a40d41938 100644 --- a/samples/openapi3/client/petstore/elm/src/Request/Store.elm +++ b/samples/openapi3/client/petstore/elm/src/Request/Store.elm @@ -40,10 +40,10 @@ deleteOrder : deleteOrder params = Http.request { method = "DELETE" - , headers = [] + , headers = List.filterMap identity [] , url = Url.crossOrigin basePath - ["store", "order", params.orderId] - [] + ["store", "order", identity params.orderId] + (List.filterMap identity []) , body = Http.emptyBody , expect = Http.expectWhatever params.onSend , timeout = Just 30000 @@ -65,10 +65,10 @@ getInventory : getInventory params = Http.request { method = "GET" - , headers = [] + , headers = List.filterMap identity [] , url = Url.crossOrigin basePath ["store", "inventory"] - [] + (List.filterMap identity []) , body = Http.emptyBody , expect = Http.expectJson params.onSend (Decode.dict Decode.int) , timeout = Just 30000 @@ -90,10 +90,10 @@ getOrderById : getOrderById params = Http.request { method = "GET" - , headers = [] + , headers = List.filterMap identity [] , url = Url.crossOrigin basePath - ["store", "order", String.fromInt params.orderId] - [] + ["store", "order", String.fromInt params.orderId] + (List.filterMap identity []) , body = Http.emptyBody , expect = Http.expectJson params.onSend Order_.decoder , timeout = Just 30000 @@ -113,10 +113,10 @@ placeOrder : placeOrder params = Http.request { method = "POST" - , headers = [] + , headers = List.filterMap identity [] , url = Url.crossOrigin basePath ["store", "order"] - [] + (List.filterMap identity []) , body = Http.jsonBody <| Order_.encode params.body , expect = Http.expectJson params.onSend Order_.decoder , timeout = Just 30000 diff --git a/samples/openapi3/client/petstore/elm/src/Request/User.elm b/samples/openapi3/client/petstore/elm/src/Request/User.elm index 6d6d21918a6..0bb8411573b 100644 --- a/samples/openapi3/client/petstore/elm/src/Request/User.elm +++ b/samples/openapi3/client/petstore/elm/src/Request/User.elm @@ -40,10 +40,10 @@ createUser : createUser params = Http.request { method = "POST" - , headers = [] + , headers = List.filterMap identity [] , url = Url.crossOrigin basePath ["user"] - [] + (List.filterMap identity []) , body = Http.jsonBody <| User.encode params.body , expect = Http.expectWhatever params.onSend , timeout = Just 30000 @@ -63,10 +63,10 @@ createUsersWithArrayInput : createUsersWithArrayInput params = Http.request { method = "POST" - , headers = [] + , headers = List.filterMap identity [] , url = Url.crossOrigin basePath ["user", "createWithArray"] - [] + (List.filterMap identity []) , body = Http.jsonBody <| User.encode params.body , expect = Http.expectWhatever params.onSend , timeout = Just 30000 @@ -86,10 +86,10 @@ createUsersWithListInput : createUsersWithListInput params = Http.request { method = "POST" - , headers = [] + , headers = List.filterMap identity [] , url = Url.crossOrigin basePath ["user", "createWithList"] - [] + (List.filterMap identity []) , body = Http.jsonBody <| User.encode params.body , expect = Http.expectWhatever params.onSend , timeout = Just 30000 @@ -111,10 +111,10 @@ deleteUser : deleteUser params = Http.request { method = "DELETE" - , headers = [] + , headers = List.filterMap identity [] , url = Url.crossOrigin basePath - ["user", params.username] - [] + ["user", identity params.username] + (List.filterMap identity []) , body = Http.emptyBody , expect = Http.expectWhatever params.onSend , timeout = Just 30000 @@ -134,10 +134,10 @@ getUserByName : getUserByName params = Http.request { method = "GET" - , headers = [] + , headers = List.filterMap identity [] , url = Url.crossOrigin basePath - ["user", params.username] - [] + ["user", identity params.username] + (List.filterMap identity []) , body = Http.emptyBody , expect = Http.expectJson params.onSend User.decoder , timeout = Just 30000 @@ -157,10 +157,10 @@ loginUser : loginUser params = Http.request { method = "GET" - , headers = [] + , headers = List.filterMap identity [] , url = Url.crossOrigin basePath ["user", "login"] - (List.filterMap identity [Just (Url.string "username" params.username), Just (Url.string "password" params.password)]) + (List.filterMap identity [(Just << Url.string "username" << identity) params.username, (Just << Url.string "password" << identity) params.password]) , body = Http.emptyBody , expect = Http.expectJson params.onSend Decode.string , timeout = Just 30000 @@ -180,10 +180,10 @@ logoutUser : logoutUser params = Http.request { method = "GET" - , headers = [] + , headers = List.filterMap identity [] , url = Url.crossOrigin basePath ["user", "logout"] - [] + (List.filterMap identity []) , body = Http.emptyBody , expect = Http.expectWhatever params.onSend , timeout = Just 30000 @@ -205,10 +205,10 @@ updateUser : updateUser params = Http.request { method = "PUT" - , headers = [] + , headers = List.filterMap identity [] , url = Url.crossOrigin basePath - ["user", params.username] - [] + ["user", identity params.username] + (List.filterMap identity []) , body = Http.jsonBody <| User.encode params.body , expect = Http.expectWhatever params.onSend , timeout = Just 30000