forked from loafle/openapi-generator-original
update erlang client, server default value (#378)
This commit is contained in:
parent
68780afe9d
commit
e2d6f7c88f
@ -17,15 +17,11 @@
|
|||||||
|
|
||||||
package org.openapitools.codegen.languages;
|
package org.openapitools.codegen.languages;
|
||||||
|
|
||||||
|
|
||||||
import com.samskivert.mustache.Mustache;
|
import com.samskivert.mustache.Mustache;
|
||||||
import com.samskivert.mustache.Template;
|
import com.samskivert.mustache.Template;
|
||||||
|
|
||||||
import org.openapitools.codegen.*;
|
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.oas.models.media.*;
|
||||||
import io.swagger.v3.core.util.Json;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -34,15 +30,13 @@ import java.io.IOException;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class ErlangClientCodegen extends DefaultCodegen implements CodegenConfig {
|
public class ErlangClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||||
static Logger LOGGER = LoggerFactory.getLogger(ErlangClientCodegen.class);
|
static Logger LOGGER = LoggerFactory.getLogger(ErlangClientCodegen.class);
|
||||||
|
|
||||||
protected String packageName = "swagger";
|
protected String packageName = "openapi";
|
||||||
protected String packageVersion = "1.0.0";
|
protected String packageVersion = "1.0.0";
|
||||||
protected String sourceFolder = "src";
|
protected String sourceFolder = "src";
|
||||||
|
|
||||||
@ -142,7 +136,7 @@ public class ErlangClientCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) {
|
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) {
|
||||||
setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME));
|
setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME));
|
||||||
} else {
|
} else {
|
||||||
setPackageName("swagger");
|
setPackageName("openapi");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_VERSION)) {
|
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_VERSION)) {
|
||||||
@ -178,7 +172,7 @@ public class ErlangClientCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String qsEncode(Object o) {
|
public String qsEncode(Object o) {
|
||||||
String r = new String();
|
String r = "";
|
||||||
CodegenParameter q = (CodegenParameter) o;
|
CodegenParameter q = (CodegenParameter) o;
|
||||||
if (q.required) {
|
if (q.required) {
|
||||||
if (q.isListContainer) {
|
if (q.isListContainer) {
|
||||||
@ -344,8 +338,7 @@ public class ErlangClientCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
int lengthRequired(List<CodegenParameter> allParams) {
|
int lengthRequired(List<CodegenParameter> allParams) {
|
||||||
int l = 0;
|
int l = 0;
|
||||||
for (CodegenParameter o : allParams) {
|
for (CodegenParameter o : allParams) {
|
||||||
CodegenParameter q = (CodegenParameter) o;
|
if (o.required || o.isBodyParam)
|
||||||
if (q.required || q.isBodyParam)
|
|
||||||
l++;
|
l++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ public class ErlangServerCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
|
|
||||||
protected String apiVersion = "1.0.0";
|
protected String apiVersion = "1.0.0";
|
||||||
protected String apiPath = "src";
|
protected String apiPath = "src";
|
||||||
protected String packageName = "swagger";
|
protected String packageName = "openapi";
|
||||||
|
|
||||||
public ErlangServerCodegen() {
|
public ErlangServerCodegen() {
|
||||||
super();
|
super();
|
||||||
@ -50,7 +50,8 @@ public class ErlangServerCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME));
|
setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME));
|
||||||
} else {
|
} else {
|
||||||
additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName);
|
additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName);
|
||||||
};
|
}
|
||||||
|
;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Models. You can write model files using the modelTemplateFiles map.
|
* Models. You can write model files using the modelTemplateFiles map.
|
||||||
@ -66,8 +67,8 @@ public class ErlangServerCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
* class
|
* class
|
||||||
*/
|
*/
|
||||||
apiTemplateFiles.put(
|
apiTemplateFiles.put(
|
||||||
"handler.mustache", // the template to use
|
"handler.mustache", // the template to use
|
||||||
".erl"); // the extension for each file to write
|
".erl"); // the extension for each file to write
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Template Location. This is the location which templates will be read from. The generator
|
* 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
|
* Reserved words. Override this with reserved words specific to your language
|
||||||
*/
|
*/
|
||||||
setReservedWordsLowerCase(
|
setReservedWordsLowerCase(
|
||||||
Arrays.asList(
|
Arrays.asList(
|
||||||
"after","and","andalso","band","begin","bnot","bor","bsl","bsr","bxor","case",
|
"after", "and", "andalso", "band", "begin", "bnot", "bor", "bsl", "bsr", "bxor", "case",
|
||||||
"catch","cond","div","end","fun","if","let","not","of","or","orelse","receive",
|
"catch", "cond", "div", "end", "fun", "if", "let", "not", "of", "or", "orelse", "receive",
|
||||||
"rem","try","when","xor"
|
"rem", "try", "when", "xor"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
instantiationTypes.clear();
|
instantiationTypes.clear();
|
||||||
|
|
||||||
@ -114,7 +115,7 @@ public class ErlangServerCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
|
|
||||||
cliOptions.clear();
|
cliOptions.clear();
|
||||||
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "Erlang package name (convention: lowercase).")
|
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
|
* Additional Properties. These values can be passed to the templates and
|
||||||
* are available in models, apis, and supporting files
|
* 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
|
* 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
|
* 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("app.src.mustache", "", "src" + File.separator + this.packageName + ".app.src"));
|
||||||
supportingFiles.add(new SupportingFile("router.mustache", "", toSourceFilePath("router", "erl")));
|
supportingFiles.add(new SupportingFile("router.mustache", "", toSourceFilePath("router", "erl")));
|
||||||
supportingFiles.add(new SupportingFile("api.mustache", "", toSourceFilePath("api", "erl")));
|
supportingFiles.add(new SupportingFile("api.mustache", "", toSourceFilePath("api", "erl")));
|
||||||
supportingFiles.add(new SupportingFile("server.mustache", "", toSourceFilePath("server", "erl")));
|
supportingFiles.add(new SupportingFile("server.mustache", "", toSourceFilePath("server", "erl")));
|
||||||
supportingFiles.add(new SupportingFile("utils.mustache", "", toSourceFilePath("utils", "erl")));
|
supportingFiles.add(new SupportingFile("utils.mustache", "", toSourceFilePath("utils", "erl")));
|
||||||
supportingFiles.add(new SupportingFile("auth.mustache", "", toSourceFilePath("auth", "erl")));
|
supportingFiles.add(new SupportingFile("auth.mustache", "", toSourceFilePath("auth", "erl")));
|
||||||
supportingFiles.add(new SupportingFile("openapi.mustache", "", toPrivFilePath("openapi", "json")));
|
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("default_logic_handler.mustache", "", toSourceFilePath("default_logic_handler", "erl")));
|
||||||
supportingFiles.add(new SupportingFile("logic_handler.mustache", "", toSourceFilePath("logic_handler", "erl")));
|
supportingFiles.add(new SupportingFile("logic_handler.mustache", "", toSourceFilePath("logic_handler", "erl")));
|
||||||
writeOptional(outputFolder, new SupportingFile("README.mustache", "", "README.md"));
|
writeOptional(outputFolder, new SupportingFile("README.mustache", "", "README.md"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,7 +175,7 @@ public class ErlangServerCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getHelp() {
|
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.";
|
"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
|
* @return the escaped term
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String escapeReservedWord(String name) {
|
public String escapeReservedWord(String name) {
|
||||||
if(this.reservedWordsMappings().containsKey(name)) {
|
if (this.reservedWordsMappings().containsKey(name)) {
|
||||||
return this.reservedWordsMappings().get(name);
|
return this.reservedWordsMappings().get(name);
|
||||||
}
|
}
|
||||||
return "_" + name;
|
return "_" + name;
|
||||||
@ -261,7 +262,7 @@ public class ErlangServerCodegen extends DefaultCodegen implements CodegenConfig
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected String toSourceFilePath(String name, String extension) {
|
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) {
|
protected String toIncludeFilePath(String name, String extension) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# Swagger client server library for Erlang
|
# OpenAPI client server library for Erlang
|
||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# Swagger rest server library for Erlang
|
# OpenAPI server library for Erlang
|
||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
-export([request_param_info/2]).
|
-export([request_param_info/2]).
|
||||||
-export([populate_request/3]).
|
-export([populate_request/3]).
|
||||||
-export([validate_response/4]).
|
-export([validate_response/4]).
|
||||||
%% exported to silence swagger complains
|
%% exported to silence openapi complains
|
||||||
-export([get_value/3, validate_response_body/4]).
|
-export([get_value/3, validate_response_body/4]).
|
||||||
|
|
||||||
-type operation_id() :: atom().
|
-type operation_id() :: atom().
|
||||||
|
@ -39,7 +39,7 @@ authorize_api_key(LogicHandler, OperationID, From, KeyParam, Req0) ->
|
|||||||
get_api_key(header, KeyParam, Req0) ->
|
get_api_key(header, KeyParam, Req0) ->
|
||||||
{Headers, Req} = cowboy_req:headers(Req0),
|
{Headers, Req} = cowboy_req:headers(Req0),
|
||||||
{
|
{
|
||||||
swagger_utils:get_opt(
|
openapi_utils:get_opt(
|
||||||
{{packageName}}_utils:to_header(KeyParam),
|
{{packageName}}_utils:to_header(KeyParam),
|
||||||
Headers
|
Headers
|
||||||
),
|
),
|
||||||
|
@ -63,11 +63,11 @@ get_operations() ->
|
|||||||
}.
|
}.
|
||||||
|
|
||||||
prepare_validator() ->
|
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#">>}]).
|
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),
|
{ok, AppName} = application:get_application(?MODULE),
|
||||||
filename:join({{packageName}}_utils:priv_dir(AppName), "openapi.json").
|
filename:join({{packageName}}_utils:priv_dir(AppName), "openapi.json").
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# Swagger client server library for Erlang
|
# OpenAPI client server library for Erlang
|
||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# Swagger rest server library for Erlang
|
# OpenAPI server library for Erlang
|
||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
|
|
||||||
|
@ -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 `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."},
|
||||||
{vsn, "1.0.0"},
|
{vsn, "1.0.0"},
|
||||||
{registered, []},
|
{registered, []},
|
@ -1,10 +1,10 @@
|
|||||||
-module(swagger_api).
|
-module(openapi_api).
|
||||||
|
|
||||||
-export([request_params/1]).
|
-export([request_params/1]).
|
||||||
-export([request_param_info/2]).
|
-export([request_param_info/2]).
|
||||||
-export([populate_request/3]).
|
-export([populate_request/3]).
|
||||||
-export([validate_response/4]).
|
-export([validate_response/4]).
|
||||||
%% exported to silence swagger complains
|
%% exported to silence openapi complains
|
||||||
-export([get_value/3, validate_response_body/4]).
|
-export([get_value/3, validate_response_body/4]).
|
||||||
|
|
||||||
-type operation_id() :: atom().
|
-type operation_id() :: atom().
|
||||||
@ -546,7 +546,7 @@ validate(_, _Name, undefined, _ValidatorState) ->
|
|||||||
|
|
||||||
validate(Rule = {type, 'integer'}, Name, Value, _ValidatorState) ->
|
validate(Rule = {type, 'integer'}, Name, Value, _ValidatorState) ->
|
||||||
try
|
try
|
||||||
{ok, swagger_utils:to_int(Value)}
|
{ok, openapi_utils:to_int(Value)}
|
||||||
catch
|
catch
|
||||||
error:badarg ->
|
error:badarg ->
|
||||||
validation_error(Rule, Name)
|
validation_error(Rule, Name)
|
||||||
@ -554,7 +554,7 @@ validate(Rule = {type, 'integer'}, Name, Value, _ValidatorState) ->
|
|||||||
|
|
||||||
validate(Rule = {type, 'float'}, Name, Value, _ValidatorState) ->
|
validate(Rule = {type, 'float'}, Name, Value, _ValidatorState) ->
|
||||||
try
|
try
|
||||||
{ok, swagger_utils:to_float(Value)}
|
{ok, openapi_utils:to_float(Value)}
|
||||||
catch
|
catch
|
||||||
error:badarg ->
|
error:badarg ->
|
||||||
validation_error(Rule, Name)
|
validation_error(Rule, Name)
|
||||||
@ -649,7 +649,7 @@ validate(Rule = {pattern, Pattern}, Name, Value, _ValidatorState) ->
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
validate(Rule = schema, Name, Value, ValidatorState) ->
|
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
|
try
|
||||||
_ = validate_with_schema(Value, Definition, ValidatorState),
|
_ = validate_with_schema(Value, Definition, ValidatorState),
|
||||||
ok
|
ok
|
||||||
@ -698,17 +698,17 @@ get_value(body, _Name, Req0) ->
|
|||||||
|
|
||||||
get_value(qs_val, Name, Req0) ->
|
get_value(qs_val, Name, Req0) ->
|
||||||
{QS, Req} = cowboy_req:qs_vals(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};
|
{Value, Req};
|
||||||
|
|
||||||
get_value(header, Name, Req0) ->
|
get_value(header, Name, Req0) ->
|
||||||
{Headers, Req} = cowboy_req:headers(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};
|
{Value, Req};
|
||||||
|
|
||||||
get_value(binding, Name, Req0) ->
|
get_value(binding, Name, Req0) ->
|
||||||
{Bindings, Req} = cowboy_req:bindings(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}.
|
{Value, Req}.
|
||||||
|
|
||||||
prepare_body(Body) ->
|
prepare_body(Body) ->
|
||||||
@ -749,4 +749,4 @@ prepare_param(Rules, Name, Value, ValidatorState) ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
binary_to_lower(V) when is_binary(V) ->
|
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))).
|
@ -1,10 +1,10 @@
|
|||||||
-module(swagger_auth).
|
-module(openapi_auth).
|
||||||
|
|
||||||
-export([authorize_api_key/5]).
|
-export([authorize_api_key/5]).
|
||||||
|
|
||||||
-spec authorize_api_key(
|
-spec authorize_api_key(
|
||||||
LogicHandler :: atom(),
|
LogicHandler :: atom(),
|
||||||
OperationID :: swagger_api:operation_id(),
|
OperationID :: openapi_api:operation_id(),
|
||||||
From :: header | qs_val,
|
From :: header | qs_val,
|
||||||
KeyParam :: iodata() | atom(),
|
KeyParam :: iodata() | atom(),
|
||||||
Req ::cowboy_req:req()
|
Req ::cowboy_req:req()
|
||||||
@ -18,7 +18,7 @@ authorize_api_key(LogicHandler, OperationID, From, KeyParam, Req0) ->
|
|||||||
AuthHeader = <<"">>,
|
AuthHeader = <<"">>,
|
||||||
{false, AuthHeader, Req};
|
{false, AuthHeader, Req};
|
||||||
_ ->
|
_ ->
|
||||||
Result = swagger_logic_handler:authorize_api_key(
|
Result = openapi_logic_handler:authorize_api_key(
|
||||||
LogicHandler,
|
LogicHandler,
|
||||||
OperationID,
|
OperationID,
|
||||||
ApiKey
|
ApiKey
|
||||||
@ -35,8 +35,8 @@ authorize_api_key(LogicHandler, OperationID, From, KeyParam, Req0) ->
|
|||||||
get_api_key(header, KeyParam, Req0) ->
|
get_api_key(header, KeyParam, Req0) ->
|
||||||
{Headers, Req} = cowboy_req:headers(Req0),
|
{Headers, Req} = cowboy_req:headers(Req0),
|
||||||
{
|
{
|
||||||
swagger_utils:get_opt(
|
openapi_utils:get_opt(
|
||||||
swagger_utils:to_header(KeyParam),
|
openapi_utils:to_header(KeyParam),
|
||||||
Headers
|
Headers
|
||||||
),
|
),
|
||||||
Req
|
Req
|
||||||
@ -44,7 +44,7 @@ get_api_key(header, KeyParam, Req0) ->
|
|||||||
|
|
||||||
get_api_key(qs_val, KeyParam, Req0) ->
|
get_api_key(qs_val, KeyParam, Req0) ->
|
||||||
{QS, Req} = cowboy_req:qs_vals(Req0),
|
{QS, Req} = cowboy_req:qs_vals(Req0),
|
||||||
{ swagger_utils:get_opt(KeyParam, QS), Req}.
|
{ openapi_utils:get_opt(KeyParam, QS), Req}.
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -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([handle_request/3]).
|
||||||
-export([authorize_api_key/2]).
|
-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, #{}}.
|
authorize_api_key(_, _) -> {true, #{}}.
|
||||||
|
|
||||||
-spec handle_request(
|
-spec handle_request(
|
||||||
OperationID :: swagger_api:operation_id(),
|
OperationID :: openapi_api:operation_id(),
|
||||||
Req :: cowboy_req:req(),
|
Req :: cowboy_req:req(),
|
||||||
Context :: #{}
|
Context :: #{}
|
||||||
) ->
|
) ->
|
@ -1,4 +1,4 @@
|
|||||||
-module(swagger_logic_handler).
|
-module(openapi_logic_handler).
|
||||||
|
|
||||||
-export([handle_request/4]).
|
-export([handle_request/4]).
|
||||||
-export([authorize_api_key/3]).
|
-export([authorize_api_key/3]).
|
||||||
@ -12,18 +12,18 @@
|
|||||||
-export_type([handler_response/0]).
|
-export_type([handler_response/0]).
|
||||||
|
|
||||||
-callback authorize_api_key(
|
-callback authorize_api_key(
|
||||||
OperationID :: swagger_api:operation_id(),
|
OperationID :: openapi_api:operation_id(),
|
||||||
ApiKey :: binary()
|
ApiKey :: binary()
|
||||||
) ->
|
) ->
|
||||||
Result :: boolean() | {boolean(), context()}.
|
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().
|
handler_response().
|
||||||
|
|
||||||
-spec handle_request(
|
-spec handle_request(
|
||||||
Handler :: atom(),
|
Handler :: atom(),
|
||||||
OperationID :: swagger_api:operation_id(),
|
OperationID :: openapi_api:operation_id(),
|
||||||
Request :: any(),
|
Request :: any(),
|
||||||
Context :: context()
|
Context :: context()
|
||||||
) ->
|
) ->
|
||||||
@ -32,7 +32,7 @@
|
|||||||
handle_request(Handler, OperationID, Req, Context) ->
|
handle_request(Handler, OperationID, Req, Context) ->
|
||||||
Handler:handle_request(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()}.
|
Result :: false | {true, context()}.
|
||||||
authorize_api_key(Handler, OperationID, ApiKey) ->
|
authorize_api_key(Handler, OperationID, ApiKey) ->
|
||||||
Handler:authorize_api_key(OperationID, ApiKey).
|
Handler:authorize_api_key(OperationID, ApiKey).
|
@ -1,5 +1,5 @@
|
|||||||
%% basic handler
|
%% basic handler
|
||||||
-module(swagger_pet_handler).
|
-module(openapi_pet_handler).
|
||||||
|
|
||||||
%% Cowboy REST callbacks
|
%% Cowboy REST callbacks
|
||||||
-export([allowed_methods/2]).
|
-export([allowed_methods/2]).
|
||||||
@ -19,7 +19,7 @@
|
|||||||
-export([handle_request_json/2]).
|
-export([handle_request_json/2]).
|
||||||
|
|
||||||
-record(state, {
|
-record(state, {
|
||||||
operation_id :: swagger_api:operation_id(),
|
operation_id :: openapi_api:operation_id(),
|
||||||
logic_handler :: atom(),
|
logic_handler :: atom(),
|
||||||
validator_state :: jesse_state:state(),
|
validator_state :: jesse_state:state(),
|
||||||
context=#{} :: #{}
|
context=#{} :: #{}
|
||||||
@ -27,13 +27,13 @@
|
|||||||
|
|
||||||
-type state() :: state().
|
-type state() :: state().
|
||||||
|
|
||||||
-spec init(TransportName :: atom(), 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 :: swagger_router:init_opts()}.
|
{upgrade, protocol, cowboy_rest, Req :: cowboy_req:req(), Opts :: openapi_router:init_opts()}.
|
||||||
|
|
||||||
init(_Transport, Req, Opts) ->
|
init(_Transport, Req, Opts) ->
|
||||||
{upgrade, protocol, cowboy_rest, 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()}.
|
{ok, Req :: cowboy_req:req(), State :: state()}.
|
||||||
|
|
||||||
rest_init(Req0, {Operations, LogicHandler, ValidatorState}) ->
|
rest_init(Req0, {Operations, LogicHandler, ValidatorState}) ->
|
||||||
@ -134,7 +134,7 @@ is_authorized(
|
|||||||
}
|
}
|
||||||
) ->
|
) ->
|
||||||
From = header,
|
From = header,
|
||||||
Result = swagger_auth:authorize_api_key(
|
Result = openapi_auth:authorize_api_key(
|
||||||
LogicHandler,
|
LogicHandler,
|
||||||
OperationID,
|
OperationID,
|
||||||
From,
|
From,
|
||||||
@ -153,7 +153,7 @@ is_authorized(
|
|||||||
}
|
}
|
||||||
) ->
|
) ->
|
||||||
From = header,
|
From = header,
|
||||||
Result = swagger_auth:authorize_api_key(
|
Result = openapi_auth:authorize_api_key(
|
||||||
LogicHandler,
|
LogicHandler,
|
||||||
OperationID,
|
OperationID,
|
||||||
From,
|
From,
|
||||||
@ -172,7 +172,7 @@ is_authorized(
|
|||||||
}
|
}
|
||||||
) ->
|
) ->
|
||||||
From = header,
|
From = header,
|
||||||
Result = swagger_auth:authorize_api_key(
|
Result = openapi_auth:authorize_api_key(
|
||||||
LogicHandler,
|
LogicHandler,
|
||||||
OperationID,
|
OperationID,
|
||||||
From,
|
From,
|
||||||
@ -191,7 +191,7 @@ is_authorized(
|
|||||||
}
|
}
|
||||||
) ->
|
) ->
|
||||||
From = header,
|
From = header,
|
||||||
Result = swagger_auth:authorize_api_key(
|
Result = openapi_auth:authorize_api_key(
|
||||||
LogicHandler,
|
LogicHandler,
|
||||||
OperationID,
|
OperationID,
|
||||||
From,
|
From,
|
||||||
@ -210,7 +210,7 @@ is_authorized(
|
|||||||
}
|
}
|
||||||
) ->
|
) ->
|
||||||
From = header,
|
From = header,
|
||||||
Result = swagger_auth:authorize_api_key(
|
Result = openapi_auth:authorize_api_key(
|
||||||
LogicHandler,
|
LogicHandler,
|
||||||
OperationID,
|
OperationID,
|
||||||
From,
|
From,
|
||||||
@ -229,7 +229,7 @@ is_authorized(
|
|||||||
}
|
}
|
||||||
) ->
|
) ->
|
||||||
From = header,
|
From = header,
|
||||||
Result = swagger_auth:authorize_api_key(
|
Result = openapi_auth:authorize_api_key(
|
||||||
LogicHandler,
|
LogicHandler,
|
||||||
OperationID,
|
OperationID,
|
||||||
From,
|
From,
|
||||||
@ -248,7 +248,7 @@ is_authorized(
|
|||||||
}
|
}
|
||||||
) ->
|
) ->
|
||||||
From = header,
|
From = header,
|
||||||
Result = swagger_auth:authorize_api_key(
|
Result = openapi_auth:authorize_api_key(
|
||||||
LogicHandler,
|
LogicHandler,
|
||||||
OperationID,
|
OperationID,
|
||||||
From,
|
From,
|
||||||
@ -267,7 +267,7 @@ is_authorized(
|
|||||||
}
|
}
|
||||||
) ->
|
) ->
|
||||||
From = header,
|
From = header,
|
||||||
Result = swagger_auth:authorize_api_key(
|
Result = openapi_auth:authorize_api_key(
|
||||||
LogicHandler,
|
LogicHandler,
|
||||||
OperationID,
|
OperationID,
|
||||||
From,
|
From,
|
||||||
@ -459,15 +459,15 @@ handle_request_json(
|
|||||||
context = Context
|
context = Context
|
||||||
}
|
}
|
||||||
) ->
|
) ->
|
||||||
case swagger_api:populate_request(OperationID, Req0, ValidatorState) of
|
case openapi_api:populate_request(OperationID, Req0, ValidatorState) of
|
||||||
{ok, Populated, Req1} ->
|
{ok, Populated, Req1} ->
|
||||||
{Code, Headers, Body} = swagger_logic_handler:handle_request(
|
{Code, Headers, Body} = openapi_logic_handler:handle_request(
|
||||||
LogicHandler,
|
LogicHandler,
|
||||||
OperationID,
|
OperationID,
|
||||||
Populated,
|
Populated,
|
||||||
Context
|
Context
|
||||||
),
|
),
|
||||||
_ = swagger_api:validate_response(
|
_ = openapi_api:validate_response(
|
||||||
OperationID,
|
OperationID,
|
||||||
Code,
|
Code,
|
||||||
Body,
|
Body,
|
@ -1,9 +1,9 @@
|
|||||||
-module(swagger_router).
|
-module(openapi_router).
|
||||||
|
|
||||||
-export([get_paths/1]).
|
-export([get_paths/1]).
|
||||||
|
|
||||||
-type operations() :: #{
|
-type operations() :: #{
|
||||||
Method :: binary() => swagger_api:operation_id()
|
Method :: binary() => openapi_api:operation_id()
|
||||||
}.
|
}.
|
||||||
|
|
||||||
-type init_opts() :: {
|
-type init_opts() :: {
|
||||||
@ -58,112 +58,112 @@ get_operations() ->
|
|||||||
'AddPet' => #{
|
'AddPet' => #{
|
||||||
path => "/v2/pet",
|
path => "/v2/pet",
|
||||||
method => <<"POST">>,
|
method => <<"POST">>,
|
||||||
handler => 'swagger_pet_handler'
|
handler => 'openapi_pet_handler'
|
||||||
},
|
},
|
||||||
'DeletePet' => #{
|
'DeletePet' => #{
|
||||||
path => "/v2/pet/:petId",
|
path => "/v2/pet/:petId",
|
||||||
method => <<"DELETE">>,
|
method => <<"DELETE">>,
|
||||||
handler => 'swagger_pet_handler'
|
handler => 'openapi_pet_handler'
|
||||||
},
|
},
|
||||||
'FindPetsByStatus' => #{
|
'FindPetsByStatus' => #{
|
||||||
path => "/v2/pet/findByStatus",
|
path => "/v2/pet/findByStatus",
|
||||||
method => <<"GET">>,
|
method => <<"GET">>,
|
||||||
handler => 'swagger_pet_handler'
|
handler => 'openapi_pet_handler'
|
||||||
},
|
},
|
||||||
'FindPetsByTags' => #{
|
'FindPetsByTags' => #{
|
||||||
path => "/v2/pet/findByTags",
|
path => "/v2/pet/findByTags",
|
||||||
method => <<"GET">>,
|
method => <<"GET">>,
|
||||||
handler => 'swagger_pet_handler'
|
handler => 'openapi_pet_handler'
|
||||||
},
|
},
|
||||||
'GetPetById' => #{
|
'GetPetById' => #{
|
||||||
path => "/v2/pet/:petId",
|
path => "/v2/pet/:petId",
|
||||||
method => <<"GET">>,
|
method => <<"GET">>,
|
||||||
handler => 'swagger_pet_handler'
|
handler => 'openapi_pet_handler'
|
||||||
},
|
},
|
||||||
'UpdatePet' => #{
|
'UpdatePet' => #{
|
||||||
path => "/v2/pet",
|
path => "/v2/pet",
|
||||||
method => <<"PUT">>,
|
method => <<"PUT">>,
|
||||||
handler => 'swagger_pet_handler'
|
handler => 'openapi_pet_handler'
|
||||||
},
|
},
|
||||||
'UpdatePetWithForm' => #{
|
'UpdatePetWithForm' => #{
|
||||||
path => "/v2/pet/:petId",
|
path => "/v2/pet/:petId",
|
||||||
method => <<"POST">>,
|
method => <<"POST">>,
|
||||||
handler => 'swagger_pet_handler'
|
handler => 'openapi_pet_handler'
|
||||||
},
|
},
|
||||||
'UploadFile' => #{
|
'UploadFile' => #{
|
||||||
path => "/v2/pet/:petId/uploadImage",
|
path => "/v2/pet/:petId/uploadImage",
|
||||||
method => <<"POST">>,
|
method => <<"POST">>,
|
||||||
handler => 'swagger_pet_handler'
|
handler => 'openapi_pet_handler'
|
||||||
},
|
},
|
||||||
'DeleteOrder' => #{
|
'DeleteOrder' => #{
|
||||||
path => "/v2/store/order/:orderId",
|
path => "/v2/store/order/:orderId",
|
||||||
method => <<"DELETE">>,
|
method => <<"DELETE">>,
|
||||||
handler => 'swagger_store_handler'
|
handler => 'openapi_store_handler'
|
||||||
},
|
},
|
||||||
'GetInventory' => #{
|
'GetInventory' => #{
|
||||||
path => "/v2/store/inventory",
|
path => "/v2/store/inventory",
|
||||||
method => <<"GET">>,
|
method => <<"GET">>,
|
||||||
handler => 'swagger_store_handler'
|
handler => 'openapi_store_handler'
|
||||||
},
|
},
|
||||||
'GetOrderById' => #{
|
'GetOrderById' => #{
|
||||||
path => "/v2/store/order/:orderId",
|
path => "/v2/store/order/:orderId",
|
||||||
method => <<"GET">>,
|
method => <<"GET">>,
|
||||||
handler => 'swagger_store_handler'
|
handler => 'openapi_store_handler'
|
||||||
},
|
},
|
||||||
'PlaceOrder' => #{
|
'PlaceOrder' => #{
|
||||||
path => "/v2/store/order",
|
path => "/v2/store/order",
|
||||||
method => <<"POST">>,
|
method => <<"POST">>,
|
||||||
handler => 'swagger_store_handler'
|
handler => 'openapi_store_handler'
|
||||||
},
|
},
|
||||||
'CreateUser' => #{
|
'CreateUser' => #{
|
||||||
path => "/v2/user",
|
path => "/v2/user",
|
||||||
method => <<"POST">>,
|
method => <<"POST">>,
|
||||||
handler => 'swagger_user_handler'
|
handler => 'openapi_user_handler'
|
||||||
},
|
},
|
||||||
'CreateUsersWithArrayInput' => #{
|
'CreateUsersWithArrayInput' => #{
|
||||||
path => "/v2/user/createWithArray",
|
path => "/v2/user/createWithArray",
|
||||||
method => <<"POST">>,
|
method => <<"POST">>,
|
||||||
handler => 'swagger_user_handler'
|
handler => 'openapi_user_handler'
|
||||||
},
|
},
|
||||||
'CreateUsersWithListInput' => #{
|
'CreateUsersWithListInput' => #{
|
||||||
path => "/v2/user/createWithList",
|
path => "/v2/user/createWithList",
|
||||||
method => <<"POST">>,
|
method => <<"POST">>,
|
||||||
handler => 'swagger_user_handler'
|
handler => 'openapi_user_handler'
|
||||||
},
|
},
|
||||||
'DeleteUser' => #{
|
'DeleteUser' => #{
|
||||||
path => "/v2/user/:username",
|
path => "/v2/user/:username",
|
||||||
method => <<"DELETE">>,
|
method => <<"DELETE">>,
|
||||||
handler => 'swagger_user_handler'
|
handler => 'openapi_user_handler'
|
||||||
},
|
},
|
||||||
'GetUserByName' => #{
|
'GetUserByName' => #{
|
||||||
path => "/v2/user/:username",
|
path => "/v2/user/:username",
|
||||||
method => <<"GET">>,
|
method => <<"GET">>,
|
||||||
handler => 'swagger_user_handler'
|
handler => 'openapi_user_handler'
|
||||||
},
|
},
|
||||||
'LoginUser' => #{
|
'LoginUser' => #{
|
||||||
path => "/v2/user/login",
|
path => "/v2/user/login",
|
||||||
method => <<"GET">>,
|
method => <<"GET">>,
|
||||||
handler => 'swagger_user_handler'
|
handler => 'openapi_user_handler'
|
||||||
},
|
},
|
||||||
'LogoutUser' => #{
|
'LogoutUser' => #{
|
||||||
path => "/v2/user/logout",
|
path => "/v2/user/logout",
|
||||||
method => <<"GET">>,
|
method => <<"GET">>,
|
||||||
handler => 'swagger_user_handler'
|
handler => 'openapi_user_handler'
|
||||||
},
|
},
|
||||||
'UpdateUser' => #{
|
'UpdateUser' => #{
|
||||||
path => "/v2/user/:username",
|
path => "/v2/user/:username",
|
||||||
method => <<"PUT">>,
|
method => <<"PUT">>,
|
||||||
handler => 'swagger_user_handler'
|
handler => 'openapi_user_handler'
|
||||||
}
|
}
|
||||||
}.
|
}.
|
||||||
|
|
||||||
prepare_validator() ->
|
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#">>}]).
|
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),
|
{ok, AppName} = application:get_application(?MODULE),
|
||||||
filename:join(swagger_utils:priv_dir(AppName), "openapi.json").
|
filename:join(openapi_utils:priv_dir(AppName), "openapi.json").
|
||||||
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
|||||||
-module(swagger_server).
|
-module(openapi_server).
|
||||||
|
|
||||||
|
|
||||||
-define(DEFAULT_ACCEPTORS_POOLSIZE, 100).
|
-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]).
|
-export([child_spec/2]).
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ get_socket_transport(IP, Port, Options) ->
|
|||||||
{ip, IP},
|
{ip, IP},
|
||||||
{port, Port}
|
{port, Port}
|
||||||
],
|
],
|
||||||
case swagger_utils:get_opt(ssl, Options) of
|
case openapi_utils:get_opt(ssl, Options) of
|
||||||
SslOpts = [_|_] ->
|
SslOpts = [_|_] ->
|
||||||
{ranch_ssl, Opts ++ SslOpts};
|
{ranch_ssl, Opts ++ SslOpts};
|
||||||
undefined ->
|
undefined ->
|
||||||
@ -55,7 +55,7 @@ get_cowboy_config(LogicHandler, [{Key, Value}| Rest], Opts) ->
|
|||||||
get_cowboy_config(LogicHandler, Rest, store_key(Key, Value, Opts)).
|
get_cowboy_config(LogicHandler, Rest, store_key(Key, Value, Opts)).
|
||||||
|
|
||||||
get_default_dispatch(LogicHandler) ->
|
get_default_dispatch(LogicHandler) ->
|
||||||
Paths = swagger_router:get_paths(LogicHandler),
|
Paths = openapi_router:get_paths(LogicHandler),
|
||||||
{dispatch, cowboy_router:compile(Paths)}.
|
{dispatch, cowboy_router:compile(Paths)}.
|
||||||
|
|
||||||
get_default_opts(LogicHandler) ->
|
get_default_opts(LogicHandler) ->
|
@ -1,5 +1,5 @@
|
|||||||
%% basic handler
|
%% basic handler
|
||||||
-module(swagger_store_handler).
|
-module(openapi_store_handler).
|
||||||
|
|
||||||
%% Cowboy REST callbacks
|
%% Cowboy REST callbacks
|
||||||
-export([allowed_methods/2]).
|
-export([allowed_methods/2]).
|
||||||
@ -19,7 +19,7 @@
|
|||||||
-export([handle_request_json/2]).
|
-export([handle_request_json/2]).
|
||||||
|
|
||||||
-record(state, {
|
-record(state, {
|
||||||
operation_id :: swagger_api:operation_id(),
|
operation_id :: openapi_api:operation_id(),
|
||||||
logic_handler :: atom(),
|
logic_handler :: atom(),
|
||||||
validator_state :: jesse_state:state(),
|
validator_state :: jesse_state:state(),
|
||||||
context=#{} :: #{}
|
context=#{} :: #{}
|
||||||
@ -27,13 +27,13 @@
|
|||||||
|
|
||||||
-type state() :: state().
|
-type state() :: state().
|
||||||
|
|
||||||
-spec init(TransportName :: atom(), 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 :: swagger_router:init_opts()}.
|
{upgrade, protocol, cowboy_rest, Req :: cowboy_req:req(), Opts :: openapi_router:init_opts()}.
|
||||||
|
|
||||||
init(_Transport, Req, Opts) ->
|
init(_Transport, Req, Opts) ->
|
||||||
{upgrade, protocol, cowboy_rest, 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()}.
|
{ok, Req :: cowboy_req:req(), State :: state()}.
|
||||||
|
|
||||||
rest_init(Req0, {Operations, LogicHandler, ValidatorState}) ->
|
rest_init(Req0, {Operations, LogicHandler, ValidatorState}) ->
|
||||||
@ -102,7 +102,7 @@ is_authorized(
|
|||||||
}
|
}
|
||||||
) ->
|
) ->
|
||||||
From = header,
|
From = header,
|
||||||
Result = swagger_auth:authorize_api_key(
|
Result = openapi_auth:authorize_api_key(
|
||||||
LogicHandler,
|
LogicHandler,
|
||||||
OperationID,
|
OperationID,
|
||||||
From,
|
From,
|
||||||
@ -254,15 +254,15 @@ handle_request_json(
|
|||||||
context = Context
|
context = Context
|
||||||
}
|
}
|
||||||
) ->
|
) ->
|
||||||
case swagger_api:populate_request(OperationID, Req0, ValidatorState) of
|
case openapi_api:populate_request(OperationID, Req0, ValidatorState) of
|
||||||
{ok, Populated, Req1} ->
|
{ok, Populated, Req1} ->
|
||||||
{Code, Headers, Body} = swagger_logic_handler:handle_request(
|
{Code, Headers, Body} = openapi_logic_handler:handle_request(
|
||||||
LogicHandler,
|
LogicHandler,
|
||||||
OperationID,
|
OperationID,
|
||||||
Populated,
|
Populated,
|
||||||
Context
|
Context
|
||||||
),
|
),
|
||||||
_ = swagger_api:validate_response(
|
_ = openapi_api:validate_response(
|
||||||
OperationID,
|
OperationID,
|
||||||
Code,
|
Code,
|
||||||
Body,
|
Body,
|
@ -1,5 +1,5 @@
|
|||||||
%% basic handler
|
%% basic handler
|
||||||
-module(swagger_user_handler).
|
-module(openapi_user_handler).
|
||||||
|
|
||||||
%% Cowboy REST callbacks
|
%% Cowboy REST callbacks
|
||||||
-export([allowed_methods/2]).
|
-export([allowed_methods/2]).
|
||||||
@ -19,7 +19,7 @@
|
|||||||
-export([handle_request_json/2]).
|
-export([handle_request_json/2]).
|
||||||
|
|
||||||
-record(state, {
|
-record(state, {
|
||||||
operation_id :: swagger_api:operation_id(),
|
operation_id :: openapi_api:operation_id(),
|
||||||
logic_handler :: atom(),
|
logic_handler :: atom(),
|
||||||
validator_state :: jesse_state:state(),
|
validator_state :: jesse_state:state(),
|
||||||
context=#{} :: #{}
|
context=#{} :: #{}
|
||||||
@ -27,13 +27,13 @@
|
|||||||
|
|
||||||
-type state() :: state().
|
-type state() :: state().
|
||||||
|
|
||||||
-spec init(TransportName :: atom(), 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 :: swagger_router:init_opts()}.
|
{upgrade, protocol, cowboy_rest, Req :: cowboy_req:req(), Opts :: openapi_router:init_opts()}.
|
||||||
|
|
||||||
init(_Transport, Req, Opts) ->
|
init(_Transport, Req, Opts) ->
|
||||||
{upgrade, protocol, cowboy_rest, 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()}.
|
{ok, Req :: cowboy_req:req(), State :: state()}.
|
||||||
|
|
||||||
rest_init(Req0, {Operations, LogicHandler, ValidatorState}) ->
|
rest_init(Req0, {Operations, LogicHandler, ValidatorState}) ->
|
||||||
@ -307,15 +307,15 @@ handle_request_json(
|
|||||||
context = Context
|
context = Context
|
||||||
}
|
}
|
||||||
) ->
|
) ->
|
||||||
case swagger_api:populate_request(OperationID, Req0, ValidatorState) of
|
case openapi_api:populate_request(OperationID, Req0, ValidatorState) of
|
||||||
{ok, Populated, Req1} ->
|
{ok, Populated, Req1} ->
|
||||||
{Code, Headers, Body} = swagger_logic_handler:handle_request(
|
{Code, Headers, Body} = openapi_logic_handler:handle_request(
|
||||||
LogicHandler,
|
LogicHandler,
|
||||||
OperationID,
|
OperationID,
|
||||||
Populated,
|
Populated,
|
||||||
Context
|
Context
|
||||||
),
|
),
|
||||||
_ = swagger_api:validate_response(
|
_ = openapi_api:validate_response(
|
||||||
OperationID,
|
OperationID,
|
||||||
Code,
|
Code,
|
||||||
Body,
|
Body,
|
@ -1,4 +1,4 @@
|
|||||||
-module(swagger_utils).
|
-module(openapi_utils).
|
||||||
|
|
||||||
-export([to_binary/1]).
|
-export([to_binary/1]).
|
||||||
-export([to_list/1]).
|
-export([to_list/1]).
|
Loading…
x
Reference in New Issue
Block a user