Skip to content

Commit

Permalink
Support enum
Browse files Browse the repository at this point in the history
Fixes #11
  • Loading branch information
mohsen1 committed Apr 17, 2015
1 parent d8daa61 commit ef29d2a
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 21 deletions.
48 changes: 48 additions & 0 deletions demo/demo.js
Expand Up @@ -43,6 +43,54 @@ app.controller('MainCtrl', function($scope) {
}
},

{
title: 'Primitive Enum',
schema: {
description: 'This string can only be one of predefined values',
type: 'string',
enum: ['one', 'two', 'three']
}
},

{
title: 'Object Enum',
schema: {
description: 'Car can only be one of two available options',
type: 'object',
title: 'Car',
properties: {
make: {type: 'string'},
model: {type: 'string'}
},
enum: [
{
make: 'Toyota',
model: 'Camry'
},
{
make: 'Nissan',
model: 'Rouge'
}
]
}
},

{
title: 'Array Enum',
schema: {
description: 'ways to count 10 items',
title: 'Numbers',
type: 'array',
maxItems: 10,
minItems: 10,
items: {type: 'string'},
enum: [
['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten'],
['alpha', 'beta', 'gamma', 'delta', 'epsilon', 'zeta', 'eta', 'theta', 'iota', 'kappa']
]
}
},

{
title: 'Required',
schema: {
Expand Down
18 changes: 9 additions & 9 deletions dist/json-schema-view.css
@@ -1,7 +1,7 @@
/*!
* json-schema-view
* https://github.com/mohsen1/json-schema-view
* Version: 0.3.9 - 2015-01-14T06:36:20.883Z
* Version: 0.4.0 - 2015-04-17T19:29:44.699Z
* License: MIT
*/

Expand All @@ -16,23 +16,23 @@ json-schema-view {
json-schema-view > * {
font-size: 14px;
}
.json-schema-view .toggler,
json-schema-view .toggler {
.json-schema-view .toggle-handle,
json-schema-view .toggle-handle {
cursor: pointer;
margin: auto .3em;
font-size: 10px;
display: inline-block;
transform-origin: 50% 40%;
transition: transform 150ms ease-in;
}
.json-schema-view .toggler:after,
json-schema-view .toggler:after {
.json-schema-view .toggle-handle:after,
json-schema-view .toggle-handle:after {
content: "▼";
}
.json-schema-view .toggler,
json-schema-view .toggler,
.json-schema-view .toggler:hover,
json-schema-view .toggler:hover {
.json-schema-view .toggle-handle,
json-schema-view .toggle-handle,
.json-schema-view .toggle-handle:hover,
json-schema-view .toggle-handle:hover {
text-decoration: none;
color: #333333;
}
Expand Down
5 changes: 3 additions & 2 deletions dist/json-schema-view.js
@@ -1,7 +1,7 @@
/*!
* json-schema-view
* https://github.com/mohsen1/json-schema-view
* Version: 0.3.9 - 2015-01-14T06:36:20.876Z
* Version: 0.4.0 - 2015-04-17T19:29:44.695Z
* License: MIT
*/

Expand Down Expand Up @@ -136,4 +136,5 @@ angular.module('RecursionHelper', []).factory('RecursionHelper', ['$compile', fu
};
}]);

angular.module("mohsen1.json-schema-view").run(["$templateCache", function($templateCache) {$templateCache.put("json-schema-view.html","<div class=\"json-schema-view\" ng-class=\"{collapsed: isCollapsed}\"><div class=\"primitive\" ng-if=\"isPrimitive\"><a class=\"title\" ng-click=\"toggle()\"><span class=\"toggler\" ng-if=\"isPrimitiveCollapsible()\"></span>{{schema.title}}</a> <span class=\"type\">{{schema.type}}</span> <span class=\"required\" ng-if=\"isRequired(schema)\">*</span> <span class=\"format\" ng-if=\"!isCollapsed && schema.format\">({{schema.format}})</span> <span class=\"range minimum\" ng-if=\"!isCollapsed && schema.minimum\">minimum:{{schema.minimum}}</span> <span class=\"range maximum\" ng-if=\"!isCollapsed && schema.maximum\">maximum:{{schema.maximum}}</span> <span class=\"range minLength\" ng-if=\"!isCollapsed && schema.minLength\">minLength:{{schema.minLength}}</span> <span class=\"range maxLength\" ng-if=\"!isCollapsed && schema.maxLength\">maxLength:{{schema.maxLength}}</span><div class=\"description\">{{schema.description}}</div></div><div ng-if=\"isArray\" class=\"array\"><a class=\"title\" ng-click=\"toggle()\"><span class=\"toggler\"></span>{{schema.title}} <span class=\"opening bracket\">[</span><span class=\"closing bracket\" ng-if=\"isCollapsed\">]</span></a><div class=\"inner\"><div class=\"description\">{{schema.description}}</div><json-schema-view ng-if=\"!isCollapsed\" schema=\"schema.items\" open=\"open - 1\"></json-schema-view></div><span class=\"closing bracket\" ng-if=\"!isCollapsed\">]</span></div><div ng-if=\"!isPrimitive && !isArray\" class=\"object\"><a class=\"title\" ng-click=\"toggle()\"><span class=\"toggler\"></span>{{schema.title}} <span class=\"opening brace\">{</span><span class=\"closing brace\" ng-if=\"isCollapsed\">}</span></a><div class=\"inner\"><div class=\"description\">{{schema.description}}</div><div class=\"property\" ng-repeat=\"(propertyName, property) in schema.properties\"><span class=\"name\">{{propertyName}}:</span><json-schema-view schema=\"property\" open=\"open - 1\"></json-schema-view></div></div><span class=\"closeing brace\" ng-if=\"!isCollapsed\">}</span></div></div>");}]);
angular.module("mohsen1.json-schema-view").run(["$templateCache", function($templateCache) {$templateCache.put("enum.html","<div class=\"inner enums\" ng-if=\"!isCollapsed && schema.enum\"><b>Enum:</b><json-formatter class=\"inner\" json=\"schema.enum\" open=\"open\"></json-formatter></div>");
$templateCache.put("json-schema-view.html","<div class=\"json-schema-view\" ng-class=\"{collapsed: isCollapsed}\"><div class=\"primitive\" ng-if=\"isPrimitive\"><a class=\"title\" ng-click=\"toggle()\"><span class=\"toggle-handle\" ng-if=\"isPrimitiveCollapsible()\"></span>{{schema.title}}</a> <span class=\"type\">{{schema.type}}</span> <span class=\"required\" ng-if=\"isRequired(schema)\">*</span> <span class=\"format\" ng-if=\"!isCollapsed && schema.format\">({{schema.format}})</span> <span class=\"range minimum\" ng-if=\"!isCollapsed && schema.minimum\">minimum:{{schema.minimum}}</span> <span class=\"range maximum\" ng-if=\"!isCollapsed && schema.maximum\">maximum:{{schema.maximum}}</span> <span class=\"range minLength\" ng-if=\"!isCollapsed && schema.minLength\">minLength:{{schema.minLength}}</span> <span class=\"range maxLength\" ng-if=\"!isCollapsed && schema.maxLength\">maxLength:{{schema.maxLength}}</span><div class=\"inner description\">{{schema.description}}</div><div ng-include=\"\'enum.html\'\" ng-if=\"!isCollapsed && schema.enum\"></div></div><div ng-if=\"isArray\" class=\"array\"><a class=\"title\" ng-click=\"toggle()\"><span class=\"toggle-handle\"></span>{{schema.title}} <span class=\"opening bracket\">[</span><span class=\"closing bracket\" ng-if=\"isCollapsed\">]</span></a><div class=\"inner\"><div class=\"description\">{{schema.description}}</div><json-schema-view ng-if=\"!isCollapsed\" schema=\"schema.items\" open=\"open - 1\"></json-schema-view></div><div ng-include=\"\'enum.html\'\" ng-if=\"!isCollapsed && schema.enum\"></div><span class=\"closing bracket\" ng-if=\"!isCollapsed\">]</span></div><div ng-if=\"!isPrimitive && !isArray\" class=\"object\"><a class=\"title\" ng-click=\"toggle()\"><span class=\"toggle-handle\"></span>{{schema.title}} <span class=\"opening brace\">{</span><span class=\"closing brace\" ng-if=\"isCollapsed\">}</span></a><div class=\"inner\"><div class=\"description\">{{schema.description}}</div><div class=\"property\" ng-repeat=\"(propertyName, property) in schema.properties\"><span class=\"name\">{{propertyName}}:</span><json-schema-view schema=\"property\" open=\"open - 1\"></json-schema-view></div></div><div ng-include=\"\'enum.html\'\" ng-if=\"!isCollapsed && schema.enum\"></div><span class=\"closeing brace\" ng-if=\"!isCollapsed\">}</span></div></div>");}]);
4 changes: 2 additions & 2 deletions dist/json-schema-view.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/json-schema-view.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/enum.html
@@ -0,0 +1,4 @@
<div class="inner enums" ng-if="!isCollapsed && schema.enum">
<b>Enum:</b>
<json-formatter class="inner" json="schema.enum" open="open"></json-formatter>
</div>

0 comments on commit ef29d2a

Please sign in to comment.