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. # if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" 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 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. # if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" 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 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. # if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" 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 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 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% java %JAVA_OPTS% -jar %executable% %ags%

View File

@ -5,6 +5,6 @@ If Not Exist %executable% (
) )
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M 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% 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 %% @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) ->
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) -> add_pet(Ctx, PetstorePet, Optional) ->
_OptionalParams = maps:get(params, Optional, #{}), _OptionalParams = maps:get(params, Optional, #{}),
Cfg = maps:get(cfg, Optional, application:get_env(kuberl, config, #{})), 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 %% @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) ->
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) -> update_pet(Ctx, PetstorePet, Optional) ->
_OptionalParams = maps:get(params, Optional, #{}), _OptionalParams = maps:get(params, Optional, #{}),
Cfg = maps:get(cfg, Optional, application:get_env(kuberl, config, #{})), Cfg = maps:get(cfg, Optional, application:get_env(kuberl, config, #{})),

View File

@ -86,7 +86,7 @@ place_order(Ctx, PetstoreOrder, Optional) ->
QS = [], QS = [],
Headers = [], Headers = [],
Body1 = PetstoreOrder, Body1 = PetstoreOrder,
ContentTypeHeader = petstore_utils:select_header_content_type([]), ContentTypeHeader = petstore_utils:select_header_content_type([<<"application/json">>]),
Opts = maps:get(hackney_opts, Optional, []), Opts = maps:get(hackney_opts, Optional, []),
petstore_utils:request(Ctx, Method, [?BASE_URL, Path], QS, ContentTypeHeader++Headers, Body1, Opts, Cfg). 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 = [], QS = [],
Headers = [], Headers = [],
Body1 = PetstoreUser, Body1 = PetstoreUser,
ContentTypeHeader = petstore_utils:select_header_content_type([]), ContentTypeHeader = petstore_utils:select_header_content_type([<<"application/json">>]),
Opts = maps:get(hackney_opts, Optional, []), Opts = maps:get(hackney_opts, Optional, []),
petstore_utils:request(Ctx, Method, [?BASE_URL, Path], QS, ContentTypeHeader++Headers, Body1, Opts, Cfg). 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 = [], QS = [],
Headers = [], Headers = [],
Body1 = PetstoreUserArray, Body1 = PetstoreUserArray,
ContentTypeHeader = petstore_utils:select_header_content_type([]), ContentTypeHeader = petstore_utils:select_header_content_type([<<"application/json">>]),
Opts = maps:get(hackney_opts, Optional, []), Opts = maps:get(hackney_opts, Optional, []),
petstore_utils:request(Ctx, Method, [?BASE_URL, Path], QS, ContentTypeHeader++Headers, Body1, Opts, Cfg). 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 = [], QS = [],
Headers = [], Headers = [],
Body1 = PetstoreUserArray, Body1 = PetstoreUserArray,
ContentTypeHeader = petstore_utils:select_header_content_type([]), ContentTypeHeader = petstore_utils:select_header_content_type([<<"application/json">>]),
Opts = maps:get(hackney_opts, Optional, []), Opts = maps:get(hackney_opts, Optional, []),
petstore_utils:request(Ctx, Method, [?BASE_URL, Path], QS, ContentTypeHeader++Headers, Body1, Opts, Cfg). 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 = [], QS = [],
Headers = [], Headers = [],
Body1 = PetstoreUser, Body1 = PetstoreUser,
ContentTypeHeader = petstore_utils:select_header_content_type([]), ContentTypeHeader = petstore_utils:select_header_content_type([<<"application/json">>]),
Opts = maps:get(hackney_opts, Optional, []), Opts = maps:get(hackney_opts, Optional, []),
petstore_utils:request(Ctx, Method, [?BASE_URL, Path], QS, ContentTypeHeader++Headers, Body1, Opts, Cfg). 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"), Host = application:get_env(petstore, host, "http://localhost:8080"),
Path = ["/user"], Path = ["/user"],
Body = PetstoreUser, Body = PetstoreUser,
ContentType = "text/plain", ContentType = hd(["application/json"]),
petstore_utils:request(Method, [Host, ?BASE_URL, Path], jsx:encode(Body), ContentType). 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"), Host = application:get_env(petstore, host, "http://localhost:8080"),
Path = ["/user/createWithArray"], Path = ["/user/createWithArray"],
Body = PetstoreUserArray, Body = PetstoreUserArray,
ContentType = "text/plain", ContentType = hd(["application/json"]),
petstore_utils:request(Method, [Host, ?BASE_URL, Path], jsx:encode(Body), ContentType). 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"), Host = application:get_env(petstore, host, "http://localhost:8080"),
Path = ["/user/createWithList"], Path = ["/user/createWithList"],
Body = PetstoreUserArray, Body = PetstoreUserArray,
ContentType = "text/plain", ContentType = hd(["application/json"]),
petstore_utils:request(Method, [Host, ?BASE_URL, Path], jsx:encode(Body), ContentType). 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"), Host = application:get_env(petstore, host, "http://localhost:8080"),
Path = ["/user/", Username, ""], Path = ["/user/", Username, ""],
Body = PetstoreUser, Body = PetstoreUser,
ContentType = "text/plain", ContentType = hd(["application/json"]),
petstore_utils:request(Method, [Host, ?BASE_URL, Path], jsx:encode(Body), ContentType). 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" : { "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.", "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" : { "license" : {
@ -9,6 +9,10 @@
"title" : "OpenAPI Petstore", "title" : "OpenAPI Petstore",
"version" : "1.0.0" "version" : "1.0.0"
}, },
"externalDocs" : {
"description" : "Find out more about Swagger",
"url" : "http://swagger.io"
},
"servers" : [ { "servers" : [ {
"url" : "http://petstore.swagger.io/v2" "url" : "http://petstore.swagger.io/v2"
} ], } ],
@ -27,24 +31,25 @@
"post" : { "post" : {
"operationId" : "addPet", "operationId" : "addPet",
"requestBody" : { "requestBody" : {
"content" : { "$ref" : "#/components/requestBodies/Pet"
"application/json" : {
"schema" : {
"$ref" : "#/components/schemas/Pet"
}
}, },
"responses" : {
"200" : {
"content" : {
"application/xml" : { "application/xml" : {
"schema" : { "schema" : {
"$ref" : "#/components/schemas/Pet" "$ref" : "#/components/schemas/Pet"
} }
},
"application/json" : {
"schema" : {
"$ref" : "#/components/schemas/Pet"
}
} }
}, },
"description" : "Pet object that needs to be added to the store", "description" : "successful operation"
"required" : true
}, },
"responses" : {
"405" : { "405" : {
"content" : { },
"description" : "Invalid input" "description" : "Invalid input"
} }
}, },
@ -52,38 +57,36 @@
"petstore_auth" : [ "write:pets", "read:pets" ] "petstore_auth" : [ "write:pets", "read:pets" ]
} ], } ],
"summary" : "Add a new pet to the store", "summary" : "Add a new pet to the store",
"tags" : [ "pet" ], "tags" : [ "pet" ]
"x-codegen-request-body-name" : "body"
}, },
"put" : { "put" : {
"operationId" : "updatePet", "operationId" : "updatePet",
"requestBody" : { "requestBody" : {
"content" : { "$ref" : "#/components/requestBodies/Pet"
"application/json" : {
"schema" : {
"$ref" : "#/components/schemas/Pet"
}
}, },
"responses" : {
"200" : {
"content" : {
"application/xml" : { "application/xml" : {
"schema" : { "schema" : {
"$ref" : "#/components/schemas/Pet" "$ref" : "#/components/schemas/Pet"
} }
},
"application/json" : {
"schema" : {
"$ref" : "#/components/schemas/Pet"
}
} }
}, },
"description" : "Pet object that needs to be added to the store", "description" : "successful operation"
"required" : true
}, },
"responses" : {
"400" : { "400" : {
"content" : { },
"description" : "Invalid ID supplied" "description" : "Invalid ID supplied"
}, },
"404" : { "404" : {
"content" : { },
"description" : "Pet not found" "description" : "Pet not found"
}, },
"405" : { "405" : {
"content" : { },
"description" : "Validation exception" "description" : "Validation exception"
} }
}, },
@ -91,8 +94,7 @@
"petstore_auth" : [ "write:pets", "read:pets" ] "petstore_auth" : [ "write:pets", "read:pets" ]
} ], } ],
"summary" : "Update an existing pet", "summary" : "Update an existing pet",
"tags" : [ "pet" ], "tags" : [ "pet" ]
"x-codegen-request-body-name" : "body"
} }
}, },
"/pet/findByStatus" : { "/pet/findByStatus" : {
@ -138,12 +140,11 @@
"description" : "successful operation" "description" : "successful operation"
}, },
"400" : { "400" : {
"content" : { },
"description" : "Invalid status value" "description" : "Invalid status value"
} }
}, },
"security" : [ { "security" : [ {
"petstore_auth" : [ "write:pets", "read:pets" ] "petstore_auth" : [ "read:pets" ]
} ], } ],
"summary" : "Finds Pets by status", "summary" : "Finds Pets by status",
"tags" : [ "pet" ] "tags" : [ "pet" ]
@ -191,12 +192,11 @@
"description" : "successful operation" "description" : "successful operation"
}, },
"400" : { "400" : {
"content" : { },
"description" : "Invalid tag value" "description" : "Invalid tag value"
} }
}, },
"security" : [ { "security" : [ {
"petstore_auth" : [ "write:pets", "read:pets" ] "petstore_auth" : [ "read:pets" ]
} ], } ],
"summary" : "Finds Pets by tags", "summary" : "Finds Pets by tags",
"tags" : [ "pet" ] "tags" : [ "pet" ]
@ -206,24 +206,28 @@
"delete" : { "delete" : {
"operationId" : "deletePet", "operationId" : "deletePet",
"parameters" : [ { "parameters" : [ {
"explode" : false,
"in" : "header", "in" : "header",
"name" : "api_key", "name" : "api_key",
"required" : false,
"schema" : { "schema" : {
"type" : "string" "type" : "string"
} },
"style" : "simple"
}, { }, {
"description" : "Pet id to delete", "description" : "Pet id to delete",
"explode" : false,
"in" : "path", "in" : "path",
"name" : "petId", "name" : "petId",
"required" : true, "required" : true,
"schema" : { "schema" : {
"format" : "int64", "format" : "int64",
"type" : "integer" "type" : "integer"
} },
"style" : "simple"
} ], } ],
"responses" : { "responses" : {
"400" : { "400" : {
"content" : { },
"description" : "Invalid pet value" "description" : "Invalid pet value"
} }
}, },
@ -238,13 +242,15 @@
"operationId" : "getPetById", "operationId" : "getPetById",
"parameters" : [ { "parameters" : [ {
"description" : "ID of pet to return", "description" : "ID of pet to return",
"explode" : false,
"in" : "path", "in" : "path",
"name" : "petId", "name" : "petId",
"required" : true, "required" : true,
"schema" : { "schema" : {
"format" : "int64", "format" : "int64",
"type" : "integer" "type" : "integer"
} },
"style" : "simple"
} ], } ],
"responses" : { "responses" : {
"200" : { "200" : {
@ -263,11 +269,9 @@
"description" : "successful operation" "description" : "successful operation"
}, },
"400" : { "400" : {
"content" : { },
"description" : "Invalid ID supplied" "description" : "Invalid ID supplied"
}, },
"404" : { "404" : {
"content" : { },
"description" : "Pet not found" "description" : "Pet not found"
} }
}, },
@ -281,15 +285,18 @@
"operationId" : "updatePetWithForm", "operationId" : "updatePetWithForm",
"parameters" : [ { "parameters" : [ {
"description" : "ID of pet that needs to be updated", "description" : "ID of pet that needs to be updated",
"explode" : false,
"in" : "path", "in" : "path",
"name" : "petId", "name" : "petId",
"required" : true, "required" : true,
"schema" : { "schema" : {
"format" : "int64", "format" : "int64",
"type" : "integer" "type" : "integer"
} },
"style" : "simple"
} ], } ],
"requestBody" : { "requestBody" : {
"$ref" : "#/components/requestBodies/inline_object",
"content" : { "content" : {
"application/x-www-form-urlencoded" : { "application/x-www-form-urlencoded" : {
"schema" : { "schema" : {
@ -302,14 +309,14 @@
"description" : "Updated status of the pet", "description" : "Updated status of the pet",
"type" : "string" "type" : "string"
} }
} },
"type" : "object"
} }
} }
} }
}, },
"responses" : { "responses" : {
"405" : { "405" : {
"content" : { },
"description" : "Invalid input" "description" : "Invalid input"
} }
}, },
@ -325,15 +332,18 @@
"operationId" : "uploadFile", "operationId" : "uploadFile",
"parameters" : [ { "parameters" : [ {
"description" : "ID of pet to update", "description" : "ID of pet to update",
"explode" : false,
"in" : "path", "in" : "path",
"name" : "petId", "name" : "petId",
"required" : true, "required" : true,
"schema" : { "schema" : {
"format" : "int64", "format" : "int64",
"type" : "integer" "type" : "integer"
} },
"style" : "simple"
} ], } ],
"requestBody" : { "requestBody" : {
"$ref" : "#/components/requestBodies/inline_object_1",
"content" : { "content" : {
"multipart/form-data" : { "multipart/form-data" : {
"schema" : { "schema" : {
@ -347,7 +357,8 @@
"format" : "binary", "format" : "binary",
"type" : "string" "type" : "string"
} }
} },
"type" : "object"
} }
} }
} }
@ -403,7 +414,7 @@
"operationId" : "placeOrder", "operationId" : "placeOrder",
"requestBody" : { "requestBody" : {
"content" : { "content" : {
"*/*" : { "application/json" : {
"schema" : { "schema" : {
"$ref" : "#/components/schemas/Order" "$ref" : "#/components/schemas/Order"
} }
@ -429,13 +440,11 @@
"description" : "successful operation" "description" : "successful operation"
}, },
"400" : { "400" : {
"content" : { },
"description" : "Invalid Order" "description" : "Invalid Order"
} }
}, },
"summary" : "Place an order for a pet", "summary" : "Place an order for a pet",
"tags" : [ "store" ], "tags" : [ "store" ]
"x-codegen-request-body-name" : "body"
} }
}, },
"/store/order/{orderId}" : { "/store/order/{orderId}" : {
@ -444,20 +453,20 @@
"operationId" : "deleteOrder", "operationId" : "deleteOrder",
"parameters" : [ { "parameters" : [ {
"description" : "ID of the order that needs to be deleted", "description" : "ID of the order that needs to be deleted",
"explode" : false,
"in" : "path", "in" : "path",
"name" : "orderId", "name" : "orderId",
"required" : true, "required" : true,
"schema" : { "schema" : {
"type" : "string" "type" : "string"
} },
"style" : "simple"
} ], } ],
"responses" : { "responses" : {
"400" : { "400" : {
"content" : { },
"description" : "Invalid ID supplied" "description" : "Invalid ID supplied"
}, },
"404" : { "404" : {
"content" : { },
"description" : "Order not found" "description" : "Order not found"
} }
}, },
@ -469,6 +478,7 @@
"operationId" : "getOrderById", "operationId" : "getOrderById",
"parameters" : [ { "parameters" : [ {
"description" : "ID of pet that needs to be fetched", "description" : "ID of pet that needs to be fetched",
"explode" : false,
"in" : "path", "in" : "path",
"name" : "orderId", "name" : "orderId",
"required" : true, "required" : true,
@ -477,7 +487,8 @@
"maximum" : 5, "maximum" : 5,
"minimum" : 1, "minimum" : 1,
"type" : "integer" "type" : "integer"
} },
"style" : "simple"
} ], } ],
"responses" : { "responses" : {
"200" : { "200" : {
@ -496,11 +507,9 @@
"description" : "successful operation" "description" : "successful operation"
}, },
"400" : { "400" : {
"content" : { },
"description" : "Invalid ID supplied" "description" : "Invalid ID supplied"
}, },
"404" : { "404" : {
"content" : { },
"description" : "Order not found" "description" : "Order not found"
} }
}, },
@ -514,7 +523,7 @@
"operationId" : "createUser", "operationId" : "createUser",
"requestBody" : { "requestBody" : {
"content" : { "content" : {
"*/*" : { "application/json" : {
"schema" : { "schema" : {
"$ref" : "#/components/schemas/User" "$ref" : "#/components/schemas/User"
} }
@ -525,69 +534,50 @@
}, },
"responses" : { "responses" : {
"default" : { "default" : {
"content" : { },
"description" : "successful operation" "description" : "successful operation"
} }
}, },
"security" : [ {
"api_key" : [ ]
} ],
"summary" : "Create user", "summary" : "Create user",
"tags" : [ "user" ], "tags" : [ "user" ]
"x-codegen-request-body-name" : "body"
} }
}, },
"/user/createWithArray" : { "/user/createWithArray" : {
"post" : { "post" : {
"operationId" : "createUsersWithArrayInput", "operationId" : "createUsersWithArrayInput",
"requestBody" : { "requestBody" : {
"content" : { "$ref" : "#/components/requestBodies/UserArray"
"*/*" : {
"schema" : {
"items" : {
"$ref" : "#/components/schemas/User"
},
"type" : "array"
}
}
},
"description" : "List of user object",
"required" : true
}, },
"responses" : { "responses" : {
"default" : { "default" : {
"content" : { },
"description" : "successful operation" "description" : "successful operation"
} }
}, },
"security" : [ {
"api_key" : [ ]
} ],
"summary" : "Creates list of users with given input array", "summary" : "Creates list of users with given input array",
"tags" : [ "user" ], "tags" : [ "user" ]
"x-codegen-request-body-name" : "body"
} }
}, },
"/user/createWithList" : { "/user/createWithList" : {
"post" : { "post" : {
"operationId" : "createUsersWithListInput", "operationId" : "createUsersWithListInput",
"requestBody" : { "requestBody" : {
"content" : { "$ref" : "#/components/requestBodies/UserArray"
"*/*" : {
"schema" : {
"items" : {
"$ref" : "#/components/schemas/User"
},
"type" : "array"
}
}
},
"description" : "List of user object",
"required" : true
}, },
"responses" : { "responses" : {
"default" : { "default" : {
"content" : { },
"description" : "successful operation" "description" : "successful operation"
} }
}, },
"security" : [ {
"api_key" : [ ]
} ],
"summary" : "Creates list of users with given input array", "summary" : "Creates list of users with given input array",
"tags" : [ "user" ], "tags" : [ "user" ]
"x-codegen-request-body-name" : "body"
} }
}, },
"/user/login" : { "/user/login" : {
@ -595,20 +585,25 @@
"operationId" : "loginUser", "operationId" : "loginUser",
"parameters" : [ { "parameters" : [ {
"description" : "The user name for login", "description" : "The user name for login",
"explode" : true,
"in" : "query", "in" : "query",
"name" : "username", "name" : "username",
"required" : true, "required" : true,
"schema" : { "schema" : {
"pattern" : "^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$",
"type" : "string" "type" : "string"
} },
"style" : "form"
}, { }, {
"description" : "The password for login in clear text", "description" : "The password for login in clear text",
"explode" : true,
"in" : "query", "in" : "query",
"name" : "password", "name" : "password",
"required" : true, "required" : true,
"schema" : { "schema" : {
"type" : "string" "type" : "string"
} },
"style" : "form"
} ], } ],
"responses" : { "responses" : {
"200" : { "200" : {
@ -626,24 +621,36 @@
}, },
"description" : "successful operation", "description" : "successful operation",
"headers" : { "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" : { "X-Rate-Limit" : {
"description" : "calls per hour allowed by the user", "description" : "calls per hour allowed by the user",
"explode" : false,
"schema" : { "schema" : {
"format" : "int32", "format" : "int32",
"type" : "integer" "type" : "integer"
} },
"style" : "simple"
}, },
"X-Expires-After" : { "X-Expires-After" : {
"description" : "date in UTC when toekn expires", "description" : "date in UTC when toekn expires",
"explode" : false,
"schema" : { "schema" : {
"format" : "date-time", "format" : "date-time",
"type" : "string" "type" : "string"
} },
"style" : "simple"
} }
} }
}, },
"400" : { "400" : {
"content" : { },
"description" : "Invalid username/password supplied" "description" : "Invalid username/password supplied"
} }
}, },
@ -656,10 +663,12 @@
"operationId" : "logoutUser", "operationId" : "logoutUser",
"responses" : { "responses" : {
"default" : { "default" : {
"content" : { },
"description" : "successful operation" "description" : "successful operation"
} }
}, },
"security" : [ {
"api_key" : [ ]
} ],
"summary" : "Logs out current logged in user session", "summary" : "Logs out current logged in user session",
"tags" : [ "user" ] "tags" : [ "user" ]
} }
@ -670,23 +679,26 @@
"operationId" : "deleteUser", "operationId" : "deleteUser",
"parameters" : [ { "parameters" : [ {
"description" : "The name that needs to be deleted", "description" : "The name that needs to be deleted",
"explode" : false,
"in" : "path", "in" : "path",
"name" : "username", "name" : "username",
"required" : true, "required" : true,
"schema" : { "schema" : {
"type" : "string" "type" : "string"
} },
"style" : "simple"
} ], } ],
"responses" : { "responses" : {
"400" : { "400" : {
"content" : { },
"description" : "Invalid username supplied" "description" : "Invalid username supplied"
}, },
"404" : { "404" : {
"content" : { },
"description" : "User not found" "description" : "User not found"
} }
}, },
"security" : [ {
"api_key" : [ ]
} ],
"summary" : "Delete user", "summary" : "Delete user",
"tags" : [ "user" ] "tags" : [ "user" ]
}, },
@ -694,12 +706,14 @@
"operationId" : "getUserByName", "operationId" : "getUserByName",
"parameters" : [ { "parameters" : [ {
"description" : "The name that needs to be fetched. Use user1 for testing.", "description" : "The name that needs to be fetched. Use user1 for testing.",
"explode" : false,
"in" : "path", "in" : "path",
"name" : "username", "name" : "username",
"required" : true, "required" : true,
"schema" : { "schema" : {
"type" : "string" "type" : "string"
} },
"style" : "simple"
} ], } ],
"responses" : { "responses" : {
"200" : { "200" : {
@ -718,11 +732,9 @@
"description" : "successful operation" "description" : "successful operation"
}, },
"400" : { "400" : {
"content" : { },
"description" : "Invalid username supplied" "description" : "Invalid username supplied"
}, },
"404" : { "404" : {
"content" : { },
"description" : "User not found" "description" : "User not found"
} }
}, },
@ -734,16 +746,18 @@
"operationId" : "updateUser", "operationId" : "updateUser",
"parameters" : [ { "parameters" : [ {
"description" : "name that need to be deleted", "description" : "name that need to be deleted",
"explode" : false,
"in" : "path", "in" : "path",
"name" : "username", "name" : "username",
"required" : true, "required" : true,
"schema" : { "schema" : {
"type" : "string" "type" : "string"
} },
"style" : "simple"
} ], } ],
"requestBody" : { "requestBody" : {
"content" : { "content" : {
"*/*" : { "application/json" : {
"schema" : { "schema" : {
"$ref" : "#/components/schemas/User" "$ref" : "#/components/schemas/User"
} }
@ -754,21 +768,71 @@
}, },
"responses" : { "responses" : {
"400" : { "400" : {
"content" : { },
"description" : "Invalid user supplied" "description" : "Invalid user supplied"
}, },
"404" : { "404" : {
"content" : { },
"description" : "User not found" "description" : "User not found"
} }
}, },
"security" : [ {
"api_key" : [ ]
} ],
"summary" : "Updated user", "summary" : "Updated user",
"tags" : [ "user" ], "tags" : [ "user" ]
"x-codegen-request-body-name" : "body"
} }
} }
}, },
"components" : { "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" : { "schemas" : {
"Order" : { "Order" : {
"description" : "An order for a pets from the pet store", "description" : "An order for a pets from the pet store",
@ -825,6 +889,7 @@
"type" : "integer" "type" : "integer"
}, },
"name" : { "name" : {
"pattern" : "^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$",
"type" : "string" "type" : "string"
} }
}, },
@ -987,6 +1052,33 @@
}, },
"title" : "An uploaded response", "title" : "An uploaded response",
"type" : "object" "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" : { "securitySchemes" : {

View File

@ -349,6 +349,7 @@ request_param_info('LoginUser', 'username') ->
source => qs_val , source => qs_val ,
rules => [ rules => [
{type, 'binary'}, {type, 'binary'},
{pattern, "/^[a-zA-Z0-9]+[a-zA-Z0-9\\.\\-_]*[a-zA-Z0-9]+$/" },
required required
] ]
}; };
@ -427,6 +428,8 @@ populate_request_param(OperationID, Name, Req0, ValidatorState) ->
) -> ok | no_return(). ) -> ok | no_return().
validate_response('AddPet', 200, Body, ValidatorState) ->
validate_response_body('Pet', 'Pet', Body, ValidatorState);
validate_response('AddPet', 405, Body, ValidatorState) -> validate_response('AddPet', 405, Body, ValidatorState) ->
validate_response_body('', '', 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('GetPetById', 404, Body, ValidatorState) ->
validate_response_body('', '', 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('UpdatePet', 400, Body, ValidatorState) ->
validate_response_body('', '', Body, ValidatorState); validate_response_body('', '', Body, ValidatorState);
validate_response('UpdatePet', 404, Body, ValidatorState) -> validate_response('UpdatePet', 404, Body, ValidatorState) ->

View File

@ -119,6 +119,120 @@ allowed_methods(Req, State) ->
Req :: cowboy_req:req(), Req :: cowboy_req:req(),
State :: state() 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) -> is_authorized(Req, State) ->
{true, Req, State}. {true, Req, State}.