Migrate Erlang samples to use OAS 3 spec (#6297)

* erlang samples switch to oas3 spec

* add new files

* update samples
This commit is contained in:
William Cheng 2020-05-15 11:24:37 +08:00 committed by GitHub
parent d77ab6b9e2
commit 654e94c645
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 430 additions and 198 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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%

View File

@ -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%

View File

@ -1 +1 @@
3.2.2-SNAPSHOT
5.0.0-SNAPSHOT

View File

@ -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
}.

View File

@ -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
}.

View File

@ -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, #{})),

View File

@ -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).

View File

@ -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).

View File

@ -1 +1 @@
3.3.2-SNAPSHOT
5.0.0-SNAPSHOT

View File

@ -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)).

View File

@ -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)).

View File

@ -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).

View File

@ -0,0 +1 @@
5.0.0-SNAPSHOT

View File

@ -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"
}
}
},
"description" : "Pet object that needs to be added to the store",
"required" : true
"description" : "successful operation"
},
"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"
}
}
},
"description" : "Pet object that needs to be added to the store",
"required" : true
"description" : "successful operation"
},
"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" : [ {
"api_key" : [ ]
} ],
"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" : [ {
"api_key" : [ ]
} ],
"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" : [ {
"api_key" : [ ]
} ],
"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 `api_key` 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" : [ {
"api_key" : [ ]
} ],
"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" : [ {
"api_key" : [ ]
} ],
"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" : [ {
"api_key" : [ ]
} ],
"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" : {

View File

@ -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) ->

View File

@ -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 = header,
Result = openapi_auth:authorize_api_key(
LogicHandler,
OperationID,
From,
"api_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 = header,
Result = openapi_auth:authorize_api_key(
LogicHandler,
OperationID,
From,
"api_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 = header,
Result = openapi_auth:authorize_api_key(
LogicHandler,
OperationID,
From,
"api_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 = header,
Result = openapi_auth:authorize_api_key(
LogicHandler,
OperationID,
From,
"api_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 = header,
Result = openapi_auth:authorize_api_key(
LogicHandler,
OperationID,
From,
"api_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 = header,
Result = openapi_auth:authorize_api_key(
LogicHandler,
OperationID,
From,
"api_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}.