Skip to content

Commit

Permalink
Merge pull request #3134 from wing328/js_travis
Browse files Browse the repository at this point in the history
[Javascript] Add auto-generated test files and .travis.yml to JS API client
  • Loading branch information
wing328 authored Jun 14, 2016
2 parents b782dc0 + 9f3b8ba commit e2e90db
Show file tree
Hide file tree
Showing 40 changed files with 1,759 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -292,6 +296,8 @@ public void preprocessSwagger(Swagger swagger) {
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"));
supportingFiles.add(new SupportingFile("travis.yml", "", ".travis.yml"));
}

@Override
Expand Down Expand Up @@ -322,6 +328,16 @@ private String createPath(String... segments) {
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());
Expand Down Expand Up @@ -400,6 +416,16 @@ public String toModelDocFilename(String name) {
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
Expand Down
Original file line number Diff line number Diff line change
@@ -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}}
});

}));
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--timeout 10000
Original file line number Diff line number Diff line change
@@ -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}}
});

}));
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
language: node_js
node_js:
- "6"
- "6.1"
- "5"
- "5.11"

7 changes: 7 additions & 0 deletions samples/client/petstore/javascript/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
language: node_js
node_js:
- "6"
- "6.1"
- "5"
- "5.11"

25 changes: 25 additions & 0 deletions samples/client/petstore/javascript/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,28 @@
of your accepting any such warranty or additional liability.

END OF TERMS AND CONDITIONS

APPENDIX: How to apply the Apache License to your work.

To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright {yyyy} {name of copyright owner}

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
2 changes: 1 addition & 1 deletion samples/client/petstore/javascript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This SDK is automatically generated by the [Swagger Codegen](https://github.com/

- API version: 1.0.0
- Package version: 1.0.0
- Build date: 2016-05-29T20:52:27.873+08:00
- Build date: 2016-06-15T00:01:43.395+08:00
- Build package: class io.swagger.codegen.languages.JavascriptClientCodegen

## Installation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**mapProperty** | **{String: String}** | | [optional]
**mapOfMapProperty** | **{String: {String: String}}** | | [optional]


3 changes: 3 additions & 0 deletions samples/client/petstore/javascript/docs/ArrayTest.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**arrayOfString** | **[String]** | | [optional]
**arrayArrayOfInteger** | **[[Integer]]** | | [optional]
**arrayArrayOfModel** | **[[ReadOnlyFirst]]** | | [optional]


Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**uuid** | **String** | | [optional]
**dateTime** | **Date** | | [optional]
**map** | [**{String: Animal}**](Animal.md) | | [optional]


1 change: 1 addition & 0 deletions samples/client/petstore/javascript/mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--timeout 10000
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
* Constructs a new <code>AdditionalPropertiesClass</code>.
* @alias module:model/AdditionalPropertiesClass
* @class
* @extends Object
*/
var exports = function() {
var _this = this;

return _this;


};

/**
Expand All @@ -46,12 +46,25 @@
exports.constructFromObject = function(data, obj) {
if (data) {
obj = obj || new exports();
ApiClient.constructFromObject(data, obj, String);

if (data.hasOwnProperty('map_property')) {
obj['map_property'] = ApiClient.convertToType(data['map_property'], {'String': 'String'});
}
if (data.hasOwnProperty('map_of_map_property')) {
obj['map_of_map_property'] = ApiClient.convertToType(data['map_of_map_property'], {'String': {'String': 'String'}});
}
}
return obj;
}

/**
* @member {Object.<String, String>} map_property
*/
exports.prototype['map_property'] = undefined;
/**
* @member {Object.<String, Object.<String, String>>} map_of_map_property
*/
exports.prototype['map_of_map_property'] = undefined;



Expand Down
24 changes: 24 additions & 0 deletions samples/client/petstore/javascript/src/model/ArrayTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
var exports = function() {
var _this = this;




};

/**
Expand All @@ -45,10 +48,31 @@
if (data) {
obj = obj || new exports();

if (data.hasOwnProperty('array_of_string')) {
obj['array_of_string'] = ApiClient.convertToType(data['array_of_string'], ['String']);
}
if (data.hasOwnProperty('array_array_of_integer')) {
obj['array_array_of_integer'] = ApiClient.convertToType(data['array_array_of_integer'], [['Integer']]);
}
if (data.hasOwnProperty('array_array_of_model')) {
obj['array_array_of_model'] = ApiClient.convertToType(data['array_array_of_model'], [[ReadOnlyFirst]]);
}
}
return obj;
}

/**
* @member {Array.<String>} array_of_string
*/
exports.prototype['array_of_string'] = undefined;
/**
* @member {Array.<Array.<Integer>>} array_array_of_integer
*/
exports.prototype['array_array_of_integer'] = undefined;
/**
* @member {Array.<Array.<module:model/ReadOnlyFirst>>} array_array_of_model
*/
exports.prototype['array_array_of_model'] = undefined;



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@
* Constructs a new <code>MixedPropertiesAndAdditionalPropertiesClass</code>.
* @alias module:model/MixedPropertiesAndAdditionalPropertiesClass
* @class
* @extends Object
*/
var exports = function() {
var _this = this;



return _this;

};

/**
Expand All @@ -48,14 +47,16 @@
exports.constructFromObject = function(data, obj) {
if (data) {
obj = obj || new exports();
ApiClient.constructFromObject(data, obj, Animal);

if (data.hasOwnProperty('uuid')) {
obj['uuid'] = ApiClient.convertToType(data['uuid'], 'String');
}
if (data.hasOwnProperty('dateTime')) {
obj['dateTime'] = ApiClient.convertToType(data['dateTime'], 'Date');
}
if (data.hasOwnProperty('map')) {
obj['map'] = ApiClient.convertToType(data['map'], {'String': Animal});
}
}
return obj;
}
Expand All @@ -68,6 +69,10 @@
* @member {Date} dateTime
*/
exports.prototype['dateTime'] = undefined;
/**
* @member {Object.<String, module:model/Animal>} map
*/
exports.prototype['map'] = undefined;



Expand Down
Loading

0 comments on commit e2e90db

Please sign in to comment.