Update Erlang server samples with Petstore OAS2 (#150)

* update erlang server samples with petstore oas2

* fix compilation in erlang server
This commit is contained in:
William Cheng 2018-04-26 13:34:02 +08:00 committed by GitHub
parent e1a0355398
commit df26bcb40c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 1129 additions and 33 deletions

4
.gitignore vendored
View File

@ -191,3 +191,7 @@ samples/client/petstore/elixir/mix.lock
# groovy # groovy
samples/client/petstore/groovy/build samples/client/petstore/groovy/build
# erlang
samples/server/petstore/erlang-server/_build/
samples/server/petstore/erlang-server/rebar.lock

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} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -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 -l 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/2_0/petstore.yaml -l erlang-server -o samples/server/petstore/erlang-server $@"
java $JAVA_OPTS -jar $executable $ags java $JAVA_OPTS -jar $executable $ags

View File

@ -53,7 +53,7 @@ request_params(_) ->
{{#operations}}{{#operation}}{{#allParams}} {{#operations}}{{#operation}}{{#allParams}}
request_param_info('{{operationId}}', {{^isBodyParam}}'{{baseName}}'{{/isBodyParam}}{{#isBodyParam}}'{{dataType}}'{{/isBodyParam}}) -> request_param_info('{{operationId}}', {{^isBodyParam}}'{{baseName}}'{{/isBodyParam}}{{#isBodyParam}}'{{dataType}}'{{/isBodyParam}}) ->
#{ #{
source => {{#isQueryParam}}qs_val{{/isQueryParam}} {{#isPathParam}}binding{{/isPathParam}} {{#isHeaderParam}}header{{/isHeaderParam}}{{#isBodyParam}}body{{/isBodyParam}}, source => {{#isQueryParam}}qs_val{{/isQueryParam}} {{#isPathParam}}binding{{/isPathParam}} {{#isHeaderParam}}header{{/isHeaderParam}}{{#isBodyParam}}body{{/isBodyParam}}{{#isFormParam}}body{{/isFormParam}},
rules => [{{#isString}} rules => [{{#isString}}
{type, 'binary'},{{/isString}}{{#isInteger}} {type, 'binary'},{{/isString}}{{#isInteger}}
{type, 'integer'},{{/isInteger}}{{#isLong}} {type, 'integer'},{{/isInteger}}{{#isLong}}

View File

@ -70,7 +70,8 @@ allowed_methods(Req, State) ->
Req :: cowboy_req:req(), Req :: cowboy_req:req(),
State :: state() State :: state()
}. }.
{{#operations}}{{#operation}} {{#operations}}
{{#operation}}
{{#authMethods}} {{#authMethods}}
is_authorized( is_authorized(
Req0, Req0,
@ -93,8 +94,23 @@ is_authorized(
{false, AuthHeader, Req} -> {{false, AuthHeader}, Req, State} {false, AuthHeader, Req} -> {{false, AuthHeader}, Req, State}
end; end;
{{/isApiKey}} {{/isApiKey}}
{{#isOAuth}}
From = header,
Result = {{packageName}}_auth:authorize_api_key(
LogicHandler,
OperationID,
From,
"Authorization",
Req0
),
case Result of
{true, Context, Req} -> {true, Req, State#state{context = Context}};
{false, AuthHeader, Req} -> {{false, AuthHeader}, Req, State}
end;
{{/isOAuth}}
{{/authMethods}} {{/authMethods}}
{{/operation}}{{/operations}} {{/operation}}
{{/operations}}
{{^authMethods}} {{^authMethods}}
is_authorized(Req, State) -> is_authorized(Req, State) ->
{true, Req, State}. {true, Req, State}.

View File

@ -1 +1 @@
2.2.3-SNAPSHOT 3.0.0-SNAPSHOT

File diff suppressed because it is too large Load Diff

View File

@ -225,7 +225,7 @@ request_param_info('UpdatePetWithForm', 'petId') ->
request_param_info('UpdatePetWithForm', 'name') -> request_param_info('UpdatePetWithForm', 'name') ->
#{ #{
source => , source => body,
rules => [ rules => [
{type, 'binary'}, {type, 'binary'},
not_required not_required
@ -234,7 +234,7 @@ request_param_info('UpdatePetWithForm', 'name') ->
request_param_info('UpdatePetWithForm', 'status') -> request_param_info('UpdatePetWithForm', 'status') ->
#{ #{
source => , source => body,
rules => [ rules => [
{type, 'binary'}, {type, 'binary'},
not_required not_required
@ -252,7 +252,7 @@ request_param_info('UploadFile', 'petId') ->
request_param_info('UploadFile', 'additionalMetadata') -> request_param_info('UploadFile', 'additionalMetadata') ->
#{ #{
source => , source => body,
rules => [ rules => [
{type, 'binary'}, {type, 'binary'},
not_required not_required
@ -261,8 +261,9 @@ request_param_info('UploadFile', 'additionalMetadata') ->
request_param_info('UploadFile', 'file') -> request_param_info('UploadFile', 'file') ->
#{ #{
source => , source => body,
rules => [ rules => [
{type, 'binary'},
not_required not_required
] ]
}; };

View File

@ -126,7 +126,6 @@ allowed_methods(Req, State) ->
Req :: cowboy_req:req(), Req :: cowboy_req:req(),
State :: state() State :: state()
}. }.
is_authorized( is_authorized(
Req0, Req0,
State = #state{ State = #state{
@ -134,7 +133,18 @@ is_authorized(
logic_handler = LogicHandler logic_handler = LogicHandler
} }
) -> ) ->
From = header,
Result = swagger_auth:authorize_api_key(
LogicHandler,
OperationID,
From,
"Authorization",
Req0
),
case Result of
{true, Context, Req} -> {true, Req, State#state{context = Context}};
{false, AuthHeader, Req} -> {{false, AuthHeader}, Req, State}
end;
is_authorized( is_authorized(
Req0, Req0,
State = #state{ State = #state{
@ -142,7 +152,18 @@ is_authorized(
logic_handler = LogicHandler logic_handler = LogicHandler
} }
) -> ) ->
From = header,
Result = swagger_auth:authorize_api_key(
LogicHandler,
OperationID,
From,
"Authorization",
Req0
),
case Result of
{true, Context, Req} -> {true, Req, State#state{context = Context}};
{false, AuthHeader, Req} -> {{false, AuthHeader}, Req, State}
end;
is_authorized( is_authorized(
Req0, Req0,
State = #state{ State = #state{
@ -150,7 +171,18 @@ is_authorized(
logic_handler = LogicHandler logic_handler = LogicHandler
} }
) -> ) ->
From = header,
Result = swagger_auth:authorize_api_key(
LogicHandler,
OperationID,
From,
"Authorization",
Req0
),
case Result of
{true, Context, Req} -> {true, Req, State#state{context = Context}};
{false, AuthHeader, Req} -> {{false, AuthHeader}, Req, State}
end;
is_authorized( is_authorized(
Req0, Req0,
State = #state{ State = #state{
@ -158,7 +190,18 @@ is_authorized(
logic_handler = LogicHandler logic_handler = LogicHandler
} }
) -> ) ->
From = header,
Result = swagger_auth:authorize_api_key(
LogicHandler,
OperationID,
From,
"Authorization",
Req0
),
case Result of
{true, Context, Req} -> {true, Req, State#state{context = Context}};
{false, AuthHeader, Req} -> {{false, AuthHeader}, Req, State}
end;
is_authorized( is_authorized(
Req0, Req0,
State = #state{ State = #state{
@ -178,7 +221,6 @@ is_authorized(
{true, Context, Req} -> {true, Req, State#state{context = Context}}; {true, Context, Req} -> {true, Req, State#state{context = Context}};
{false, AuthHeader, Req} -> {{false, AuthHeader}, Req, State} {false, AuthHeader, Req} -> {{false, AuthHeader}, Req, State}
end; end;
is_authorized( is_authorized(
Req0, Req0,
State = #state{ State = #state{
@ -186,7 +228,18 @@ is_authorized(
logic_handler = LogicHandler logic_handler = LogicHandler
} }
) -> ) ->
From = header,
Result = swagger_auth:authorize_api_key(
LogicHandler,
OperationID,
From,
"Authorization",
Req0
),
case Result of
{true, Context, Req} -> {true, Req, State#state{context = Context}};
{false, AuthHeader, Req} -> {{false, AuthHeader}, Req, State}
end;
is_authorized( is_authorized(
Req0, Req0,
State = #state{ State = #state{
@ -194,7 +247,18 @@ is_authorized(
logic_handler = LogicHandler logic_handler = LogicHandler
} }
) -> ) ->
From = header,
Result = swagger_auth:authorize_api_key(
LogicHandler,
OperationID,
From,
"Authorization",
Req0
),
case Result of
{true, Context, Req} -> {true, Req, State#state{context = Context}};
{false, AuthHeader, Req} -> {{false, AuthHeader}, Req, State}
end;
is_authorized( is_authorized(
Req0, Req0,
State = #state{ State = #state{
@ -202,7 +266,18 @@ is_authorized(
logic_handler = LogicHandler logic_handler = LogicHandler
} }
) -> ) ->
From = header,
Result = swagger_auth:authorize_api_key(
LogicHandler,
OperationID,
From,
"Authorization",
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}.

View File

@ -164,6 +164,6 @@ prepare_validator() ->
get_swagger_path() -> get_swagger_path() ->
{ok, AppName} = application:get_application(?MODULE), {ok, AppName} = application:get_application(?MODULE),
filename:join(swagger_utils:priv_dir(AppName), "swagger.json"). filename:join(swagger_utils:priv_dir(AppName), "openapi.json").

View File

@ -94,8 +94,6 @@ allowed_methods(Req, State) ->
Req :: cowboy_req:req(), Req :: cowboy_req:req(),
State :: state() State :: state()
}. }.
is_authorized( is_authorized(
Req0, Req0,
State = #state{ State = #state{
@ -115,9 +113,6 @@ is_authorized(
{true, Context, Req} -> {true, Req, State#state{context = Context}}; {true, Context, Req} -> {true, Req, State#state{context = Context}};
{false, AuthHeader, Req} -> {{false, AuthHeader}, Req, State} {false, AuthHeader, Req} -> {{false, AuthHeader}, Req, State}
end; end;
is_authorized(Req, State) -> is_authorized(Req, State) ->
{true, Req, State}. {true, Req, State}.

View File

@ -126,15 +126,6 @@ allowed_methods(Req, State) ->
Req :: cowboy_req:req(), Req :: cowboy_req:req(),
State :: state() State :: state()
}. }.
is_authorized(Req, State) -> is_authorized(Req, State) ->
{true, Req, State}. {true, Req, State}.