Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate Erlang samples to use OAS 3 spec #6297

Merged
merged 4 commits into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/erlang-petstore-client.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion bin/erlang-petstore-proper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion bin/erlang-petstore-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
32 changes: 0 additions & 32 deletions bin/openapi3/erlang-petstore-client.sh

This file was deleted.

32 changes: 0 additions & 32 deletions bin/openapi3/erlang-petstore-server.sh

This file was deleted.

2 changes: 1 addition & 1 deletion bin/windows/erlang-petstore-client.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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%
2 changes: 1 addition & 1 deletion bin/windows/erlang-petstore-server.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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%
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.2-SNAPSHOT
5.0.0-SNAPSHOT
Original file line number Diff line number Diff line change
@@ -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
}.
Original file line number Diff line number Diff line change
@@ -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
}.
Original file line number Diff line number Diff line change
Expand Up @@ -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, #{})),
Expand Down Expand Up @@ -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, #{})),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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).
Expand All @@ -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).
Expand Down Expand Up @@ -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).
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.3.2-SNAPSHOT
5.0.0-SNAPSHOT
Original file line number Diff line number Diff line change
@@ -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)).

Original file line number Diff line number Diff line change
@@ -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)).

8 changes: 4 additions & 4 deletions samples/client/petstore/erlang-proper/src/petstore_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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).

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

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

Expand Down Expand Up @@ -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).

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5.0.0-SNAPSHOT
Loading