From 5e554d5d5fde4360a50467eaf1015ac727935d12 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 14 May 2020 17:38:58 +0800 Subject: [PATCH 1/3] erlang samples switch to oas3 spec --- bin/erlang-petstore-client.sh | 2 +- bin/erlang-petstore-proper.sh | 2 +- bin/erlang-petstore-server.sh | 2 +- bin/openapi3/erlang-petstore-client.sh | 32 -- bin/openapi3/erlang-petstore-server.sh | 32 -- bin/windows/erlang-petstore-client.bat | 2 +- bin/windows/erlang-petstore-server.bat | 2 +- .../erlang-client/.openapi-generator/VERSION | 2 +- .../erlang-client/src/petstore_pet_api.erl | 8 +- .../erlang-client/src/petstore_store_api.erl | 2 +- .../erlang-client/src/petstore_user_api.erl | 8 +- .../erlang-client/src/petstore_utils.erl | 5 +- .../erlang-proper/.openapi-generator/VERSION | 2 +- .../erlang-proper/src/petstore_api.erl | 8 +- .../petstore/erlang-server/priv/openapi.json | 321 ++++++++++++------ .../erlang-server/src/openapi_api.erl | 5 + .../erlang-server/src/openapi_auth.erl | 2 + .../src/openapi_default_logic_handler.erl | 4 + .../src/openapi_logic_handler.erl | 9 + .../src/openapi_user_handler.erl | 114 +++++++ 20 files changed, 367 insertions(+), 197 deletions(-) delete mode 100755 bin/openapi3/erlang-petstore-client.sh delete mode 100755 bin/openapi3/erlang-petstore-server.sh diff --git a/bin/erlang-petstore-client.sh b/bin/erlang-petstore-client.sh index 77ee5acf0ef9..5ff65bf39282 100755 --- a/bin/erlang-petstore-client.sh +++ b/bin/erlang-petstore-client.sh @@ -27,6 +27,6 @@ fi # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate -t modules/openapi-generator/src/main/resources/erlang-client --additional-properties packageName=petstore -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g erlang-client -o samples/client/petstore/erlang-client $@" +ags="generate -t modules/openapi-generator/src/main/resources/erlang-client --additional-properties packageName=petstore -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g erlang-client -o samples/client/petstore/erlang-client $@" java $JAVA_OPTS -jar $executable $ags diff --git a/bin/erlang-petstore-proper.sh b/bin/erlang-petstore-proper.sh index 4c19eec46df7..2db7ed0e0e31 100755 --- a/bin/erlang-petstore-proper.sh +++ b/bin/erlang-petstore-proper.sh @@ -27,6 +27,6 @@ fi # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate -t modules/openapi-generator/src/main/resources/erlang-proper --additional-properties packageName=petstore -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g erlang-proper -o samples/client/petstore/erlang-proper $@" +ags="generate -t modules/openapi-generator/src/main/resources/erlang-proper --additional-properties packageName=petstore -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g erlang-proper -o samples/client/petstore/erlang-proper $@" java $JAVA_OPTS -jar $executable $ags diff --git a/bin/erlang-petstore-server.sh b/bin/erlang-petstore-server.sh index a66451facb26..de587f37b971 100755 --- a/bin/erlang-petstore-server.sh +++ b/bin/erlang-petstore-server.sh @@ -27,6 +27,6 @@ fi # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate -t modules/openapi-generator/src/main/resources/erlang-server -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g erlang-server -o samples/server/petstore/erlang-server $@" +ags="generate -t modules/openapi-generator/src/main/resources/erlang-server -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g erlang-server -o samples/server/petstore/erlang-server $@" java $JAVA_OPTS -jar $executable $ags diff --git a/bin/openapi3/erlang-petstore-client.sh b/bin/openapi3/erlang-petstore-client.sh deleted file mode 100755 index fc75014a41e6..000000000000 --- a/bin/openapi3/erlang-petstore-client.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/sh - -SCRIPT="$0" -echo "# START SCRIPT: $SCRIPT" - -while [ -h "$SCRIPT" ] ; do - ls=`ls -ld "$SCRIPT"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - SCRIPT="$link" - else - SCRIPT=`dirname "$SCRIPT"`/"$link" - fi -done - -if [ ! -d "${APP_DIR}" ]; then - APP_DIR=`dirname "$SCRIPT"`/.. - APP_DIR=`cd "${APP_DIR}"; pwd` -fi - -executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar" - -if [ ! -f "$executable" ] -then - mvn clean package -fi - -# if you've executed sbt assembly previously it will use that instead. -export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate -t modules/openapi-generator/src/main/resources/erlang-client --additional-properties packageName=petstore -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g erlang-client -o samples/client/petstore/erlang-client $@" - -java $JAVA_OPTS -jar $executable $ags diff --git a/bin/openapi3/erlang-petstore-server.sh b/bin/openapi3/erlang-petstore-server.sh deleted file mode 100755 index 22968e5db505..000000000000 --- a/bin/openapi3/erlang-petstore-server.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/sh - -SCRIPT="$0" -echo "# START SCRIPT: $SCRIPT" - -while [ -h "$SCRIPT" ] ; do - ls=`ls -ld "$SCRIPT"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - SCRIPT="$link" - else - SCRIPT=`dirname "$SCRIPT"`/"$link" - fi -done - -if [ ! -d "${APP_DIR}" ]; then - APP_DIR=`dirname "$SCRIPT"`/.. - APP_DIR=`cd "${APP_DIR}"; pwd` -fi - -executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar" - -if [ ! -f "$executable" ] -then - mvn clean package -fi - -# if you've executed sbt assembly previously it will use that instead. -export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate -t modules/openapi-generator/src/main/resources/erlang-server -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g erlang-server -o samples/server/petstore/erlang-server $@" - -java $JAVA_OPTS -jar $executable $ags diff --git a/bin/windows/erlang-petstore-client.bat b/bin/windows/erlang-petstore-client.bat index cece95882d9b..88d0c61506dd 100755 --- a/bin/windows/erlang-petstore-client.bat +++ b/bin/windows/erlang-petstore-client.bat @@ -5,6 +5,6 @@ If Not Exist %executable% ( ) REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -set ags=generate -t modules\openapi-generator\src\main\resources\erlang-client -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g erlang-client -o samples\client\petstore\erlang-client +set ags=generate -t modules\openapi-generator\src\main\resources\erlang-client -i modules\openapi-generator\src\test\resources\3_0\petstore.yaml -g erlang-client -o samples\client\petstore\erlang-client java %JAVA_OPTS% -jar %executable% %ags% diff --git a/bin/windows/erlang-petstore-server.bat b/bin/windows/erlang-petstore-server.bat index dbae5bf9faf7..9b53c9f606c1 100755 --- a/bin/windows/erlang-petstore-server.bat +++ b/bin/windows/erlang-petstore-server.bat @@ -5,6 +5,6 @@ If Not Exist %executable% ( ) REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -set ags=generate -t modules\openapi-generator\src\main\resources\erlang-server -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g erlang-server -o samples\server\petstore\erlang-server +set ags=generate -t modules\openapi-generator\src\main\resources\erlang-server -i modules\openapi-generator\src\test\resources\3_0\petstore.yaml -g erlang-server -o samples\server\petstore\erlang-server java %JAVA_OPTS% -jar %executable% %ags% diff --git a/samples/client/petstore/erlang-client/.openapi-generator/VERSION b/samples/client/petstore/erlang-client/.openapi-generator/VERSION index 105bb87d77b3..d99e7162d01f 100644 --- a/samples/client/petstore/erlang-client/.openapi-generator/VERSION +++ b/samples/client/petstore/erlang-client/.openapi-generator/VERSION @@ -1 +1 @@ -3.2.2-SNAPSHOT \ No newline at end of file +5.0.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/erlang-client/src/petstore_pet_api.erl b/samples/client/petstore/erlang-client/src/petstore_pet_api.erl index bbb664f66bda..54991ba9dd19 100644 --- a/samples/client/petstore/erlang-client/src/petstore_pet_api.erl +++ b/samples/client/petstore/erlang-client/src/petstore_pet_api.erl @@ -13,11 +13,11 @@ %% @doc Add a new pet to the store %% --spec add_pet(ctx:ctx(), petstore_pet:petstore_pet()) -> {ok, [], petstore_utils:response_info()} | {ok, hackney:client_ref()} | {error, term(), petstore_utils:response_info()}. +-spec add_pet(ctx:ctx(), petstore_pet:petstore_pet()) -> {ok, petstore_pet:petstore_pet(), petstore_utils:response_info()} | {ok, hackney:client_ref()} | {error, term(), petstore_utils:response_info()}. add_pet(Ctx, PetstorePet) -> add_pet(Ctx, PetstorePet, #{}). --spec add_pet(ctx:ctx(), petstore_pet:petstore_pet(), maps:map()) -> {ok, [], petstore_utils:response_info()} | {ok, hackney:client_ref()} | {error, term(), petstore_utils:response_info()}. +-spec add_pet(ctx:ctx(), petstore_pet:petstore_pet(), maps:map()) -> {ok, petstore_pet:petstore_pet(), petstore_utils:response_info()} | {ok, hackney:client_ref()} | {error, term(), petstore_utils:response_info()}. add_pet(Ctx, PetstorePet, Optional) -> _OptionalParams = maps:get(params, Optional, #{}), Cfg = maps:get(cfg, Optional, application:get_env(kuberl, config, #{})), @@ -118,11 +118,11 @@ get_pet_by_id(Ctx, PetId, Optional) -> %% @doc Update an existing pet %% --spec update_pet(ctx:ctx(), petstore_pet:petstore_pet()) -> {ok, [], petstore_utils:response_info()} | {ok, hackney:client_ref()} | {error, term(), petstore_utils:response_info()}. +-spec update_pet(ctx:ctx(), petstore_pet:petstore_pet()) -> {ok, petstore_pet:petstore_pet(), petstore_utils:response_info()} | {ok, hackney:client_ref()} | {error, term(), petstore_utils:response_info()}. update_pet(Ctx, PetstorePet) -> update_pet(Ctx, PetstorePet, #{}). --spec update_pet(ctx:ctx(), petstore_pet:petstore_pet(), maps:map()) -> {ok, [], petstore_utils:response_info()} | {ok, hackney:client_ref()} | {error, term(), petstore_utils:response_info()}. +-spec update_pet(ctx:ctx(), petstore_pet:petstore_pet(), maps:map()) -> {ok, petstore_pet:petstore_pet(), petstore_utils:response_info()} | {ok, hackney:client_ref()} | {error, term(), petstore_utils:response_info()}. update_pet(Ctx, PetstorePet, Optional) -> _OptionalParams = maps:get(params, Optional, #{}), Cfg = maps:get(cfg, Optional, application:get_env(kuberl, config, #{})), diff --git a/samples/client/petstore/erlang-client/src/petstore_store_api.erl b/samples/client/petstore/erlang-client/src/petstore_store_api.erl index 178cd0a2cb23..2e72823d9d90 100644 --- a/samples/client/petstore/erlang-client/src/petstore_store_api.erl +++ b/samples/client/petstore/erlang-client/src/petstore_store_api.erl @@ -86,7 +86,7 @@ place_order(Ctx, PetstoreOrder, Optional) -> QS = [], Headers = [], Body1 = PetstoreOrder, - ContentTypeHeader = petstore_utils:select_header_content_type([]), + ContentTypeHeader = petstore_utils:select_header_content_type([<<"application/json">>]), Opts = maps:get(hackney_opts, Optional, []), petstore_utils:request(Ctx, Method, [?BASE_URL, Path], QS, ContentTypeHeader++Headers, Body1, Opts, Cfg). diff --git a/samples/client/petstore/erlang-client/src/petstore_user_api.erl b/samples/client/petstore/erlang-client/src/petstore_user_api.erl index b1f07026be88..45a8a9d78726 100644 --- a/samples/client/petstore/erlang-client/src/petstore_user_api.erl +++ b/samples/client/petstore/erlang-client/src/petstore_user_api.erl @@ -27,7 +27,7 @@ create_user(Ctx, PetstoreUser, Optional) -> QS = [], Headers = [], Body1 = PetstoreUser, - ContentTypeHeader = petstore_utils:select_header_content_type([]), + ContentTypeHeader = petstore_utils:select_header_content_type([<<"application/json">>]), Opts = maps:get(hackney_opts, Optional, []), petstore_utils:request(Ctx, Method, [?BASE_URL, Path], QS, ContentTypeHeader++Headers, Body1, Opts, Cfg). @@ -48,7 +48,7 @@ create_users_with_array_input(Ctx, PetstoreUserArray, Optional) -> QS = [], Headers = [], Body1 = PetstoreUserArray, - ContentTypeHeader = petstore_utils:select_header_content_type([]), + ContentTypeHeader = petstore_utils:select_header_content_type([<<"application/json">>]), Opts = maps:get(hackney_opts, Optional, []), petstore_utils:request(Ctx, Method, [?BASE_URL, Path], QS, ContentTypeHeader++Headers, Body1, Opts, Cfg). @@ -69,7 +69,7 @@ create_users_with_list_input(Ctx, PetstoreUserArray, Optional) -> QS = [], Headers = [], Body1 = PetstoreUserArray, - ContentTypeHeader = petstore_utils:select_header_content_type([]), + ContentTypeHeader = petstore_utils:select_header_content_type([<<"application/json">>]), Opts = maps:get(hackney_opts, Optional, []), petstore_utils:request(Ctx, Method, [?BASE_URL, Path], QS, ContentTypeHeader++Headers, Body1, Opts, Cfg). @@ -174,7 +174,7 @@ update_user(Ctx, Username, PetstoreUser, Optional) -> QS = [], Headers = [], Body1 = PetstoreUser, - ContentTypeHeader = petstore_utils:select_header_content_type([]), + ContentTypeHeader = petstore_utils:select_header_content_type([<<"application/json">>]), Opts = maps:get(hackney_opts, Optional, []), petstore_utils:request(Ctx, Method, [?BASE_URL, Path], QS, ContentTypeHeader++Headers, Body1, Opts, Cfg). diff --git a/samples/client/petstore/erlang-client/src/petstore_utils.erl b/samples/client/petstore/erlang-client/src/petstore_utils.erl index b96ec3da5ad6..e44f922f504a 100644 --- a/samples/client/petstore/erlang-client/src/petstore_utils.erl +++ b/samples/client/petstore/erlang-client/src/petstore_utils.erl @@ -75,7 +75,10 @@ update_params_with_auth(Cfg, Headers, QS) -> Auths = #{ 'api_key' => #{type => 'apiKey', key => <<"api_key">>, - in => header}, 'petstore_auth' => + in => header}, 'auth_cookie' => + #{type => 'apiKey', + key => <<"AUTH_KEY">>, + in => }, 'petstore_auth' => #{type => 'oauth2', key => <<"Authorization">>, in => header}}, diff --git a/samples/client/petstore/erlang-proper/.openapi-generator/VERSION b/samples/client/petstore/erlang-proper/.openapi-generator/VERSION index a65271290834..d99e7162d01f 100644 --- a/samples/client/petstore/erlang-proper/.openapi-generator/VERSION +++ b/samples/client/petstore/erlang-proper/.openapi-generator/VERSION @@ -1 +1 @@ -3.3.2-SNAPSHOT \ No newline at end of file +5.0.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/erlang-proper/src/petstore_api.erl b/samples/client/petstore/erlang-proper/src/petstore_api.erl index 2f852cfd4073..b45cf6a16072 100644 --- a/samples/client/petstore/erlang-proper/src/petstore_api.erl +++ b/samples/client/petstore/erlang-proper/src/petstore_api.erl @@ -21,7 +21,7 @@ create_user(PetstoreUser) -> Host = application:get_env(petstore, host, "http://localhost:8080"), Path = ["/user"], Body = PetstoreUser, - ContentType = "text/plain", + ContentType = hd(["application/json"]), petstore_utils:request(Method, [Host, ?BASE_URL, Path], jsx:encode(Body), ContentType). @@ -34,7 +34,7 @@ create_users_with_array_input(PetstoreUserArray) -> Host = application:get_env(petstore, host, "http://localhost:8080"), Path = ["/user/createWithArray"], Body = PetstoreUserArray, - ContentType = "text/plain", + ContentType = hd(["application/json"]), petstore_utils:request(Method, [Host, ?BASE_URL, Path], jsx:encode(Body), ContentType). @@ -47,7 +47,7 @@ create_users_with_list_input(PetstoreUserArray) -> Host = application:get_env(petstore, host, "http://localhost:8080"), Path = ["/user/createWithList"], Body = PetstoreUserArray, - ContentType = "text/plain", + ContentType = hd(["application/json"]), petstore_utils:request(Method, [Host, ?BASE_URL, Path], jsx:encode(Body), ContentType). @@ -105,7 +105,7 @@ update_user(Username, PetstoreUser) -> Host = application:get_env(petstore, host, "http://localhost:8080"), Path = ["/user/", Username, ""], Body = PetstoreUser, - ContentType = "text/plain", + ContentType = hd(["application/json"]), petstore_utils:request(Method, [Host, ?BASE_URL, Path], jsx:encode(Body), ContentType). diff --git a/samples/server/petstore/erlang-server/priv/openapi.json b/samples/server/petstore/erlang-server/priv/openapi.json index c72a9d39daa2..1968b835d96a 100644 --- a/samples/server/petstore/erlang-server/priv/openapi.json +++ b/samples/server/petstore/erlang-server/priv/openapi.json @@ -1,5 +1,5 @@ { - "openapi" : "3.0.1", + "openapi" : "3.0.0", "info" : { "description" : "This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.", "license" : { @@ -9,6 +9,10 @@ "title" : "OpenAPI Petstore", "version" : "1.0.0" }, + "externalDocs" : { + "description" : "Find out more about Swagger", + "url" : "http://swagger.io" + }, "servers" : [ { "url" : "http://petstore.swagger.io/v2" } ], @@ -27,24 +31,25 @@ "post" : { "operationId" : "addPet", "requestBody" : { - "content" : { - "application/json" : { - "schema" : { - "$ref" : "#/components/schemas/Pet" + "$ref" : "#/components/requestBodies/Pet" + }, + "responses" : { + "200" : { + "content" : { + "application/xml" : { + "schema" : { + "$ref" : "#/components/schemas/Pet" + } + }, + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/Pet" + } } }, - "application/xml" : { - "schema" : { - "$ref" : "#/components/schemas/Pet" - } - } + "description" : "successful operation" }, - "description" : "Pet object that needs to be added to the store", - "required" : true - }, - "responses" : { "405" : { - "content" : { }, "description" : "Invalid input" } }, @@ -52,38 +57,36 @@ "petstore_auth" : [ "write:pets", "read:pets" ] } ], "summary" : "Add a new pet to the store", - "tags" : [ "pet" ], - "x-codegen-request-body-name" : "body" + "tags" : [ "pet" ] }, "put" : { "operationId" : "updatePet", "requestBody" : { - "content" : { - "application/json" : { - "schema" : { - "$ref" : "#/components/schemas/Pet" + "$ref" : "#/components/requestBodies/Pet" + }, + "responses" : { + "200" : { + "content" : { + "application/xml" : { + "schema" : { + "$ref" : "#/components/schemas/Pet" + } + }, + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/Pet" + } } }, - "application/xml" : { - "schema" : { - "$ref" : "#/components/schemas/Pet" - } - } + "description" : "successful operation" }, - "description" : "Pet object that needs to be added to the store", - "required" : true - }, - "responses" : { "400" : { - "content" : { }, "description" : "Invalid ID supplied" }, "404" : { - "content" : { }, "description" : "Pet not found" }, "405" : { - "content" : { }, "description" : "Validation exception" } }, @@ -91,8 +94,7 @@ "petstore_auth" : [ "write:pets", "read:pets" ] } ], "summary" : "Update an existing pet", - "tags" : [ "pet" ], - "x-codegen-request-body-name" : "body" + "tags" : [ "pet" ] } }, "/pet/findByStatus" : { @@ -138,12 +140,11 @@ "description" : "successful operation" }, "400" : { - "content" : { }, "description" : "Invalid status value" } }, "security" : [ { - "petstore_auth" : [ "write:pets", "read:pets" ] + "petstore_auth" : [ "read:pets" ] } ], "summary" : "Finds Pets by status", "tags" : [ "pet" ] @@ -191,12 +192,11 @@ "description" : "successful operation" }, "400" : { - "content" : { }, "description" : "Invalid tag value" } }, "security" : [ { - "petstore_auth" : [ "write:pets", "read:pets" ] + "petstore_auth" : [ "read:pets" ] } ], "summary" : "Finds Pets by tags", "tags" : [ "pet" ] @@ -206,24 +206,28 @@ "delete" : { "operationId" : "deletePet", "parameters" : [ { + "explode" : false, "in" : "header", "name" : "api_key", + "required" : false, "schema" : { "type" : "string" - } + }, + "style" : "simple" }, { "description" : "Pet id to delete", + "explode" : false, "in" : "path", "name" : "petId", "required" : true, "schema" : { "format" : "int64", "type" : "integer" - } + }, + "style" : "simple" } ], "responses" : { "400" : { - "content" : { }, "description" : "Invalid pet value" } }, @@ -238,13 +242,15 @@ "operationId" : "getPetById", "parameters" : [ { "description" : "ID of pet to return", + "explode" : false, "in" : "path", "name" : "petId", "required" : true, "schema" : { "format" : "int64", "type" : "integer" - } + }, + "style" : "simple" } ], "responses" : { "200" : { @@ -263,11 +269,9 @@ "description" : "successful operation" }, "400" : { - "content" : { }, "description" : "Invalid ID supplied" }, "404" : { - "content" : { }, "description" : "Pet not found" } }, @@ -281,15 +285,18 @@ "operationId" : "updatePetWithForm", "parameters" : [ { "description" : "ID of pet that needs to be updated", + "explode" : false, "in" : "path", "name" : "petId", "required" : true, "schema" : { "format" : "int64", "type" : "integer" - } + }, + "style" : "simple" } ], "requestBody" : { + "$ref" : "#/components/requestBodies/inline_object", "content" : { "application/x-www-form-urlencoded" : { "schema" : { @@ -302,14 +309,14 @@ "description" : "Updated status of the pet", "type" : "string" } - } + }, + "type" : "object" } } } }, "responses" : { "405" : { - "content" : { }, "description" : "Invalid input" } }, @@ -325,15 +332,18 @@ "operationId" : "uploadFile", "parameters" : [ { "description" : "ID of pet to update", + "explode" : false, "in" : "path", "name" : "petId", "required" : true, "schema" : { "format" : "int64", "type" : "integer" - } + }, + "style" : "simple" } ], "requestBody" : { + "$ref" : "#/components/requestBodies/inline_object_1", "content" : { "multipart/form-data" : { "schema" : { @@ -347,7 +357,8 @@ "format" : "binary", "type" : "string" } - } + }, + "type" : "object" } } } @@ -403,7 +414,7 @@ "operationId" : "placeOrder", "requestBody" : { "content" : { - "*/*" : { + "application/json" : { "schema" : { "$ref" : "#/components/schemas/Order" } @@ -429,13 +440,11 @@ "description" : "successful operation" }, "400" : { - "content" : { }, "description" : "Invalid Order" } }, "summary" : "Place an order for a pet", - "tags" : [ "store" ], - "x-codegen-request-body-name" : "body" + "tags" : [ "store" ] } }, "/store/order/{orderId}" : { @@ -444,20 +453,20 @@ "operationId" : "deleteOrder", "parameters" : [ { "description" : "ID of the order that needs to be deleted", + "explode" : false, "in" : "path", "name" : "orderId", "required" : true, "schema" : { "type" : "string" - } + }, + "style" : "simple" } ], "responses" : { "400" : { - "content" : { }, "description" : "Invalid ID supplied" }, "404" : { - "content" : { }, "description" : "Order not found" } }, @@ -469,6 +478,7 @@ "operationId" : "getOrderById", "parameters" : [ { "description" : "ID of pet that needs to be fetched", + "explode" : false, "in" : "path", "name" : "orderId", "required" : true, @@ -477,7 +487,8 @@ "maximum" : 5, "minimum" : 1, "type" : "integer" - } + }, + "style" : "simple" } ], "responses" : { "200" : { @@ -496,11 +507,9 @@ "description" : "successful operation" }, "400" : { - "content" : { }, "description" : "Invalid ID supplied" }, "404" : { - "content" : { }, "description" : "Order not found" } }, @@ -514,7 +523,7 @@ "operationId" : "createUser", "requestBody" : { "content" : { - "*/*" : { + "application/json" : { "schema" : { "$ref" : "#/components/schemas/User" } @@ -525,69 +534,50 @@ }, "responses" : { "default" : { - "content" : { }, "description" : "successful operation" } }, + "security" : [ { + "auth_cookie" : [ ] + } ], "summary" : "Create user", - "tags" : [ "user" ], - "x-codegen-request-body-name" : "body" + "tags" : [ "user" ] } }, "/user/createWithArray" : { "post" : { "operationId" : "createUsersWithArrayInput", "requestBody" : { - "content" : { - "*/*" : { - "schema" : { - "items" : { - "$ref" : "#/components/schemas/User" - }, - "type" : "array" - } - } - }, - "description" : "List of user object", - "required" : true + "$ref" : "#/components/requestBodies/UserArray" }, "responses" : { "default" : { - "content" : { }, "description" : "successful operation" } }, + "security" : [ { + "auth_cookie" : [ ] + } ], "summary" : "Creates list of users with given input array", - "tags" : [ "user" ], - "x-codegen-request-body-name" : "body" + "tags" : [ "user" ] } }, "/user/createWithList" : { "post" : { "operationId" : "createUsersWithListInput", "requestBody" : { - "content" : { - "*/*" : { - "schema" : { - "items" : { - "$ref" : "#/components/schemas/User" - }, - "type" : "array" - } - } - }, - "description" : "List of user object", - "required" : true + "$ref" : "#/components/requestBodies/UserArray" }, "responses" : { "default" : { - "content" : { }, "description" : "successful operation" } }, + "security" : [ { + "auth_cookie" : [ ] + } ], "summary" : "Creates list of users with given input array", - "tags" : [ "user" ], - "x-codegen-request-body-name" : "body" + "tags" : [ "user" ] } }, "/user/login" : { @@ -595,20 +585,25 @@ "operationId" : "loginUser", "parameters" : [ { "description" : "The user name for login", + "explode" : true, "in" : "query", "name" : "username", "required" : true, "schema" : { + "pattern" : "^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$", "type" : "string" - } + }, + "style" : "form" }, { "description" : "The password for login in clear text", + "explode" : true, "in" : "query", "name" : "password", "required" : true, "schema" : { "type" : "string" - } + }, + "style" : "form" } ], "responses" : { "200" : { @@ -626,24 +621,36 @@ }, "description" : "successful operation", "headers" : { + "Set-Cookie" : { + "description" : "Cookie authentication key for use with the `auth_cookie` apiKey authentication.", + "explode" : false, + "schema" : { + "example" : "AUTH_KEY=abcde12345; Path=/; HttpOnly", + "type" : "string" + }, + "style" : "simple" + }, "X-Rate-Limit" : { "description" : "calls per hour allowed by the user", + "explode" : false, "schema" : { "format" : "int32", "type" : "integer" - } + }, + "style" : "simple" }, "X-Expires-After" : { "description" : "date in UTC when toekn expires", + "explode" : false, "schema" : { "format" : "date-time", "type" : "string" - } + }, + "style" : "simple" } } }, "400" : { - "content" : { }, "description" : "Invalid username/password supplied" } }, @@ -656,10 +663,12 @@ "operationId" : "logoutUser", "responses" : { "default" : { - "content" : { }, "description" : "successful operation" } }, + "security" : [ { + "auth_cookie" : [ ] + } ], "summary" : "Logs out current logged in user session", "tags" : [ "user" ] } @@ -670,23 +679,26 @@ "operationId" : "deleteUser", "parameters" : [ { "description" : "The name that needs to be deleted", + "explode" : false, "in" : "path", "name" : "username", "required" : true, "schema" : { "type" : "string" - } + }, + "style" : "simple" } ], "responses" : { "400" : { - "content" : { }, "description" : "Invalid username supplied" }, "404" : { - "content" : { }, "description" : "User not found" } }, + "security" : [ { + "auth_cookie" : [ ] + } ], "summary" : "Delete user", "tags" : [ "user" ] }, @@ -694,12 +706,14 @@ "operationId" : "getUserByName", "parameters" : [ { "description" : "The name that needs to be fetched. Use user1 for testing.", + "explode" : false, "in" : "path", "name" : "username", "required" : true, "schema" : { "type" : "string" - } + }, + "style" : "simple" } ], "responses" : { "200" : { @@ -718,11 +732,9 @@ "description" : "successful operation" }, "400" : { - "content" : { }, "description" : "Invalid username supplied" }, "404" : { - "content" : { }, "description" : "User not found" } }, @@ -734,16 +746,18 @@ "operationId" : "updateUser", "parameters" : [ { "description" : "name that need to be deleted", + "explode" : false, "in" : "path", "name" : "username", "required" : true, "schema" : { "type" : "string" - } + }, + "style" : "simple" } ], "requestBody" : { "content" : { - "*/*" : { + "application/json" : { "schema" : { "$ref" : "#/components/schemas/User" } @@ -754,21 +768,71 @@ }, "responses" : { "400" : { - "content" : { }, "description" : "Invalid user supplied" }, "404" : { - "content" : { }, "description" : "User not found" } }, + "security" : [ { + "auth_cookie" : [ ] + } ], "summary" : "Updated user", - "tags" : [ "user" ], - "x-codegen-request-body-name" : "body" + "tags" : [ "user" ] } } }, "components" : { + "requestBodies" : { + "UserArray" : { + "content" : { + "application/json" : { + "schema" : { + "items" : { + "$ref" : "#/components/schemas/User" + }, + "type" : "array" + } + } + }, + "description" : "List of user object", + "required" : true + }, + "Pet" : { + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/Pet" + } + }, + "application/xml" : { + "schema" : { + "$ref" : "#/components/schemas/Pet" + } + } + }, + "description" : "Pet object that needs to be added to the store", + "required" : true + }, + "inline_object" : { + "content" : { + "application/x-www-form-urlencoded" : { + "schema" : { + "$ref" : "#/components/schemas/inline_object" + } + } + } + }, + "inline_object_1" : { + "content" : { + "multipart/form-data" : { + "schema" : { + "$ref" : "#/components/schemas/inline_object_1" + } + } + } + } + }, "schemas" : { "Order" : { "description" : "An order for a pets from the pet store", @@ -825,6 +889,7 @@ "type" : "integer" }, "name" : { + "pattern" : "^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$", "type" : "string" } }, @@ -987,6 +1052,33 @@ }, "title" : "An uploaded response", "type" : "object" + }, + "inline_object" : { + "properties" : { + "name" : { + "description" : "Updated name of the pet", + "type" : "string" + }, + "status" : { + "description" : "Updated status of the pet", + "type" : "string" + } + }, + "type" : "object" + }, + "inline_object_1" : { + "properties" : { + "additionalMetadata" : { + "description" : "Additional data to pass to server", + "type" : "string" + }, + "file" : { + "description" : "file to upload", + "format" : "binary", + "type" : "string" + } + }, + "type" : "object" } }, "securitySchemes" : { @@ -1006,6 +1098,11 @@ "in" : "header", "name" : "api_key", "type" : "apiKey" + }, + "auth_cookie" : { + "in" : "cookie", + "name" : "AUTH_KEY", + "type" : "apiKey" } } } diff --git a/samples/server/petstore/erlang-server/src/openapi_api.erl b/samples/server/petstore/erlang-server/src/openapi_api.erl index ba4b3a0e7aff..a1a6fa220ec3 100644 --- a/samples/server/petstore/erlang-server/src/openapi_api.erl +++ b/samples/server/petstore/erlang-server/src/openapi_api.erl @@ -349,6 +349,7 @@ request_param_info('LoginUser', 'username') -> source => qs_val , rules => [ {type, 'binary'}, + {pattern, "/^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$/" }, required ] }; @@ -427,6 +428,8 @@ populate_request_param(OperationID, Name, Req0, ValidatorState) -> ) -> ok | no_return(). +validate_response('AddPet', 200, Body, ValidatorState) -> + validate_response_body('Pet', 'Pet', Body, ValidatorState); validate_response('AddPet', 405, Body, ValidatorState) -> validate_response_body('', '', Body, ValidatorState); @@ -450,6 +453,8 @@ validate_response('GetPetById', 400, Body, ValidatorState) -> validate_response('GetPetById', 404, Body, ValidatorState) -> validate_response_body('', '', Body, ValidatorState); +validate_response('UpdatePet', 200, Body, ValidatorState) -> + validate_response_body('Pet', 'Pet', Body, ValidatorState); validate_response('UpdatePet', 400, Body, ValidatorState) -> validate_response_body('', '', Body, ValidatorState); validate_response('UpdatePet', 404, Body, ValidatorState) -> diff --git a/samples/server/petstore/erlang-server/src/openapi_auth.erl b/samples/server/petstore/erlang-server/src/openapi_auth.erl index 06f1f163953b..7cc2c138e19d 100644 --- a/samples/server/petstore/erlang-server/src/openapi_auth.erl +++ b/samples/server/petstore/erlang-server/src/openapi_auth.erl @@ -24,6 +24,8 @@ authorize_api_key(LogicHandler, OperationID, From, KeyParam, Req0) -> ApiKey ), case Result of + {true, Context} -> + {true, Context, Req}; {true, Context} -> {true, Context, Req}; false -> diff --git a/samples/server/petstore/erlang-server/src/openapi_default_logic_handler.erl b/samples/server/petstore/erlang-server/src/openapi_default_logic_handler.erl index da6e79a74ebd..a1b9e14385db 100644 --- a/samples/server/petstore/erlang-server/src/openapi_default_logic_handler.erl +++ b/samples/server/petstore/erlang-server/src/openapi_default_logic_handler.erl @@ -4,7 +4,11 @@ -export([handle_request/3]). -export([authorize_api_key/2]). +-export([authorize_api_key/2]). + +-spec authorize_api_key(OperationID :: openapi_api:operation_id(), ApiKey :: binary()) -> {true, #{}}. +authorize_api_key(_, _) -> {true, #{}}. -spec authorize_api_key(OperationID :: openapi_api:operation_id(), ApiKey :: binary()) -> {true, #{}}. authorize_api_key(_, _) -> {true, #{}}. diff --git a/samples/server/petstore/erlang-server/src/openapi_logic_handler.erl b/samples/server/petstore/erlang-server/src/openapi_logic_handler.erl index 2c05ce24836e..4d45fe7a59c8 100644 --- a/samples/server/petstore/erlang-server/src/openapi_logic_handler.erl +++ b/samples/server/petstore/erlang-server/src/openapi_logic_handler.erl @@ -16,6 +16,11 @@ ApiKey :: binary() ) -> Result :: boolean() | {boolean(), context()}. +-callback authorize_api_key( + OperationID :: openapi_api:operation_id(), + ApiKey :: binary() +) -> + Result :: boolean() | {boolean(), context()}. -callback handle_request(OperationID :: openapi_api:operation_id(), cowboy_req:req(), Context :: context()) -> @@ -36,3 +41,7 @@ handle_request(Handler, OperationID, Req, Context) -> Result :: false | {true, context()}. authorize_api_key(Handler, OperationID, ApiKey) -> Handler:authorize_api_key(OperationID, ApiKey). +-spec authorize_api_key(Handler :: atom(), OperationID :: openapi_api:operation_id(), ApiKey :: binary()) -> + Result :: false | {true, context()}. +authorize_api_key(Handler, OperationID, ApiKey) -> + Handler:authorize_api_key(OperationID, ApiKey). diff --git a/samples/server/petstore/erlang-server/src/openapi_user_handler.erl b/samples/server/petstore/erlang-server/src/openapi_user_handler.erl index 6381a75aeb2a..7ab3f0b2ee4d 100644 --- a/samples/server/petstore/erlang-server/src/openapi_user_handler.erl +++ b/samples/server/petstore/erlang-server/src/openapi_user_handler.erl @@ -119,6 +119,120 @@ allowed_methods(Req, State) -> Req :: cowboy_req:req(), State :: state() }. +is_authorized( + Req0, + State = #state{ + operation_id = 'CreateUser' = OperationID, + logic_handler = LogicHandler + } +) -> + From = , + Result = openapi_auth:authorize_api_key( + LogicHandler, + OperationID, + From, + "AUTH_KEY", + Req0 + ), + case Result of + {true, Context, Req} -> {true, Req, State#state{context = Context}}; + {false, AuthHeader, Req} -> {{false, AuthHeader}, Req, State} + end; +is_authorized( + Req0, + State = #state{ + operation_id = 'CreateUsersWithArrayInput' = OperationID, + logic_handler = LogicHandler + } +) -> + From = , + Result = openapi_auth:authorize_api_key( + LogicHandler, + OperationID, + From, + "AUTH_KEY", + Req0 + ), + case Result of + {true, Context, Req} -> {true, Req, State#state{context = Context}}; + {false, AuthHeader, Req} -> {{false, AuthHeader}, Req, State} + end; +is_authorized( + Req0, + State = #state{ + operation_id = 'CreateUsersWithListInput' = OperationID, + logic_handler = LogicHandler + } +) -> + From = , + Result = openapi_auth:authorize_api_key( + LogicHandler, + OperationID, + From, + "AUTH_KEY", + Req0 + ), + case Result of + {true, Context, Req} -> {true, Req, State#state{context = Context}}; + {false, AuthHeader, Req} -> {{false, AuthHeader}, Req, State} + end; +is_authorized( + Req0, + State = #state{ + operation_id = 'DeleteUser' = OperationID, + logic_handler = LogicHandler + } +) -> + From = , + Result = openapi_auth:authorize_api_key( + LogicHandler, + OperationID, + From, + "AUTH_KEY", + Req0 + ), + case Result of + {true, Context, Req} -> {true, Req, State#state{context = Context}}; + {false, AuthHeader, Req} -> {{false, AuthHeader}, Req, State} + end; +is_authorized( + Req0, + State = #state{ + operation_id = 'LogoutUser' = OperationID, + logic_handler = LogicHandler + } +) -> + From = , + Result = openapi_auth:authorize_api_key( + LogicHandler, + OperationID, + From, + "AUTH_KEY", + Req0 + ), + case Result of + {true, Context, Req} -> {true, Req, State#state{context = Context}}; + {false, AuthHeader, Req} -> {{false, AuthHeader}, Req, State} + end; +is_authorized( + Req0, + State = #state{ + operation_id = 'UpdateUser' = OperationID, + logic_handler = LogicHandler + } +) -> + From = , + Result = openapi_auth:authorize_api_key( + LogicHandler, + OperationID, + From, + "AUTH_KEY", + Req0 + ), + case Result of + {true, Context, Req} -> {true, Req, State#state{context = Context}}; + {false, AuthHeader, Req} -> {{false, AuthHeader}, Req, State} + end; is_authorized(Req, State) -> {true, Req, State}. From 1b1ca4555cd878a09993cf8f3038ce263defa87f Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 14 May 2020 17:39:27 +0800 Subject: [PATCH 2/3] add new files --- .../src/petstore_inline_object.erl | 17 +++++++++++++ .../src/petstore_inline_object_1.erl | 17 +++++++++++++ .../src/model/petstore_inline_object.erl | 25 +++++++++++++++++++ .../src/model/petstore_inline_object_1.erl | 25 +++++++++++++++++++ .../erlang-server/.openapi-generator/VERSION | 1 + 5 files changed, 85 insertions(+) create mode 100644 samples/client/petstore/erlang-client/src/petstore_inline_object.erl create mode 100644 samples/client/petstore/erlang-client/src/petstore_inline_object_1.erl create mode 100644 samples/client/petstore/erlang-proper/src/model/petstore_inline_object.erl create mode 100644 samples/client/petstore/erlang-proper/src/model/petstore_inline_object_1.erl create mode 100644 samples/server/petstore/erlang-server/.openapi-generator/VERSION diff --git a/samples/client/petstore/erlang-client/src/petstore_inline_object.erl b/samples/client/petstore/erlang-client/src/petstore_inline_object.erl new file mode 100644 index 000000000000..9863a8e30bb7 --- /dev/null +++ b/samples/client/petstore/erlang-client/src/petstore_inline_object.erl @@ -0,0 +1,17 @@ +-module(petstore_inline_object). + +-export([encode/1]). + +-export_type([petstore_inline_object/0]). + +-type petstore_inline_object() :: + #{ 'name' => binary(), + 'status' => binary() + }. + +encode(#{ 'name' := Name, + 'status' := Status + }) -> + #{ 'name' => Name, + 'status' => Status + }. diff --git a/samples/client/petstore/erlang-client/src/petstore_inline_object_1.erl b/samples/client/petstore/erlang-client/src/petstore_inline_object_1.erl new file mode 100644 index 000000000000..faf9a97e8964 --- /dev/null +++ b/samples/client/petstore/erlang-client/src/petstore_inline_object_1.erl @@ -0,0 +1,17 @@ +-module(petstore_inline_object_1). + +-export([encode/1]). + +-export_type([petstore_inline_object_1/0]). + +-type petstore_inline_object_1() :: + #{ 'additionalMetadata' => binary(), + 'file' => binary() + }. + +encode(#{ 'additionalMetadata' := AdditionalMetadata, + 'file' := File + }) -> + #{ 'additionalMetadata' => AdditionalMetadata, + 'file' => File + }. diff --git a/samples/client/petstore/erlang-proper/src/model/petstore_inline_object.erl b/samples/client/petstore/erlang-proper/src/model/petstore_inline_object.erl new file mode 100644 index 000000000000..aa84f722e79c --- /dev/null +++ b/samples/client/petstore/erlang-proper/src/model/petstore_inline_object.erl @@ -0,0 +1,25 @@ +-module(petstore_inline_object). + +-include("petstore.hrl"). + +-export([petstore_inline_object/0]). + +-export([petstore_inline_object/1]). + +-export_type([petstore_inline_object/0]). + +-type petstore_inline_object() :: + [ {'name', binary() } + | {'status', binary() } + ]. + + +petstore_inline_object() -> + petstore_inline_object([]). + +petstore_inline_object(Fields) -> + Default = [ {'name', binary() } + , {'status', binary() } + ], + lists:ukeymerge(1, lists:sort(Fields), lists:sort(Default)). + diff --git a/samples/client/petstore/erlang-proper/src/model/petstore_inline_object_1.erl b/samples/client/petstore/erlang-proper/src/model/petstore_inline_object_1.erl new file mode 100644 index 000000000000..3af5b444422c --- /dev/null +++ b/samples/client/petstore/erlang-proper/src/model/petstore_inline_object_1.erl @@ -0,0 +1,25 @@ +-module(petstore_inline_object_1). + +-include("petstore.hrl"). + +-export([petstore_inline_object_1/0]). + +-export([petstore_inline_object_1/1]). + +-export_type([petstore_inline_object_1/0]). + +-type petstore_inline_object_1() :: + [ {'additionalMetadata', binary() } + | {'file', binary() } + ]. + + +petstore_inline_object_1() -> + petstore_inline_object_1([]). + +petstore_inline_object_1(Fields) -> + Default = [ {'additionalMetadata', binary() } + , {'file', binary() } + ], + lists:ukeymerge(1, lists:sort(Fields), lists:sort(Default)). + diff --git a/samples/server/petstore/erlang-server/.openapi-generator/VERSION b/samples/server/petstore/erlang-server/.openapi-generator/VERSION new file mode 100644 index 000000000000..d99e7162d01f --- /dev/null +++ b/samples/server/petstore/erlang-server/.openapi-generator/VERSION @@ -0,0 +1 @@ +5.0.0-SNAPSHOT \ No newline at end of file From 1291e2cf2e2ddfb9b727fbd4e06ed09d65c17500 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Fri, 15 May 2020 09:27:22 +0800 Subject: [PATCH 3/3] update samples --- .../erlang-client/src/petstore_utils.erl | 5 +--- .../petstore/erlang-server/priv/openapi.json | 19 ++++++--------- .../erlang-server/src/openapi_auth.erl | 2 -- .../src/openapi_default_logic_handler.erl | 4 ---- .../src/openapi_logic_handler.erl | 9 ------- .../src/openapi_user_handler.erl | 24 +++++++++---------- 6 files changed, 20 insertions(+), 43 deletions(-) diff --git a/samples/client/petstore/erlang-client/src/petstore_utils.erl b/samples/client/petstore/erlang-client/src/petstore_utils.erl index e44f922f504a..b96ec3da5ad6 100644 --- a/samples/client/petstore/erlang-client/src/petstore_utils.erl +++ b/samples/client/petstore/erlang-client/src/petstore_utils.erl @@ -75,10 +75,7 @@ update_params_with_auth(Cfg, Headers, QS) -> Auths = #{ 'api_key' => #{type => 'apiKey', key => <<"api_key">>, - in => header}, 'auth_cookie' => - #{type => 'apiKey', - key => <<"AUTH_KEY">>, - in => }, 'petstore_auth' => + in => header}, 'petstore_auth' => #{type => 'oauth2', key => <<"Authorization">>, in => header}}, diff --git a/samples/server/petstore/erlang-server/priv/openapi.json b/samples/server/petstore/erlang-server/priv/openapi.json index 1968b835d96a..4be6ecab7079 100644 --- a/samples/server/petstore/erlang-server/priv/openapi.json +++ b/samples/server/petstore/erlang-server/priv/openapi.json @@ -538,7 +538,7 @@ } }, "security" : [ { - "auth_cookie" : [ ] + "api_key" : [ ] } ], "summary" : "Create user", "tags" : [ "user" ] @@ -556,7 +556,7 @@ } }, "security" : [ { - "auth_cookie" : [ ] + "api_key" : [ ] } ], "summary" : "Creates list of users with given input array", "tags" : [ "user" ] @@ -574,7 +574,7 @@ } }, "security" : [ { - "auth_cookie" : [ ] + "api_key" : [ ] } ], "summary" : "Creates list of users with given input array", "tags" : [ "user" ] @@ -622,7 +622,7 @@ "description" : "successful operation", "headers" : { "Set-Cookie" : { - "description" : "Cookie authentication key for use with the `auth_cookie` apiKey authentication.", + "description" : "Cookie authentication key for use with the `api_key` apiKey authentication.", "explode" : false, "schema" : { "example" : "AUTH_KEY=abcde12345; Path=/; HttpOnly", @@ -667,7 +667,7 @@ } }, "security" : [ { - "auth_cookie" : [ ] + "api_key" : [ ] } ], "summary" : "Logs out current logged in user session", "tags" : [ "user" ] @@ -697,7 +697,7 @@ } }, "security" : [ { - "auth_cookie" : [ ] + "api_key" : [ ] } ], "summary" : "Delete user", "tags" : [ "user" ] @@ -775,7 +775,7 @@ } }, "security" : [ { - "auth_cookie" : [ ] + "api_key" : [ ] } ], "summary" : "Updated user", "tags" : [ "user" ] @@ -1098,11 +1098,6 @@ "in" : "header", "name" : "api_key", "type" : "apiKey" - }, - "auth_cookie" : { - "in" : "cookie", - "name" : "AUTH_KEY", - "type" : "apiKey" } } } diff --git a/samples/server/petstore/erlang-server/src/openapi_auth.erl b/samples/server/petstore/erlang-server/src/openapi_auth.erl index 7cc2c138e19d..06f1f163953b 100644 --- a/samples/server/petstore/erlang-server/src/openapi_auth.erl +++ b/samples/server/petstore/erlang-server/src/openapi_auth.erl @@ -24,8 +24,6 @@ authorize_api_key(LogicHandler, OperationID, From, KeyParam, Req0) -> ApiKey ), case Result of - {true, Context} -> - {true, Context, Req}; {true, Context} -> {true, Context, Req}; false -> diff --git a/samples/server/petstore/erlang-server/src/openapi_default_logic_handler.erl b/samples/server/petstore/erlang-server/src/openapi_default_logic_handler.erl index a1b9e14385db..da6e79a74ebd 100644 --- a/samples/server/petstore/erlang-server/src/openapi_default_logic_handler.erl +++ b/samples/server/petstore/erlang-server/src/openapi_default_logic_handler.erl @@ -4,11 +4,7 @@ -export([handle_request/3]). -export([authorize_api_key/2]). --export([authorize_api_key/2]). - --spec authorize_api_key(OperationID :: openapi_api:operation_id(), ApiKey :: binary()) -> {true, #{}}. -authorize_api_key(_, _) -> {true, #{}}. -spec authorize_api_key(OperationID :: openapi_api:operation_id(), ApiKey :: binary()) -> {true, #{}}. authorize_api_key(_, _) -> {true, #{}}. diff --git a/samples/server/petstore/erlang-server/src/openapi_logic_handler.erl b/samples/server/petstore/erlang-server/src/openapi_logic_handler.erl index 4d45fe7a59c8..2c05ce24836e 100644 --- a/samples/server/petstore/erlang-server/src/openapi_logic_handler.erl +++ b/samples/server/petstore/erlang-server/src/openapi_logic_handler.erl @@ -16,11 +16,6 @@ ApiKey :: binary() ) -> Result :: boolean() | {boolean(), context()}. --callback authorize_api_key( - OperationID :: openapi_api:operation_id(), - ApiKey :: binary() -) -> - Result :: boolean() | {boolean(), context()}. -callback handle_request(OperationID :: openapi_api:operation_id(), cowboy_req:req(), Context :: context()) -> @@ -41,7 +36,3 @@ handle_request(Handler, OperationID, Req, Context) -> Result :: false | {true, context()}. authorize_api_key(Handler, OperationID, ApiKey) -> Handler:authorize_api_key(OperationID, ApiKey). --spec authorize_api_key(Handler :: atom(), OperationID :: openapi_api:operation_id(), ApiKey :: binary()) -> - Result :: false | {true, context()}. -authorize_api_key(Handler, OperationID, ApiKey) -> - Handler:authorize_api_key(OperationID, ApiKey). diff --git a/samples/server/petstore/erlang-server/src/openapi_user_handler.erl b/samples/server/petstore/erlang-server/src/openapi_user_handler.erl index 7ab3f0b2ee4d..4c71b5ebcfd0 100644 --- a/samples/server/petstore/erlang-server/src/openapi_user_handler.erl +++ b/samples/server/petstore/erlang-server/src/openapi_user_handler.erl @@ -126,12 +126,12 @@ is_authorized( logic_handler = LogicHandler } ) -> - From = , + From = header, Result = openapi_auth:authorize_api_key( LogicHandler, OperationID, From, - "AUTH_KEY", + "api_key", Req0 ), case Result of @@ -145,12 +145,12 @@ is_authorized( logic_handler = LogicHandler } ) -> - From = , + From = header, Result = openapi_auth:authorize_api_key( LogicHandler, OperationID, From, - "AUTH_KEY", + "api_key", Req0 ), case Result of @@ -164,12 +164,12 @@ is_authorized( logic_handler = LogicHandler } ) -> - From = , + From = header, Result = openapi_auth:authorize_api_key( LogicHandler, OperationID, From, - "AUTH_KEY", + "api_key", Req0 ), case Result of @@ -183,12 +183,12 @@ is_authorized( logic_handler = LogicHandler } ) -> - From = , + From = header, Result = openapi_auth:authorize_api_key( LogicHandler, OperationID, From, - "AUTH_KEY", + "api_key", Req0 ), case Result of @@ -202,12 +202,12 @@ is_authorized( logic_handler = LogicHandler } ) -> - From = , + From = header, Result = openapi_auth:authorize_api_key( LogicHandler, OperationID, From, - "AUTH_KEY", + "api_key", Req0 ), case Result of @@ -221,12 +221,12 @@ is_authorized( logic_handler = LogicHandler } ) -> - From = , + From = header, Result = openapi_auth:authorize_api_key( LogicHandler, OperationID, From, - "AUTH_KEY", + "api_key", Req0 ), case Result of