Minor improvements to the Lua client generator (#6219)

* minor improvement to lua client gen

* add new files
This commit is contained in:
William Cheng 2020-05-09 14:26:54 +08:00 committed by GitHub
parent d6d241bdab
commit d5304055ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 214 additions and 51 deletions

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} -Xmx1024M -DloggerPath=conf/log4j.properties $@" export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties $@"
ags="generate -t modules/openapi-generator/src/main/resources/lua -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g lua -o samples/client/petstore/lua --additional-properties packageName=petstore $@" ags="generate -t modules/openapi-generator/src/main/resources/lua -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g lua -o samples/client/petstore/lua --additional-properties packageName=petstore $@"
java $JAVA_OPTS -jar $executable $ags java $JAVA_OPTS -jar $executable $ags

View File

@ -1,32 +0,0 @@
#!/bin/sh
SCRIPT="$0"
echo "# START SCRIPT: $SCRIPT"
while [ -h "$SCRIPT" ] ; do
ls=`ls -ld "$SCRIPT"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
SCRIPT="$link"
else
SCRIPT=`dirname "$SCRIPT"`/"$link"
fi
done
if [ ! -d "${APP_DIR}" ]; then
APP_DIR=`dirname "$SCRIPT"`/..
APP_DIR=`cd "${APP_DIR}"; pwd`
fi
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
if [ ! -f "$executable" ]
then
mvn clean package
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/lua -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g lua -o samples/client/petstore/lua --additional-properties packageName=petstore $@"
java $JAVA_OPTS -jar $executable $ags

View File

@ -88,6 +88,7 @@ declare -a samples=(
"${root}/bin/scala-akka-petstore.sh" "${root}/bin/scala-akka-petstore.sh"
"${root}/bin/openapi3/scala-akka-petstore.sh" "${root}/bin/openapi3/scala-akka-petstore.sh"
"${root}/bin/openapi3/scala-sttp-petstore.sh" "${root}/bin/openapi3/scala-sttp-petstore.sh"
"${root}/bin/lua-petstore.sh"
) )
# Some special case generators may expect to be run as a stanalone process (e.g. modifying classpath) # Some special case generators may expect to be run as a stanalone process (e.g. modifying classpath)

View File

@ -5,6 +5,6 @@ If Not Exist %executable% (
) )
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -DloggerPath=conf/log4j.properties REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -DloggerPath=conf/log4j.properties
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g lua -o samples\client\petstore\lua set ags=generate -i modules\openapi-generator\src\test\resources\3_0\petstore.yaml -g lua -o samples\client\petstore\lua
java %JAVA_OPTS% -jar %executable% %ags% java %JAVA_OPTS% -jar %executable% %ags%

View File

@ -40,7 +40,7 @@ The following generators are available:
* [jmeter](generators/jmeter.md) * [jmeter](generators/jmeter.md)
* [k6 (beta)](generators/k6.md) * [k6 (beta)](generators/k6.md)
* [kotlin](generators/kotlin.md) * [kotlin](generators/kotlin.md)
* [lua](generators/lua.md) * [lua (beta)](generators/lua.md)
* [nim (beta)](generators/nim.md) * [nim (beta)](generators/nim.md)
* [objc](generators/objc.md) * [objc](generators/objc.md)
* [ocaml](generators/ocaml.md) * [ocaml](generators/ocaml.md)

View File

@ -21,6 +21,8 @@ import io.swagger.v3.oas.models.media.ArraySchema;
import io.swagger.v3.oas.models.media.Schema; import io.swagger.v3.oas.models.media.Schema;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.openapitools.codegen.*; import org.openapitools.codegen.*;
import org.openapitools.codegen.meta.GeneratorMetadata;
import org.openapitools.codegen.meta.Stability;
import org.openapitools.codegen.meta.features.*; import org.openapitools.codegen.meta.features.*;
import org.openapitools.codegen.utils.ModelUtils; import org.openapitools.codegen.utils.ModelUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -79,6 +81,10 @@ public class LuaClientCodegen extends DefaultCodegen implements CodegenConfig {
) )
); );
generatorMetadata = GeneratorMetadata.newBuilder(generatorMetadata)
.stability(Stability.BETA)
.build();
outputFolder = "generated-code/lua"; outputFolder = "generated-code/lua";
modelTemplateFiles.put("model.mustache", ".lua"); modelTemplateFiles.put("model.mustache", ".lua");
apiTemplateFiles.put("api.mustache", ".lua"); apiTemplateFiles.put("api.mustache", ".lua");

View File

@ -1 +1 @@
3.3.4 5.0.0-SNAPSHOT

View File

@ -1,11 +1,17 @@
#!/bin/sh #!/bin/sh
# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ # ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
# #
# Usage example: /bin/sh ./git_push.sh wing328 openapi-pestore-perl "minor update" # Usage example: /bin/sh ./git_push.sh wing328 openapi-pestore-perl "minor update" "gitlab.com"
git_user_id=$1 git_user_id=$1
git_repo_id=$2 git_repo_id=$2
release_note=$3 release_note=$3
git_host=$4
if [ "$git_host" = "" ]; then
git_host="github.com"
echo "[INFO] No command line input provided. Set \$git_host to $git_host"
fi
if [ "$git_user_id" = "" ]; then if [ "$git_user_id" = "" ]; then
git_user_id="GIT_USER_ID" git_user_id="GIT_USER_ID"
@ -37,9 +43,9 @@ if [ "$git_remote" = "" ]; then # git remote not defined
if [ "$GIT_TOKEN" = "" ]; then if [ "$GIT_TOKEN" = "" ]; then
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment." echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment."
git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git
else else
git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git git remote add origin https://${git_user_id}:${GIT_TOKEN}@${git_host}/${git_user_id}/${git_repo_id}.git
fi fi
fi fi
@ -47,6 +53,6 @@ fi
git pull origin master git pull origin master
# Pushes (Forces) the changes in the local repository up to the remote repository # Pushes (Forces) the changes in the local repository up to the remote repository
echo "Git pushing to https://github.com/${git_user_id}/${git_repo_id}.git" echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git"
git push origin master 2>&1 | grep -v 'To https' git push origin master 2>&1 | grep -v 'To https'

View File

@ -28,6 +28,8 @@ build = {
["petstore.api.user_api"] = "petstore/api/user_api.lua"; ["petstore.api.user_api"] = "petstore/api/user_api.lua";
["petstore.model.api_response"] = "petstore/model/api_response.lua"; ["petstore.model.api_response"] = "petstore/model/api_response.lua";
["petstore.model.category"] = "petstore/model/category.lua"; ["petstore.model.category"] = "petstore/model/category.lua";
["petstore.model.inline_object"] = "petstore/model/inline_object.lua";
["petstore.model.inline_object_1"] = "petstore/model/inline_object_1.lua";
["petstore.model.order"] = "petstore/model/order.lua"; ["petstore.model.order"] = "petstore/model/order.lua";
["petstore.model.pet"] = "petstore/model/pet.lua"; ["petstore.model.pet"] = "petstore/model/pet.lua";
["petstore.model.tag"] = "petstore/model/tag.lua"; ["petstore.model.tag"] = "petstore/model/tag.lua";

View File

@ -3,7 +3,7 @@
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
OpenAPI spec version: 1.0.0 The version of the OpenAPI document: 1.0.0
Generated by: https://openapi-generator.tech Generated by: https://openapi-generator.tech
]] ]]
@ -60,6 +60,10 @@ function pet_api:add_pet(pet)
--local var_content_type = { "application/json", "application/xml" } --local var_content_type = { "application/json", "application/xml" }
req.headers:upsert("accept", "application/json") req.headers:upsert("accept", "application/json")
-- TODO: create a function to select proper content-type
--local var_accept = { "application/xml", "application/json" }
req.headers:upsert("content-type", "application/xml")
req:set_body(dkjson.encode(pet)) req:set_body(dkjson.encode(pet))
-- oAuth -- oAuth
@ -74,7 +78,18 @@ function pet_api:add_pet(pet)
end end
local http_status = headers:get(":status") local http_status = headers:get(":status")
if http_status:sub(1,1) == "2" then if http_status:sub(1,1) == "2" then
return nil, headers local body, err, errno2 = stream:get_body_as_string()
-- exception when getting the HTTP body
if not body then
return nil, err, errno2
end
stream:shutdown()
local result, _, err3 = dkjson.decode(body)
-- exception when decoding the HTTP body
if result == nil then
return nil, err3
end
return petstore_pet.cast(result), headers
else else
local body, err, errno2 = stream:get_body_as_string() local body, err, errno2 = stream:get_body_as_string()
if not body then if not body then
@ -295,6 +310,10 @@ function pet_api:update_pet(pet)
--local var_content_type = { "application/json", "application/xml" } --local var_content_type = { "application/json", "application/xml" }
req.headers:upsert("accept", "application/json") req.headers:upsert("accept", "application/json")
-- TODO: create a function to select proper content-type
--local var_accept = { "application/xml", "application/json" }
req.headers:upsert("content-type", "application/xml")
req:set_body(dkjson.encode(pet)) req:set_body(dkjson.encode(pet))
-- oAuth -- oAuth
@ -309,7 +328,18 @@ function pet_api:update_pet(pet)
end end
local http_status = headers:get(":status") local http_status = headers:get(":status")
if http_status:sub(1,1) == "2" then if http_status:sub(1,1) == "2" then
return nil, headers local body, err, errno2 = stream:get_body_as_string()
-- exception when getting the HTTP body
if not body then
return nil, err, errno2
end
stream:shutdown()
local result, _, err3 = dkjson.decode(body)
-- exception when decoding the HTTP body
if result == nil then
return nil, err3
end
return petstore_pet.cast(result), headers
else else
local body, err, errno2 = stream:get_body_as_string() local body, err, errno2 = stream:get_body_as_string()
if not body then if not body then

View File

@ -3,7 +3,7 @@
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
OpenAPI spec version: 1.0.0 The version of the OpenAPI document: 1.0.0
Generated by: https://openapi-generator.tech Generated by: https://openapi-generator.tech
]] ]]
@ -182,6 +182,10 @@ function store_api:place_order(order)
-- set HTTP verb -- set HTTP verb
req.headers:upsert(":method", "POST") req.headers:upsert(":method", "POST")
-- TODO: create a function to select proper accept
--local var_content_type = { "application/json" }
req.headers:upsert("accept", "application/json")
-- TODO: create a function to select proper content-type -- TODO: create a function to select proper content-type
--local var_accept = { "application/xml", "application/json" } --local var_accept = { "application/xml", "application/json" }
req.headers:upsert("content-type", "application/xml") req.headers:upsert("content-type", "application/xml")

View File

@ -3,7 +3,7 @@
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
OpenAPI spec version: 1.0.0 The version of the OpenAPI document: 1.0.0
Generated by: https://openapi-generator.tech Generated by: https://openapi-generator.tech
]] ]]
@ -55,6 +55,10 @@ function user_api:create_user(user)
-- set HTTP verb -- set HTTP verb
req.headers:upsert(":method", "POST") req.headers:upsert(":method", "POST")
-- TODO: create a function to select proper accept
--local var_content_type = { "application/json" }
req.headers:upsert("accept", "application/json")
req:set_body(dkjson.encode(user)) req:set_body(dkjson.encode(user))
@ -88,6 +92,10 @@ function user_api:create_users_with_array_input(user)
-- set HTTP verb -- set HTTP verb
req.headers:upsert(":method", "POST") req.headers:upsert(":method", "POST")
-- TODO: create a function to select proper accept
--local var_content_type = { "application/json" }
req.headers:upsert("accept", "application/json")
req:set_body(dkjson.encode(user)) req:set_body(dkjson.encode(user))
@ -121,6 +129,10 @@ function user_api:create_users_with_list_input(user)
-- set HTTP verb -- set HTTP verb
req.headers:upsert(":method", "POST") req.headers:upsert(":method", "POST")
-- TODO: create a function to select proper accept
--local var_content_type = { "application/json" }
req.headers:upsert("accept", "application/json")
req:set_body(dkjson.encode(user)) req:set_body(dkjson.encode(user))
@ -308,6 +320,10 @@ function user_api:update_user(username, user)
-- set HTTP verb -- set HTTP verb
req.headers:upsert(":method", "PUT") req.headers:upsert(":method", "PUT")
-- TODO: create a function to select proper accept
--local var_content_type = { "application/json" }
req.headers:upsert("accept", "application/json")
req:set_body(dkjson.encode(user)) req:set_body(dkjson.encode(user))

View File

@ -3,7 +3,7 @@
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
OpenAPI spec version: 1.0.0 The version of the OpenAPI document: 1.0.0
Generated by: https://openapi-generator.tech Generated by: https://openapi-generator.tech
]] ]]

View File

@ -3,7 +3,7 @@
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
OpenAPI spec version: 1.0.0 The version of the OpenAPI document: 1.0.0
Generated by: https://openapi-generator.tech Generated by: https://openapi-generator.tech
]] ]]

View File

@ -0,0 +1,32 @@
--[[
OpenAPI Petstore
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
The version of the OpenAPI document: 1.0.0
Generated by: https://openapi-generator.tech
]]
-- inline_object class
local inline_object = {}
local inline_object_mt = {
__name = "inline_object";
__index = inline_object;
}
local function cast_inline_object(t)
return setmetatable(t, inline_object_mt)
end
local function new_inline_object(name, status)
return cast_inline_object({
["name"] = name;
["status"] = status;
})
end
return {
cast = cast_inline_object;
new = new_inline_object;
}

View File

@ -0,0 +1,32 @@
--[[
OpenAPI Petstore
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
The version of the OpenAPI document: 1.0.0
Generated by: https://openapi-generator.tech
]]
-- inline_object_1 class
local inline_object_1 = {}
local inline_object_1_mt = {
__name = "inline_object_1";
__index = inline_object_1;
}
local function cast_inline_object_1(t)
return setmetatable(t, inline_object_1_mt)
end
local function new_inline_object_1(additional_metadata, file)
return cast_inline_object_1({
["additionalMetadata"] = additional_metadata;
["file"] = file;
})
end
return {
cast = cast_inline_object_1;
new = new_inline_object_1;
}

View File

@ -3,7 +3,7 @@
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
OpenAPI spec version: 1.0.0 The version of the OpenAPI document: 1.0.0
Generated by: https://openapi-generator.tech Generated by: https://openapi-generator.tech
]] ]]

View File

@ -3,7 +3,7 @@
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
OpenAPI spec version: 1.0.0 The version of the OpenAPI document: 1.0.0
Generated by: https://openapi-generator.tech Generated by: https://openapi-generator.tech
]] ]]

View File

@ -3,7 +3,7 @@
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
OpenAPI spec version: 1.0.0 The version of the OpenAPI document: 1.0.0
Generated by: https://openapi-generator.tech Generated by: https://openapi-generator.tech
]] ]]

View File

@ -3,7 +3,7 @@
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
OpenAPI spec version: 1.0.0 The version of the OpenAPI document: 1.0.0
Generated by: https://openapi-generator.tech Generated by: https://openapi-generator.tech
]] ]]

View File

@ -0,0 +1,33 @@
--[[
OpenAPI Petstore
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
The version of the OpenAPI document: 1.0.0
Generated by: https://openapi-generator.tech
]]
--[[
Unit tests for petstore.model.inline_object_1
Automatically generated by openapi-generator (https://openapi-generator.tech)
Please update as you see appropriate
]]
describe("inline_object_1", function()
local petstore_inline_object_1 = require "petstore.model.inline_object_1"
-- unit tests for the property 'additional_metadata'
describe("property additional_metadata test", function()
it("should work", function()
-- TODO assertion here: http://olivinelabs.com/busted/#asserts
end)
end)
-- unit tests for the property 'file'
describe("property file test", function()
it("should work", function()
-- TODO assertion here: http://olivinelabs.com/busted/#asserts
end)
end)
end)

View File

@ -0,0 +1,33 @@
--[[
OpenAPI Petstore
This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
The version of the OpenAPI document: 1.0.0
Generated by: https://openapi-generator.tech
]]
--[[
Unit tests for petstore.model.inline_object
Automatically generated by openapi-generator (https://openapi-generator.tech)
Please update as you see appropriate
]]
describe("inline_object", function()
local petstore_inline_object = require "petstore.model.inline_object"
-- unit tests for the property 'name'
describe("property name test", function()
it("should work", function()
-- TODO assertion here: http://olivinelabs.com/busted/#asserts
end)
end)
-- unit tests for the property 'status'
describe("property status test", function()
it("should work", function()
-- TODO assertion here: http://olivinelabs.com/busted/#asserts
end)
end)
end)