update erlang client, server default value (#378)

This commit is contained in:
William Cheng 2018-05-09 10:31:42 +08:00 committed by GitHub
parent 68780afe9d
commit e2d6f7c88f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 124 additions and 130 deletions

View File

@ -17,15 +17,11 @@
package org.openapitools.codegen.languages;
import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.Template;
import org.openapitools.codegen.*;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.media.*;
import io.swagger.v3.core.util.Json;
import java.io.File;
import java.util.*;
@ -34,15 +30,13 @@ import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ErlangClientCodegen extends DefaultCodegen implements CodegenConfig {
static Logger LOGGER = LoggerFactory.getLogger(ErlangClientCodegen.class);
protected String packageName = "swagger";
protected String packageName = "openapi";
protected String packageVersion = "1.0.0";
protected String sourceFolder = "src";
@ -142,7 +136,7 @@ public class ErlangClientCodegen extends DefaultCodegen implements CodegenConfig
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) {
setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME));
} else {
setPackageName("swagger");
setPackageName("openapi");
}
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_VERSION)) {
@ -178,7 +172,7 @@ public class ErlangClientCodegen extends DefaultCodegen implements CodegenConfig
}
public String qsEncode(Object o) {
String r = new String();
String r = "";
CodegenParameter q = (CodegenParameter) o;
if (q.required) {
if (q.isListContainer) {
@ -344,8 +338,7 @@ public class ErlangClientCodegen extends DefaultCodegen implements CodegenConfig
int lengthRequired(List<CodegenParameter> allParams) {
int l = 0;
for (CodegenParameter o : allParams) {
CodegenParameter q = (CodegenParameter) o;
if (q.required || q.isBodyParam)
if (o.required || o.isBodyParam)
l++;
}

View File

@ -38,7 +38,7 @@ public class ErlangServerCodegen extends DefaultCodegen implements CodegenConfig
protected String apiVersion = "1.0.0";
protected String apiPath = "src";
protected String packageName = "swagger";
protected String packageName = "openapi";
public ErlangServerCodegen() {
super();
@ -50,7 +50,8 @@ public class ErlangServerCodegen extends DefaultCodegen implements CodegenConfig
setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME));
} else {
additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName);
};
}
;
/**
* Models. You can write model files using the modelTemplateFiles map.
@ -66,8 +67,8 @@ public class ErlangServerCodegen extends DefaultCodegen implements CodegenConfig
* class
*/
apiTemplateFiles.put(
"handler.mustache", // the template to use
".erl"); // the extension for each file to write
"handler.mustache", // the template to use
".erl"); // the extension for each file to write
/**
* Template Location. This is the location which templates will be read from. The generator
@ -79,12 +80,12 @@ public class ErlangServerCodegen extends DefaultCodegen implements CodegenConfig
* Reserved words. Override this with reserved words specific to your language
*/
setReservedWordsLowerCase(
Arrays.asList(
"after","and","andalso","band","begin","bnot","bor","bsl","bsr","bxor","case",
"catch","cond","div","end","fun","if","let","not","of","or","orelse","receive",
"rem","try","when","xor"
)
);
Arrays.asList(
"after", "and", "andalso", "band", "begin", "bnot", "bor", "bsl", "bsr", "bxor", "case",
"catch", "cond", "div", "end", "fun", "if", "let", "not", "of", "or", "orelse", "receive",
"rem", "try", "when", "xor"
)
);
instantiationTypes.clear();
@ -114,7 +115,7 @@ public class ErlangServerCodegen extends DefaultCodegen implements CodegenConfig
cliOptions.clear();
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "Erlang package name (convention: lowercase).")
.defaultValue(this.packageName));
.defaultValue(this.packageName));
/**
* Additional Properties. These values can be passed to the templates and
* are available in models, apis, and supporting files
@ -126,16 +127,16 @@ public class ErlangServerCodegen extends DefaultCodegen implements CodegenConfig
* entire object tree available. If the input file has a suffix of `.mustache
* it will be processed by the template engine. Otherwise, it will be copied
*/
supportingFiles.add(new SupportingFile("rebar.config.mustache","", "rebar.config"));
supportingFiles.add(new SupportingFile("rebar.config.mustache", "", "rebar.config"));
supportingFiles.add(new SupportingFile("app.src.mustache", "", "src" + File.separator + this.packageName + ".app.src"));
supportingFiles.add(new SupportingFile("router.mustache", "", toSourceFilePath("router", "erl")));
supportingFiles.add(new SupportingFile("api.mustache", "", toSourceFilePath("api", "erl")));
supportingFiles.add(new SupportingFile("server.mustache", "", toSourceFilePath("server", "erl")));
supportingFiles.add(new SupportingFile("utils.mustache", "", toSourceFilePath("utils", "erl")));
supportingFiles.add(new SupportingFile("auth.mustache", "", toSourceFilePath("auth", "erl")));
supportingFiles.add(new SupportingFile("router.mustache", "", toSourceFilePath("router", "erl")));
supportingFiles.add(new SupportingFile("api.mustache", "", toSourceFilePath("api", "erl")));
supportingFiles.add(new SupportingFile("server.mustache", "", toSourceFilePath("server", "erl")));
supportingFiles.add(new SupportingFile("utils.mustache", "", toSourceFilePath("utils", "erl")));
supportingFiles.add(new SupportingFile("auth.mustache", "", toSourceFilePath("auth", "erl")));
supportingFiles.add(new SupportingFile("openapi.mustache", "", toPrivFilePath("openapi", "json")));
supportingFiles.add(new SupportingFile("default_logic_handler.mustache", "", toSourceFilePath("default_logic_handler", "erl")));
supportingFiles.add(new SupportingFile("logic_handler.mustache", "", toSourceFilePath("logic_handler", "erl")));
supportingFiles.add(new SupportingFile("default_logic_handler.mustache", "", toSourceFilePath("default_logic_handler", "erl")));
supportingFiles.add(new SupportingFile("logic_handler.mustache", "", toSourceFilePath("logic_handler", "erl")));
writeOptional(outputFolder, new SupportingFile("README.mustache", "", "README.md"));
}
@ -174,7 +175,7 @@ public class ErlangServerCodegen extends DefaultCodegen implements CodegenConfig
*/
@Override
public String getHelp() {
return "Generates an Erlang server library (beta) using the Swagger Codegen project. By default, " +
return "Generates an Erlang server library (beta) using OpenAPI Generator (https://openapi-generator.tech). By default, " +
"it will also generate service classes, which can be disabled with the `-Dnoservice` environment variable.";
}
@ -193,8 +194,8 @@ public class ErlangServerCodegen extends DefaultCodegen implements CodegenConfig
* @return the escaped term
*/
@Override
public String escapeReservedWord(String name) {
if(this.reservedWordsMappings().containsKey(name)) {
public String escapeReservedWord(String name) {
if (this.reservedWordsMappings().containsKey(name)) {
return this.reservedWordsMappings().get(name);
}
return "_" + name;
@ -261,7 +262,7 @@ public class ErlangServerCodegen extends DefaultCodegen implements CodegenConfig
}
protected String toSourceFilePath(String name, String extension) {
return "src" + File.separator + toModuleName(name) + "." + extension;
return "src" + File.separator + toModuleName(name) + "." + extension;
}
protected String toIncludeFilePath(String name, String extension) {

View File

@ -1,4 +1,4 @@
# Swagger client server library for Erlang
# OpenAPI client server library for Erlang
## Overview

View File

@ -1,4 +1,4 @@
# Swagger rest server library for Erlang
# OpenAPI server library for Erlang
## Overview

View File

@ -4,7 +4,7 @@
-export([request_param_info/2]).
-export([populate_request/3]).
-export([validate_response/4]).
%% exported to silence swagger complains
%% exported to silence openapi complains
-export([get_value/3, validate_response_body/4]).
-type operation_id() :: atom().

View File

@ -39,7 +39,7 @@ authorize_api_key(LogicHandler, OperationID, From, KeyParam, Req0) ->
get_api_key(header, KeyParam, Req0) ->
{Headers, Req} = cowboy_req:headers(Req0),
{
swagger_utils:get_opt(
openapi_utils:get_opt(
{{packageName}}_utils:to_header(KeyParam),
Headers
),

View File

@ -63,11 +63,11 @@ get_operations() ->
}.
prepare_validator() ->
R = jsx:decode(element(2, file:read_file(get_swagger_path()))),
R = jsx:decode(element(2, file:read_file(get_openapi_path()))),
jesse_state:new(R, [{default_schema_ver, <<"http://json-schema.org/draft-04/schema#">>}]).
get_swagger_path() ->
get_openapi_path() ->
{ok, AppName} = application:get_application(?MODULE),
filename:join({{packageName}}_utils:priv_dir(AppName), "openapi.json").

View File

@ -1,4 +1,4 @@
# Swagger client server library for Erlang
# OpenAPI client server library for Erlang
## Overview

View File

@ -1,4 +1,4 @@
# Swagger rest server library for Erlang
# OpenAPI server library for Erlang
## Overview

View File

@ -1,4 +1,4 @@
{application, swagger, [
{application, openapi, [
{description, "This is a sample server Petstore server. For this sample, you can use the api key &#x60;special-key&#x60; to test the authorization filters."},
{vsn, "1.0.0"},
{registered, []},

View File

@ -1,10 +1,10 @@
-module(swagger_api).
-module(openapi_api).
-export([request_params/1]).
-export([request_param_info/2]).
-export([populate_request/3]).
-export([validate_response/4]).
%% exported to silence swagger complains
%% exported to silence openapi complains
-export([get_value/3, validate_response_body/4]).
-type operation_id() :: atom().
@ -546,7 +546,7 @@ validate(_, _Name, undefined, _ValidatorState) ->
validate(Rule = {type, 'integer'}, Name, Value, _ValidatorState) ->
try
{ok, swagger_utils:to_int(Value)}
{ok, openapi_utils:to_int(Value)}
catch
error:badarg ->
validation_error(Rule, Name)
@ -554,7 +554,7 @@ validate(Rule = {type, 'integer'}, Name, Value, _ValidatorState) ->
validate(Rule = {type, 'float'}, Name, Value, _ValidatorState) ->
try
{ok, swagger_utils:to_float(Value)}
{ok, openapi_utils:to_float(Value)}
catch
error:badarg ->
validation_error(Rule, Name)
@ -649,7 +649,7 @@ validate(Rule = {pattern, Pattern}, Name, Value, _ValidatorState) ->
end;
validate(Rule = schema, Name, Value, ValidatorState) ->
Definition = list_to_binary("#/definitions/" ++ swagger_utils:to_list(Name)),
Definition = list_to_binary("#/definitions/" ++ openapi_utils:to_list(Name)),
try
_ = validate_with_schema(Value, Definition, ValidatorState),
ok
@ -698,17 +698,17 @@ get_value(body, _Name, Req0) ->
get_value(qs_val, Name, Req0) ->
{QS, Req} = cowboy_req:qs_vals(Req0),
Value = swagger_utils:get_opt(swagger_utils:to_qs(Name), QS),
Value = openapi_utils:get_opt(openapi_utils:to_qs(Name), QS),
{Value, Req};
get_value(header, Name, Req0) ->
{Headers, Req} = cowboy_req:headers(Req0),
Value = swagger_utils:get_opt(swagger_utils:to_header(Name), Headers),
Value = openapi_utils:get_opt(openapi_utils:to_header(Name), Headers),
{Value, Req};
get_value(binding, Name, Req0) ->
{Bindings, Req} = cowboy_req:bindings(Req0),
Value = swagger_utils:get_opt(swagger_utils:to_binding(Name), Bindings),
Value = openapi_utils:get_opt(openapi_utils:to_binding(Name), Bindings),
{Value, Req}.
prepare_body(Body) ->
@ -749,4 +749,4 @@ prepare_param(Rules, Name, Value, ValidatorState) ->
end.
binary_to_lower(V) when is_binary(V) ->
list_to_binary(string:to_lower(swagger_utils:to_list(V))).
list_to_binary(string:to_lower(openapi_utils:to_list(V))).

View File

@ -1,10 +1,10 @@
-module(swagger_auth).
-module(openapi_auth).
-export([authorize_api_key/5]).
-spec authorize_api_key(
LogicHandler :: atom(),
OperationID :: swagger_api:operation_id(),
OperationID :: openapi_api:operation_id(),
From :: header | qs_val,
KeyParam :: iodata() | atom(),
Req ::cowboy_req:req()
@ -18,7 +18,7 @@ authorize_api_key(LogicHandler, OperationID, From, KeyParam, Req0) ->
AuthHeader = <<"">>,
{false, AuthHeader, Req};
_ ->
Result = swagger_logic_handler:authorize_api_key(
Result = openapi_logic_handler:authorize_api_key(
LogicHandler,
OperationID,
ApiKey
@ -35,8 +35,8 @@ authorize_api_key(LogicHandler, OperationID, From, KeyParam, Req0) ->
get_api_key(header, KeyParam, Req0) ->
{Headers, Req} = cowboy_req:headers(Req0),
{
swagger_utils:get_opt(
swagger_utils:to_header(KeyParam),
openapi_utils:get_opt(
openapi_utils:to_header(KeyParam),
Headers
),
Req
@ -44,7 +44,7 @@ get_api_key(header, KeyParam, Req0) ->
get_api_key(qs_val, KeyParam, Req0) ->
{QS, Req} = cowboy_req:qs_vals(Req0),
{ swagger_utils:get_opt(KeyParam, QS), Req}.
{ openapi_utils:get_opt(KeyParam, QS), Req}.

View File

@ -1,16 +1,16 @@
-module(swagger_default_logic_handler).
-module(openapi_default_logic_handler).
-behaviour(swagger_logic_handler).
-behaviour(openapi_logic_handler).
-export([handle_request/3]).
-export([authorize_api_key/2]).
-spec authorize_api_key(OperationID :: swagger_api:operation_id(), ApiKey :: binary()) -> {true, #{}}.
-spec authorize_api_key(OperationID :: openapi_api:operation_id(), ApiKey :: binary()) -> {true, #{}}.
authorize_api_key(_, _) -> {true, #{}}.
-spec handle_request(
OperationID :: swagger_api:operation_id(),
OperationID :: openapi_api:operation_id(),
Req :: cowboy_req:req(),
Context :: #{}
) ->

View File

@ -1,4 +1,4 @@
-module(swagger_logic_handler).
-module(openapi_logic_handler).
-export([handle_request/4]).
-export([authorize_api_key/3]).
@ -12,18 +12,18 @@
-export_type([handler_response/0]).
-callback authorize_api_key(
OperationID :: swagger_api:operation_id(),
OperationID :: openapi_api:operation_id(),
ApiKey :: binary()
) ->
Result :: boolean() | {boolean(), context()}.
-callback handle_request(OperationID :: swagger_api:operation_id(), Request :: any(), Context :: context()) ->
-callback handle_request(OperationID :: openapi_api:operation_id(), Request :: any(), Context :: context()) ->
handler_response().
-spec handle_request(
Handler :: atom(),
OperationID :: swagger_api:operation_id(),
OperationID :: openapi_api:operation_id(),
Request :: any(),
Context :: context()
) ->
@ -32,7 +32,7 @@
handle_request(Handler, OperationID, Req, Context) ->
Handler:handle_request(OperationID, Req, Context).
-spec authorize_api_key(Handler :: atom(), OperationID :: swagger_api:operation_id(), ApiKey :: binary()) ->
-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).

View File

@ -1,5 +1,5 @@
%% basic handler
-module(swagger_pet_handler).
-module(openapi_pet_handler).
%% Cowboy REST callbacks
-export([allowed_methods/2]).
@ -19,7 +19,7 @@
-export([handle_request_json/2]).
-record(state, {
operation_id :: swagger_api:operation_id(),
operation_id :: openapi_api:operation_id(),
logic_handler :: atom(),
validator_state :: jesse_state:state(),
context=#{} :: #{}
@ -27,13 +27,13 @@
-type state() :: state().
-spec init(TransportName :: atom(), Req :: cowboy_req:req(), Opts :: swagger_router:init_opts()) ->
{upgrade, protocol, cowboy_rest, Req :: cowboy_req:req(), Opts :: swagger_router:init_opts()}.
-spec init(TransportName :: atom(), Req :: cowboy_req:req(), Opts :: openapi_router:init_opts()) ->
{upgrade, protocol, cowboy_rest, Req :: cowboy_req:req(), Opts :: openapi_router:init_opts()}.
init(_Transport, Req, Opts) ->
{upgrade, protocol, cowboy_rest, Req, Opts}.
-spec rest_init(Req :: cowboy_req:req(), Opts :: swagger_router:init_opts()) ->
-spec rest_init(Req :: cowboy_req:req(), Opts :: openapi_router:init_opts()) ->
{ok, Req :: cowboy_req:req(), State :: state()}.
rest_init(Req0, {Operations, LogicHandler, ValidatorState}) ->
@ -134,7 +134,7 @@ is_authorized(
}
) ->
From = header,
Result = swagger_auth:authorize_api_key(
Result = openapi_auth:authorize_api_key(
LogicHandler,
OperationID,
From,
@ -153,7 +153,7 @@ is_authorized(
}
) ->
From = header,
Result = swagger_auth:authorize_api_key(
Result = openapi_auth:authorize_api_key(
LogicHandler,
OperationID,
From,
@ -172,7 +172,7 @@ is_authorized(
}
) ->
From = header,
Result = swagger_auth:authorize_api_key(
Result = openapi_auth:authorize_api_key(
LogicHandler,
OperationID,
From,
@ -191,7 +191,7 @@ is_authorized(
}
) ->
From = header,
Result = swagger_auth:authorize_api_key(
Result = openapi_auth:authorize_api_key(
LogicHandler,
OperationID,
From,
@ -210,7 +210,7 @@ is_authorized(
}
) ->
From = header,
Result = swagger_auth:authorize_api_key(
Result = openapi_auth:authorize_api_key(
LogicHandler,
OperationID,
From,
@ -229,7 +229,7 @@ is_authorized(
}
) ->
From = header,
Result = swagger_auth:authorize_api_key(
Result = openapi_auth:authorize_api_key(
LogicHandler,
OperationID,
From,
@ -248,7 +248,7 @@ is_authorized(
}
) ->
From = header,
Result = swagger_auth:authorize_api_key(
Result = openapi_auth:authorize_api_key(
LogicHandler,
OperationID,
From,
@ -267,7 +267,7 @@ is_authorized(
}
) ->
From = header,
Result = swagger_auth:authorize_api_key(
Result = openapi_auth:authorize_api_key(
LogicHandler,
OperationID,
From,
@ -459,15 +459,15 @@ handle_request_json(
context = Context
}
) ->
case swagger_api:populate_request(OperationID, Req0, ValidatorState) of
case openapi_api:populate_request(OperationID, Req0, ValidatorState) of
{ok, Populated, Req1} ->
{Code, Headers, Body} = swagger_logic_handler:handle_request(
{Code, Headers, Body} = openapi_logic_handler:handle_request(
LogicHandler,
OperationID,
Populated,
Context
),
_ = swagger_api:validate_response(
_ = openapi_api:validate_response(
OperationID,
Code,
Body,

View File

@ -1,9 +1,9 @@
-module(swagger_router).
-module(openapi_router).
-export([get_paths/1]).
-type operations() :: #{
Method :: binary() => swagger_api:operation_id()
Method :: binary() => openapi_api:operation_id()
}.
-type init_opts() :: {
@ -58,112 +58,112 @@ get_operations() ->
'AddPet' => #{
path => "/v2/pet",
method => <<"POST">>,
handler => 'swagger_pet_handler'
handler => 'openapi_pet_handler'
},
'DeletePet' => #{
path => "/v2/pet/:petId",
method => <<"DELETE">>,
handler => 'swagger_pet_handler'
handler => 'openapi_pet_handler'
},
'FindPetsByStatus' => #{
path => "/v2/pet/findByStatus",
method => <<"GET">>,
handler => 'swagger_pet_handler'
handler => 'openapi_pet_handler'
},
'FindPetsByTags' => #{
path => "/v2/pet/findByTags",
method => <<"GET">>,
handler => 'swagger_pet_handler'
handler => 'openapi_pet_handler'
},
'GetPetById' => #{
path => "/v2/pet/:petId",
method => <<"GET">>,
handler => 'swagger_pet_handler'
handler => 'openapi_pet_handler'
},
'UpdatePet' => #{
path => "/v2/pet",
method => <<"PUT">>,
handler => 'swagger_pet_handler'
handler => 'openapi_pet_handler'
},
'UpdatePetWithForm' => #{
path => "/v2/pet/:petId",
method => <<"POST">>,
handler => 'swagger_pet_handler'
handler => 'openapi_pet_handler'
},
'UploadFile' => #{
path => "/v2/pet/:petId/uploadImage",
method => <<"POST">>,
handler => 'swagger_pet_handler'
handler => 'openapi_pet_handler'
},
'DeleteOrder' => #{
path => "/v2/store/order/:orderId",
method => <<"DELETE">>,
handler => 'swagger_store_handler'
handler => 'openapi_store_handler'
},
'GetInventory' => #{
path => "/v2/store/inventory",
method => <<"GET">>,
handler => 'swagger_store_handler'
handler => 'openapi_store_handler'
},
'GetOrderById' => #{
path => "/v2/store/order/:orderId",
method => <<"GET">>,
handler => 'swagger_store_handler'
handler => 'openapi_store_handler'
},
'PlaceOrder' => #{
path => "/v2/store/order",
method => <<"POST">>,
handler => 'swagger_store_handler'
handler => 'openapi_store_handler'
},
'CreateUser' => #{
path => "/v2/user",
method => <<"POST">>,
handler => 'swagger_user_handler'
handler => 'openapi_user_handler'
},
'CreateUsersWithArrayInput' => #{
path => "/v2/user/createWithArray",
method => <<"POST">>,
handler => 'swagger_user_handler'
handler => 'openapi_user_handler'
},
'CreateUsersWithListInput' => #{
path => "/v2/user/createWithList",
method => <<"POST">>,
handler => 'swagger_user_handler'
handler => 'openapi_user_handler'
},
'DeleteUser' => #{
path => "/v2/user/:username",
method => <<"DELETE">>,
handler => 'swagger_user_handler'
handler => 'openapi_user_handler'
},
'GetUserByName' => #{
path => "/v2/user/:username",
method => <<"GET">>,
handler => 'swagger_user_handler'
handler => 'openapi_user_handler'
},
'LoginUser' => #{
path => "/v2/user/login",
method => <<"GET">>,
handler => 'swagger_user_handler'
handler => 'openapi_user_handler'
},
'LogoutUser' => #{
path => "/v2/user/logout",
method => <<"GET">>,
handler => 'swagger_user_handler'
handler => 'openapi_user_handler'
},
'UpdateUser' => #{
path => "/v2/user/:username",
method => <<"PUT">>,
handler => 'swagger_user_handler'
handler => 'openapi_user_handler'
}
}.
prepare_validator() ->
R = jsx:decode(element(2, file:read_file(get_swagger_path()))),
R = jsx:decode(element(2, file:read_file(get_openapi_path()))),
jesse_state:new(R, [{default_schema_ver, <<"http://json-schema.org/draft-04/schema#">>}]).
get_swagger_path() ->
get_openapi_path() ->
{ok, AppName} = application:get_application(?MODULE),
filename:join(swagger_utils:priv_dir(AppName), "openapi.json").
filename:join(openapi_utils:priv_dir(AppName), "openapi.json").

View File

@ -1,8 +1,8 @@
-module(swagger_server).
-module(openapi_server).
-define(DEFAULT_ACCEPTORS_POOLSIZE, 100).
-define(DEFAULT_LOGIC_HANDLER, swagger_default_logic_handler).
-define(DEFAULT_LOGIC_HANDLER, openapi_default_logic_handler).
-export([child_spec/2]).
@ -31,7 +31,7 @@ get_socket_transport(IP, Port, Options) ->
{ip, IP},
{port, Port}
],
case swagger_utils:get_opt(ssl, Options) of
case openapi_utils:get_opt(ssl, Options) of
SslOpts = [_|_] ->
{ranch_ssl, Opts ++ SslOpts};
undefined ->
@ -55,7 +55,7 @@ get_cowboy_config(LogicHandler, [{Key, Value}| Rest], Opts) ->
get_cowboy_config(LogicHandler, Rest, store_key(Key, Value, Opts)).
get_default_dispatch(LogicHandler) ->
Paths = swagger_router:get_paths(LogicHandler),
Paths = openapi_router:get_paths(LogicHandler),
{dispatch, cowboy_router:compile(Paths)}.
get_default_opts(LogicHandler) ->

View File

@ -1,5 +1,5 @@
%% basic handler
-module(swagger_store_handler).
-module(openapi_store_handler).
%% Cowboy REST callbacks
-export([allowed_methods/2]).
@ -19,7 +19,7 @@
-export([handle_request_json/2]).
-record(state, {
operation_id :: swagger_api:operation_id(),
operation_id :: openapi_api:operation_id(),
logic_handler :: atom(),
validator_state :: jesse_state:state(),
context=#{} :: #{}
@ -27,13 +27,13 @@
-type state() :: state().
-spec init(TransportName :: atom(), Req :: cowboy_req:req(), Opts :: swagger_router:init_opts()) ->
{upgrade, protocol, cowboy_rest, Req :: cowboy_req:req(), Opts :: swagger_router:init_opts()}.
-spec init(TransportName :: atom(), Req :: cowboy_req:req(), Opts :: openapi_router:init_opts()) ->
{upgrade, protocol, cowboy_rest, Req :: cowboy_req:req(), Opts :: openapi_router:init_opts()}.
init(_Transport, Req, Opts) ->
{upgrade, protocol, cowboy_rest, Req, Opts}.
-spec rest_init(Req :: cowboy_req:req(), Opts :: swagger_router:init_opts()) ->
-spec rest_init(Req :: cowboy_req:req(), Opts :: openapi_router:init_opts()) ->
{ok, Req :: cowboy_req:req(), State :: state()}.
rest_init(Req0, {Operations, LogicHandler, ValidatorState}) ->
@ -102,7 +102,7 @@ is_authorized(
}
) ->
From = header,
Result = swagger_auth:authorize_api_key(
Result = openapi_auth:authorize_api_key(
LogicHandler,
OperationID,
From,
@ -254,15 +254,15 @@ handle_request_json(
context = Context
}
) ->
case swagger_api:populate_request(OperationID, Req0, ValidatorState) of
case openapi_api:populate_request(OperationID, Req0, ValidatorState) of
{ok, Populated, Req1} ->
{Code, Headers, Body} = swagger_logic_handler:handle_request(
{Code, Headers, Body} = openapi_logic_handler:handle_request(
LogicHandler,
OperationID,
Populated,
Context
),
_ = swagger_api:validate_response(
_ = openapi_api:validate_response(
OperationID,
Code,
Body,

View File

@ -1,5 +1,5 @@
%% basic handler
-module(swagger_user_handler).
-module(openapi_user_handler).
%% Cowboy REST callbacks
-export([allowed_methods/2]).
@ -19,7 +19,7 @@
-export([handle_request_json/2]).
-record(state, {
operation_id :: swagger_api:operation_id(),
operation_id :: openapi_api:operation_id(),
logic_handler :: atom(),
validator_state :: jesse_state:state(),
context=#{} :: #{}
@ -27,13 +27,13 @@
-type state() :: state().
-spec init(TransportName :: atom(), Req :: cowboy_req:req(), Opts :: swagger_router:init_opts()) ->
{upgrade, protocol, cowboy_rest, Req :: cowboy_req:req(), Opts :: swagger_router:init_opts()}.
-spec init(TransportName :: atom(), Req :: cowboy_req:req(), Opts :: openapi_router:init_opts()) ->
{upgrade, protocol, cowboy_rest, Req :: cowboy_req:req(), Opts :: openapi_router:init_opts()}.
init(_Transport, Req, Opts) ->
{upgrade, protocol, cowboy_rest, Req, Opts}.
-spec rest_init(Req :: cowboy_req:req(), Opts :: swagger_router:init_opts()) ->
-spec rest_init(Req :: cowboy_req:req(), Opts :: openapi_router:init_opts()) ->
{ok, Req :: cowboy_req:req(), State :: state()}.
rest_init(Req0, {Operations, LogicHandler, ValidatorState}) ->
@ -307,15 +307,15 @@ handle_request_json(
context = Context
}
) ->
case swagger_api:populate_request(OperationID, Req0, ValidatorState) of
case openapi_api:populate_request(OperationID, Req0, ValidatorState) of
{ok, Populated, Req1} ->
{Code, Headers, Body} = swagger_logic_handler:handle_request(
{Code, Headers, Body} = openapi_logic_handler:handle_request(
LogicHandler,
OperationID,
Populated,
Context
),
_ = swagger_api:validate_response(
_ = openapi_api:validate_response(
OperationID,
Code,
Body,

View File

@ -1,4 +1,4 @@
-module(swagger_utils).
-module(openapi_utils).
-export([to_binary/1]).
-export([to_list/1]).