From 1b662db2d24d1510750f0b508f1e2d9ced067d10 Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Thu, 12 Sep 2013 11:00:27 -0700 Subject: [PATCH] fix for required fields showing optional --- dist/lib/swagger.js | 42 ++++++++++++++++++++++++++++++++---------- lib/swagger.js | 42 ++++++++++++++++++++++++++++++++---------- 2 files changed, 64 insertions(+), 20 deletions(-) diff --git a/dist/lib/swagger.js b/dist/lib/swagger.js index 16e5b89e..9e7fb507 100644 --- a/dist/lib/swagger.js +++ b/dist/lib/swagger.js @@ -1,6 +1,6 @@ // Generated by CoffeeScript 1.4.0 (function() { - var ApiKeyAuthorization, SwaggerApi, SwaggerAuthorizations, SwaggerHttp, SwaggerModel, SwaggerModelProperty, SwaggerOperation, SwaggerRequest, SwaggerResource, + var ApiKeyAuthorization, PasswordAuthorization, SwaggerApi, SwaggerAuthorizations, SwaggerHttp, SwaggerModel, SwaggerModelProperty, SwaggerOperation, SwaggerRequest, SwaggerResource, __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; SwaggerApi = (function() { @@ -94,6 +94,7 @@ this.apis = {}; this.apisArray = []; this.produces = response.produces; + this.authSchemes = response.authorizations; if (response.info != null) { this.info = response.info; } @@ -445,18 +446,19 @@ SwaggerModel = (function() { function SwaggerModel(modelName, obj) { - var propertyName, value; + var prop, propertyName, value; this.name = obj.id != null ? obj.id : modelName; this.properties = []; for (propertyName in obj.properties) { - if (obj["enum"] != null) { - for (value in obj["enum"]) { - if (propertyName === value) { + if (obj.required != null) { + for (value in obj.required) { + if (propertyName === obj.required[value]) { obj.properties[propertyName].required = true; } } } - this.properties.push(new SwaggerModelProperty(propertyName, obj.properties[propertyName])); + prop = new SwaggerModelProperty(propertyName, obj.properties[propertyName]); + this.properties.push(prop); } } @@ -508,7 +510,6 @@ SwaggerModel.prototype.createJSONSample = function(modelsToIgnore) { var prop, result, _i, _len, _ref; - console.log("creating json sample for " + this); result = {}; modelsToIgnore = modelsToIgnore || []; modelsToIgnore.push(this.name); @@ -530,11 +531,9 @@ function SwaggerModelProperty(name, obj) { this.name = name; this.dataType = obj.type || obj.dataType || obj["$ref"]; - console.log(this.name + " has data type " + this.dataType); this.isCollection = this.dataType && (this.dataType.toLowerCase() === 'array' || this.dataType.toLowerCase() === 'list' || this.dataType.toLowerCase() === 'set'); this.descr = obj.description; this.required = obj.required; - console.log(this); if (obj.items != null) { if (obj.items.type != null) { this.refDataType = obj.items.type; @@ -630,7 +629,6 @@ this.method = this.method.toLowerCase(); this.isGetMethod = this.method === "get"; this.resourceName = this.resource.name; - console.log("model type: " + type); if (((_ref = this.type) != null ? _ref.toLowerCase() : void 0) === 'void') { this.type = void 0; } @@ -1211,6 +1209,28 @@ })(); + PasswordAuthorization = (function() { + + PasswordAuthorization.prototype.name = null; + + PasswordAuthorization.prototype.username = null; + + PasswordAuthorization.prototype.password = null; + + function PasswordAuthorization(name, username, password) { + this.name = name; + this.username = username; + this.password = password; + } + + PasswordAuthorization.prototype.apply = function(obj) { + return obj.headers["Authorization"] = "Basic " + btoa(this.username + ":" + this.password); + }; + + return PasswordAuthorization; + + })(); + this.SwaggerApi = SwaggerApi; this.SwaggerResource = SwaggerResource; @@ -1223,6 +1243,8 @@ this.ApiKeyAuthorization = ApiKeyAuthorization; + this.PasswordAuthorization = PasswordAuthorization; + this.authorizations = new SwaggerAuthorizations(); }).call(this); diff --git a/lib/swagger.js b/lib/swagger.js index 16e5b89e..9e7fb507 100644 --- a/lib/swagger.js +++ b/lib/swagger.js @@ -1,6 +1,6 @@ // Generated by CoffeeScript 1.4.0 (function() { - var ApiKeyAuthorization, SwaggerApi, SwaggerAuthorizations, SwaggerHttp, SwaggerModel, SwaggerModelProperty, SwaggerOperation, SwaggerRequest, SwaggerResource, + var ApiKeyAuthorization, PasswordAuthorization, SwaggerApi, SwaggerAuthorizations, SwaggerHttp, SwaggerModel, SwaggerModelProperty, SwaggerOperation, SwaggerRequest, SwaggerResource, __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; SwaggerApi = (function() { @@ -94,6 +94,7 @@ this.apis = {}; this.apisArray = []; this.produces = response.produces; + this.authSchemes = response.authorizations; if (response.info != null) { this.info = response.info; } @@ -445,18 +446,19 @@ SwaggerModel = (function() { function SwaggerModel(modelName, obj) { - var propertyName, value; + var prop, propertyName, value; this.name = obj.id != null ? obj.id : modelName; this.properties = []; for (propertyName in obj.properties) { - if (obj["enum"] != null) { - for (value in obj["enum"]) { - if (propertyName === value) { + if (obj.required != null) { + for (value in obj.required) { + if (propertyName === obj.required[value]) { obj.properties[propertyName].required = true; } } } - this.properties.push(new SwaggerModelProperty(propertyName, obj.properties[propertyName])); + prop = new SwaggerModelProperty(propertyName, obj.properties[propertyName]); + this.properties.push(prop); } } @@ -508,7 +510,6 @@ SwaggerModel.prototype.createJSONSample = function(modelsToIgnore) { var prop, result, _i, _len, _ref; - console.log("creating json sample for " + this); result = {}; modelsToIgnore = modelsToIgnore || []; modelsToIgnore.push(this.name); @@ -530,11 +531,9 @@ function SwaggerModelProperty(name, obj) { this.name = name; this.dataType = obj.type || obj.dataType || obj["$ref"]; - console.log(this.name + " has data type " + this.dataType); this.isCollection = this.dataType && (this.dataType.toLowerCase() === 'array' || this.dataType.toLowerCase() === 'list' || this.dataType.toLowerCase() === 'set'); this.descr = obj.description; this.required = obj.required; - console.log(this); if (obj.items != null) { if (obj.items.type != null) { this.refDataType = obj.items.type; @@ -630,7 +629,6 @@ this.method = this.method.toLowerCase(); this.isGetMethod = this.method === "get"; this.resourceName = this.resource.name; - console.log("model type: " + type); if (((_ref = this.type) != null ? _ref.toLowerCase() : void 0) === 'void') { this.type = void 0; } @@ -1211,6 +1209,28 @@ })(); + PasswordAuthorization = (function() { + + PasswordAuthorization.prototype.name = null; + + PasswordAuthorization.prototype.username = null; + + PasswordAuthorization.prototype.password = null; + + function PasswordAuthorization(name, username, password) { + this.name = name; + this.username = username; + this.password = password; + } + + PasswordAuthorization.prototype.apply = function(obj) { + return obj.headers["Authorization"] = "Basic " + btoa(this.username + ":" + this.password); + }; + + return PasswordAuthorization; + + })(); + this.SwaggerApi = SwaggerApi; this.SwaggerResource = SwaggerResource; @@ -1223,6 +1243,8 @@ this.ApiKeyAuthorization = ApiKeyAuthorization; + this.PasswordAuthorization = PasswordAuthorization; + this.authorizations = new SwaggerAuthorizations(); }).call(this);