From 5b31976196e06f92fc2a3c7c1221e201f580660a Mon Sep 17 00:00:00 2001 From: Qluxzz Date: Sun, 16 Apr 2023 21:14:51 +0200 Subject: [PATCH 01/10] Add petstore config --- bin/configs/elm-petstore.yaml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 bin/configs/elm-petstore.yaml diff --git a/bin/configs/elm-petstore.yaml b/bin/configs/elm-petstore.yaml new file mode 100644 index 000000000000..3fa86d20dbd6 --- /dev/null +++ b/bin/configs/elm-petstore.yaml @@ -0,0 +1,4 @@ +generatorName: elm +outputDir: samples/client/petstore/elm +inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml +templateDir: modules/openapi-generator/src/main/resources/elm \ No newline at end of file From 25f539f700038c5ef05122ee50d721a71e4e713a Mon Sep 17 00:00:00 2001 From: Qluxzz Date: Sun, 16 Apr 2023 21:15:15 +0200 Subject: [PATCH 02/10] Expand lambda to allow formatting of partials --- .../org/openapitools/codegen/languages/ElmClientCodegen.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 3a14bffe4ddc..75e3fbdafe36 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 @@ -473,7 +473,7 @@ public String getTypeDeclaration(Schema p) { private static class RemoveWhitespaceLambda implements Mustache.Lambda { @Override public void execute(final Template.Fragment fragment, final Writer writer) throws IOException { - writer.write(fragment.execute().replaceAll("\\s+", "")); + writer.write(fragment.execute().replaceAll("\\s+", " ").trim()); } } From 87c328a7906303b128326726bd098483c33ead84 Mon Sep 17 00:00:00 2001 From: Qluxzz Date: Sun, 16 Apr 2023 21:17:23 +0200 Subject: [PATCH 03/10] Fix order of operation with parenthesis --- .../src/main/resources/elm/recordField.mustache | 10 +++++++++- .../src/main/resources/elm/recordFieldEncoder.mustache | 2 +- .../resources/elm/recordFieldValueEncoder.mustache | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/elm/recordField.mustache b/modules/openapi-generator/src/main/resources/elm/recordField.mustache index 692081a031dc..27f5eebbe09d 100644 --- a/modules/openapi-generator/src/main/resources/elm/recordField.mustache +++ b/modules/openapi-generator/src/main/resources/elm/recordField.mustache @@ -1 +1,9 @@ -{{#isNullable}}Maybe {{#isContainer}}({{/isContainer}}{{/isNullable}}{{^isNullable}}{{^required}}Maybe {{#isContainer}}({{/isContainer}}{{/required}}{{/isNullable}}{{#isArray}}List {{/isArray}}{{#isMap}}Dict.Dict String {{/isMap}}{{#isEnum}}{{classname}}{{enumName}}{{/isEnum}}{{^isEnum}}{{#items}}({{>recordField}}){{/items}}{{^isContainer}}{{dataType}}{{/isContainer}}{{/isEnum}}{{#isContainer}}{{#isNullable}}){{/isNullable}}{{^isNullable}}{{^required}}){{/required}}{{/isNullable}}{{/isContainer}} \ No newline at end of file +{{#lambda.removeWhitespace}} +{{#isNullable}}Maybe {{#isContainer}}({{/isContainer}}{{/isNullable}} +{{^isNullable}}{{^required}}Maybe {{#isContainer}}({{/isContainer}}{{/required}}{{/isNullable}} +{{#isArray}}List {{/isArray}} +{{#isMap}}Dict.Dict String {{/isMap}} +{{#isEnum}}{{classname}}{{enumName}}{{/isEnum}} +{{^isEnum}}{{#items}}{{#isContainer}}({{/isContainer}}{{>recordField}}{{#isContainer}}){{/isContainer}}{{/items}}{{^isContainer}}{{dataType}}{{/isContainer}}{{/isEnum}} +{{#isContainer}}{{#isNullable}}){{/isNullable}}{{^isNullable}}{{^required}}){{/required}}{{/isNullable}}{{/isContainer}} +{{/lambda.removeWhitespace}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/elm/recordFieldEncoder.mustache b/modules/openapi-generator/src/main/resources/elm/recordFieldEncoder.mustache index d01a870c65fa..886da29f6996 100644 --- a/modules/openapi-generator/src/main/resources/elm/recordFieldEncoder.mustache +++ b/modules/openapi-generator/src/main/resources/elm/recordFieldEncoder.mustache @@ -1 +1 @@ -{{#required}}encode{{/required}}{{^required}}maybeEncode{{/required}}{{#isNullable}}Nullable{{/isNullable}} "{{baseName}}" {{>recordFieldValueEncoder}} {{#isCircularReference}}<| unwrap{{classname}}{{nameInCamelCase}} {{/isCircularReference}}model.{{name}} \ No newline at end of file +{{#required}}encode{{/required}}{{^required}}maybeEncode{{/required}}{{#isNullable}}Nullable{{/isNullable}} "{{baseName}}" {{#isContainer}}({{/isContainer}}{{>recordFieldValueEncoder}}{{#isContainer}}){{/isContainer}} {{#isCircularReference}}<| unwrap{{classname}}{{nameInCamelCase}} {{/isCircularReference}}model.{{name}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/elm/recordFieldValueEncoder.mustache b/modules/openapi-generator/src/main/resources/elm/recordFieldValueEncoder.mustache index 372e8790ed07..6063619c2f21 100644 --- a/modules/openapi-generator/src/main/resources/elm/recordFieldValueEncoder.mustache +++ b/modules/openapi-generator/src/main/resources/elm/recordFieldValueEncoder.mustache @@ -1 +1 @@ -{{#isContainer}}({{#isArray}}Json.Encode.list{{/isArray}}{{#isMap}}Json.Encode.dict identity{{/isMap}} {{#items}}{{>recordFieldValueEncoder}}{{/items}}{{/isContainer}}{{^isContainer}}{{>fieldEncoder}}{{/isContainer}}{{#isContainer}}){{/isContainer}} \ No newline at end of file +{{#isContainer}}{{#isArray}}Json.Encode.list{{/isArray}}{{#isMap}}Json.Encode.dict identity{{/isMap}} {{#items}}{{#isContainer}}({{/isContainer}}{{>recordFieldValueEncoder}}{{#isContainer}}){{/isContainer}}{{/items}}{{/isContainer}}{{^isContainer}}{{>fieldEncoder}}{{/isContainer}} \ No newline at end of file From aa0590753b65f8f467085b3a5469ba30bcb60b3a Mon Sep 17 00:00:00 2001 From: Qluxzz Date: Sun, 16 Apr 2023 21:18:37 +0200 Subject: [PATCH 04/10] Fix not exposing needed enum to string converters --- .../src/main/resources/elm/model.mustache | 3 ++- .../main/resources/elm/paramToString.mustache | 23 ++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/elm/model.mustache b/modules/openapi-generator/src/main/resources/elm/model.mustache index 701ffbf97db4..b78def71cf42 100644 --- a/modules/openapi-generator/src/main/resources/elm/model.mustache +++ b/modules/openapi-generator/src/main/resources/elm/model.mustache @@ -3,7 +3,8 @@ module Api.Data exposing {{#models}}{{#model}} {{#-first}}( {{/-first}}{{^-first}}, {{/-first}}{{classname}}{{#discriminator}}(..){{/discriminator}}{{^discriminator}}{{#oneOf}}{{#-first}}(..){{/-first}}{{/oneOf}}{{/discriminator}}{{#isEnum}}(..), {{#lambda.camelcase}}{{classname}}{{/lambda.camelcase}}Variants{{/isEnum}}{{^isEnum}}{{#vars}}{{#isCircularReference}}, {{classname}}{{nameInCamelCase}}(..){{/isCircularReference}}{{#isEnum}}, {{classname}}{{nameInCamelCase}}(..), {{#lambda.camelcase}}{{classname}}{{nameInCamelCase}}{{/lambda.camelcase}}Variants{{/isEnum}}{{/vars}}{{/isEnum}} {{/model}}{{/models}}{{#models}}{{#model}} , {{#lambda.camelcase}}encode{{classname}}{{/lambda.camelcase}} -{{/model}}{{/models}}{{#models}}{{#model}} , {{#lambda.camelcase}}{{classname}}{{/lambda.camelcase}}Decoder +{{/model}}{{/models}}{{#models}}{{#model}}{{#isEnum}} , stringFrom{{^paramName}}{{classname}}{{/paramName}}{{enumName}} +{{/isEnum}}{{/model}}{{/models}}{{#models}}{{#model}} , {{#lambda.camelcase}}{{classname}}{{/lambda.camelcase}}Decoder {{/model}}{{/models}} ) import Api{{#includeTime}} diff --git a/modules/openapi-generator/src/main/resources/elm/paramToString.mustache b/modules/openapi-generator/src/main/resources/elm/paramToString.mustache index 9c19c86365c1..99caa9e9e86d 100644 --- a/modules/openapi-generator/src/main/resources/elm/paramToString.mustache +++ b/modules/openapi-generator/src/main/resources/elm/paramToString.mustache @@ -1 +1,22 @@ -{{#isArray}}String.join "," << List.map {{#items}}{{>paramToString}}{{/items}}{{/isArray}}{{^isArray}}{{^isEnum}}{{^isUuid}}{{#isString}}identity{{/isString}}{{#isBinary}}identity{{/isBinary}}{{#isByteArray}}identity{{/isByteArray}}{{/isUuid}}{{/isEnum}}{{#isBoolean}}(\val -> if val then "true" else "false"){{/isBoolean}}{{#isDateTime}}Api.Time.dateTimeToString{{/isDateTime}}{{#isDate}}Api.Time.dateToString{{/isDate}}{{#isInteger}}String.fromInt{{/isInteger}}{{#isLong}}String.fromInt{{/isLong}}{{#isNumber}}String.fromFloat{{/isNumber}}{{#isFloat}}String.fromFloat{{/isFloat}}{{#isDouble}}String.fromFloat{{/isDouble}}{{#isEnum}}stringFrom{{^paramName}}Api.Data.{{classname}}{{/paramName}}{{enumName}}{{/isEnum}}{{#isUuid}}Uuid.toString{{/isUuid}}{{/isArray}} \ No newline at end of file +{{#lambda.removeWhitespace}} +{{#isArray}}(String.join "," << List.map {{#isEnum}}stringFrom{{#datatypeWithEnum}}{{datatypeWithEnum}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{dataType}}{{/datatypeWithEnum}}{{/isEnum}}{{^isEnum}} {{#items}}{{>paramToString}}{{/items}}{{/isEnum}}){{/isArray}} +{{^isArray}} +{{^isEnum}} +{{^isUuid}} +{{#isString}}identity{{/isString}} +{{#isBinary}}identity{{/isBinary}} +{{#isByteArray}}identity{{/isByteArray}} +{{/isUuid}} +{{/isEnum}} +{{#isBoolean}}(\val -> if val then "true" else "false"){{/isBoolean}} +{{#isDateTime}}Api.Time.dateTimeToString{{/isDateTime}} +{{#isDate}}Api.Time.dateToString{{/isDate}} +{{#isInteger}}String.fromInt{{/isInteger}} +{{#isLong}}String.fromInt{{/isLong}} +{{#isNumber}}String.fromFloat{{/isNumber}} +{{#isFloat}}String.fromFloat{{/isFloat}} +{{#isDouble}}String.fromFloat{{/isDouble}} +{{#allowableValues}}{{^isEnum}}Api.Data.{{/isEnum}}stringFrom{{#datatypeWithEnum}}{{datatypeWithEnum}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{dataType}}{{/datatypeWithEnum}}{{/allowableValues}} +{{#isUuid}}Uuid.toString{{/isUuid}} +{{/isArray}} +{{/lambda.removeWhitespace}} \ No newline at end of file From 3fb8278b9bb56a0b55050bbfb2a60d0f1b106a36 Mon Sep 17 00:00:00 2001 From: Qluxzz Date: Sun, 16 Apr 2023 21:19:36 +0200 Subject: [PATCH 05/10] Add support for form params including files --- .../codegen/languages/ElmClientCodegen.java | 6 ++- .../src/main/resources/elm/Api.mustache | 4 +- .../src/main/resources/elm/elm.mustache | 2 +- .../main/resources/elm/fieldDecoder.mustache | 3 +- .../resources/elm/formParamEncoder.mustache | 1 + .../src/main/resources/elm/operation.mustache | 44 +++++++++++++++---- .../resources/elm/operationParameter.mustache | 1 + 7 files changed, 47 insertions(+), 14 deletions(-) create mode 100644 modules/openapi-generator/src/main/resources/elm/formParamEncoder.mustache create mode 100644 modules/openapi-generator/src/main/resources/elm/operationParameter.mustache 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 75e3fbdafe36..09da7fa627f2 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 @@ -147,7 +147,7 @@ public ElmClientCodegen() { typeMapping.put("DateTime", "Posix"); typeMapping.put("password", "String"); typeMapping.put("ByteArray", "String"); - typeMapping.put("file", "String"); + typeMapping.put("file", "File"); typeMapping.put("binary", "String"); typeMapping.put("UUID", "Uuid"); typeMapping.put("URI", "String"); @@ -383,8 +383,12 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap operations, L anyOperationParam(ops, param -> (param.isDate || param.isDateTime) || itemsIncludesType(param.items, p -> p.isDate || p.isDateTime)); final boolean includeUuid = anyOperationResponse(ops, response -> response.isUuid) || anyOperationParam(ops, param -> param.isUuid || itemsIncludesType(param.items, p -> p.isUuid)); + final boolean includeFile = anyOperationResponse(ops, response -> response.isFile) || + anyOperationParam(ops, param -> param.isFile || itemsIncludesType(param.items, p -> p.isFile)); + operations.put("includeTime", includeTime); operations.put("includeUuid", includeUuid); + operations.put("includeFile", includeFile); return operations; } diff --git a/modules/openapi-generator/src/main/resources/elm/Api.mustache b/modules/openapi-generator/src/main/resources/elm/Api.mustache index 57b78a2620ca..9d9f45088e8f 100644 --- a/modules/openapi-generator/src/main/resources/elm/Api.mustache +++ b/modules/openapi-generator/src/main/resources/elm/Api.mustache @@ -35,7 +35,7 @@ type Request a = } -request : String -> String -> List ( String, String ) -> List (String, Maybe String) -> List (String, Maybe String) -> Maybe Json.Encode.Value -> Json.Decode.Decoder a -> Request a +request : String -> String -> List ( String, String ) -> List (String, Maybe String) -> List (String, Maybe String) -> Maybe Http.Body -> Json.Decode.Decoder a -> Request a request method path pathParams queryParams headerParams body decoder = Request { method = method @@ -43,7 +43,7 @@ request method path pathParams queryParams headerParams body decoder = , basePath = "{{basePath}}" , pathParams = interpolatePath path pathParams , queryParams = queries queryParams - , body = Maybe.withDefault Http.emptyBody (Maybe.map Http.jsonBody body) + , body = Maybe.withDefault Http.emptyBody body , decoder = decoder , timeout = Nothing , tracker = Nothing diff --git a/modules/openapi-generator/src/main/resources/elm/elm.mustache b/modules/openapi-generator/src/main/resources/elm/elm.mustache index bf0d1f8f4b6e..c3a1d917242f 100644 --- a/modules/openapi-generator/src/main/resources/elm/elm.mustache +++ b/modules/openapi-generator/src/main/resources/elm/elm.mustache @@ -9,6 +9,7 @@ "danyx23/elm-uuid": "2.1.2", "elm/browser": "1.0.1", "elm/core": "1.0.2", + "elm/file": "1.0.1", "elm/html": "1.0.0", "elm/http": "2.0.0", "elm/json": "1.1.2", @@ -18,7 +19,6 @@ }, "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", diff --git a/modules/openapi-generator/src/main/resources/elm/fieldDecoder.mustache b/modules/openapi-generator/src/main/resources/elm/fieldDecoder.mustache index 3bec7786ccf4..cb6480e57708 100644 --- a/modules/openapi-generator/src/main/resources/elm/fieldDecoder.mustache +++ b/modules/openapi-generator/src/main/resources/elm/fieldDecoder.mustache @@ -2,7 +2,8 @@ {{#isDateTime}}Api.Time.dateTimeDecoder{{/isDateTime}} {{#isDate}}Api.Time.dateDecoder{{/isDate}} {{#isByteArray}}Json.Decode.string{{/isByteArray}} -{{#isBinary}}Json.Decode.string{{/isBinary}} +{{#isBinary}}{{^isFile}}Json.Decode.string{{/isFile}}{{/isBinary}} +{{#isFile}}File.decoder{{/isFile}} {{#isString}}{{^isEnum}}{{^isUuid}}Json.Decode.string{{/isUuid}}{{/isEnum}}{{/isString}} {{#isInteger}}Json.Decode.int{{/isInteger}} {{#isLong}}Json.Decode.int{{/isLong}} diff --git a/modules/openapi-generator/src/main/resources/elm/formParamEncoder.mustache b/modules/openapi-generator/src/main/resources/elm/formParamEncoder.mustache new file mode 100644 index 000000000000..7198a2e7ae4b --- /dev/null +++ b/modules/openapi-generator/src/main/resources/elm/formParamEncoder.mustache @@ -0,0 +1 @@ +{{^required}}Maybe.map ({{/required}}{{#required}}Just <| {{/required}}{{^isFile}}Http.stringPart {{/isFile}}{{#isFile}}Http.filePart {{/isFile}}"{{paramName}}"{{#isBoolean}}(\val -> if val then "true" else "false"){{/isBoolean}}{{#isDateTime}}Api.Time.dateTimeToString{{/isDateTime}}{{#isDate}}Api.Time.dateToString{{/isDate}}{{#isInteger}}String.fromInt{{/isInteger}}{{#isLong}}String.fromInt{{/isLong}}{{#isNumber}}String.fromFloat{{/isNumber}}{{#isFloat}}String.fromFloat{{/isFloat}}{{#isDouble}}String.fromFloat{{/isDouble}}{{#allowableValues}}Api.Data.stringFrom{{#datatypeWithEnum}}{{datatypeWithEnum}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{dataType}}{{/datatypeWithEnum}}{{/allowableValues}}{{#isUuid}}Uuid.toString{{/isUuid}}{{^required}}){{/required}} {{paramName}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/elm/operation.mustache b/modules/openapi-generator/src/main/resources/elm/operation.mustache index 496e7954f69f..a52931f19db4 100644 --- a/modules/openapi-generator/src/main/resources/elm/operation.mustache +++ b/modules/openapi-generator/src/main/resources/elm/operation.mustache @@ -5,13 +5,14 @@ module Api.Request.{{classname}} exposing {{/operation}}{{/operations}} ) import Api -import Api.Data{{#includeTime}} +import Api.Data exposing (..){{#includeTime}} import Api.Time exposing (Posix){{/includeTime}} import Dict import Http import Json.Decode import Json.Encode{{#includeUuid}} -import Uuid exposing (Uuid){{/includeUuid}} +import Uuid exposing (Uuid){{/includeUuid}}{{#includeFile}} +import File exposing (File){{/includeFile}} {{#operations}} {{#operation}} {{#allParams}} @@ -26,14 +27,28 @@ import Uuid exposing (Uuid){{/includeUuid}} {{/allParams}} {{/operation}} {{/operations}} -{{#operations}}{{#operation}} - +{{#operations}} +{{#operation}} {{#notes}} {-| {{{notes}}} -} {{/notes}} -{{operationId}} : {{#allParams}}{{^required}}Maybe {{/required}}{{#isArray}}List {{/isArray}}{{datatypeWithEnum}}{{^datatypeWithEnum}}{{#isModel}}Api.Data.{{/isModel}}{{dataType}}{{/datatypeWithEnum}} -> {{/allParams}}{{#authMethods}}{{#isBasicBearer}}String -> {{/isBasicBearer}}{{/authMethods}}Api.Request {{^responses}}(){{/responses}}{{#responses}}{{#is2xx}}{{^dataType}}(){{/dataType}}{{#isMap}}(Dict.Dict String {{/isMap}}{{#isArray}}(List {{#items}}{{#isModel}}Api.Data.{{/isModel}}{{/items}}{{/isArray}}{{^isArray}}{{^primitiveType}}{{^isUuid}}Api.Data.{{/isUuid}}{{/primitiveType}}{{/isArray}}{{dataType}}{{#isArray}}){{/isArray}}{{#isMap}}){{/isMap}}{{/is2xx}}{{/responses}} +{{#lambda.removeWhitespace}} +{{operationId}} : {{#allParams}}{{>operationParameter}} -> {{/allParams}} + {{#authMethods}}{{#isBasicBearer}}String -> {{/isBasicBearer}}{{/authMethods}}Api.Request + {{#responses}} {{!-- This iterates through all different responses, some might not be 200 }} + {{#-first}} {{!-- We have no way to handle multiple return types today so we just handle the first }} + {{#is2xx}} + {{^dataType}}(){{/dataType}} + {{#isMap}}(Dict.Dict String {{/isMap}} + {{#isArray}}(List {{#items}}{{#isModel}}Api.Data.{{/isModel}}{{/items}}{{/isArray}}{{^isArray}}{{^primitiveType}}{{^isUuid}}{{^isFile}}Api.Data.{{/isFile}}{{/isUuid}}{{/primitiveType}}{{/isArray}}{{dataType}}{{#isArray}}){{/isArray}}{{#isMap}}){{/isMap}} + {{/is2xx}} + {{^is2xx}}(){{/is2xx}} + {{/-first}} + {{/responses}} +{{/lambda.removeWhitespace}} + {{operationId}}{{#allParams}} {{>paramName}}{{/allParams}}{{#authMethods}}{{#isBasicBearer}} auth_token{{/isBasicBearer}}{{/authMethods}} = Api.request "{{httpMethod}}" @@ -41,7 +56,18 @@ import Uuid exposing (Uuid){{/includeUuid}} [{{#pathParams}} ( "{{paramName}}", {{>paramToString}} {{>paramName}} ){{#-last}} {{/-last}}{{^-last}},{{/-last}}{{/pathParams}}] [{{#queryParams}} ( "{{baseName}}", {{#required}}Just <| {{/required}}{{^required}}Maybe.map {{/required}}{{>paramToString}} {{>paramName}} ){{#-last}} {{/-last}}{{^-last}},{{/-last}}{{/queryParams}}] [{{#headerParams}} ( "{{baseName}}", {{#required}}Just <| {{/required}}{{^required}}Maybe.map {{/required}}{{>paramToString}} {{>paramName}} ){{#-last}} {{/-last}}{{^-last}},{{/-last}}{{/headerParams}}] - {{#bodyParam}}({{#required}}Just ({{/required}}{{^required}}Maybe.map {{/required}}{{#isModel}}Api.Data.{{/isModel}}{{>recordFieldValueEncoder}} {{>paramName}}{{#required}}){{/required}}){{/bodyParam}}{{^bodyParam}}Nothing{{/bodyParam}} - {{^responses}}(Json.Decode.succeed ()){{/responses}}{{#responses}}{{#is2xx}}{{^dataType}}(Json.Decode.succeed ()){{/dataType}}{{#dataType}}{{>recordFieldValueDecoder}}{{/dataType}}{{/is2xx}}{{/responses}}{{#authMethods}}{{#isBasicBearer}} - |> Api.withBearerToken auth_token{{/isBasicBearer}}{{/authMethods}} -{{/operation}}{{/operations}} \ No newline at end of file + {{#bodyParam}} + (Maybe.map Http.jsonBody ({{#required}}Just ({{/required}}{{^required}}Maybe.map {{/required}}{{#isModel}}Api.Data.{{/isModel}}{{>recordFieldValueEncoder}} {{>paramName}}{{#required}}){{/required}})) + {{/bodyParam}} + {{#formParams.0}} + (Just <| Http.multipartBody <| List.filterMap identity [ {{#formParams}}{{>formParamEncoder}}{{^-last}}, {{/-last}}{{/formParams}} ]) + {{/formParams.0}} + {{^bodyParam}} + {{^formParams}} + Nothing + {{/formParams}} + {{/bodyParam}} + {{#responses}}{{#-first}}{{#is2xx}}{{^dataType}}(Json.Decode.succeed ()){{/dataType}}{{#dataType}}{{>recordFieldValueDecoder}}{{/dataType}}{{/is2xx}}{{^is2xx}}(Json.Decode.succeed ()){{/is2xx}}{{/-first}}{{/responses}}{{^responses}}(Json.Decode.succeed ()){{/responses}} +{{#authMethods}}{{#isBasicBearer}} |> Api.withBearerToken auth_token{{/isBasicBearer}}{{/authMethods}} +{{/operation}} +{{/operations}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/elm/operationParameter.mustache b/modules/openapi-generator/src/main/resources/elm/operationParameter.mustache new file mode 100644 index 000000000000..efab8a972f08 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/elm/operationParameter.mustache @@ -0,0 +1 @@ +{{^required}}Maybe {{/required}}{{#isArray}}{{^required}}({{/required}}List {{/isArray}}{{#isModel}}Api.Data.{{/isModel}}{{#items.isModel}}Api.Data.{{/items.isModel}}{{#isAnyType}}Api.Data.{{/isAnyType}}{{datatypeWithEnum}}{{^datatypeWithEnum}}{{dataType}}{{/datatypeWithEnum}}{{#isArray}}{{^required}}){{/required}}{{/isArray}} \ No newline at end of file From 399d0dfce71ee17b14b5827fa36fd1181e033b84 Mon Sep 17 00:00:00 2001 From: Qluxzz Date: Sun, 16 Apr 2023 21:21:25 +0200 Subject: [PATCH 06/10] Add generated petstore client --- samples/client/petstore/elm/.gitignore | 1 + .../petstore/elm/.openapi-generator-ignore | 23 + .../petstore/elm/.openapi-generator/FILES | 9 + .../petstore/elm/.openapi-generator/VERSION | 1 + samples/client/petstore/elm/README.md | 10 + samples/client/petstore/elm/elm.json | 32 ++ samples/client/petstore/elm/src/Api.elm | 202 +++++++ samples/client/petstore/elm/src/Api/Data.elm | 529 ++++++++++++++++++ .../petstore/elm/src/Api/Request/Pet.elm | 164 ++++++ .../petstore/elm/src/Api/Request/Store.elm | 82 +++ .../petstore/elm/src/Api/Request/User.elm | 134 +++++ samples/client/petstore/elm/src/Api/Time.elm | 70 +++ 12 files changed, 1257 insertions(+) create mode 100644 samples/client/petstore/elm/.gitignore create mode 100644 samples/client/petstore/elm/.openapi-generator-ignore create mode 100644 samples/client/petstore/elm/.openapi-generator/FILES create mode 100644 samples/client/petstore/elm/.openapi-generator/VERSION create mode 100644 samples/client/petstore/elm/README.md create mode 100644 samples/client/petstore/elm/elm.json create mode 100644 samples/client/petstore/elm/src/Api.elm create mode 100644 samples/client/petstore/elm/src/Api/Data.elm create mode 100644 samples/client/petstore/elm/src/Api/Request/Pet.elm create mode 100644 samples/client/petstore/elm/src/Api/Request/Store.elm create mode 100644 samples/client/petstore/elm/src/Api/Request/User.elm create mode 100644 samples/client/petstore/elm/src/Api/Time.elm diff --git a/samples/client/petstore/elm/.gitignore b/samples/client/petstore/elm/.gitignore new file mode 100644 index 000000000000..8b0d053e4e35 --- /dev/null +++ b/samples/client/petstore/elm/.gitignore @@ -0,0 +1 @@ +/elm-stuff \ No newline at end of file diff --git a/samples/client/petstore/elm/.openapi-generator-ignore b/samples/client/petstore/elm/.openapi-generator-ignore new file mode 100644 index 000000000000..7484ee590a38 --- /dev/null +++ b/samples/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/client/petstore/elm/.openapi-generator/FILES b/samples/client/petstore/elm/.openapi-generator/FILES new file mode 100644 index 000000000000..0095b315ebb9 --- /dev/null +++ b/samples/client/petstore/elm/.openapi-generator/FILES @@ -0,0 +1,9 @@ +.gitignore +README.md +elm.json +src/Api.elm +src/Api/Data.elm +src/Api/Request/Pet.elm +src/Api/Request/Store.elm +src/Api/Request/User.elm +src/Api/Time.elm diff --git a/samples/client/petstore/elm/.openapi-generator/VERSION b/samples/client/petstore/elm/.openapi-generator/VERSION new file mode 100644 index 000000000000..ba8a874deab9 --- /dev/null +++ b/samples/client/petstore/elm/.openapi-generator/VERSION @@ -0,0 +1 @@ +6.6.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/elm/README.md b/samples/client/petstore/elm/README.md new file mode 100644 index 000000000000..3f36740911ae --- /dev/null +++ b/samples/client/petstore/elm/README.md @@ -0,0 +1,10 @@ +# Elm API client + +This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + +## Overview +This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [openapi-spec](https://github.com/OAI/OpenAPI-Specification) from a remote server, you can easily generate an API client. + +- API version: 1.0.0 +- Package version: +- Build package: org.openapitools.codegen.languages.ElmClientCodegen diff --git a/samples/client/petstore/elm/elm.json b/samples/client/petstore/elm/elm.json new file mode 100644 index 000000000000..c3a1d917242f --- /dev/null +++ b/samples/client/petstore/elm/elm.json @@ -0,0 +1,32 @@ +{ + "type": "application", + "source-directories": [ + "src" + ], + "elm-version": "0.19.1", + "dependencies": { + "direct": { + "danyx23/elm-uuid": "2.1.2", + "elm/browser": "1.0.1", + "elm/core": "1.0.2", + "elm/file": "1.0.1", + "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/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/client/petstore/elm/src/Api.elm b/samples/client/petstore/elm/src/Api.elm new file mode 100644 index 000000000000..c70421bbda74 --- /dev/null +++ b/samples/client/petstore/elm/src/Api.elm @@ -0,0 +1,202 @@ +module Api exposing + ( Request + , request + , send + , sendWithCustomError + , sendWithCustomExpect + , task + , map + , withBasePath + , withTimeout + , withTracker + , withBearerToken + , withHeader + , withHeaders + ) + +import Http +import Json.Decode +import Json.Encode +import Task +import Url.Builder + + +type Request a = + Request + { method : String + , headers : List Http.Header + , basePath : String + , pathParams : List String + , queryParams : List Url.Builder.QueryParameter + , body : Http.Body + , decoder : Json.Decode.Decoder a + , timeout : Maybe Float + , tracker : Maybe String + } + + +request : String -> String -> List ( String, String ) -> List (String, Maybe String) -> List (String, Maybe String) -> Maybe Http.Body -> Json.Decode.Decoder a -> Request a +request method path pathParams queryParams headerParams body decoder = + Request + { method = method + , headers = headers headerParams + , basePath = "http://petstore.swagger.io/v2" + , pathParams = interpolatePath path pathParams + , queryParams = queries queryParams + , body = Maybe.withDefault Http.emptyBody body + , decoder = decoder + , timeout = Nothing + , tracker = Nothing + } + + +send : (Result Http.Error a -> msg) -> Request a -> Cmd msg +send toMsg req = + sendWithCustomError identity toMsg req + + +sendWithCustomError : (Http.Error -> e) -> (Result e a -> msg) -> Request a -> Cmd msg +sendWithCustomError mapError toMsg req = + sendWithCustomExpect (expectJson mapError toMsg) req + + +sendWithCustomExpect : (Json.Decode.Decoder a -> Http.Expect msg) -> Request a -> Cmd msg +sendWithCustomExpect expect (Request req) = + Http.request + { method = req.method + , headers = req.headers + , url = Url.Builder.crossOrigin req.basePath req.pathParams req.queryParams + , body = req.body + , expect = expect req.decoder + , timeout = req.timeout + , tracker = req.tracker + } + + +task : Request a -> Task.Task Http.Error a +task (Request req) = + Http.task + { method = req.method + , headers = req.headers + , url = Url.Builder.crossOrigin req.basePath req.pathParams req.queryParams + , body = req.body + , resolver = jsonResolver req.decoder + , timeout = req.timeout + } + + +map : (a -> b) -> Request a -> Request b +map fn (Request req) = + Request + { method = req.method + , headers = req.headers + , basePath = req.basePath + , pathParams = req.pathParams + , queryParams = req.queryParams + , body = req.body + , decoder = Json.Decode.map fn req.decoder + , timeout = req.timeout + , tracker = req.tracker + } + +withBasePath : String -> Request a -> Request a +withBasePath basePath (Request req) = + Request { req | basePath = basePath } + + +withTimeout : Float -> Request a -> Request a +withTimeout timeout (Request req) = + Request { req | timeout = Just timeout } + + +withTracker : String -> Request a -> Request a +withTracker tracker (Request req) = + Request { req | tracker = Just tracker } + + +withBearerToken : String -> Request a -> Request a +withBearerToken token (Request req) = + Request { req | headers = Http.header "Authorization" ("Bearer " ++ token) :: req.headers } + + +withHeader : String -> String -> Request a -> Request a +withHeader key value (Request req) = + Request { req | headers = req.headers ++ [ Http.header key value ] } + + +withHeaders : List ( String, String ) -> Request a -> Request a +withHeaders headers_ (Request req) = + Request { req | headers = req.headers ++ headers (List.map (Tuple.mapSecond Just) headers_) } + + +-- HELPER + + +headers : List (String, Maybe String) -> List Http.Header +headers = + List.filterMap (\(key, value) -> Maybe.map (Http.header key) value) + + +interpolatePath : String -> List ( String, String ) -> List String +interpolatePath rawPath pathParams = + let + interpolate = + (\(name, value) path -> String.replace ("{" ++ name ++ "}") value path) + in + List.foldl interpolate rawPath pathParams + |> String.split "/" + |> List.drop 1 + + +queries : List (String, Maybe String) -> List Url.Builder.QueryParameter +queries = + List.filterMap (\(key, value) -> Maybe.map (Url.Builder.string key) value) + + +expectJson : (Http.Error -> e) -> (Result e a -> msg) -> Json.Decode.Decoder a -> Http.Expect msg +expectJson mapError toMsg decoder = + Http.expectStringResponse toMsg (Result.mapError mapError << decodeResponse decoder) + + +jsonResolver : Json.Decode.Decoder a -> Http.Resolver Http.Error a +jsonResolver decoder = + Http.stringResolver (decodeResponse decoder) + + +decodeResponse : Json.Decode.Decoder a -> Http.Response String -> Result Http.Error a +decodeResponse decoder response = + case response of + Http.BadUrl_ url -> + Err (Http.BadUrl url) + + Http.Timeout_ -> + Err Http.Timeout + + Http.NetworkError_ -> + Err Http.NetworkError + + Http.BadStatus_ metadata _ -> + Err (Http.BadStatus metadata.statusCode) + + Http.GoodStatus_ _ body -> + if String.isEmpty body then + -- we might 'expect' no body if the return type is `()` + case Json.Decode.decodeString decoder "{}" of + Ok value -> + Ok value + + Err _ -> + decodeBody decoder body + + else + decodeBody decoder body + + +decodeBody : Json.Decode.Decoder a -> String -> Result Http.Error a +decodeBody decoder body = + case Json.Decode.decodeString decoder body of + Ok value -> + Ok value + + Err err -> + Err (Http.BadBody (Json.Decode.errorToString err)) diff --git a/samples/client/petstore/elm/src/Api/Data.elm b/samples/client/petstore/elm/src/Api/Data.elm new file mode 100644 index 000000000000..abf9425b1ba3 --- /dev/null +++ b/samples/client/petstore/elm/src/Api/Data.elm @@ -0,0 +1,529 @@ +{- + OpenAPI Petstore + This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + + The version of the OpenAPI document: 1.0.0 + + NOTE: This file is auto generated by the openapi-generator. + https://github.com/openapitools/openapi-generator.git + + DO NOT EDIT THIS FILE MANUALLY. + + For more info on generating Elm code, see https://eriktim.github.io/openapi-elm/ +-} + + +module Api.Data exposing + ( ApiResponse + , Category + , Order_, Order_Status(..), orderStatusVariants + , Pet, PetStatus(..), petStatusVariants + , Tag + , User + , encodeApiResponse + , encodeCategory + , encodeOrder + , encodePet + , encodeTag + , encodeUser + , apiResponseDecoder + , categoryDecoder + , orderDecoder + , petDecoder + , tagDecoder + , userDecoder + ) + +import Api +import Api.Time exposing (Posix) +import Dict +import Json.Decode +import Json.Encode + + +-- MODEL + + +{-| Describes the result of uploading an image resource +-} +type alias ApiResponse = + { code : Maybe Int + , type_ : Maybe String + , message : Maybe String + } + + +{-| A category for a pet +-} +type alias Category = + { id : Maybe Int + , name : Maybe String + } + + +{-| An order for a pets from the pet store +-} +type alias Order_ = + { id : Maybe Int + , petId : Maybe Int + , quantity : Maybe Int + , shipDate : Maybe Posix + , status : Maybe Order_Status + , complete : Maybe Bool + } + + +type Order_Status + = Order_StatusPlaced + | Order_StatusApproved + | Order_StatusDelivered + + +orderStatusVariants : List Order_Status +orderStatusVariants = + [ Order_StatusPlaced + , Order_StatusApproved + , Order_StatusDelivered + ] + + +{-| A pet for sale in the pet store +-} +type alias Pet = + { id : Maybe Int + , category : Maybe Category + , name : String + , photoUrls : List String + , tags : Maybe ( List Tag ) + , status : Maybe PetStatus + } + + +type PetStatus + = PetStatusAvailable + | PetStatusPending + | PetStatusSold + + +petStatusVariants : List PetStatus +petStatusVariants = + [ PetStatusAvailable + , PetStatusPending + , PetStatusSold + ] + + +{-| A tag for a pet +-} +type alias Tag = + { id : Maybe Int + , name : Maybe String + } + + +{-| A User who is purchasing from the pet store +-} +type alias User = + { id : Maybe Int + , username : Maybe String + , firstName : Maybe String + , lastName : Maybe String + , email : Maybe String + , password : Maybe String + , phone : Maybe String + , userStatus : Maybe Int + } + + +-- ENCODER + + +encodeApiResponse : ApiResponse -> Json.Encode.Value +encodeApiResponse = + encodeObject << encodeApiResponsePairs + + +encodeApiResponseWithTag : ( String, String ) -> ApiResponse -> Json.Encode.Value +encodeApiResponseWithTag (tagField, tag) model = + encodeObject (encodeApiResponsePairs model ++ [ encode tagField Json.Encode.string tag ]) + + +encodeApiResponsePairs : ApiResponse -> List EncodedField +encodeApiResponsePairs model = + let + pairs = + [ maybeEncode "code" Json.Encode.int model.code + , maybeEncode "type" Json.Encode.string model.type_ + , maybeEncode "message" Json.Encode.string model.message + ] + in + pairs + + +encodeCategory : Category -> Json.Encode.Value +encodeCategory = + encodeObject << encodeCategoryPairs + + +encodeCategoryWithTag : ( String, String ) -> Category -> Json.Encode.Value +encodeCategoryWithTag (tagField, tag) model = + encodeObject (encodeCategoryPairs model ++ [ encode tagField Json.Encode.string tag ]) + + +encodeCategoryPairs : Category -> List EncodedField +encodeCategoryPairs model = + let + pairs = + [ maybeEncode "id" Json.Encode.int model.id + , maybeEncode "name" Json.Encode.string model.name + ] + in + pairs + + +encodeOrder : Order_ -> Json.Encode.Value +encodeOrder = + encodeObject << encodeOrderPairs + + +encodeOrderWithTag : ( String, String ) -> Order_ -> Json.Encode.Value +encodeOrderWithTag (tagField, tag) model = + encodeObject (encodeOrderPairs model ++ [ encode tagField Json.Encode.string tag ]) + + +encodeOrderPairs : Order_ -> List EncodedField +encodeOrderPairs model = + let + pairs = + [ maybeEncode "id" Json.Encode.int model.id + , maybeEncode "petId" Json.Encode.int model.petId + , maybeEncode "quantity" Json.Encode.int model.quantity + , maybeEncode "shipDate" Api.Time.encodeDateTime model.shipDate + , maybeEncode "status" encodeOrderStatus model.status + , maybeEncode "complete" Json.Encode.bool model.complete + ] + in + pairs + +stringFromOrder_Status : Order_Status -> String +stringFromOrder_Status model = + case model of + Order_StatusPlaced -> + "placed" + + Order_StatusApproved -> + "approved" + + Order_StatusDelivered -> + "delivered" + + +encodeOrderStatus : Order_Status -> Json.Encode.Value +encodeOrderStatus = + Json.Encode.string << stringFromOrder_Status + + + +encodePet : Pet -> Json.Encode.Value +encodePet = + encodeObject << encodePetPairs + + +encodePetWithTag : ( String, String ) -> Pet -> Json.Encode.Value +encodePetWithTag (tagField, tag) model = + encodeObject (encodePetPairs model ++ [ encode tagField Json.Encode.string tag ]) + + +encodePetPairs : Pet -> List EncodedField +encodePetPairs model = + let + pairs = + [ maybeEncode "id" Json.Encode.int model.id + , maybeEncode "category" encodeCategory model.category + , encode "name" Json.Encode.string model.name + , encode "photoUrls" (Json.Encode.list Json.Encode.string) model.photoUrls + , maybeEncode "tags" (Json.Encode.list encodeTag) model.tags + , maybeEncode "status" encodePetStatus model.status + ] + in + pairs + +stringFromPetStatus : PetStatus -> String +stringFromPetStatus model = + case model of + PetStatusAvailable -> + "available" + + PetStatusPending -> + "pending" + + PetStatusSold -> + "sold" + + +encodePetStatus : PetStatus -> Json.Encode.Value +encodePetStatus = + Json.Encode.string << stringFromPetStatus + + + +encodeTag : Tag -> Json.Encode.Value +encodeTag = + encodeObject << encodeTagPairs + + +encodeTagWithTag : ( String, String ) -> Tag -> Json.Encode.Value +encodeTagWithTag (tagField, tag) model = + encodeObject (encodeTagPairs model ++ [ encode tagField Json.Encode.string tag ]) + + +encodeTagPairs : Tag -> List EncodedField +encodeTagPairs model = + let + pairs = + [ maybeEncode "id" Json.Encode.int model.id + , maybeEncode "name" Json.Encode.string model.name + ] + in + pairs + + +encodeUser : User -> Json.Encode.Value +encodeUser = + encodeObject << encodeUserPairs + + +encodeUserWithTag : ( String, String ) -> User -> Json.Encode.Value +encodeUserWithTag (tagField, tag) model = + encodeObject (encodeUserPairs model ++ [ encode tagField Json.Encode.string tag ]) + + +encodeUserPairs : User -> List EncodedField +encodeUserPairs model = + let + pairs = + [ maybeEncode "id" Json.Encode.int model.id + , maybeEncode "username" Json.Encode.string model.username + , maybeEncode "firstName" Json.Encode.string model.firstName + , maybeEncode "lastName" Json.Encode.string model.lastName + , maybeEncode "email" Json.Encode.string model.email + , maybeEncode "password" Json.Encode.string model.password + , maybeEncode "phone" Json.Encode.string model.phone + , maybeEncode "userStatus" Json.Encode.int model.userStatus + ] + in + pairs + + +-- DECODER + + +apiResponseDecoder : Json.Decode.Decoder ApiResponse +apiResponseDecoder = + Json.Decode.succeed ApiResponse + |> maybeDecode "code" Json.Decode.int Nothing + |> maybeDecode "type" Json.Decode.string Nothing + |> maybeDecode "message" Json.Decode.string Nothing + + +categoryDecoder : Json.Decode.Decoder Category +categoryDecoder = + Json.Decode.succeed Category + |> maybeDecode "id" Json.Decode.int Nothing + |> maybeDecode "name" Json.Decode.string Nothing + + +orderDecoder : Json.Decode.Decoder Order_ +orderDecoder = + Json.Decode.succeed Order_ + |> maybeDecode "id" Json.Decode.int Nothing + |> maybeDecode "petId" Json.Decode.int Nothing + |> maybeDecode "quantity" Json.Decode.int Nothing + |> maybeDecode "shipDate" Api.Time.dateTimeDecoder Nothing + |> maybeDecode "status" orderStatusDecoder Nothing + |> maybeDecode "complete" Json.Decode.bool (Just False) + + +orderStatusDecoder : Json.Decode.Decoder Order_Status +orderStatusDecoder = + Json.Decode.string + |> Json.Decode.andThen + (\value -> + case value of + "placed" -> + Json.Decode.succeed Order_StatusPlaced + + "approved" -> + Json.Decode.succeed Order_StatusApproved + + "delivered" -> + Json.Decode.succeed Order_StatusDelivered + + other -> + Json.Decode.fail <| "Unknown type: " ++ other + ) + + + +petDecoder : Json.Decode.Decoder Pet +petDecoder = + Json.Decode.succeed Pet + |> maybeDecode "id" Json.Decode.int Nothing + |> maybeDecode "category" categoryDecoder Nothing + |> decode "name" Json.Decode.string + |> decode "photoUrls" (Json.Decode.list Json.Decode.string) + |> maybeDecode "tags" (Json.Decode.list tagDecoder) Nothing + |> maybeDecode "status" petStatusDecoder Nothing + + +petStatusDecoder : Json.Decode.Decoder PetStatus +petStatusDecoder = + Json.Decode.string + |> Json.Decode.andThen + (\value -> + case value of + "available" -> + Json.Decode.succeed PetStatusAvailable + + "pending" -> + Json.Decode.succeed PetStatusPending + + "sold" -> + Json.Decode.succeed PetStatusSold + + other -> + Json.Decode.fail <| "Unknown type: " ++ other + ) + + + +tagDecoder : Json.Decode.Decoder Tag +tagDecoder = + Json.Decode.succeed Tag + |> maybeDecode "id" Json.Decode.int Nothing + |> maybeDecode "name" Json.Decode.string Nothing + + +userDecoder : Json.Decode.Decoder User +userDecoder = + Json.Decode.succeed User + |> maybeDecode "id" Json.Decode.int Nothing + |> maybeDecode "username" Json.Decode.string Nothing + |> maybeDecode "firstName" Json.Decode.string Nothing + |> maybeDecode "lastName" Json.Decode.string Nothing + |> maybeDecode "email" Json.Decode.string Nothing + |> maybeDecode "password" Json.Decode.string Nothing + |> maybeDecode "phone" Json.Decode.string Nothing + |> maybeDecode "userStatus" Json.Decode.int Nothing + + + + +-- HELPER + + +type alias EncodedField = + Maybe ( String, Json.Encode.Value ) + + +encodeObject : List EncodedField -> Json.Encode.Value +encodeObject = + Json.Encode.object << List.filterMap identity + + +encode : String -> (a -> Json.Encode.Value) -> a -> EncodedField +encode key encoder value = + Just ( key, encoder value ) + + +encodeNullable : String -> (a -> Json.Encode.Value) -> Maybe a -> EncodedField +encodeNullable key encoder value = + Just ( key, Maybe.withDefault Json.Encode.null (Maybe.map encoder value) ) + + +maybeEncode : String -> (a -> Json.Encode.Value) -> Maybe a -> EncodedField +maybeEncode key encoder = + Maybe.map (Tuple.pair key << encoder) + + +maybeEncodeNullable : String -> (a -> Json.Encode.Value) -> Maybe a -> EncodedField +maybeEncodeNullable = + encodeNullable + + +decode : String -> Json.Decode.Decoder a -> Json.Decode.Decoder (a -> b) -> Json.Decode.Decoder b +decode key decoder = + decodeChain (Json.Decode.field key decoder) + + +decodeLazy : (a -> c) -> String -> Json.Decode.Decoder a -> Json.Decode.Decoder (c -> b) -> Json.Decode.Decoder b +decodeLazy f key decoder = + decodeChainLazy f (Json.Decode.field key decoder) + + +decodeNullable : String -> Json.Decode.Decoder a -> Json.Decode.Decoder (Maybe a -> b) -> Json.Decode.Decoder b +decodeNullable key decoder = + decodeChain (maybeField key decoder Nothing) + + +decodeNullableLazy : (Maybe a -> c) -> String -> Json.Decode.Decoder a -> Json.Decode.Decoder (c -> b) -> Json.Decode.Decoder b +decodeNullableLazy f key decoder = + decodeChainLazy f (maybeField key decoder Nothing) + + +maybeDecode : String -> Json.Decode.Decoder a -> Maybe a -> Json.Decode.Decoder (Maybe a -> b) -> Json.Decode.Decoder b +maybeDecode key decoder fallback = + -- let's be kind to null-values as well + decodeChain (maybeField key decoder fallback) + + +maybeDecodeLazy : (Maybe a -> c) -> String -> Json.Decode.Decoder a -> Maybe a -> Json.Decode.Decoder (c -> b) -> Json.Decode.Decoder b +maybeDecodeLazy f key decoder fallback = + -- let's be kind to null-values as well + decodeChainLazy f (maybeField key decoder fallback) + + +maybeDecodeNullable : String -> Json.Decode.Decoder a -> Maybe a -> Json.Decode.Decoder (Maybe a -> b) -> Json.Decode.Decoder b +maybeDecodeNullable key decoder fallback = + decodeChain (maybeField key decoder fallback) + + +maybeDecodeNullableLazy : (Maybe a -> c) -> String -> Json.Decode.Decoder a -> Maybe a -> Json.Decode.Decoder (c -> b) -> Json.Decode.Decoder b +maybeDecodeNullableLazy f key decoder fallback = + decodeChainLazy f (maybeField key decoder fallback) + + +maybeField : String -> Json.Decode.Decoder a -> Maybe a -> Json.Decode.Decoder (Maybe a) +maybeField key decoder fallback = + let + fieldDecoder = + Json.Decode.field key Json.Decode.value + + valueDecoder = + Json.Decode.oneOf [ Json.Decode.map Just decoder, Json.Decode.null fallback ] + + decodeObject rawObject = + case Json.Decode.decodeValue fieldDecoder rawObject of + Ok rawValue -> + case Json.Decode.decodeValue valueDecoder rawValue of + Ok value -> + Json.Decode.succeed value + + Err error -> + Json.Decode.fail (Json.Decode.errorToString error) + + Err _ -> + Json.Decode.succeed fallback + in + Json.Decode.value + |> Json.Decode.andThen decodeObject + + +decodeChain : Json.Decode.Decoder a -> Json.Decode.Decoder (a -> b) -> Json.Decode.Decoder b +decodeChain = + Json.Decode.map2 (|>) + + +decodeChainLazy : (a -> c) -> Json.Decode.Decoder a -> Json.Decode.Decoder (c -> b) -> Json.Decode.Decoder b +decodeChainLazy f = + decodeChain << Json.Decode.map f \ No newline at end of file diff --git a/samples/client/petstore/elm/src/Api/Request/Pet.elm b/samples/client/petstore/elm/src/Api/Request/Pet.elm new file mode 100644 index 000000000000..732a42be48c0 --- /dev/null +++ b/samples/client/petstore/elm/src/Api/Request/Pet.elm @@ -0,0 +1,164 @@ +{- + OpenAPI Petstore + This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + + The version of the OpenAPI document: 1.0.0 + + NOTE: This file is auto generated by the openapi-generator. + https://github.com/openapitools/openapi-generator.git + + DO NOT EDIT THIS FILE MANUALLY. + + For more info on generating Elm code, see https://eriktim.github.io/openapi-elm/ +-} + + +module Api.Request.Pet exposing + ( addPet + , deletePet + , findPetsByStatus, Status(..), statusVariants + , findPetsByTags + , getPetById + , updatePet + , updatePetWithForm + , uploadFile + ) + +import Api +import Api.Data exposing (..) +import Dict +import Http +import Json.Decode +import Json.Encode +import File exposing (File) + + +type Status + = StatusAvailable + | StatusPending + | StatusSold + + +statusVariants : List Status +statusVariants = + [ StatusAvailable + , StatusPending + , StatusSold + ] + + +stringFromStatus : Status -> String +stringFromStatus model = + case model of + StatusAvailable -> + "available" + + StatusPending -> + "pending" + + StatusSold -> + "sold" + + + +addPet : Api.Data.Pet -> Api.Request Api.Data.Pet +addPet pet_body = + Api.request + "POST" + "/pet" + [] + [] + [] + (Maybe.map Http.jsonBody (Just (Api.Data.encodePet pet_body))) + Api.Data.petDecoder + + +deletePet : Int -> Maybe String -> Api.Request () +deletePet petId_path apiKey_header = + Api.request + "DELETE" + "/pet/{petId}" + [ ( "petId", String.fromInt petId_path ) ] + [] + [ ( "api_key", Maybe.map identity apiKey_header ) ] + Nothing + (Json.Decode.succeed ()) + + +{-| Multiple status values can be provided with comma separated strings +-} +findPetsByStatus : List Status -> Api.Request (List Api.Data.Pet) +findPetsByStatus status_query = + Api.request + "GET" + "/pet/findByStatus" + [] + [ ( "status", Just <| (String.join "," << List.map stringFromStatus) status_query ) ] + [] + Nothing + (Json.Decode.list Api.Data.petDecoder) + + +{-| Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. +-} +findPetsByTags : List String -> Api.Request (List Api.Data.Pet) +findPetsByTags tags_query = + Api.request + "GET" + "/pet/findByTags" + [] + [ ( "tags", Just <| (String.join "," << List.map identity) tags_query ) ] + [] + Nothing + (Json.Decode.list Api.Data.petDecoder) + + +{-| Returns a single pet +-} +getPetById : Int -> Api.Request Api.Data.Pet +getPetById petId_path = + Api.request + "GET" + "/pet/{petId}" + [ ( "petId", String.fromInt petId_path ) ] + [] + [] + Nothing + Api.Data.petDecoder + + +updatePet : Api.Data.Pet -> Api.Request Api.Data.Pet +updatePet pet_body = + Api.request + "PUT" + "/pet" + [] + [] + [] + (Maybe.map Http.jsonBody (Just (Api.Data.encodePet pet_body))) + Api.Data.petDecoder + + +updatePetWithForm : Int -> Maybe String -> Maybe String -> Api.Request () +updatePetWithForm petId_path name status = + Api.request + "POST" + "/pet/{petId}" + [ ( "petId", String.fromInt petId_path ) ] + [] + [] + (Just <| Http.multipartBody <| List.filterMap identity [ Maybe.map (Http.stringPart "name") name, Maybe.map (Http.stringPart "status") status ]) + (Json.Decode.succeed ()) + + +uploadFile : Int -> Maybe String -> Maybe File -> Api.Request Api.Data.ApiResponse +uploadFile petId_path additionalMetadata file = + Api.request + "POST" + "/pet/{petId}/uploadImage" + [ ( "petId", String.fromInt petId_path ) ] + [] + [] + (Just <| Http.multipartBody <| List.filterMap identity [ Maybe.map (Http.stringPart "additionalMetadata") additionalMetadata, Maybe.map (Http.filePart "file") file ]) + Api.Data.apiResponseDecoder + diff --git a/samples/client/petstore/elm/src/Api/Request/Store.elm b/samples/client/petstore/elm/src/Api/Request/Store.elm new file mode 100644 index 000000000000..510df2dc37ee --- /dev/null +++ b/samples/client/petstore/elm/src/Api/Request/Store.elm @@ -0,0 +1,82 @@ +{- + OpenAPI Petstore + This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + + The version of the OpenAPI document: 1.0.0 + + NOTE: This file is auto generated by the openapi-generator. + https://github.com/openapitools/openapi-generator.git + + DO NOT EDIT THIS FILE MANUALLY. + + For more info on generating Elm code, see https://eriktim.github.io/openapi-elm/ +-} + + +module Api.Request.Store exposing + ( deleteOrder + , getInventory + , getOrderById + , placeOrder + ) + +import Api +import Api.Data exposing (..) +import Dict +import Http +import Json.Decode +import Json.Encode + +{-| For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors +-} +deleteOrder : String -> Api.Request () +deleteOrder orderId_path = + Api.request + "DELETE" + "/store/order/{orderId}" + [ ( "orderId", identity orderId_path ) ] + [] + [] + Nothing + (Json.Decode.succeed ()) + + +{-| Returns a map of status codes to quantities +-} +getInventory : Api.Request (Dict.Dict String Int) +getInventory = + Api.request + "GET" + "/store/inventory" + [] + [] + [] + Nothing + (Json.Decode.dict Json.Decode.int) + + +{-| For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions +-} +getOrderById : Int -> Api.Request Api.Data.Order_ +getOrderById orderId_path = + Api.request + "GET" + "/store/order/{orderId}" + [ ( "orderId", String.fromInt orderId_path ) ] + [] + [] + Nothing + Api.Data.orderDecoder + + +placeOrder : Api.Data.Order_ -> Api.Request Api.Data.Order_ +placeOrder order_body = + Api.request + "POST" + "/store/order" + [] + [] + [] + (Maybe.map Http.jsonBody (Just (Api.Data.encodeOrder order_body))) + Api.Data.orderDecoder + diff --git a/samples/client/petstore/elm/src/Api/Request/User.elm b/samples/client/petstore/elm/src/Api/Request/User.elm new file mode 100644 index 000000000000..c45fc20b7a93 --- /dev/null +++ b/samples/client/petstore/elm/src/Api/Request/User.elm @@ -0,0 +1,134 @@ +{- + OpenAPI Petstore + This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + + The version of the OpenAPI document: 1.0.0 + + NOTE: This file is auto generated by the openapi-generator. + https://github.com/openapitools/openapi-generator.git + + DO NOT EDIT THIS FILE MANUALLY. + + For more info on generating Elm code, see https://eriktim.github.io/openapi-elm/ +-} + + +module Api.Request.User exposing + ( createUser + , createUsersWithArrayInput + , createUsersWithListInput + , deleteUser + , getUserByName + , loginUser + , logoutUser + , updateUser + ) + +import Api +import Api.Data exposing (..) +import Dict +import Http +import Json.Decode +import Json.Encode + +{-| This can only be done by the logged in user. +-} +createUser : Api.Data.User -> Api.Request () +createUser user_body = + Api.request + "POST" + "/user" + [] + [] + [] + (Maybe.map Http.jsonBody (Just (Api.Data.encodeUser user_body))) + (Json.Decode.succeed ()) + + +createUsersWithArrayInput : List Api.Data.User -> Api.Request () +createUsersWithArrayInput user_body = + Api.request + "POST" + "/user/createWithArray" + [] + [] + [] + (Maybe.map Http.jsonBody (Just (Json.Encode.list encodeUser user_body))) + (Json.Decode.succeed ()) + + +createUsersWithListInput : List Api.Data.User -> Api.Request () +createUsersWithListInput user_body = + Api.request + "POST" + "/user/createWithList" + [] + [] + [] + (Maybe.map Http.jsonBody (Just (Json.Encode.list encodeUser user_body))) + (Json.Decode.succeed ()) + + +{-| This can only be done by the logged in user. +-} +deleteUser : String -> Api.Request () +deleteUser username_path = + Api.request + "DELETE" + "/user/{username}" + [ ( "username", identity username_path ) ] + [] + [] + Nothing + (Json.Decode.succeed ()) + + +getUserByName : String -> Api.Request Api.Data.User +getUserByName username_path = + Api.request + "GET" + "/user/{username}" + [ ( "username", identity username_path ) ] + [] + [] + Nothing + Api.Data.userDecoder + + +loginUser : String -> String -> Api.Request String +loginUser username_query password_query = + Api.request + "GET" + "/user/login" + [] + [ ( "username", Just <| identity username_query ), ( "password", Just <| identity password_query ) ] + [] + Nothing + Json.Decode.string + + +logoutUser : Api.Request () +logoutUser = + Api.request + "GET" + "/user/logout" + [] + [] + [] + Nothing + (Json.Decode.succeed ()) + + +{-| This can only be done by the logged in user. +-} +updateUser : String -> Api.Data.User -> Api.Request () +updateUser username_path user_body = + Api.request + "PUT" + "/user/{username}" + [ ( "username", identity username_path ) ] + [] + [] + (Maybe.map Http.jsonBody (Just (Api.Data.encodeUser user_body))) + (Json.Decode.succeed ()) + diff --git a/samples/client/petstore/elm/src/Api/Time.elm b/samples/client/petstore/elm/src/Api/Time.elm new file mode 100644 index 000000000000..a44ce3de7728 --- /dev/null +++ b/samples/client/petstore/elm/src/Api/Time.elm @@ -0,0 +1,70 @@ +module Api.Time exposing + ( Posix + , dateToString + , dateTimeToString + , encodeDate + , encodeDateTime + , dateDecoder + , dateTimeDecoder + ) + +import Http +import Iso8601 +import Json.Decode +import Json.Encode +import Time + + +type alias Posix = Time.Posix + + +dateToString : Posix -> String +dateToString = + String.left 10 << dateTimeToString + + +dateTimeToString : Posix -> String +dateTimeToString = + Iso8601.fromTime + + +encodeDate : Posix -> Json.Encode.Value +encodeDate = + Json.Encode.string << dateToString + + +encodeDateTime : Posix -> Json.Encode.Value +encodeDateTime = + Json.Encode.string << dateTimeToString + + +dateDecoder : Json.Decode.Decoder Posix +dateDecoder = + Json.Decode.string + |> Json.Decode.andThen decodeDateIsoString + + +decodeDateIsoString : String -> Json.Decode.Decoder Posix +decodeDateIsoString str = + case Iso8601.toTime (str ++ "T00:00:00.000Z") of + Result.Ok posix -> + Json.Decode.succeed posix + + Result.Err _ -> + Json.Decode.fail ("Invalid calendar date: " ++ str) + + +dateTimeDecoder : Json.Decode.Decoder Posix +dateTimeDecoder = + Json.Decode.string + |> Json.Decode.andThen decodeDateTimeIsoString + + +decodeDateTimeIsoString : String -> Json.Decode.Decoder Posix +decodeDateTimeIsoString str = + case Iso8601.toTime str of + Result.Ok posix -> + Json.Decode.succeed posix + + Result.Err _ -> + Json.Decode.fail ("Invalid ISO date: " ++ str) \ No newline at end of file From c4dd470c4fb0d790e7310780bfaa2cf770d7d011 Mon Sep 17 00:00:00 2001 From: Qluxzz Date: Sun, 16 Apr 2023 21:21:32 +0200 Subject: [PATCH 07/10] Regenerate existing elm client --- samples/openapi3/client/elm/elm.json | 2 +- samples/openapi3/client/elm/src/Api.elm | 4 ++-- samples/openapi3/client/elm/src/Api/Data.elm | 14 ++++++++------ .../client/elm/src/Api/Request/Default.elm | 11 ++--------- .../client/elm/src/Api/Request/Primitive.elm | 7 +++---- 5 files changed, 16 insertions(+), 22 deletions(-) diff --git a/samples/openapi3/client/elm/elm.json b/samples/openapi3/client/elm/elm.json index bf0d1f8f4b6e..c3a1d917242f 100644 --- a/samples/openapi3/client/elm/elm.json +++ b/samples/openapi3/client/elm/elm.json @@ -9,6 +9,7 @@ "danyx23/elm-uuid": "2.1.2", "elm/browser": "1.0.1", "elm/core": "1.0.2", + "elm/file": "1.0.1", "elm/html": "1.0.0", "elm/http": "2.0.0", "elm/json": "1.1.2", @@ -18,7 +19,6 @@ }, "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", diff --git a/samples/openapi3/client/elm/src/Api.elm b/samples/openapi3/client/elm/src/Api.elm index 9d6f5de1e7e1..04fde8b6bd7b 100644 --- a/samples/openapi3/client/elm/src/Api.elm +++ b/samples/openapi3/client/elm/src/Api.elm @@ -35,7 +35,7 @@ type Request a = } -request : String -> String -> List ( String, String ) -> List (String, Maybe String) -> List (String, Maybe String) -> Maybe Json.Encode.Value -> Json.Decode.Decoder a -> Request a +request : String -> String -> List ( String, String ) -> List (String, Maybe String) -> List (String, Maybe String) -> Maybe Http.Body -> Json.Decode.Decoder a -> Request a request method path pathParams queryParams headerParams body decoder = Request { method = method @@ -43,7 +43,7 @@ request method path pathParams queryParams headerParams body decoder = , basePath = "http://localhost:9000" , pathParams = interpolatePath path pathParams , queryParams = queries queryParams - , body = Maybe.withDefault Http.emptyBody (Maybe.map Http.jsonBody body) + , body = Maybe.withDefault Http.emptyBody body , decoder = decoder , timeout = Nothing , tracker = Nothing diff --git a/samples/openapi3/client/elm/src/Api/Data.elm b/samples/openapi3/client/elm/src/Api/Data.elm index 200e64e42c37..b3ad6966ee15 100644 --- a/samples/openapi3/client/elm/src/Api/Data.elm +++ b/samples/openapi3/client/elm/src/Api/Data.elm @@ -48,6 +48,8 @@ module Api.Data exposing , encodeRecursion , encodeRecursionLoop , encodeUnsafeCharacters + , stringFromEnum + , stringFromEnumeric , absentDecoder , arrayDecoder , composedDecoder @@ -89,10 +91,10 @@ type alias Absent = {-| Model with arrays -} type alias Array = - { array : List (String) - , arrayOfArray : List (List (String)) - , arrayOfPrimitive : Maybe (List (Primitive)) - , arrayOfEnum : Maybe (List (Enum)) + { array : List String + , arrayOfArray : List (List String) + , arrayOfPrimitive : Maybe ( List Primitive ) + , arrayOfEnum : Maybe ( List Enum ) } @@ -216,10 +218,10 @@ unwrapRecursionMaybe : RecursionMaybe -> Maybe Recursion unwrapRecursionMaybe (RecursionMaybe maybe) = maybe -type RecursionList = RecursionList (Maybe (List (Recursion))) +type RecursionList = RecursionList (Maybe ( List Recursion )) -unwrapRecursionList : RecursionList -> Maybe (List (Recursion)) +unwrapRecursionList : RecursionList -> Maybe ( List Recursion ) unwrapRecursionList (RecursionList list) = list diff --git a/samples/openapi3/client/elm/src/Api/Request/Default.elm b/samples/openapi3/client/elm/src/Api/Request/Default.elm index 23e998284eb5..cdee21210441 100644 --- a/samples/openapi3/client/elm/src/Api/Request/Default.elm +++ b/samples/openapi3/client/elm/src/Api/Request/Default.elm @@ -23,7 +23,7 @@ module Api.Request.Default exposing ) import Api -import Api.Data +import Api.Data exposing (..) import Dict import Http import Json.Decode @@ -112,8 +112,6 @@ stringFromEnum model = - - headerPost : String -> Maybe Int -> Maybe HeaderType -> Api.Request String headerPost string_header integer_header headerType_header = Api.request @@ -126,7 +124,6 @@ headerPost string_header integer_header headerType_header = Json.Decode.string - maybeGet : Api.Request Api.Data.Maybe_ maybeGet = Api.request @@ -139,7 +136,6 @@ maybeGet = Api.Data.maybeDecoder - pathStringIntegerEnumerationGet : String -> Int -> Enumeration -> Api.Request () pathStringIntegerEnumerationGet string_path integer_path enumeration_path = Api.request @@ -152,7 +148,6 @@ pathStringIntegerEnumerationGet string_path integer_path enumeration_path = (Json.Decode.succeed ()) - queryGet : Maybe String -> Maybe Int -> Maybe Enum -> Api.Request () queryGet string_query int_query enum_query = Api.request @@ -165,7 +160,6 @@ queryGet string_query int_query enum_query = (Json.Decode.succeed ()) - securedPost : String -> Api.Request () securedPost auth_token = Api.request @@ -178,8 +172,6 @@ securedPost auth_token = (Json.Decode.succeed ()) |> Api.withBearerToken auth_token - - uuidGet : Maybe Uuid -> Api.Request Uuid uuidGet value_query = Api.request @@ -190,3 +182,4 @@ uuidGet value_query = [] Nothing Uuid.decoder + diff --git a/samples/openapi3/client/elm/src/Api/Request/Primitive.elm b/samples/openapi3/client/elm/src/Api/Request/Primitive.elm index 05f36eea518a..0cecd0d75f1b 100644 --- a/samples/openapi3/client/elm/src/Api/Request/Primitive.elm +++ b/samples/openapi3/client/elm/src/Api/Request/Primitive.elm @@ -18,14 +18,12 @@ module Api.Request.Primitive exposing ) import Api -import Api.Data +import Api.Data exposing (..) import Dict import Http import Json.Decode import Json.Encode - - update : Api.Data.Primitive -> Api.Request Api.Data.Primitive update primitive_body = Api.request @@ -34,5 +32,6 @@ update primitive_body = [] [] [] - (Just (Api.Data.encodePrimitive primitive_body)) + (Maybe.map Http.jsonBody (Just (Api.Data.encodePrimitive primitive_body))) Api.Data.primitiveDecoder + From c23127c92edd670f40fc9abcdd775a44c2391657 Mon Sep 17 00:00:00 2001 From: Qluxzz Date: Sun, 16 Apr 2023 21:30:48 +0200 Subject: [PATCH 08/10] Add script that all files compile successfully --- samples/client/petstore/elm/elm-compile-test | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100755 samples/client/petstore/elm/elm-compile-test diff --git a/samples/client/petstore/elm/elm-compile-test b/samples/client/petstore/elm/elm-compile-test new file mode 100755 index 000000000000..55507cfcad61 --- /dev/null +++ b/samples/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 From dc8729ee0d1507591878f5a3766a76867d7ca546 Mon Sep 17 00:00:00 2001 From: Qluxzz Date: Tue, 18 Apr 2023 20:31:04 +0200 Subject: [PATCH 09/10] Remove old unmaintained petstore client --- .../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 - samples/openapi3/client/petstore/elm/elm.json | 33 --- .../openapi3/client/petstore/elm/src/Byte.elm | 18 -- .../petstore/elm/src/Data/ApiResponse.elm | 64 ----- .../client/petstore/elm/src/Data/Category.elm | 61 ----- .../petstore/elm/src/Data/InlineObject.elm | 59 ----- .../petstore/elm/src/Data/InlineObject1.elm | 59 ----- .../client/petstore/elm/src/Data/Order_.elm | 117 --------- .../client/petstore/elm/src/Data/Pet.elm | 118 --------- .../client/petstore/elm/src/Data/Tag.elm | 61 ----- .../client/petstore/elm/src/Data/User.elm | 79 ------ .../client/petstore/elm/src/DateOnly.elm | 37 --- .../client/petstore/elm/src/DateTime.elm | 37 --- .../client/petstore/elm/src/Request/Pet.elm | 238 ------------------ .../client/petstore/elm/src/Request/Store.elm | 124 --------- .../client/petstore/elm/src/Request/User.elm | 216 ---------------- 19 files changed, 1356 deletions(-) delete mode 100644 samples/openapi3/client/petstore/elm/.gitignore delete mode 100644 samples/openapi3/client/petstore/elm/.openapi-generator-ignore delete mode 100644 samples/openapi3/client/petstore/elm/.openapi-generator/VERSION delete mode 100644 samples/openapi3/client/petstore/elm/README.md delete mode 100644 samples/openapi3/client/petstore/elm/elm.json delete mode 100644 samples/openapi3/client/petstore/elm/src/Byte.elm delete mode 100644 samples/openapi3/client/petstore/elm/src/Data/ApiResponse.elm delete mode 100644 samples/openapi3/client/petstore/elm/src/Data/Category.elm delete mode 100644 samples/openapi3/client/petstore/elm/src/Data/InlineObject.elm delete mode 100644 samples/openapi3/client/petstore/elm/src/Data/InlineObject1.elm delete mode 100644 samples/openapi3/client/petstore/elm/src/Data/Order_.elm delete mode 100644 samples/openapi3/client/petstore/elm/src/Data/Pet.elm delete mode 100644 samples/openapi3/client/petstore/elm/src/Data/Tag.elm delete mode 100644 samples/openapi3/client/petstore/elm/src/Data/User.elm delete mode 100644 samples/openapi3/client/petstore/elm/src/DateOnly.elm delete mode 100644 samples/openapi3/client/petstore/elm/src/DateTime.elm delete mode 100644 samples/openapi3/client/petstore/elm/src/Request/Pet.elm delete mode 100644 samples/openapi3/client/petstore/elm/src/Request/Store.elm delete mode 100644 samples/openapi3/client/petstore/elm/src/Request/User.elm diff --git a/samples/openapi3/client/petstore/elm/.gitignore b/samples/openapi3/client/petstore/elm/.gitignore deleted file mode 100644 index 8b0d053e4e35..000000000000 --- a/samples/openapi3/client/petstore/elm/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/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 deleted file mode 100644 index 7484ee590a38..000000000000 --- a/samples/openapi3/client/petstore/elm/.openapi-generator-ignore +++ /dev/null @@ -1,23 +0,0 @@ -# OpenAPI Generator Ignore -# Generated by openapi-generator https://github.com/openapitools/openapi-generator - -# Use this file to prevent files from being overwritten by the generator. -# The patterns follow closely to .gitignore or .dockerignore. - -# As an example, the C# client generator defines ApiClient.cs. -# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: -#ApiClient.cs - -# You can match any string of characters against a directory, file or extension with a single asterisk (*): -#foo/*/qux -# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux - -# You can recursively match patterns against a directory, file or extension with a double asterisk (**): -#foo/**/qux -# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux - -# You can also negate patterns with an exclamation (!). -# For example, you can ignore all files in a docs folder with the file extension .md: -#docs/*.md -# Then explicitly reverse the ignore rule for a single file: -#!docs/README.md diff --git a/samples/openapi3/client/petstore/elm/.openapi-generator/VERSION b/samples/openapi3/client/petstore/elm/.openapi-generator/VERSION deleted file mode 100644 index d99e7162d01f..000000000000 --- a/samples/openapi3/client/petstore/elm/.openapi-generator/VERSION +++ /dev/null @@ -1 +0,0 @@ -5.0.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 deleted file mode 100644 index 3f36740911ae..000000000000 --- a/samples/openapi3/client/petstore/elm/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# Elm API client - -This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. - -## Overview -This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [openapi-spec](https://github.com/OAI/OpenAPI-Specification) from a remote server, you can easily generate an API client. - -- API version: 1.0.0 -- Package version: -- Build package: org.openapitools.codegen.languages.ElmClientCodegen diff --git a/samples/openapi3/client/petstore/elm/elm.json b/samples/openapi3/client/petstore/elm/elm.json deleted file mode 100644 index 398da0d2d6d2..000000000000 --- a/samples/openapi3/client/petstore/elm/elm.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "type": "application", - "source-directories": [ - "src" - ], - "elm-version": "0.19.0", - "dependencies": { - "direct": { - "NoRedInk/elm-json-decode-pipeline": "1.0.0", - "danyx23/elm-uuid": "2.1.2", - "elm/browser": "1.0.1", - "elm/core": "1.0.2", - "elm/html": "1.0.0", - "elm/http": "2.0.0", - "elm/json": "1.1.2", - "elm/time": "1.0.0", - "elm/url": "1.0.0", - "rtfeldman/elm-iso8601-date-strings": "1.1.3" - }, - "indirect": { - "elm/bytes": "1.0.5", - "elm/file": "1.0.1", - "elm/parser": "1.1.0", - "elm/random": "1.0.0", - "elm/regex": "1.0.0", - "elm/virtual-dom": "1.0.2" - } - }, - "test-dependencies": { - "direct": {}, - "indirect": {} - } -} diff --git a/samples/openapi3/client/petstore/elm/src/Byte.elm b/samples/openapi3/client/petstore/elm/src/Byte.elm deleted file mode 100644 index d83623d9846f..000000000000 --- a/samples/openapi3/client/petstore/elm/src/Byte.elm +++ /dev/null @@ -1,18 +0,0 @@ -module Byte exposing (Byte, decoder, encode) - -import Json.Decode as Decode exposing (Decoder) -import Json.Encode as Encode - - -type alias Byte = - String - - -decoder : Decoder Byte -decoder = - Decode.string - - -encode : Byte -> Encode.Value -encode model = - Encode.string model diff --git a/samples/openapi3/client/petstore/elm/src/Data/ApiResponse.elm b/samples/openapi3/client/petstore/elm/src/Data/ApiResponse.elm deleted file mode 100644 index 7fbf5de80e71..000000000000 --- a/samples/openapi3/client/petstore/elm/src/Data/ApiResponse.elm +++ /dev/null @@ -1,64 +0,0 @@ -{- - OpenAPI Petstore - This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. - - The version of the OpenAPI document: 1.0.0 - - NOTE: This file is auto generated by the openapi-generator. - https://github.com/openapitools/openapi-generator.git - Do not edit this file manually. --} - - -module Data.ApiResponse exposing (ApiResponse, decoder, encode, encodeWithTag, toString) - -import Dict exposing (Dict) -import Json.Decode as Decode exposing (Decoder) -import Json.Decode.Pipeline exposing (optional, required) -import Json.Encode as Encode - - -{-| Describes the result of uploading an image resource --} -type alias ApiResponse = - { code : Maybe (Int) - , type_ : Maybe (String) - , message : Maybe (String) - } - - -decoder : Decoder ApiResponse -decoder = - Decode.succeed ApiResponse - |> optional "code" (Decode.nullable Decode.int) Nothing - |> optional "type" (Decode.nullable Decode.string) Nothing - |> optional "message" (Decode.nullable Decode.string) Nothing - - - -encode : ApiResponse -> Encode.Value -encode = - Encode.object << encodePairs - - -encodeWithTag : ( String, String ) -> ApiResponse -> Encode.Value -encodeWithTag (tagField, tag) model = - Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ] - - -encodePairs : ApiResponse -> List (String, Encode.Value) -encodePairs model = - [ ( "code", Maybe.withDefault Encode.null (Maybe.map Encode.int model.code) ) - , ( "type", Maybe.withDefault Encode.null (Maybe.map Encode.string model.type_) ) - , ( "message", Maybe.withDefault Encode.null (Maybe.map Encode.string model.message) ) - ] - - - -toString : ApiResponse -> String -toString = - Encode.encode 0 << encode - - - - diff --git a/samples/openapi3/client/petstore/elm/src/Data/Category.elm b/samples/openapi3/client/petstore/elm/src/Data/Category.elm deleted file mode 100644 index d0b29b295da0..000000000000 --- a/samples/openapi3/client/petstore/elm/src/Data/Category.elm +++ /dev/null @@ -1,61 +0,0 @@ -{- - OpenAPI Petstore - This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. - - The version of the OpenAPI document: 1.0.0 - - NOTE: This file is auto generated by the openapi-generator. - https://github.com/openapitools/openapi-generator.git - Do not edit this file manually. --} - - -module Data.Category exposing (Category, decoder, encode, encodeWithTag, toString) - -import Dict exposing (Dict) -import Json.Decode as Decode exposing (Decoder) -import Json.Decode.Pipeline exposing (optional, required) -import Json.Encode as Encode - - -{-| A category for a pet --} -type alias Category = - { id : Maybe (Int) - , name : Maybe (String) - } - - -decoder : Decoder Category -decoder = - Decode.succeed Category - |> optional "id" (Decode.nullable Decode.int) Nothing - |> optional "name" (Decode.nullable Decode.string) Nothing - - - -encode : Category -> Encode.Value -encode = - Encode.object << encodePairs - - -encodeWithTag : ( String, String ) -> Category -> Encode.Value -encodeWithTag (tagField, tag) model = - Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ] - - -encodePairs : Category -> List (String, Encode.Value) -encodePairs model = - [ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) ) - , ( "name", Maybe.withDefault Encode.null (Maybe.map Encode.string model.name) ) - ] - - - -toString : Category -> String -toString = - Encode.encode 0 << encode - - - - diff --git a/samples/openapi3/client/petstore/elm/src/Data/InlineObject.elm b/samples/openapi3/client/petstore/elm/src/Data/InlineObject.elm deleted file mode 100644 index cac10db97696..000000000000 --- a/samples/openapi3/client/petstore/elm/src/Data/InlineObject.elm +++ /dev/null @@ -1,59 +0,0 @@ -{- - OpenAPI Petstore - This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. - - The version of the OpenAPI document: 1.0.0 - - NOTE: This file is auto generated by the openapi-generator. - https://github.com/openapitools/openapi-generator.git - Do not edit this file manually. --} - - -module Data.InlineObject exposing (InlineObject, 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 InlineObject = - { name : Maybe (String) - , status : Maybe (String) - } - - -decoder : Decoder InlineObject -decoder = - Decode.succeed InlineObject - |> optional "name" (Decode.nullable Decode.string) Nothing - |> optional "status" (Decode.nullable Decode.string) Nothing - - - -encode : InlineObject -> Encode.Value -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 deleted file mode 100644 index ac64e3132f30..000000000000 --- a/samples/openapi3/client/petstore/elm/src/Data/InlineObject1.elm +++ /dev/null @@ -1,59 +0,0 @@ -{- - OpenAPI Petstore - This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. - - The version of the OpenAPI document: 1.0.0 - - NOTE: This file is auto generated by the openapi-generator. - https://github.com/openapitools/openapi-generator.git - Do not edit this file manually. --} - - -module Data.InlineObject1 exposing (InlineObject1, 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 InlineObject1 = - { additionalMetadata : Maybe (String) - , file : Maybe (String) - } - - -decoder : Decoder InlineObject1 -decoder = - Decode.succeed InlineObject1 - |> optional "additionalMetadata" (Decode.nullable Decode.string) Nothing - |> optional "file" (Decode.nullable Decode.string) Nothing - - - -encode : InlineObject1 -> Encode.Value -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 deleted file mode 100644 index 7a7325592ad6..000000000000 --- a/samples/openapi3/client/petstore/elm/src/Data/Order_.elm +++ /dev/null @@ -1,117 +0,0 @@ -{- - OpenAPI Petstore - This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. - - The version of the OpenAPI document: 1.0.0 - - NOTE: This file is auto generated by the openapi-generator. - https://github.com/openapitools/openapi-generator.git - Do not edit this file manually. --} - - -module Data.Order_ exposing (Order_, Status(..), decoder, encode, encodeWithTag, toString) - -import DateTime exposing (DateTime) -import Dict exposing (Dict) -import Json.Decode as Decode exposing (Decoder) -import Json.Decode.Pipeline exposing (optional, required) -import Json.Encode as Encode - - -{-| An order for a pets from the pet store --} -type alias Order_ = - { id : Maybe (Int) - , petId : Maybe (Int) - , quantity : Maybe (Int) - , shipDate : Maybe (DateTime) - , status : Maybe (Status) - , complete : Maybe (Bool) - } - - -type Status - = StatusPlaced - | StatusApproved - | StatusDelivered - - - -decoder : Decoder Order_ -decoder = - Decode.succeed Order_ - |> optional "id" (Decode.nullable Decode.int) Nothing - |> optional "petId" (Decode.nullable Decode.int) Nothing - |> optional "quantity" (Decode.nullable Decode.int) Nothing - |> optional "shipDate" (Decode.nullable DateTime.decoder) Nothing - |> optional "status" (Decode.nullable statusDecoder) Nothing - |> optional "complete" (Decode.nullable Decode.bool) (Just False) - - - -encode : Order_ -> Encode.Value -encode = - Encode.object << encodePairs - - -encodeWithTag : ( String, String ) -> Order_ -> Encode.Value -encodeWithTag (tagField, tag) model = - Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ] - - -encodePairs : Order_ -> List (String, Encode.Value) -encodePairs model = - [ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) ) - , ( "petId", Maybe.withDefault Encode.null (Maybe.map Encode.int model.petId) ) - , ( "quantity", Maybe.withDefault Encode.null (Maybe.map Encode.int model.quantity) ) - , ( "shipDate", Maybe.withDefault Encode.null (Maybe.map DateTime.encode model.shipDate) ) - , ( "status", Maybe.withDefault Encode.null (Maybe.map encodeStatus model.status) ) - , ( "complete", Maybe.withDefault Encode.null (Maybe.map Encode.bool model.complete) ) - ] - - - -toString : Order_ -> String -toString = - Encode.encode 0 << encode - - - - -statusDecoder : Decoder Status -statusDecoder = - Decode.string - |> Decode.andThen - (\str -> - case str of - "placed" -> - Decode.succeed StatusPlaced - - "approved" -> - Decode.succeed StatusApproved - - "delivered" -> - Decode.succeed StatusDelivered - - other -> - Decode.fail <| "Unknown type: " ++ other - ) - - - -encodeStatus : Status -> Encode.Value -encodeStatus model = - case model of - StatusPlaced -> - Encode.string "placed" - - StatusApproved -> - Encode.string "approved" - - StatusDelivered -> - 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 deleted file mode 100644 index 3267cfc059ea..000000000000 --- a/samples/openapi3/client/petstore/elm/src/Data/Pet.elm +++ /dev/null @@ -1,118 +0,0 @@ -{- - OpenAPI Petstore - This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. - - The version of the OpenAPI document: 1.0.0 - - NOTE: This file is auto generated by the openapi-generator. - https://github.com/openapitools/openapi-generator.git - Do not edit this file manually. --} - - -module Data.Pet exposing (Pet, Status(..), decoder, encode, encodeWithTag, toString) - -import Data.Category as Category exposing (Category) -import Data.Tag as Tag exposing (Tag) -import Dict exposing (Dict) -import Json.Decode as Decode exposing (Decoder) -import Json.Decode.Pipeline exposing (optional, required) -import Json.Encode as Encode - - -{-| A pet for sale in the pet store --} -type alias Pet = - { id : Maybe (Int) - , category : Maybe (Category) - , name : String - , photoUrls : (List String) - , tags : Maybe ((List Tag)) - , status : Maybe (Status) - } - - -type Status - = StatusAvailable - | StatusPending - | StatusSold - - - -decoder : Decoder Pet -decoder = - Decode.succeed Pet - |> optional "id" (Decode.nullable Decode.int) Nothing - |> optional "category" (Decode.nullable Category.decoder) Nothing - |> required "name" Decode.string - |> required "photoUrls" (Decode.list Decode.string) - |> optional "tags" (Decode.nullable (Decode.list Tag.decoder)) Nothing - |> optional "status" (Decode.nullable statusDecoder) Nothing - - - -encode : Pet -> Encode.Value -encode = - Encode.object << encodePairs - - -encodeWithTag : ( String, String ) -> Pet -> Encode.Value -encodeWithTag (tagField, tag) model = - Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ] - - -encodePairs : Pet -> List (String, Encode.Value) -encodePairs model = - [ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) ) - , ( "category", Maybe.withDefault Encode.null (Maybe.map Category.encode model.category) ) - , ( "name", Encode.string model.name ) - , ( "photoUrls", (Encode.list Encode.string) model.photoUrls ) - , ( "tags", Maybe.withDefault Encode.null (Maybe.map (Encode.list Tag.encode) model.tags) ) - , ( "status", Maybe.withDefault Encode.null (Maybe.map encodeStatus model.status) ) - ] - - - -toString : Pet -> String -toString = - Encode.encode 0 << encode - - - - -statusDecoder : Decoder Status -statusDecoder = - Decode.string - |> Decode.andThen - (\str -> - case str of - "available" -> - Decode.succeed StatusAvailable - - "pending" -> - Decode.succeed StatusPending - - "sold" -> - Decode.succeed StatusSold - - other -> - Decode.fail <| "Unknown type: " ++ other - ) - - - -encodeStatus : Status -> Encode.Value -encodeStatus model = - case model of - StatusAvailable -> - Encode.string "available" - - StatusPending -> - Encode.string "pending" - - StatusSold -> - Encode.string "sold" - - - - diff --git a/samples/openapi3/client/petstore/elm/src/Data/Tag.elm b/samples/openapi3/client/petstore/elm/src/Data/Tag.elm deleted file mode 100644 index 2fbd439fe976..000000000000 --- a/samples/openapi3/client/petstore/elm/src/Data/Tag.elm +++ /dev/null @@ -1,61 +0,0 @@ -{- - OpenAPI Petstore - This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. - - The version of the OpenAPI document: 1.0.0 - - NOTE: This file is auto generated by the openapi-generator. - https://github.com/openapitools/openapi-generator.git - Do not edit this file manually. --} - - -module Data.Tag exposing (Tag, decoder, encode, encodeWithTag, toString) - -import Dict exposing (Dict) -import Json.Decode as Decode exposing (Decoder) -import Json.Decode.Pipeline exposing (optional, required) -import Json.Encode as Encode - - -{-| A tag for a pet --} -type alias Tag = - { id : Maybe (Int) - , name : Maybe (String) - } - - -decoder : Decoder Tag -decoder = - Decode.succeed Tag - |> optional "id" (Decode.nullable Decode.int) Nothing - |> optional "name" (Decode.nullable Decode.string) Nothing - - - -encode : Tag -> Encode.Value -encode = - Encode.object << encodePairs - - -encodeWithTag : ( String, String ) -> Tag -> Encode.Value -encodeWithTag (tagField, tag) model = - Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ] - - -encodePairs : Tag -> List (String, Encode.Value) -encodePairs model = - [ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) ) - , ( "name", Maybe.withDefault Encode.null (Maybe.map Encode.string model.name) ) - ] - - - -toString : Tag -> String -toString = - Encode.encode 0 << encode - - - - diff --git a/samples/openapi3/client/petstore/elm/src/Data/User.elm b/samples/openapi3/client/petstore/elm/src/Data/User.elm deleted file mode 100644 index 819857888dc1..000000000000 --- a/samples/openapi3/client/petstore/elm/src/Data/User.elm +++ /dev/null @@ -1,79 +0,0 @@ -{- - OpenAPI Petstore - This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. - - The version of the OpenAPI document: 1.0.0 - - NOTE: This file is auto generated by the openapi-generator. - https://github.com/openapitools/openapi-generator.git - Do not edit this file manually. --} - - -module Data.User exposing (User, decoder, encode, encodeWithTag, toString) - -import Dict exposing (Dict) -import Json.Decode as Decode exposing (Decoder) -import Json.Decode.Pipeline exposing (optional, required) -import Json.Encode as Encode - - -{-| A User who is purchasing from the pet store --} -type alias User = - { id : Maybe (Int) - , username : Maybe (String) - , firstName : Maybe (String) - , lastName : Maybe (String) - , email : Maybe (String) - , password : Maybe (String) - , phone : Maybe (String) - , userStatus : Maybe (Int) - } - - -decoder : Decoder User -decoder = - Decode.succeed User - |> optional "id" (Decode.nullable Decode.int) Nothing - |> optional "username" (Decode.nullable Decode.string) Nothing - |> optional "firstName" (Decode.nullable Decode.string) Nothing - |> optional "lastName" (Decode.nullable Decode.string) Nothing - |> optional "email" (Decode.nullable Decode.string) Nothing - |> optional "password" (Decode.nullable Decode.string) Nothing - |> optional "phone" (Decode.nullable Decode.string) Nothing - |> optional "userStatus" (Decode.nullable Decode.int) Nothing - - - -encode : User -> Encode.Value -encode = - Encode.object << encodePairs - - -encodeWithTag : ( String, String ) -> User -> Encode.Value -encodeWithTag (tagField, tag) model = - Encode.object <| encodePairs model ++ [ ( tagField, Encode.string tag ) ] - - -encodePairs : User -> List (String, Encode.Value) -encodePairs model = - [ ( "id", Maybe.withDefault Encode.null (Maybe.map Encode.int model.id) ) - , ( "username", Maybe.withDefault Encode.null (Maybe.map Encode.string model.username) ) - , ( "firstName", Maybe.withDefault Encode.null (Maybe.map Encode.string model.firstName) ) - , ( "lastName", Maybe.withDefault Encode.null (Maybe.map Encode.string model.lastName) ) - , ( "email", Maybe.withDefault Encode.null (Maybe.map Encode.string model.email) ) - , ( "password", Maybe.withDefault Encode.null (Maybe.map Encode.string model.password) ) - , ( "phone", Maybe.withDefault Encode.null (Maybe.map Encode.string model.phone) ) - , ( "userStatus", Maybe.withDefault Encode.null (Maybe.map Encode.int model.userStatus) ) - ] - - - -toString : User -> String -toString = - Encode.encode 0 << encode - - - - diff --git a/samples/openapi3/client/petstore/elm/src/DateOnly.elm b/samples/openapi3/client/petstore/elm/src/DateOnly.elm deleted file mode 100644 index a31efc88c381..000000000000 --- a/samples/openapi3/client/petstore/elm/src/DateOnly.elm +++ /dev/null @@ -1,37 +0,0 @@ -module DateOnly exposing (DateOnly, decoder, encode, toString) - -import Iso8601 -import Json.Decode as Decode exposing (Decoder) -import Json.Encode as Encode -import Result -import Time - - -type alias DateOnly = - Time.Posix - - -decoder : Decoder DateOnly -decoder = - Decode.string - |> Decode.andThen decodeIsoString - - -encode : DateOnly -> Encode.Value -encode = - Encode.string << toString - - -decodeIsoString : String -> Decoder DateOnly -decodeIsoString str = - case Iso8601.toTime (str ++ "T00:00:00.000Z") of - Result.Ok posix -> - Decode.succeed posix - - Result.Err _ -> - Decode.fail <| "Invalid date: " ++ str - - -toString : DateOnly -> String -toString = - String.left 10 << Iso8601.fromTime diff --git a/samples/openapi3/client/petstore/elm/src/DateTime.elm b/samples/openapi3/client/petstore/elm/src/DateTime.elm deleted file mode 100644 index 7d4a5c642c13..000000000000 --- a/samples/openapi3/client/petstore/elm/src/DateTime.elm +++ /dev/null @@ -1,37 +0,0 @@ -module DateTime exposing (DateTime, decoder, encode, toString) - -import Iso8601 -import Json.Decode as Decode exposing (Decoder) -import Json.Encode as Encode -import Result -import Time - - -type alias DateTime = - Time.Posix - - -decoder : Decoder DateTime -decoder = - Decode.string - |> Decode.andThen decodeIsoString - - -encode : DateTime -> Encode.Value -encode = - Encode.string << toString - - -decodeIsoString : String -> Decoder DateTime -decodeIsoString str = - case Iso8601.toTime str of - Result.Ok posix -> - Decode.succeed posix - - Result.Err _ -> - Decode.fail <| "Invalid date: " ++ str - - -toString : DateTime -> String -toString = - Iso8601.fromTime \ No newline at end of file diff --git a/samples/openapi3/client/petstore/elm/src/Request/Pet.elm b/samples/openapi3/client/petstore/elm/src/Request/Pet.elm deleted file mode 100644 index a7a77529477a..000000000000 --- a/samples/openapi3/client/petstore/elm/src/Request/Pet.elm +++ /dev/null @@ -1,238 +0,0 @@ -{- - OpenAPI Petstore - This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. - - The version of the OpenAPI document: 1.0.0 - - NOTE: This file is auto generated by the openapi-generator. - https://github.com/openapitools/openapi-generator.git - Do not edit this file manually. --} - - -module Request.Pet exposing (addPet, deletePet, findPetsByStatus, Status(..), findPetsByTags, getPetById, updatePet, updatePetWithForm, uploadFile) - -import Data.Pet as Pet exposing (Pet) -import Data.ApiResponse as ApiResponse exposing (ApiResponse) -import Dict -import Http -import Json.Decode as Decode -import Url.Builder as Url - - -type Status - = StatusAvailable - | StatusPending - | StatusSold - -stringifyStatus : Status -> String -stringifyStatus value = - case value of - StatusAvailable -> - "available" - - StatusPending -> - "pending" - - StatusSold -> - "sold" - - - - - -basePath : String -basePath = - "http://petstore.swagger.io/v2" - - -addPet : - { onSend : Result Http.Error () -> msg - - - , body : Pet - - - } - -> Cmd msg -addPet params = - Http.request - { method = "POST" - , headers = List.filterMap identity [] - , url = Url.crossOrigin basePath - ["pet"] - (List.filterMap identity []) - , body = Http.jsonBody <| Pet.encode params.body - , expect = Http.expectWhatever params.onSend - , timeout = Just 30000 - , tracker = Nothing - } - - -deletePet : - { apiKey : Maybe (String) - } -> - { onSend : Result Http.Error () -> msg - - - - , petId : Int - - } - -> Cmd msg -deletePet headers params = - Http.request - { method = "DELETE" - , headers = List.filterMap identity [Maybe.map (Http.header "api_key" << identity) headers.apiKey] - , url = Url.crossOrigin basePath - ["pet", String.fromInt params.petId] - (List.filterMap identity []) - , body = Http.emptyBody - , expect = Http.expectWhatever params.onSend - , timeout = Just 30000 - , tracker = Nothing - } - - -{-| Multiple status values can be provided with comma separated strings --} -findPetsByStatus : - { onSend : Result Http.Error (List Pet) -> msg - - - - - , status : List Status - } - -> Cmd msg -findPetsByStatus params = - Http.request - { method = "GET" - , headers = List.filterMap identity [] - , url = Url.crossOrigin basePath - ["pet", "findByStatus"] - (List.filterMap identity [(Just << Url.string "status" << String.join "," << List.map stringifyStatus) params.status]) - , body = Http.emptyBody - , expect = Http.expectJson params.onSend (Decode.list Pet.decoder) - , timeout = Just 30000 - , tracker = Nothing - } - - -{-| Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. --} -findPetsByTags : - { onSend : Result Http.Error (List Pet) -> msg - - - - - , tags : List String - } - -> Cmd msg -findPetsByTags params = - Http.request - { method = "GET" - , headers = List.filterMap identity [] - , url = Url.crossOrigin basePath - ["pet", "findByTags"] - (List.filterMap identity [(Just << Url.string "tags" << String.join "," << List.map identity) params.tags]) - , body = Http.emptyBody - , expect = Http.expectJson params.onSend (Decode.list Pet.decoder) - , timeout = Just 30000 - , tracker = Nothing - } - - -{-| Returns a single pet --} -getPetById : - { onSend : Result Http.Error Pet -> msg - - - - , petId : Int - - } - -> Cmd msg -getPetById params = - Http.request - { method = "GET" - , headers = List.filterMap identity [] - , url = Url.crossOrigin basePath - ["pet", String.fromInt params.petId] - (List.filterMap identity []) - , body = Http.emptyBody - , expect = Http.expectJson params.onSend Pet.decoder - , timeout = Just 30000 - , tracker = Nothing - } - - -updatePet : - { onSend : Result Http.Error () -> msg - - - , body : Pet - - - } - -> Cmd msg -updatePet params = - Http.request - { method = "PUT" - , headers = List.filterMap identity [] - , url = Url.crossOrigin basePath - ["pet"] - (List.filterMap identity []) - , body = Http.jsonBody <| Pet.encode params.body - , expect = Http.expectWhatever params.onSend - , timeout = Just 30000 - , tracker = Nothing - } - - -updatePetWithForm : - { onSend : Result Http.Error () -> msg - - - - , petId : Int - - } - -> Cmd msg -updatePetWithForm params = - Http.request - { method = "POST" - , headers = List.filterMap identity [] - , url = Url.crossOrigin basePath - ["pet", String.fromInt params.petId] - (List.filterMap identity []) - , body = Http.emptyBody - , expect = Http.expectWhatever params.onSend - , timeout = Just 30000 - , tracker = Nothing - } - - -uploadFile : - { onSend : Result Http.Error ApiResponse -> msg - - - - , petId : Int - - } - -> Cmd msg -uploadFile params = - Http.request - { method = "POST" - , headers = List.filterMap identity [] - , url = Url.crossOrigin basePath - ["pet", String.fromInt params.petId, "uploadImage"] - (List.filterMap identity []) - , body = Http.emptyBody - , expect = Http.expectJson params.onSend ApiResponse.decoder - , timeout = Just 30000 - , tracker = Nothing - } diff --git a/samples/openapi3/client/petstore/elm/src/Request/Store.elm b/samples/openapi3/client/petstore/elm/src/Request/Store.elm deleted file mode 100644 index fca396829b09..000000000000 --- a/samples/openapi3/client/petstore/elm/src/Request/Store.elm +++ /dev/null @@ -1,124 +0,0 @@ -{- - OpenAPI Petstore - This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. - - The version of the OpenAPI document: 1.0.0 - - NOTE: This file is auto generated by the openapi-generator. - https://github.com/openapitools/openapi-generator.git - Do not edit this file manually. --} - - -module Request.Store exposing (deleteOrder, getInventory, getOrderById, placeOrder) - -import Data.Order_ as Order_ exposing (Order_) -import Dict -import Http -import Json.Decode as Decode -import Url.Builder as Url - - - - -basePath : String -basePath = - "http://petstore.swagger.io/v2" - - -{-| For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors --} -deleteOrder : - { onSend : Result Http.Error () -> msg - - - - , orderId : String - - } - -> Cmd msg -deleteOrder params = - Http.request - { method = "DELETE" - , headers = List.filterMap identity [] - , url = Url.crossOrigin basePath - ["store", "order", identity params.orderId] - (List.filterMap identity []) - , body = Http.emptyBody - , expect = Http.expectWhatever params.onSend - , timeout = Just 30000 - , tracker = Nothing - } - - -{-| Returns a map of status codes to quantities --} -getInventory : - { onSend : Result Http.Error (Dict.Dict String Int) -> msg - - - - - - } - -> Cmd msg -getInventory params = - Http.request - { method = "GET" - , headers = List.filterMap identity [] - , url = Url.crossOrigin basePath - ["store", "inventory"] - (List.filterMap identity []) - , body = Http.emptyBody - , expect = Http.expectJson params.onSend (Decode.dict Decode.int) - , timeout = Just 30000 - , tracker = Nothing - } - - -{-| For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions --} -getOrderById : - { onSend : Result Http.Error Order_ -> msg - - - - , orderId : Int - - } - -> Cmd msg -getOrderById params = - Http.request - { method = "GET" - , headers = List.filterMap identity [] - , url = Url.crossOrigin basePath - ["store", "order", String.fromInt params.orderId] - (List.filterMap identity []) - , body = Http.emptyBody - , expect = Http.expectJson params.onSend Order_.decoder - , timeout = Just 30000 - , tracker = Nothing - } - - -placeOrder : - { onSend : Result Http.Error Order_ -> msg - - - , body : Order_ - - - } - -> Cmd msg -placeOrder params = - Http.request - { method = "POST" - , headers = List.filterMap identity [] - , url = Url.crossOrigin basePath - ["store", "order"] - (List.filterMap identity []) - , body = Http.jsonBody <| Order_.encode params.body - , expect = Http.expectJson params.onSend Order_.decoder - , timeout = Just 30000 - , tracker = Nothing - } diff --git a/samples/openapi3/client/petstore/elm/src/Request/User.elm b/samples/openapi3/client/petstore/elm/src/Request/User.elm deleted file mode 100644 index 0bb8411573b6..000000000000 --- a/samples/openapi3/client/petstore/elm/src/Request/User.elm +++ /dev/null @@ -1,216 +0,0 @@ -{- - OpenAPI Petstore - This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. - - The version of the OpenAPI document: 1.0.0 - - NOTE: This file is auto generated by the openapi-generator. - https://github.com/openapitools/openapi-generator.git - Do not edit this file manually. --} - - -module Request.User exposing (createUser, createUsersWithArrayInput, createUsersWithListInput, deleteUser, getUserByName, loginUser, logoutUser, updateUser) - -import Data.User as User exposing (User) -import Dict -import Http -import Json.Decode as Decode -import Url.Builder as Url - - - - -basePath : String -basePath = - "http://petstore.swagger.io/v2" - - -{-| This can only be done by the logged in user. --} -createUser : - { onSend : Result Http.Error () -> msg - - - , body : User - - - } - -> Cmd msg -createUser params = - Http.request - { method = "POST" - , headers = List.filterMap identity [] - , url = Url.crossOrigin basePath - ["user"] - (List.filterMap identity []) - , body = Http.jsonBody <| User.encode params.body - , expect = Http.expectWhatever params.onSend - , timeout = Just 30000 - , tracker = Nothing - } - - -createUsersWithArrayInput : - { onSend : Result Http.Error () -> msg - - - , body : User - - - } - -> Cmd msg -createUsersWithArrayInput params = - Http.request - { method = "POST" - , headers = List.filterMap identity [] - , url = Url.crossOrigin basePath - ["user", "createWithArray"] - (List.filterMap identity []) - , body = Http.jsonBody <| User.encode params.body - , expect = Http.expectWhatever params.onSend - , timeout = Just 30000 - , tracker = Nothing - } - - -createUsersWithListInput : - { onSend : Result Http.Error () -> msg - - - , body : User - - - } - -> Cmd msg -createUsersWithListInput params = - Http.request - { method = "POST" - , headers = List.filterMap identity [] - , url = Url.crossOrigin basePath - ["user", "createWithList"] - (List.filterMap identity []) - , body = Http.jsonBody <| User.encode params.body - , expect = Http.expectWhatever params.onSend - , timeout = Just 30000 - , tracker = Nothing - } - - -{-| This can only be done by the logged in user. --} -deleteUser : - { onSend : Result Http.Error () -> msg - - - - , username : String - - } - -> Cmd msg -deleteUser params = - Http.request - { method = "DELETE" - , headers = List.filterMap identity [] - , url = Url.crossOrigin basePath - ["user", identity params.username] - (List.filterMap identity []) - , body = Http.emptyBody - , expect = Http.expectWhatever params.onSend - , timeout = Just 30000 - , tracker = Nothing - } - - -getUserByName : - { onSend : Result Http.Error User -> msg - - - - , username : String - - } - -> Cmd msg -getUserByName params = - Http.request - { method = "GET" - , headers = List.filterMap identity [] - , url = Url.crossOrigin basePath - ["user", identity params.username] - (List.filterMap identity []) - , body = Http.emptyBody - , expect = Http.expectJson params.onSend User.decoder - , timeout = Just 30000 - , tracker = Nothing - } - - -loginUser : - { onSend : Result Http.Error String -> msg - - - - - , username : String , password : String - } - -> Cmd msg -loginUser params = - Http.request - { method = "GET" - , headers = List.filterMap identity [] - , url = Url.crossOrigin basePath - ["user", "login"] - (List.filterMap identity [(Just << Url.string "username" << identity) params.username, (Just << Url.string "password" << identity) params.password]) - , body = Http.emptyBody - , expect = Http.expectJson params.onSend Decode.string - , timeout = Just 30000 - , tracker = Nothing - } - - -logoutUser : - { onSend : Result Http.Error () -> msg - - - - - - } - -> Cmd msg -logoutUser params = - Http.request - { method = "GET" - , headers = List.filterMap identity [] - , url = Url.crossOrigin basePath - ["user", "logout"] - (List.filterMap identity []) - , body = Http.emptyBody - , expect = Http.expectWhatever params.onSend - , timeout = Just 30000 - , tracker = Nothing - } - - -{-| This can only be done by the logged in user. --} -updateUser : - { onSend : Result Http.Error () -> msg - - - , body : User - , username : String - - } - -> Cmd msg -updateUser params = - Http.request - { method = "PUT" - , headers = List.filterMap identity [] - , url = Url.crossOrigin basePath - ["user", identity params.username] - (List.filterMap identity []) - , body = Http.jsonBody <| User.encode params.body - , expect = Http.expectWhatever params.onSend - , timeout = Just 30000 - , tracker = Nothing - } From a3a0ea84139e2594578f8cafec1d15b3e208b7c8 Mon Sep 17 00:00:00 2001 From: Qluxzz Date: Wed, 26 Apr 2023 15:06:57 +0200 Subject: [PATCH 10/10] Add pipeline to try and compile elm clients --- .github/workflows/samples-elm.yaml | 32 ++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .github/workflows/samples-elm.yaml diff --git a/.github/workflows/samples-elm.yaml b/.github/workflows/samples-elm.yaml new file mode 100644 index 000000000000..28e9047e952b --- /dev/null +++ b/.github/workflows/samples-elm.yaml @@ -0,0 +1,32 @@ +name: Samples Elm + +on: + push: + paths: + - samples/client/petstore/elm/** + pull_request: + paths: + - samples/client/petstore/elm/** +jobs: + build: + name: Build Elm clients + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + sample: + # clients + - samples/client/petstore/elm + steps: + - uses: actions/checkout@v3 + - uses: jorelali/setup-elm@v5 + with: + elm-version: 0.19.1 + - name: Build + working-directory: ${{ matrix.sample }} + # Try to compile all .elm files + # This fails if: + # An .elm file couldn't be compiled + # No .elm files were found + # No elm.json file could be found in the root of the working directory + run: elm make $(find . -name *.elm) --output=/dev/null