Skip to content

Commit

Permalink
🔥
Browse files Browse the repository at this point in the history
  • Loading branch information
wcandillon committed Aug 11, 2016
1 parent 7d7f8ee commit f0817cd
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 87 deletions.
30 changes: 3 additions & 27 deletions lib/codegen.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,6 @@ var lint = require('jshint').JSHINT;
var _ = require('lodash');
var ts = require('./typescript');

var replaceCharacterWithCamelCase = function(id, character) {
if(id.indexOf(character) === -1) {
return id;
}
var tokens = [];
id.split(character).forEach(function(token, index){
if(index === 0) {
tokens.push(token[0].toLowerCase() + token.substring(1));
} else {
tokens.push(token[0].toUpperCase() + token.substring(1));
}
});
return tokens.join('');
};

var camelCase = function(opts, id) {
var kebabRemovedId = replaceCharacterWithCamelCase(id, '-');
if (opts.convertSnakeCase) {
return replaceCharacterWithCamelCase(kebabRemovedId, '_');
} else {
return kebabRemovedId;
}
};

var normalizeName = function(id) {
return id.replace(/\.|\-|\{|\}/g, '_');
};
Expand All @@ -50,7 +26,7 @@ var getPathToMethodName = function(opts, m, path){
}
result.push(segment);
});
var result = camelCase(opts, segments.join('-'));
var result = _.camelCase(segments.join('-'));
return m.toLowerCase() + result[0].toUpperCase() + result.substring(1);
};

Expand Down Expand Up @@ -131,7 +107,7 @@ var getViewForSwagger2 = function(opts, type){
var segments = parameter.$ref.split('/');
parameter = swagger.parameters[segments.length === 1 ? segments[0] : segments[2] ];
}
parameter.camelCaseName = camelCase(opts, parameter.name);
parameter.camelCaseName = _.camelCase(parameter.name);
if(parameter.enum && parameter.enum.length === 1) {
parameter.isSingleton = true;
parameter.singleton = parameter.enum[0];
Expand Down Expand Up @@ -196,7 +172,7 @@ var getViewForSwagger1 = function(opts, type){

op.parameters = op.parameters ? op.parameters : [];
op.parameters.forEach(function(parameter) {
parameter.camelCaseName = camelCase(opts, parameter.name);
parameter.camelCaseName = _.camelCase(parameter.name);
if(parameter.enum && parameter.enum.length === 1) {
parameter.isSingleton = true;
parameter.singleton = parameter.enum[0];
Expand Down
2 changes: 1 addition & 1 deletion lib/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function convertType(swaggerType) {
typespec.isRef = typespec.tsType === 'ref';
typespec.isObject = typespec.tsType === 'object';
typespec.isArray = typespec.tsType === 'array';
typespec.isAtomic = _.contains(['string', 'number', 'boolean', 'any'], typespec.tsType);
typespec.isAtomic = _.includes(['string', 'number', 'boolean', 'any'], typespec.tsType);

return typespec;

Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "swagger-js-codegen",
"main": "./lib/codegen.js",
"version": "1.6.8",
"version": "1.6.7",
"description": "A Swagger codegen for JavaScript",
"scripts": {
"test": "grunt"
Expand Down Expand Up @@ -32,7 +32,7 @@
"dependencies": {
"js-beautify": "~1.5.1",
"jshint": "~2.5.1",
"lodash": "^2.4.1",
"lodash": "4.14.1",
"mustache": "^2.0.0"
},
"devDependencies": {
Expand All @@ -44,7 +44,6 @@
"matchdep": "~0.3.0",
"vows": "~0.7.0",
"grunt-jsonlint": "~1.0.4",
"request": "~2.40.0",
"rewire": "^2.5.1"
"request": "~2.40.0"
}
}
6 changes: 3 additions & 3 deletions tests/node-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ vows.describe('Test Generated API').addBatch({
return promise;
},
'Should have missing parameter error': function(error){
assert.equal(error.message, 'Missing required query parameter: grant_type');
assert.equal(error.message, 'Missing required query parameter: grantType');
}
},
'Calling Authenticate method with wrong password': {
Expand All @@ -42,7 +42,7 @@ vows.describe('Test Generated API').addBatch({
auth.authenticate({
email: 'w+test@28.io',
password: 'foobartest',
grant_type: 'client_credentials'
grantType: 'client_credentials'
}).then(callback, callback);
return promise;
},
Expand All @@ -59,7 +59,7 @@ vows.describe('Test Generated API').addBatch({
auth.authenticate({
email: 'w+test@28.io',
password: 'foobar',
grant_type: 'client_credentials'
grantType: 'client_credentials'
}).then(function(result){
promise.emit('success', result);
}, function(result){
Expand Down
2 changes: 1 addition & 1 deletion tests/node-protected.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ vows.describe('Test Protected').addBatch({
protectedAPI.auth({
email: 'w+test@28.io',
password: 'foobar',
grant_type: 'client_credentials'
grantType: 'client_credentials'
}).then(function(result){
promise.emit('success', result);
}, function(result){
Expand Down
51 changes: 0 additions & 51 deletions tests/utilities.js

This file was deleted.

0 comments on commit f0817cd

Please sign in to comment.