Add minimum and maximum information for numeric fields (fixes #33)

This commit is contained in:
Roman Hotsiy 2016-03-17 01:27:09 +02:00
parent ac7116ad04
commit 13286558d0
3 changed files with 30 additions and 1 deletions

View File

@ -47,6 +47,10 @@ $sub-schema-offset: ($bullet-size/2) + $bullet-margin;
width: 75%; width: 75%;
} }
.param-range {
color: rgba($primary-color, .7);
}
.param-description { .param-description {
font-size: 13px; font-size: 13px;
} }

View File

@ -11,7 +11,9 @@
<td class="param-info"> <td class="param-info">
<div> <div>
<span class="param-type {{prop.type}}" [ngClass]="{'with-hint': prop._displayTypeHint}" <span class="param-type {{prop.type}}" [ngClass]="{'with-hint': prop._displayTypeHint}"
title="{{prop._displayTypeHint}}"> {{prop._displayType}} {{prop._displayFormat}}</span> title="{{prop._displayTypeHint}}"> {{prop._displayType}} {{prop._displayFormat}}
<span class="param-range" *ngIf="prop._range"> {{prop._range}} </span>
</span>
<span *ngIf="prop.required" class="param-required">Required</span> <span *ngIf="prop.required" class="param-required">Required</span>
<div *ngIf="prop.enum" class="param-enum"> <div *ngIf="prop.enum" class="param-enum">
<span *ngFor="#enumItem of prop.enum" class="enum-value {{enumItem.type}}"> {{enumItem.val | json}} </span> <span *ngFor="#enumItem of prop.enum" class="enum-value {{enumItem.type}}"> {{enumItem.val | json}} </span>

View File

@ -163,5 +163,28 @@ const injectors = {
`${propertySchema.title} (${propertySchema.type})` : propertySchema.type; `${propertySchema.title} (${propertySchema.type})` : propertySchema.type;
} }
} }
},
integer: {
check: (propertySchema) => (propertySchema.type === 'integer' || propertySchema.type === 'number'),
inject: (injectTo, propertySchema = injectTo) => {
var range = '';
if (propertySchema.minimum && propertySchema.maximum) {
range += propertySchema.exclusiveMinimum ? '( ' : '[ ';
range += propertySchema.minimum;
range += ' .. ';
range += propertySchema.maximum;
range += propertySchema.exclusiveMaximum ? ' )' : ' ]';
} else if (propertySchema.maximum) {
range += propertySchema.exclusiveMaximum? '< ' : '<= ';
range += propertySchema.maximum;
} else if (propertySchema.minimum) {
range += propertySchema.exclusiveMinimum ? '> ' : '>= ';
range += propertySchema.minimum;
}
if (range) {
injectTo._range = range;
}
}
} }
}; };