Merge branch 'bshamblen-property_hovet push origin develop_2.0r_over' into develop_2.0

This commit is contained in:
Tony Tam
2015-01-29 13:02:36 -08:00
8 changed files with 246 additions and 2 deletions

26
dist/css/screen.css vendored
View File

@@ -391,6 +391,32 @@
font-weight: bold; font-weight: bold;
color: #000; color: #000;
} }
.swagger-section .swagger-ui-wrap .model-signature .description .propWrap .optionsWrapper {
border-spacing: 0;
position: absolute;
background-color: #ffffff;
border: 1px solid #bbbbbb;
display: none;
font-size: 11px;
max-width: 400px;
line-height: 30px;
color: black;
padding: 5px;
margin-left: 10px;
}
.swagger-section .swagger-ui-wrap .model-signature .description .propWrap .optionsWrapper th {
text-align: center;
background-color: #eeeeee;
border: 1px solid #bbbbbb;
font-size: 11px;
color: #666666;
font-weight: bold;
padding: 5px;
line-height: 15px;
}
.swagger-section .swagger-ui-wrap .model-signature .description .propWrap .optionsWrapper .optionName {
font-weight: bold;
}
.swagger-section .swagger-ui-wrap .model-signature .propName { .swagger-section .swagger-ui-wrap .model-signature .propName {
font-weight: bold; font-weight: bold;
} }

View File

@@ -2458,8 +2458,22 @@ var Property = function(name, obj, required) {
this.description = obj.description; this.description = obj.description;
this.obj = obj; this.obj = obj;
this.optional = true; this.optional = true;
this.optional = !required;
this.default = obj.default || null; this.default = obj.default || null;
this.example = obj.example || null; this.example = obj.example || null;
this.collectionFormat = obj.collectionFormat || null;
this.maximum = obj.maximum || null;
this.exclusiveMaximum = obj.exclusiveMaximum || null;
this.minimum = obj.minimum || null;
this.exclusiveMinimum = obj.exclusiveMinimum || null;
this.maxLength = obj.maxLength || null;
this.minLength = obj.minLength || null;
this.pattern = obj.pattern || null;
this.maxItems = obj.maxItems || null;
this.minItems = obj.minItems || null;
this.uniqueItems = obj.uniqueItems || null;
this.enum = obj.enum || null;
this.multipleOf = obj.multipleOf || null;
}; };
Property.prototype.getSampleValue = function (modelsToIgnore) { Property.prototype.getSampleValue = function (modelsToIgnore) {
@@ -2575,9 +2589,71 @@ Property.prototype.toString = function() {
if(typeof this.description !== 'undefined') if(typeof this.description !== 'undefined')
str += ': ' + this.description; str += ': ' + this.description;
var options = '';
var isArray = this.schema.type === 'array';
var type = isArray ? this.schema.items.type : this.schema.type;
if (this.default)
options += optionHtml('Default', this.default);
switch (type) {
case 'string':
if (this.minLength)
options += optionHtml('Min. Length', this.minLength);
if (this.maxLength)
options += optionHtml('Max. Length', this.maxLength);
if (this.pattern)
options += optionHtml('Reg. Exp.', this.pattern);
break;
case 'integer':
case 'number':
if (this.minimum)
options += optionHtml('Min. Value', this.minimum);
if (this.exclusiveMinimum)
options += optionHtml('Exclusive Min.', "true");
if (this.maximum)
options += optionHtml('Max. Value', this.maximum);
if (this.exclusiveMaximum)
options += optionHtml('Exclusive Max.', "true");
if (this.multipleOf)
options += optionHtml('Multiple Of', this.multipleOf);
break;
}
if (isArray) {
if (this.minItems)
options += optionHtml('Min. Items', this.minItems);
if (this.maxItems)
options += optionHtml('Max. Items', this.maxItems);
if (this.uniqueItems)
options += optionHtml('Unique Items', "true");
if (this.collectionFormat)
options += optionHtml('Coll. Format', this.collectionFormat);
}
if (this.enum) {
var enumString;
if (type === 'number' || type === 'integer')
enumString = this.enum.join(', ');
else {
enumString = '"' + this.enum.join('", "') + '"';
}
options += optionHtml('Enum', enumString);
}
if (options.length > 0)
str = '<span class="propWrap">' + str + '<table class="optionsWrapper"><tr><th colspan="2">' + this.name + '</th></tr>' + options + '</table></span>';
return str; return str;
}; };
optionHtml = function(label, value) {
return '<tr><td class="optionName">' + label + ':</td><td>' + value + '</td></tr>';
}
typeFromJsonSchema = function(type, format) { typeFromJsonSchema = function(type, format) {
var str; var str;
if(type === 'integer' && format === 'int32') if(type === 'integer' && format === 'int32')

7
dist/swagger-ui.js vendored
View File

@@ -1639,7 +1639,12 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
resources[id] = resource; resources[id] = resource;
this.addResource(resource, this.model.auths); this.addResource(resource, this.model.auths);
} }
return this; this;
return $('.propWrap').hover(function() {
return $('.optionsWrapper', $(this)).show();
}, function() {
return $('.optionsWrapper', $(this)).hide();
});
}; };
MainView.prototype.addResource = function(resource, auths) { MainView.prototype.addResource = function(resource, auths) {

File diff suppressed because one or more lines are too long

View File

@@ -2458,8 +2458,22 @@ var Property = function(name, obj, required) {
this.description = obj.description; this.description = obj.description;
this.obj = obj; this.obj = obj;
this.optional = true; this.optional = true;
this.optional = !required;
this.default = obj.default || null; this.default = obj.default || null;
this.example = obj.example || null; this.example = obj.example || null;
this.collectionFormat = obj.collectionFormat || null;
this.maximum = obj.maximum || null;
this.exclusiveMaximum = obj.exclusiveMaximum || null;
this.minimum = obj.minimum || null;
this.exclusiveMinimum = obj.exclusiveMinimum || null;
this.maxLength = obj.maxLength || null;
this.minLength = obj.minLength || null;
this.pattern = obj.pattern || null;
this.maxItems = obj.maxItems || null;
this.minItems = obj.minItems || null;
this.uniqueItems = obj.uniqueItems || null;
this.enum = obj.enum || null;
this.multipleOf = obj.multipleOf || null;
}; };
Property.prototype.getSampleValue = function (modelsToIgnore) { Property.prototype.getSampleValue = function (modelsToIgnore) {
@@ -2575,9 +2589,71 @@ Property.prototype.toString = function() {
if(typeof this.description !== 'undefined') if(typeof this.description !== 'undefined')
str += ': ' + this.description; str += ': ' + this.description;
var options = '';
var isArray = this.schema.type === 'array';
var type = isArray ? this.schema.items.type : this.schema.type;
if (this.default)
options += optionHtml('Default', this.default);
switch (type) {
case 'string':
if (this.minLength)
options += optionHtml('Min. Length', this.minLength);
if (this.maxLength)
options += optionHtml('Max. Length', this.maxLength);
if (this.pattern)
options += optionHtml('Reg. Exp.', this.pattern);
break;
case 'integer':
case 'number':
if (this.minimum)
options += optionHtml('Min. Value', this.minimum);
if (this.exclusiveMinimum)
options += optionHtml('Exclusive Min.', "true");
if (this.maximum)
options += optionHtml('Max. Value', this.maximum);
if (this.exclusiveMaximum)
options += optionHtml('Exclusive Max.', "true");
if (this.multipleOf)
options += optionHtml('Multiple Of', this.multipleOf);
break;
}
if (isArray) {
if (this.minItems)
options += optionHtml('Min. Items', this.minItems);
if (this.maxItems)
options += optionHtml('Max. Items', this.maxItems);
if (this.uniqueItems)
options += optionHtml('Unique Items', "true");
if (this.collectionFormat)
options += optionHtml('Coll. Format', this.collectionFormat);
}
if (this.enum) {
var enumString;
if (type === 'number' || type === 'integer')
enumString = this.enum.join(', ');
else {
enumString = '"' + this.enum.join('", "') + '"';
}
options += optionHtml('Enum', enumString);
}
if (options.length > 0)
str = '<span class="propWrap">' + str + '<table class="optionsWrapper"><tr><th colspan="2">' + this.name + '</th></tr>' + options + '</table></span>';
return str; return str;
}; };
optionHtml = function(label, value) {
return '<tr><td class="optionName">' + label + ':</td><td>' + value + '</td></tr>';
}
typeFromJsonSchema = function(type, format) { typeFromJsonSchema = function(type, format) {
var str; var str;
if(type === 'integer' && format === 'int32') if(type === 'integer' && format === 'int32')

View File

@@ -64,6 +64,13 @@ class MainView extends Backbone.View
@addResource resource, @model.auths @addResource resource, @model.auths
@ @
$('.propWrap').hover(
->
$('.optionsWrapper', $(this)).show()
,->
$('.optionsWrapper', $(this)).hide()
)
addResource: (resource, auths) -> addResource: (resource, auths) ->
# Render a resource and add it to resources li # Render a resource and add it to resources li
resource.id = resource.id.replace(/\s/g, '_') resource.id = resource.id.replace(/\s/g, '_')

View File

@@ -391,6 +391,32 @@
font-weight: bold; font-weight: bold;
color: #000; color: #000;
} }
.swagger-section .swagger-ui-wrap .model-signature .description .propWrap .optionsWrapper {
border-spacing: 0;
position: absolute;
background-color: #ffffff;
border: 1px solid #bbbbbb;
display: none;
font-size: 11px;
max-width: 400px;
line-height: 30px;
color: black;
padding: 5px;
margin-left: 10px;
}
.swagger-section .swagger-ui-wrap .model-signature .description .propWrap .optionsWrapper th {
text-align: center;
background-color: #eeeeee;
border: 1px solid #bbbbbb;
font-size: 11px;
color: #666666;
font-weight: bold;
padding: 5px;
line-height: 15px;
}
.swagger-section .swagger-ui-wrap .model-signature .description .propWrap .optionsWrapper .optionName {
font-weight: bold;
}
.swagger-section .swagger-ui-wrap .model-signature .propName { .swagger-section .swagger-ui-wrap .model-signature .propName {
font-weight: bold; font-weight: bold;
} }

View File

@@ -281,6 +281,34 @@
font-weight: bold; font-weight: bold;
color: #000; color: #000;
} }
.propWrap {
.optionsWrapper {
border-spacing: 0;
position: absolute;
background-color: #ffffff;
border: 1px solid #bbbbbb;
display: none;
font-size: 11px;
max-width: 400px;
line-height: 30px;
color: black;
padding: 5px;
margin-left:10px;
th {
text-align: center;
background-color: #eeeeee;
border: 1px solid #bbbbbb;
font-size: 11px;
color: #666666;
font-weight: bold;
padding: 5px;
line-height: 15px;
}
.optionName {
font-weight: bold;
}
}
}
} }
.propName { .propName {
font-weight: bold; font-weight: bold;