forked from loafle/openapi-generator-original
[lua] Allow connection on port != 80 or 443 (#1712)
* Allow connection on port != 80 or 443 In the current implementation a client can't connect on another port than 80 or 443 This commit allows to specify a host like "localhost:8080" when creating the client The port is then used when initiating http requests * Update Petstore Sample for CI * Fix unused return value * Update petstore sample * Rename host parameter into authority
This commit is contained in:
@@ -18,14 +18,16 @@ local {{{classname}}}_mt = {
|
||||
__index = {{{classname}}};
|
||||
}
|
||||
|
||||
local function new_{{classname}}(host, basePath, schemes)
|
||||
local function new_{{classname}}(authority, basePath, schemes)
|
||||
local schemes_map = {}
|
||||
for _,v in ipairs(schemes) do
|
||||
schemes_map[v] = v
|
||||
end
|
||||
local default_scheme = schemes_map.https or schemes_map.http
|
||||
local host, port = http_util.split_authority(authority, default_scheme)
|
||||
return setmetatable({
|
||||
host = host;
|
||||
port = port;
|
||||
basePath = basePath or "{{{basePath}}}";
|
||||
schemes = schemes_map;
|
||||
default_scheme = default_scheme;
|
||||
@@ -41,6 +43,7 @@ function {{classname}}:{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}},
|
||||
local req = http_request.new_from_uri({
|
||||
scheme = self.default_scheme;
|
||||
host = self.host;
|
||||
port = self.port;
|
||||
path = string.format("%s{{{vendorExtensions.x-codegen-path}}}{{#queryParams}}{{#-first}}?{{/-first}}{{{baseName}}}=%s{{^-last}}&{{/-last}}{{/queryParams}}",
|
||||
self.basePath{{#pathParams}}, {{paramName}}{{/pathParams}}{{#queryParams}}, http_util.encodeURIComponent({{paramName}}){{/queryParams}});
|
||||
})
|
||||
@@ -159,4 +162,3 @@ return {
|
||||
new = new_{{classname}};
|
||||
}
|
||||
{{/operations}}
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
3.3.3-SNAPSHOT
|
||||
3.3.4
|
||||
@@ -25,14 +25,16 @@ local pet_api_mt = {
|
||||
__index = pet_api;
|
||||
}
|
||||
|
||||
local function new_pet_api(host, basePath, schemes)
|
||||
local function new_pet_api(authority, basePath, schemes)
|
||||
local schemes_map = {}
|
||||
for _,v in ipairs(schemes) do
|
||||
schemes_map[v] = v
|
||||
end
|
||||
local default_scheme = schemes_map.https or schemes_map.http
|
||||
local host, port = http_util.split_authority(authority, default_scheme)
|
||||
return setmetatable({
|
||||
host = host;
|
||||
port = port;
|
||||
basePath = basePath or "http://petstore.swagger.io/v2";
|
||||
schemes = schemes_map;
|
||||
default_scheme = default_scheme;
|
||||
@@ -47,6 +49,7 @@ function pet_api:add_pet(pet)
|
||||
local req = http_request.new_from_uri({
|
||||
scheme = self.default_scheme;
|
||||
host = self.host;
|
||||
port = self.port;
|
||||
path = string.format("%s/pet",
|
||||
self.basePath);
|
||||
})
|
||||
@@ -87,6 +90,7 @@ function pet_api:delete_pet(pet_id, api_key)
|
||||
local req = http_request.new_from_uri({
|
||||
scheme = self.default_scheme;
|
||||
host = self.host;
|
||||
port = self.port;
|
||||
path = string.format("%s/pet/%s",
|
||||
self.basePath, pet_id);
|
||||
})
|
||||
@@ -124,6 +128,7 @@ function pet_api:find_pets_by_status(status)
|
||||
local req = http_request.new_from_uri({
|
||||
scheme = self.default_scheme;
|
||||
host = self.host;
|
||||
port = self.port;
|
||||
path = string.format("%s/pet/findByStatus?status=%s",
|
||||
self.basePath, http_util.encodeURIComponent(status));
|
||||
})
|
||||
@@ -176,6 +181,7 @@ function pet_api:find_pets_by_tags(tags)
|
||||
local req = http_request.new_from_uri({
|
||||
scheme = self.default_scheme;
|
||||
host = self.host;
|
||||
port = self.port;
|
||||
path = string.format("%s/pet/findByTags?tags=%s",
|
||||
self.basePath, http_util.encodeURIComponent(tags));
|
||||
})
|
||||
@@ -228,6 +234,7 @@ function pet_api:get_pet_by_id(pet_id)
|
||||
local req = http_request.new_from_uri({
|
||||
scheme = self.default_scheme;
|
||||
host = self.host;
|
||||
port = self.port;
|
||||
path = string.format("%s/pet/%s",
|
||||
self.basePath, pet_id);
|
||||
})
|
||||
@@ -277,6 +284,7 @@ function pet_api:update_pet(pet)
|
||||
local req = http_request.new_from_uri({
|
||||
scheme = self.default_scheme;
|
||||
host = self.host;
|
||||
port = self.port;
|
||||
path = string.format("%s/pet",
|
||||
self.basePath);
|
||||
})
|
||||
@@ -317,6 +325,7 @@ function pet_api:update_pet_with_form(pet_id, name, status)
|
||||
local req = http_request.new_from_uri({
|
||||
scheme = self.default_scheme;
|
||||
host = self.host;
|
||||
port = self.port;
|
||||
path = string.format("%s/pet/%s",
|
||||
self.basePath, pet_id);
|
||||
})
|
||||
@@ -359,6 +368,7 @@ function pet_api:upload_file(pet_id, additional_metadata, file)
|
||||
local req = http_request.new_from_uri({
|
||||
scheme = self.default_scheme;
|
||||
host = self.host;
|
||||
port = self.port;
|
||||
path = string.format("%s/pet/%s/uploadImage",
|
||||
self.basePath, pet_id);
|
||||
})
|
||||
@@ -415,4 +425,3 @@ end
|
||||
return {
|
||||
new = new_pet_api;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,14 +24,16 @@ local store_api_mt = {
|
||||
__index = store_api;
|
||||
}
|
||||
|
||||
local function new_store_api(host, basePath, schemes)
|
||||
local function new_store_api(authority, basePath, schemes)
|
||||
local schemes_map = {}
|
||||
for _,v in ipairs(schemes) do
|
||||
schemes_map[v] = v
|
||||
end
|
||||
local default_scheme = schemes_map.https or schemes_map.http
|
||||
local host, port = http_util.split_authority(authority, default_scheme)
|
||||
return setmetatable({
|
||||
host = host;
|
||||
port = port;
|
||||
basePath = basePath or "http://petstore.swagger.io/v2";
|
||||
schemes = schemes_map;
|
||||
default_scheme = default_scheme;
|
||||
@@ -46,6 +48,7 @@ function store_api:delete_order(order_id)
|
||||
local req = http_request.new_from_uri({
|
||||
scheme = self.default_scheme;
|
||||
host = self.host;
|
||||
port = self.port;
|
||||
path = string.format("%s/store/order/%s",
|
||||
self.basePath, order_id);
|
||||
})
|
||||
@@ -76,6 +79,7 @@ function store_api:get_inventory()
|
||||
local req = http_request.new_from_uri({
|
||||
scheme = self.default_scheme;
|
||||
host = self.host;
|
||||
port = self.port;
|
||||
path = string.format("%s/store/inventory",
|
||||
self.basePath);
|
||||
})
|
||||
@@ -125,6 +129,7 @@ function store_api:get_order_by_id(order_id)
|
||||
local req = http_request.new_from_uri({
|
||||
scheme = self.default_scheme;
|
||||
host = self.host;
|
||||
port = self.port;
|
||||
path = string.format("%s/store/order/%s",
|
||||
self.basePath, order_id);
|
||||
})
|
||||
@@ -170,6 +175,7 @@ function store_api:place_order(order)
|
||||
local req = http_request.new_from_uri({
|
||||
scheme = self.default_scheme;
|
||||
host = self.host;
|
||||
port = self.port;
|
||||
path = string.format("%s/store/order",
|
||||
self.basePath);
|
||||
})
|
||||
@@ -216,4 +222,3 @@ end
|
||||
return {
|
||||
new = new_store_api;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,14 +24,16 @@ local user_api_mt = {
|
||||
__index = user_api;
|
||||
}
|
||||
|
||||
local function new_user_api(host, basePath, schemes)
|
||||
local function new_user_api(authority, basePath, schemes)
|
||||
local schemes_map = {}
|
||||
for _,v in ipairs(schemes) do
|
||||
schemes_map[v] = v
|
||||
end
|
||||
local default_scheme = schemes_map.https or schemes_map.http
|
||||
local host, port = http_util.split_authority(authority, default_scheme)
|
||||
return setmetatable({
|
||||
host = host;
|
||||
port = port;
|
||||
basePath = basePath or "http://petstore.swagger.io/v2";
|
||||
schemes = schemes_map;
|
||||
default_scheme = default_scheme;
|
||||
@@ -46,6 +48,7 @@ function user_api:create_user(user)
|
||||
local req = http_request.new_from_uri({
|
||||
scheme = self.default_scheme;
|
||||
host = self.host;
|
||||
port = self.port;
|
||||
path = string.format("%s/user",
|
||||
self.basePath);
|
||||
})
|
||||
@@ -78,6 +81,7 @@ function user_api:create_users_with_array_input(user)
|
||||
local req = http_request.new_from_uri({
|
||||
scheme = self.default_scheme;
|
||||
host = self.host;
|
||||
port = self.port;
|
||||
path = string.format("%s/user/createWithArray",
|
||||
self.basePath);
|
||||
})
|
||||
@@ -110,6 +114,7 @@ function user_api:create_users_with_list_input(user)
|
||||
local req = http_request.new_from_uri({
|
||||
scheme = self.default_scheme;
|
||||
host = self.host;
|
||||
port = self.port;
|
||||
path = string.format("%s/user/createWithList",
|
||||
self.basePath);
|
||||
})
|
||||
@@ -142,6 +147,7 @@ function user_api:delete_user(username)
|
||||
local req = http_request.new_from_uri({
|
||||
scheme = self.default_scheme;
|
||||
host = self.host;
|
||||
port = self.port;
|
||||
path = string.format("%s/user/%s",
|
||||
self.basePath, username);
|
||||
})
|
||||
@@ -172,6 +178,7 @@ function user_api:get_user_by_name(username)
|
||||
local req = http_request.new_from_uri({
|
||||
scheme = self.default_scheme;
|
||||
host = self.host;
|
||||
port = self.port;
|
||||
path = string.format("%s/user/%s",
|
||||
self.basePath, username);
|
||||
})
|
||||
@@ -217,6 +224,7 @@ function user_api:login_user(username, password)
|
||||
local req = http_request.new_from_uri({
|
||||
scheme = self.default_scheme;
|
||||
host = self.host;
|
||||
port = self.port;
|
||||
path = string.format("%s/user/login?username=%s&password=%s",
|
||||
self.basePath, http_util.encodeURIComponent(username), http_util.encodeURIComponent(password));
|
||||
})
|
||||
@@ -262,6 +270,7 @@ function user_api:logout_user()
|
||||
local req = http_request.new_from_uri({
|
||||
scheme = self.default_scheme;
|
||||
host = self.host;
|
||||
port = self.port;
|
||||
path = string.format("%s/user/logout",
|
||||
self.basePath);
|
||||
})
|
||||
@@ -292,6 +301,7 @@ function user_api:update_user(username, user)
|
||||
local req = http_request.new_from_uri({
|
||||
scheme = self.default_scheme;
|
||||
host = self.host;
|
||||
port = self.port;
|
||||
path = string.format("%s/user/%s",
|
||||
self.basePath, username);
|
||||
})
|
||||
@@ -323,4 +333,3 @@ end
|
||||
return {
|
||||
new = new_user_api;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user