From 13286558d0dd180e6c448417d5deccf938666105 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Thu, 17 Mar 2016 01:27:09 +0200 Subject: [PATCH] Add minimum and maximum information for numeric fields (fixes #33) --- .../JsonSchema/json-schema-common.scss | 4 ++++ lib/components/JsonSchema/json-schema.html | 4 +++- lib/components/JsonSchema/json-schema.js | 23 +++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/components/JsonSchema/json-schema-common.scss b/lib/components/JsonSchema/json-schema-common.scss index a939c365..d4ae7d5a 100644 --- a/lib/components/JsonSchema/json-schema-common.scss +++ b/lib/components/JsonSchema/json-schema-common.scss @@ -47,6 +47,10 @@ $sub-schema-offset: ($bullet-size/2) + $bullet-margin; width: 75%; } +.param-range { + color: rgba($primary-color, .7); +} + .param-description { font-size: 13px; } diff --git a/lib/components/JsonSchema/json-schema.html b/lib/components/JsonSchema/json-schema.html index c43fe903..c22bc7e8 100644 --- a/lib/components/JsonSchema/json-schema.html +++ b/lib/components/JsonSchema/json-schema.html @@ -11,7 +11,9 @@
{{prop._displayType}} {{prop._displayFormat}} + title="{{prop._displayTypeHint}}"> {{prop._displayType}} {{prop._displayFormat}} + {{prop._range}} + Required
{{enumItem.val | json}} diff --git a/lib/components/JsonSchema/json-schema.js b/lib/components/JsonSchema/json-schema.js index 18309505..c5ef5430 100644 --- a/lib/components/JsonSchema/json-schema.js +++ b/lib/components/JsonSchema/json-schema.js @@ -163,5 +163,28 @@ const injectors = { `${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; + } + } } };