From df10c725ab442a4ac2239b670695fb2eb4429222 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 25 Jan 2018 22:01:04 +0800 Subject: [PATCH] Add lua test script, minor fix to Lua API files (#7490) * add lua test script, minor fix to api files * fix model import, avoid null header issue * add space before equal sign --- bin/lua-petstore.sh | 4 +- .../io/swagger/codegen/DefaultGenerator.java | 4 +- .../codegen/languages/LuaClientCodegen.java | 16 ++++- .../src/main/resources/lua/api.mustache | 32 ++++++---- .../java/okhttp-gson/.swagger-codegen/VERSION | 2 +- .../gen/io/swagger/client/BuildConfig.java | 8 --- .../main/gen/io/swagger/client/Manifest.java | 7 --- .../src/main/gen/io/swagger/client/R.java | 7 --- .../java/io/swagger/client/model/Animal.java | 3 + .../petstore/lua/.swagger-codegen/VERSION | 2 +- samples/client/petstore/lua/git_push.sh | 2 +- .../lua/{ => petstore}/api/pet_api.lua | 59 +++++++++++++------ .../lua/{ => petstore}/api/store_api.lua | 22 ++++--- .../lua/{ => petstore}/api/user_api.lua | 16 +++-- .../lua/{ => petstore}/model/api_response.lua | 0 .../lua/{ => petstore}/model/category.lua | 0 .../lua/{ => petstore}/model/order.lua | 0 .../petstore/lua/{ => petstore}/model/pet.lua | 0 .../petstore/lua/{ => petstore}/model/tag.lua | 0 .../lua/{ => petstore}/model/user.lua | 0 samples/client/petstore/lua/test.lua | 12 ++++ 21 files changed, 123 insertions(+), 73 deletions(-) delete mode 100644 samples/client/petstore/java/okhttp-gson/src/main/gen/io/swagger/client/BuildConfig.java delete mode 100644 samples/client/petstore/java/okhttp-gson/src/main/gen/io/swagger/client/Manifest.java delete mode 100644 samples/client/petstore/java/okhttp-gson/src/main/gen/io/swagger/client/R.java rename samples/client/petstore/lua/{ => petstore}/api/pet_api.lua (90%) rename samples/client/petstore/lua/{ => petstore}/api/store_api.lua (94%) rename samples/client/petstore/lua/{ => petstore}/api/user_api.lua (97%) rename samples/client/petstore/lua/{ => petstore}/model/api_response.lua (100%) rename samples/client/petstore/lua/{ => petstore}/model/category.lua (100%) rename samples/client/petstore/lua/{ => petstore}/model/order.lua (100%) rename samples/client/petstore/lua/{ => petstore}/model/pet.lua (100%) rename samples/client/petstore/lua/{ => petstore}/model/tag.lua (100%) rename samples/client/petstore/lua/{ => petstore}/model/user.lua (100%) create mode 100644 samples/client/petstore/lua/test.lua diff --git a/bin/lua-petstore.sh b/bin/lua-petstore.sh index 2b8f732d14b..a3f84ebc13d 100755 --- a/bin/lua-petstore.sh +++ b/bin/lua-petstore.sh @@ -25,7 +25,7 @@ then fi # if you've executed sbt assembly previously it will use that instead. -export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate -t modules/swagger-codegen/src/main/resources/lua -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l lua -o samples/client/petstore/lua -DpackageName=petstore $@" +export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties $@" +ags="generate -t modules/swagger-codegen/src/main/resources/lua -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l lua -o samples/client/petstore/lua -DpackageName=petstore" java $JAVA_OPTS -jar $executable $ags diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java index 839af675fe1..1c249003cdd 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java @@ -977,7 +977,9 @@ public class DefaultGenerator extends AbstractGenerator implements Generator { } if (mapping != null) { im.put("import", mapping); - imports.add(im); + if (!imports.contains(im)) { // avoid duplicates + imports.add(im); + } } } diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/LuaClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/LuaClientCodegen.java index 30288b8baf1..2006e9eba76 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/LuaClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/LuaClientCodegen.java @@ -89,7 +89,8 @@ public class LuaClientCodegen extends DefaultCodegen implements CodegenConfig { typeMapping.put("date", "string"); typeMapping.put("DateTime", "string"); typeMapping.put("password", "string"); - typeMapping.put("file", "TODO_FILE_MAPPING"); + // TODO fix file mapping + typeMapping.put("file", "string"); // map binary to string as a workaround // the correct solution is to use []byte typeMapping.put("binary", "string"); @@ -181,11 +182,11 @@ public class LuaClientCodegen extends DefaultCodegen implements CodegenConfig { @Override public String apiFileFolder() { - return outputFolder + File.separator + "api" + File.separator; + return outputFolder + File.separator + packageName + File.separator + "api" + File.separator; } public String modelFileFolder() { - return outputFolder + File.separator + "model" + File.separator; + return outputFolder + File.separator + packageName + File.separator + "model" + File.separator; } @Override @@ -519,4 +520,13 @@ public class LuaClientCodegen extends DefaultCodegen implements CodegenConfig { return enumName; } } + + @Override + public String toModelImport(String name) { + if (needToImport(toModelName(name))) { + return toModelName(name); + } + + return name; + } } diff --git a/modules/swagger-codegen/src/main/resources/lua/api.mustache b/modules/swagger-codegen/src/main/resources/lua/api.mustache index 3e6f6a0b48c..dad9be40382 100644 --- a/modules/swagger-codegen/src/main/resources/lua/api.mustache +++ b/modules/swagger-codegen/src/main/resources/lua/api.mustache @@ -8,12 +8,14 @@ local dkjson = require "dkjson" local basexx = require "basexx" -- model import -local {{{packageName}}}_{{classname}} = require "{{{packageName}}}.api.{{classname}}" +{{#imports}} +local {{{packageName}}}_{{import}} = require "{{{packageName}}}.model.{{import}}" +{{/imports}} -local {{{packageName}}}= {} -local {{{packageName}}}_mt = { +local {{{classname}}} = {} +local {{{classname}}}_mt = { __name = "{{{classname}}}"; - __index = {{{packageName}}}; + __index = {{{classname}}}; } local function new_{{classname}}(host, basePath, schemes) @@ -31,7 +33,7 @@ local function new_{{classname}}(host, basePath, schemes) http_password = nil; api_key = {}; access_token = nil; - }, {{{packageName}}}_mt) + }, {{{classname}}}_mt) end {{#operation}} @@ -60,7 +62,9 @@ function {{classname}}:{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasProduces}} {{#headerParams}} - req.headers:upsert("{{baseName}}", {{paramName}}) + if {{paramName}} then + req.headers:upsert("{{baseName}}", {{paramName}}) + end {{/headerParams}} {{#formParams}} {{#-first}} @@ -79,7 +83,9 @@ function {{classname}}:{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{#isApiKey}} {{#isKeyInHeader}} -- api key in headers '{{keyParamName}}' - req.headers:upsert("{{{name}}}", api_key['{{{keyParamName}}}']) + if self.api_key['{{{keyParamName}}}'] then + req.headers:upsert("{{{name}}}", self.api_key['{{{keyParamName}}}']) + end {{/isKeyInHeader}} {{#isKeyInQuery}} -- TODO: api key in query '{{keyParamName}}' @@ -91,7 +97,9 @@ function {{classname}}:{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/isBasic}} {{#isOAuth}} -- oAuth - req.headers:upsert("authorization", "Bearer " .. self.access_token) + if self.access_token then + req.headers:upsert("authorization", "Bearer " .. self.access_token) + end {{/isOAuth}} {{/authMethods}} @@ -120,7 +128,7 @@ function {{classname}}:{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{^returnTypeIsPrimitive}} {{#isListContainer}} for _, ob in ipairs(result) do - cast_{{returnType}}(ob) + {{packageName}}_{{returnType}}.cast(ob) end return result, headers {{/isListContainer}} @@ -129,7 +137,7 @@ function {{classname}}:{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/isMapContainer}} {{^isMapContainer}} {{^isListContainer}} - return cast_{{returnType}}(result), headers + return {{packageName}}_{{returnType}}.cast(result), headers {{/isListContainer}} {{/isMapContainer}} {{/returnTypeIsPrimitive}} @@ -149,4 +157,8 @@ function {{classname}}:{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, end {{/operation}} +return { + new = new_{{classname}}; +} {{/operations}} + diff --git a/samples/client/petstore/java/okhttp-gson/.swagger-codegen/VERSION b/samples/client/petstore/java/okhttp-gson/.swagger-codegen/VERSION index 50794f17f1a..855ff9501eb 100644 --- a/samples/client/petstore/java/okhttp-gson/.swagger-codegen/VERSION +++ b/samples/client/petstore/java/okhttp-gson/.swagger-codegen/VERSION @@ -1 +1 @@ -2.3.1-SNAPSHOT \ No newline at end of file +2.4.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/java/okhttp-gson/src/main/gen/io/swagger/client/BuildConfig.java b/samples/client/petstore/java/okhttp-gson/src/main/gen/io/swagger/client/BuildConfig.java deleted file mode 100644 index 720765940d3..00000000000 --- a/samples/client/petstore/java/okhttp-gson/src/main/gen/io/swagger/client/BuildConfig.java +++ /dev/null @@ -1,8 +0,0 @@ -/*___Generated_by_IDEA___*/ - -package io.swagger.client; - -/* This stub is only used by the IDE. It is NOT the BuildConfig class actually packed into the APK */ -public final class BuildConfig { - public final static boolean DEBUG = Boolean.parseBoolean(null); -} \ No newline at end of file diff --git a/samples/client/petstore/java/okhttp-gson/src/main/gen/io/swagger/client/Manifest.java b/samples/client/petstore/java/okhttp-gson/src/main/gen/io/swagger/client/Manifest.java deleted file mode 100644 index 41e0523a208..00000000000 --- a/samples/client/petstore/java/okhttp-gson/src/main/gen/io/swagger/client/Manifest.java +++ /dev/null @@ -1,7 +0,0 @@ -/*___Generated_by_IDEA___*/ - -package io.swagger.client; - -/* This stub is only used by the IDE. It is NOT the Manifest class actually packed into the APK */ -public final class Manifest { -} \ No newline at end of file diff --git a/samples/client/petstore/java/okhttp-gson/src/main/gen/io/swagger/client/R.java b/samples/client/petstore/java/okhttp-gson/src/main/gen/io/swagger/client/R.java deleted file mode 100644 index cd0683364d5..00000000000 --- a/samples/client/petstore/java/okhttp-gson/src/main/gen/io/swagger/client/R.java +++ /dev/null @@ -1,7 +0,0 @@ -/*___Generated_by_IDEA___*/ - -package io.swagger.client; - -/* This stub is only used by the IDE. It is NOT the R class actually packed into the APK */ -public final class R { -} \ No newline at end of file diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/model/Animal.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/model/Animal.java index f4b0464382d..fbbaef5c1e4 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/model/Animal.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/model/Animal.java @@ -36,6 +36,9 @@ public class Animal { @SerializedName("color") private String color = "red"; + public Animal() { + this.className = this.getClass().getSimpleName(); + } public Animal className(String className) { this.className = className; return this; diff --git a/samples/client/petstore/lua/.swagger-codegen/VERSION b/samples/client/petstore/lua/.swagger-codegen/VERSION index f9f7450d135..855ff9501eb 100644 --- a/samples/client/petstore/lua/.swagger-codegen/VERSION +++ b/samples/client/petstore/lua/.swagger-codegen/VERSION @@ -1 +1 @@ -2.3.0-SNAPSHOT \ No newline at end of file +2.4.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/lua/git_push.sh b/samples/client/petstore/lua/git_push.sh index ed374619b13..ae01b182ae9 100644 --- a/samples/client/petstore/lua/git_push.sh +++ b/samples/client/petstore/lua/git_push.sh @@ -36,7 +36,7 @@ git_remote=`git remote` if [ "$git_remote" = "" ]; then # git remote not defined if [ "$GIT_TOKEN" = "" ]; then - echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git crediential 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 else git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git diff --git a/samples/client/petstore/lua/api/pet_api.lua b/samples/client/petstore/lua/petstore/api/pet_api.lua similarity index 90% rename from samples/client/petstore/lua/api/pet_api.lua rename to samples/client/petstore/lua/petstore/api/pet_api.lua index 3bc6b8e1c9a..77157811f21 100644 --- a/samples/client/petstore/lua/api/pet_api.lua +++ b/samples/client/petstore/lua/petstore/api/pet_api.lua @@ -16,12 +16,13 @@ local dkjson = require "dkjson" local basexx = require "basexx" -- model import -local petstore_pet_api = require "petstore.api.pet_api" +local petstore_api_response = require "petstore.model.api_response" +local petstore_pet = require "petstore.model.pet" -local petstore= {} -local petstore_mt = { +local pet_api = {} +local pet_api_mt = { __name = "pet_api"; - __index = petstore; + __index = pet_api; } local function new_pet_api(host, basePath, schemes) @@ -39,7 +40,7 @@ local function new_pet_api(host, basePath, schemes) http_password = nil; api_key = {}; access_token = nil; - }, petstore_mt) + }, pet_api_mt) end function pet_api:add_pet(body) @@ -65,7 +66,9 @@ function pet_api:add_pet(body) req:set_body(dkjson.encode(body)) -- oAuth - req.headers:upsert("authorization", "Bearer " .. self.access_token) + if self.access_token then + req.headers:upsert("authorization", "Bearer " .. self.access_token) + end -- make the HTTP call local headers, stream, errno = req:go() @@ -101,9 +104,13 @@ function pet_api:delete_pet(pet_id, api_key) --local var_accept = { "application/xml", "application/json" } req.headers:upsert("content-type", "application/xml") - req.headers:upsert("api_key", api_key) + if api_key then + req.headers:upsert("api_key", api_key) + end -- oAuth - req.headers:upsert("authorization", "Bearer " .. self.access_token) + if self.access_token then + req.headers:upsert("authorization", "Bearer " .. self.access_token) + end -- make the HTTP call local headers, stream, errno = req:go() @@ -140,7 +147,9 @@ function pet_api:find_pets_by_status(status) req.headers:upsert("content-type", "application/xml") -- oAuth - req.headers:upsert("authorization", "Bearer " .. self.access_token) + if self.access_token then + req.headers:upsert("authorization", "Bearer " .. self.access_token) + end -- make the HTTP call local headers, stream, errno = req:go() @@ -161,7 +170,7 @@ function pet_api:find_pets_by_status(status) return nil, err3 end for _, ob in ipairs(result) do - cast_pet(ob) + petstore_pet.cast(ob) end return result, headers else @@ -191,7 +200,9 @@ function pet_api:find_pets_by_tags(tags) req.headers:upsert("content-type", "application/xml") -- oAuth - req.headers:upsert("authorization", "Bearer " .. self.access_token) + if self.access_token then + req.headers:upsert("authorization", "Bearer " .. self.access_token) + end -- make the HTTP call local headers, stream, errno = req:go() @@ -212,7 +223,7 @@ function pet_api:find_pets_by_tags(tags) return nil, err3 end for _, ob in ipairs(result) do - cast_pet(ob) + petstore_pet.cast(ob) end return result, headers else @@ -242,7 +253,9 @@ function pet_api:get_pet_by_id(pet_id) req.headers:upsert("content-type", "application/xml") -- api key in headers 'api_key' - req.headers:upsert("api_key", api_key['api_key']) + if self.api_key['api_key'] then + req.headers:upsert("api_key", self.api_key['api_key']) + end -- make the HTTP call local headers, stream, errno = req:go() @@ -262,7 +275,7 @@ function pet_api:get_pet_by_id(pet_id) if result == nil then return nil, err3 end - return cast_pet(result), headers + return petstore_pet.cast(result), headers else local body, err, errno2 = stream:get_body_as_string() if not body then @@ -297,7 +310,9 @@ function pet_api:update_pet(body) req:set_body(dkjson.encode(body)) -- oAuth - req.headers:upsert("authorization", "Bearer " .. self.access_token) + if self.access_token then + req.headers:upsert("authorization", "Bearer " .. self.access_token) + end -- make the HTTP call local headers, stream, errno = req:go() @@ -343,7 +358,9 @@ function pet_api:update_pet_with_form(pet_id, name, status) ["status"] = status; })) -- oAuth - req.headers:upsert("authorization", "Bearer " .. self.access_token) + if self.access_token then + req.headers:upsert("authorization", "Bearer " .. self.access_token) + end -- make the HTTP call local headers, stream, errno = req:go() @@ -389,7 +406,9 @@ function pet_api:upload_file(pet_id, additional_metadata, file) ["file"] = file; })) -- oAuth - req.headers:upsert("authorization", "Bearer " .. self.access_token) + if self.access_token then + req.headers:upsert("authorization", "Bearer " .. self.access_token) + end -- make the HTTP call local headers, stream, errno = req:go() @@ -409,7 +428,7 @@ function pet_api:upload_file(pet_id, additional_metadata, file) if result == nil then return nil, err3 end - return cast_api_response(result), headers + return petstore_api_response.cast(result), headers else local body, err, errno2 = stream:get_body_as_string() if not body then @@ -421,3 +440,7 @@ function pet_api:upload_file(pet_id, additional_metadata, file) end end +return { + new = new_pet_api; +} + diff --git a/samples/client/petstore/lua/api/store_api.lua b/samples/client/petstore/lua/petstore/api/store_api.lua similarity index 94% rename from samples/client/petstore/lua/api/store_api.lua rename to samples/client/petstore/lua/petstore/api/store_api.lua index fad9f8de747..ac17bacacad 100644 --- a/samples/client/petstore/lua/api/store_api.lua +++ b/samples/client/petstore/lua/petstore/api/store_api.lua @@ -16,12 +16,12 @@ local dkjson = require "dkjson" local basexx = require "basexx" -- model import -local petstore_store_api = require "petstore.api.store_api" +local petstore_order = require "petstore.model.order" -local petstore= {} -local petstore_mt = { +local store_api = {} +local store_api_mt = { __name = "store_api"; - __index = petstore; + __index = store_api; } local function new_store_api(host, basePath, schemes) @@ -39,7 +39,7 @@ local function new_store_api(host, basePath, schemes) http_password = nil; api_key = {}; access_token = nil; - }, petstore_mt) + }, store_api_mt) end function store_api:delete_order(order_id) @@ -93,7 +93,9 @@ function store_api:get_inventory() req.headers:upsert("content-type", "application/json") -- api key in headers 'api_key' - req.headers:upsert("api_key", api_key['api_key']) + if self.api_key['api_key'] then + req.headers:upsert("api_key", self.api_key['api_key']) + end -- make the HTTP call local headers, stream, errno = req:go() @@ -159,7 +161,7 @@ function store_api:get_order_by_id(order_id) if result == nil then return nil, err3 end - return cast_order(result), headers + return petstore_order.cast(result), headers else local body, err, errno2 = stream:get_body_as_string() if not body then @@ -207,7 +209,7 @@ function store_api:place_order(body) if result == nil then return nil, err3 end - return cast_order(result), headers + return petstore_order.cast(result), headers else local body, err, errno2 = stream:get_body_as_string() if not body then @@ -219,3 +221,7 @@ function store_api:place_order(body) end end +return { + new = new_store_api; +} + diff --git a/samples/client/petstore/lua/api/user_api.lua b/samples/client/petstore/lua/petstore/api/user_api.lua similarity index 97% rename from samples/client/petstore/lua/api/user_api.lua rename to samples/client/petstore/lua/petstore/api/user_api.lua index d48e7e46604..78c13f6972e 100644 --- a/samples/client/petstore/lua/api/user_api.lua +++ b/samples/client/petstore/lua/petstore/api/user_api.lua @@ -16,12 +16,12 @@ local dkjson = require "dkjson" local basexx = require "basexx" -- model import -local petstore_user_api = require "petstore.api.user_api" +local petstore_user = require "petstore.model.user" -local petstore= {} -local petstore_mt = { +local user_api = {} +local user_api_mt = { __name = "user_api"; - __index = petstore; + __index = user_api; } local function new_user_api(host, basePath, schemes) @@ -39,7 +39,7 @@ local function new_user_api(host, basePath, schemes) http_password = nil; api_key = {}; access_token = nil; - }, petstore_mt) + }, user_api_mt) end function user_api:create_user(body) @@ -222,7 +222,7 @@ function user_api:get_user_by_name(username) if result == nil then return nil, err3 end - return cast_user(result), headers + return petstore_user.cast(result), headers else local body, err, errno2 = stream:get_body_as_string() if not body then @@ -352,3 +352,7 @@ function user_api:update_user(username, body) end end +return { + new = new_user_api; +} + diff --git a/samples/client/petstore/lua/model/api_response.lua b/samples/client/petstore/lua/petstore/model/api_response.lua similarity index 100% rename from samples/client/petstore/lua/model/api_response.lua rename to samples/client/petstore/lua/petstore/model/api_response.lua diff --git a/samples/client/petstore/lua/model/category.lua b/samples/client/petstore/lua/petstore/model/category.lua similarity index 100% rename from samples/client/petstore/lua/model/category.lua rename to samples/client/petstore/lua/petstore/model/category.lua diff --git a/samples/client/petstore/lua/model/order.lua b/samples/client/petstore/lua/petstore/model/order.lua similarity index 100% rename from samples/client/petstore/lua/model/order.lua rename to samples/client/petstore/lua/petstore/model/order.lua diff --git a/samples/client/petstore/lua/model/pet.lua b/samples/client/petstore/lua/petstore/model/pet.lua similarity index 100% rename from samples/client/petstore/lua/model/pet.lua rename to samples/client/petstore/lua/petstore/model/pet.lua diff --git a/samples/client/petstore/lua/model/tag.lua b/samples/client/petstore/lua/petstore/model/tag.lua similarity index 100% rename from samples/client/petstore/lua/model/tag.lua rename to samples/client/petstore/lua/petstore/model/tag.lua diff --git a/samples/client/petstore/lua/model/user.lua b/samples/client/petstore/lua/petstore/model/user.lua similarity index 100% rename from samples/client/petstore/lua/model/user.lua rename to samples/client/petstore/lua/petstore/model/user.lua diff --git a/samples/client/petstore/lua/test.lua b/samples/client/petstore/lua/test.lua new file mode 100644 index 00000000000..2694c082cf5 --- /dev/null +++ b/samples/client/petstore/lua/test.lua @@ -0,0 +1,12 @@ +local petstore_client = require "petstore.api.pet_api" +local petstore_client_pet = require "petstore.model.pet" + +local my_pet_http_api = petstore_client.new("petstore.swagger.io", "/v2", {"http"}) + +local my_pet = my_pet_http_api:get_pet_by_id(5) +for k,v in pairs(my_pet) do + print(k,v) +end + +local my_new_pet = petstore_client_pet.new("Mr. Barks") +my_pet_http_api:add_pet(my_new_pet)