forked from loafle/openapi-generator-original
add auto-generated test cases for js api client
This commit is contained in:
parent
b782dc0178
commit
4c277631e4
@ -74,12 +74,16 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
protected boolean emitJSDoc = true;
|
||||
protected String apiDocPath = "docs/";
|
||||
protected String modelDocPath = "docs/";
|
||||
protected String apiTestPath = "api/";
|
||||
protected String modelTestPath = "model/";
|
||||
|
||||
public JavascriptClientCodegen() {
|
||||
super();
|
||||
outputFolder = "generated-code/js";
|
||||
modelTemplateFiles.put("model.mustache", ".js");
|
||||
modelTestTemplateFiles.put("model_test.mustache", ".js");
|
||||
apiTemplateFiles.put("api.mustache", ".js");
|
||||
apiTestTemplateFiles.put("api_test.mustache", ".js");
|
||||
templateDir = "Javascript";
|
||||
apiPackage = "api";
|
||||
modelPackage = "model";
|
||||
@ -292,6 +296,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
supportingFiles.add(new SupportingFile("ApiClient.mustache", createPath(sourceFolder, invokerPackage), "ApiClient.js"));
|
||||
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("mocha.opts", "", "mocha.opts"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -322,6 +327,16 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiTestFileFolder() {
|
||||
return (outputFolder + "/test/" + apiTestPath).replace('/', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelTestFileFolder() {
|
||||
return (outputFolder + "/test/" + modelTestPath).replace('/', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return createPath(outputFolder, sourceFolder, invokerPackage, apiPackage());
|
||||
@ -400,6 +415,16 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
return toModelName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiTestFilename(String name) {
|
||||
return toApiName(name) + ".spec";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelTestFilename(String name) {
|
||||
return toModelName(name) + ".spec";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// sanitize name
|
||||
|
@ -0,0 +1,54 @@
|
||||
(function(root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD.
|
||||
define(['expect.js', '../../src/index'], factory);
|
||||
} else if (typeof module === 'object' && module.exports) {
|
||||
// CommonJS-like environments that support module.exports, like Node.
|
||||
factory(require('expect.js'), require('../../src/index'));
|
||||
} else {
|
||||
// Browser globals (root is window)
|
||||
factory(root.expect, root.{{moduleName}});
|
||||
}
|
||||
}(this, function(expect, {{moduleName}}) {
|
||||
'use strict';
|
||||
|
||||
var instance;
|
||||
|
||||
beforeEach(function() {
|
||||
instance = new {{moduleName}}.{{classname}}();
|
||||
});
|
||||
|
||||
var getProperty = function(object, getter, property) {
|
||||
// Use getter method if present; otherwise, get the property directly.
|
||||
if (typeof object[getter] === 'function')
|
||||
return object[getter]();
|
||||
else
|
||||
return object[property];
|
||||
}
|
||||
|
||||
var setProperty = function(object, setter, property, value) {
|
||||
// Use setter method if present; otherwise, set the property directly.
|
||||
if (typeof object[setter] === 'function')
|
||||
object[setter](value);
|
||||
else
|
||||
object[property] = value;
|
||||
}
|
||||
|
||||
describe('{{classname}}', function() {
|
||||
{{#operations}}
|
||||
{{#operation}}
|
||||
describe('{{operationId}}', function() {
|
||||
it('should call {{operationId}} successfully', function(done) {
|
||||
//uncomment below and update the code to test {{operationId}}
|
||||
//instance.{{operationId}}(pet, function(error) {
|
||||
// if (error) throw error;
|
||||
//expect().to.be();
|
||||
//});
|
||||
done();
|
||||
});
|
||||
});
|
||||
{{/operation}}
|
||||
{{/operations}}
|
||||
});
|
||||
|
||||
}));
|
@ -0,0 +1 @@
|
||||
--timeout 10000
|
@ -0,0 +1,64 @@
|
||||
(function(root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD.
|
||||
define(['expect.js', '../../src/index'], factory);
|
||||
} else if (typeof module === 'object' && module.exports) {
|
||||
// CommonJS-like environments that support module.exports, like Node.
|
||||
factory(require('expect.js'), require('../../src/index'));
|
||||
} else {
|
||||
// Browser globals (root is window)
|
||||
factory(root.expect, root.{{moduleName}});
|
||||
}
|
||||
}(this, function(expect, {{moduleName}}) {
|
||||
'use strict';
|
||||
|
||||
var instance;
|
||||
|
||||
beforeEach(function() {
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
{{^isEnum}}
|
||||
instance = new {{moduleName}}.{{classname}}();
|
||||
{{/isEnum}}
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
});
|
||||
|
||||
var getProperty = function(object, getter, property) {
|
||||
// Use getter method if present; otherwise, get the property directly.
|
||||
if (typeof object[getter] === 'function')
|
||||
return object[getter]();
|
||||
else
|
||||
return object[property];
|
||||
}
|
||||
|
||||
var setProperty = function(object, setter, property, value) {
|
||||
// Use setter method if present; otherwise, set the property directly.
|
||||
if (typeof object[setter] === 'function')
|
||||
object[setter](value);
|
||||
else
|
||||
object[property] = value;
|
||||
}
|
||||
|
||||
describe('{{classname}}', function() {
|
||||
it('should create an instance of {{classname}}', function() {
|
||||
// uncomment below and update the code to test {{classname}}
|
||||
//var instane = new {{moduleName}}.{{classname}}();
|
||||
//expect(instance).to.be.a({{moduleName}}.{{classname}});
|
||||
});
|
||||
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
{{#vars}}
|
||||
it('should have the property {{name}} (base name: "{{baseName}}")', function() {
|
||||
// uncomment below and update the code to test the property {{name}}
|
||||
//var instane = new {{moduleName}}.{{classname}}();
|
||||
//expect(instance).to.be();
|
||||
});
|
||||
|
||||
{{/vars}}
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
});
|
||||
|
||||
}));
|
Loading…
x
Reference in New Issue
Block a user