Handle additional properties (fixes #4)

This commit is contained in:
Roman Hotsiy 2016-04-28 20:17:38 +03:00
parent 9cc251e4a7
commit b65d8c96e5
4 changed files with 27 additions and 8 deletions

View File

@ -70,7 +70,7 @@ $sub-schema-offset: ($bullet-size/2) + $bullet-margin;
}
.param-type {
color: $black;
color: rgba($black, 0.4);
font-size: 0.929em;
line-height: $param-name-height;
vertical-align: middle;
@ -83,10 +83,6 @@ $sub-schema-offset: ($bullet-size/2) + $bullet-margin;
font-weight: $base-font-weight;
}
.param-type {
color: rgba($black, 0.4);
}
.param-type.with-hint {
display: inline-block;
margin-bottom: 0.4em;

View File

@ -11,7 +11,11 @@
<table *ngIf="!schema.isTrivial" class="params-wrap" [ngClass]="{'params-array': schema._isArray}">
<!-- <caption> {{_displayType}} </caption> -->
<template ngFor [ngForOf]="schema.properties" #prop="$implicit" #last="last">
<tr class="param" [ngClass]="{'last': last, 'discriminator': prop.isDiscriminator && !derivedEmtpy, 'complex': prop._pointer}">
<tr class="param" [ngClass]="{'last': last,
'discriminator': prop.isDiscriminator && !derivedEmtpy,
'complex': prop._pointer,
'additional': prop._additional
}">
<td class="param-name">
<span class="param-name-content">{{prop._name}}</span>
</td>

View File

@ -89,7 +89,7 @@ export default class JsonSchema extends BaseComponent {
}
let discriminatorFieldIdx = -1;
let props = Object.keys(schema.properties).map((prop, idx) => {
let props = schema.properties && Object.keys(schema.properties).map((prop, idx) => {
let propertySchema = schema.properties[prop];
let propPointer = propertySchema._pointer ||
JsonPointer.join(schema._pointer || this.pointer, ['properties', prop]);
@ -105,6 +105,15 @@ export default class JsonSchema extends BaseComponent {
}
return propertySchema;
});
props = props || [];
if (schema.additionalProperties && schema.additionalProperties !== false) {
let propsSchema = this.prepareAdditionalProperties(schema.additionalProperties);
propsSchema._additional = true;
props.push(propsSchema);
}
// Move discriminator field to the end of properties list
if (discriminatorFieldIdx > -1) {
let discrProp = props.splice(discriminatorFieldIdx, 1);
@ -116,6 +125,11 @@ export default class JsonSchema extends BaseComponent {
schema.properties = props;
}
prepareAdditionalProperties(schema) {
return JsonSchema.injectPropertyData(schema, '<Additional Properties> *',
JsonPointer.join(schema._pointer || this.pointer, ['additionalProperties']));
}
static injectPropertyData(propertySchema, propertyName, propPointer) {
propertySchema = Object.assign({}, propertySchema);
@ -190,7 +204,8 @@ const injectors = {
simpleType: {
check: (propertySchema) => {
if (propertySchema.type === 'object') {
return !propertySchema.properties || !Object.keys(propertySchema.properties).length;
return (!propertySchema.properties || !Object.keys(propertySchema.properties).length)
&& (typeof propertySchema.additionalProperties !== 'object');
}
return (propertySchema.type !== 'array') && propertySchema.type;
},

View File

@ -73,6 +73,10 @@ json-schema[nesteven="true"] {
border-bottom: 0;
}
.param.additional > .param-name {
color: rgba($black, 0.4);
}
.params-wrap {
border-collapse: collapse;
width: 100%;