Skip to content

Commit

Permalink
Add auto-generated Lua spec files for APIs, models (#7562)
Browse files Browse the repository at this point in the history
* add auto-generated lua spec files for api, models

* use partial header in test files
  • Loading branch information
wing328 committed Feb 2, 2018
1 parent dfbef43 commit 6c79052
Show file tree
Hide file tree
Showing 12 changed files with 595 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
public class LuaClientCodegen extends DefaultCodegen implements CodegenConfig {
static Logger LOGGER = LoggerFactory.getLogger(LuaClientCodegen.class);

protected String specFolder = "spec";
protected String packageName = "swagger-client";
protected String packageVersion = "1.0.0-1";
protected String apiDocPath = "docs/";
Expand Down Expand Up @@ -142,8 +143,8 @@ public void processOpts() {
additionalProperties.put("apiDocPath", apiDocPath);
additionalProperties.put("modelDocPath", modelDocPath);

apiTestTemplateFiles.clear(); // TODO: add api test template
modelTestTemplateFiles.clear(); // TODO: add model test template
apiTestTemplateFiles.put("api_test.mustache", ".lua");
modelTestTemplateFiles.put("model_test.mustache", ".lua");

apiDocTemplateFiles.clear(); // TODO: add api doc template
modelDocTemplateFiles.clear(); // TODO: add model doc template
Expand Down Expand Up @@ -260,6 +261,16 @@ public String toApiFilename(String name) {
return underscore(name) + "_api";
}

@Override
public String toApiTestFilename(String name) {
return toApiFilename(name) + "_spec";
}

@Override
public String toModelTestFilename(String name) {
return toModelFilename(name) + "_spec";
}

/**
* Overrides postProcessParameter to add a vendor extension "x-exportParamName".
* This is useful when paramName starts with a lowercase letter, but we need that
Expand All @@ -270,21 +281,16 @@ public String toApiFilename(String name) {
@Override
public void postProcessParameter(CodegenParameter parameter){

//// Give the base class a chance to process
//super.postProcessParameter(parameter);

//char firstChar = parameter.paramName.charAt(0);

//if (Character.isUpperCase(firstChar)) {
// // First char is already uppercase, just use paramName.
// parameter.vendorExtensions.put("x-exportParamName", parameter.paramName);
}

//}
@Override
public String apiTestFileFolder() {
return outputFolder + File.separator + apiPackage + File.separator + specFolder.replace("/", File.separator);
}

//// It's a lowercase first char, let's convert it to uppercase
//StringBuilder sb = new StringBuilder(parameter.paramName);
//sb.setCharAt(0, Character.toUpperCase(firstChar));
//parameter.vendorExtensions.put("x-exportParamName", sb.toString());
@Override
public String modelTestFileFolder() {
return outputFolder + File.separator + modelPackage + File.separator + specFolder.replace("/", File.separator);
}

@Override
Expand Down
30 changes: 30 additions & 0 deletions modules/swagger-codegen/src/main/resources/lua/api_test.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--[[
{{> partial_header}}
]]

local petstore_{{classname}} = require "{{packageName}}.api.{{{classname}}}"
{{#models}}
[[-- import all models --]]
{{#model}}
local {{packageName}}_{{{classname}}} = require "{{packageName}}.model.{{{classname}}}"
{{/model}}
{{/models}}

--[[
Unit tests for {{{packageName}}}.api.{{{classname}}}
Automatically generated by swagger-codegen (github.com/swagger-api/swagger-codegen)
Please update as you see appropriate
]]
{{#operations}}
describe("{{classname}}", function()
{{#operation}}
-- unit tests for {{operationId}}
describe("{{operationId}} test", function()
it("should work", function()
-- TODO assertion here: http://olivinelabs.com/busted/#asserts
end)
end)

{{/operation}}
end)
{{/operations}}
26 changes: 26 additions & 0 deletions modules/swagger-codegen/src/main/resources/lua/model_test.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--[[
{{> partial_header}}
]]

{{#models}}
{{#model}}
local {{packageName}}_{{{classname}}} = require "{{packageName}}.model.{{{classname}}}"

--[[
Unit tests for {{{packageName}}}.model.{{{classname}}}
Automatically generated by swagger-codegen (github.com/swagger-api/swagger-codegen)
Please update as you see appropriate
]]
describe("{{classname}}", function()
{{#vars}}
-- 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)

{{/vars}}
end)
{{/model}}
{{/models}}
42 changes: 42 additions & 0 deletions samples/client/petstore/lua/petstore/spec/api_response_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
--[[
Swagger Petstore
This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
OpenAPI spec version: 1.0.0
Contact: [email protected]
Generated by: https://github.com/swagger-api/swagger-codegen.git
Swagger Codegen version: 2.4.0-SNAPSHOT
]]

local petstore_api_response = require "petstore.model.api_response"

--[[
Unit tests for petstore.model.api_response
Automatically generated by swagger-codegen (github.com/swagger-api/swagger-codegen)
Please update as you see appropriate
]]
describe("api_response", function()
-- unit tests for the property 'code'
describe("property code test", function()
it("should work", function()
-- TODO assertion here: http://olivinelabs.com/busted/#asserts
end)
end)

-- unit tests for the property 'type'
describe("property type test", function()
it("should work", function()
-- TODO assertion here: http://olivinelabs.com/busted/#asserts
end)
end)

-- unit tests for the property 'message'
describe("property message test", function()
it("should work", function()
-- TODO assertion here: http://olivinelabs.com/busted/#asserts
end)
end)

end)
35 changes: 35 additions & 0 deletions samples/client/petstore/lua/petstore/spec/category_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
--[[
Swagger Petstore
This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
OpenAPI spec version: 1.0.0
Contact: [email protected]
Generated by: https://github.com/swagger-api/swagger-codegen.git
Swagger Codegen version: 2.4.0-SNAPSHOT
]]

local petstore_category = require "petstore.model.category"

--[[
Unit tests for petstore.model.category
Automatically generated by swagger-codegen (github.com/swagger-api/swagger-codegen)
Please update as you see appropriate
]]
describe("category", function()
-- unit tests for the property 'id'
describe("property id test", function()
it("should work", function()
-- TODO assertion here: http://olivinelabs.com/busted/#asserts
end)
end)

-- 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)

end)
63 changes: 63 additions & 0 deletions samples/client/petstore/lua/petstore/spec/order_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
--[[
Swagger Petstore
This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
OpenAPI spec version: 1.0.0
Contact: [email protected]
Generated by: https://github.com/swagger-api/swagger-codegen.git
Swagger Codegen version: 2.4.0-SNAPSHOT
]]

local petstore_order = require "petstore.model.order"

--[[
Unit tests for petstore.model.order
Automatically generated by swagger-codegen (github.com/swagger-api/swagger-codegen)
Please update as you see appropriate
]]
describe("order", function()
-- unit tests for the property 'id'
describe("property id test", function()
it("should work", function()
-- TODO assertion here: http://olivinelabs.com/busted/#asserts
end)
end)

-- unit tests for the property 'pet_id'
describe("property pet_id test", function()
it("should work", function()
-- TODO assertion here: http://olivinelabs.com/busted/#asserts
end)
end)

-- unit tests for the property 'quantity'
describe("property quantity test", function()
it("should work", function()
-- TODO assertion here: http://olivinelabs.com/busted/#asserts
end)
end)

-- unit tests for the property 'ship_date'
describe("property ship_date 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)

-- unit tests for the property 'complete'
describe("property complete test", function()
it("should work", function()
-- TODO assertion here: http://olivinelabs.com/busted/#asserts
end)
end)

end)
77 changes: 77 additions & 0 deletions samples/client/petstore/lua/petstore/spec/pet_api_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
--[[
Swagger Petstore
This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
OpenAPI spec version: 1.0.0
Contact: [email protected]
Generated by: https://github.com/swagger-api/swagger-codegen.git
Swagger Codegen version: 2.4.0-SNAPSHOT
]]

local petstore_pet_api = require "petstore.api.pet_api"

--[[
Unit tests for petstore.api.pet_api
Automatically generated by swagger-codegen (github.com/swagger-api/swagger-codegen)
Please update as you see appropriate
]]
describe("pet_api", function()
-- unit tests for add_pet
describe("add_pet test", function()
it("should work", function()
-- TODO assertion here: http://olivinelabs.com/busted/#asserts
end)
end)

-- unit tests for delete_pet
describe("delete_pet test", function()
it("should work", function()
-- TODO assertion here: http://olivinelabs.com/busted/#asserts
end)
end)

-- unit tests for find_pets_by_status
describe("find_pets_by_status test", function()
it("should work", function()
-- TODO assertion here: http://olivinelabs.com/busted/#asserts
end)
end)

-- unit tests for find_pets_by_tags
describe("find_pets_by_tags test", function()
it("should work", function()
-- TODO assertion here: http://olivinelabs.com/busted/#asserts
end)
end)

-- unit tests for get_pet_by_id
describe("get_pet_by_id test", function()
it("should work", function()
-- TODO assertion here: http://olivinelabs.com/busted/#asserts
end)
end)

-- unit tests for update_pet
describe("update_pet test", function()
it("should work", function()
-- TODO assertion here: http://olivinelabs.com/busted/#asserts
end)
end)

-- unit tests for update_pet_with_form
describe("update_pet_with_form test", function()
it("should work", function()
-- TODO assertion here: http://olivinelabs.com/busted/#asserts
end)
end)

-- unit tests for upload_file
describe("upload_file test", function()
it("should work", function()
-- TODO assertion here: http://olivinelabs.com/busted/#asserts
end)
end)

end)
Loading

0 comments on commit 6c79052

Please sign in to comment.