Display enums info

This commit is contained in:
Roman Hotsiy 2016-02-06 17:00:31 +02:00
parent fae59c7917
commit e861ae9add
4 changed files with 40 additions and 3 deletions

View File

@ -72,11 +72,11 @@ $sub-schema-offset: ($bullet-size/2) + $bullet-margin;
color: #999; color: #999;
} }
.param-type.string { .param-type.string, .enum-value.string {
color: rgba(0, 80, 0, 0.7); color: rgba(0, 80, 0, 0.7);
} }
.param-type.integer, .param-type.number { .param-type.integer, .param-type.number, .enum-value.number {
color: rgba(74, 139, 179, 0.8); color: rgba(74, 139, 179, 0.8);
} }
@ -84,7 +84,7 @@ $sub-schema-offset: ($bullet-size/2) + $bullet-margin;
color: rgba(0, 50, 159, 0.7); color: rgba(0, 50, 159, 0.7);
} }
.param-type.boolean { .param-type.boolean, .enum-value.boolean {
color: firebrick; color: firebrick;
} }
@ -158,3 +158,25 @@ $sub-schema-offset: ($bullet-size/2) + $bullet-margin;
.param-schema .param-wrap:first-of-type .param-name:before { .param-schema .param-wrap:first-of-type .param-name:before {
display: none !important; display: none !important;
} }
.param-enum {
color: #666;
&:before {
content: "Values: {"
}
&:after {
content: "}"
}
> .enum-value {
&:after {
content: ", ";
}
&:last-of-type:after {
content: none;
}
}
}

View File

@ -13,6 +13,9 @@
<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>
<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">
<span *ngFor="#enumItem of prop.enum" class="enum-value {{enumItem.type}}"> {{enumItem.val | json}} </span>
</div>
</div> </div>
<div class="param-description" innerHtml="{{prop.description | marked}}"></div> <div class="param-description" innerHtml="{{prop.description | marked}}"></div>
<div class="discriminator-info" *ngIf="prop.isDiscriminator"> This field value determines the exact schema: </div> <div class="discriminator-info" *ngIf="prop.isDiscriminator"> This field value determines the exact schema: </div>

View File

@ -99,14 +99,18 @@ export default class JsonSchema extends BaseComponent {
} }
static injectPropData(propData, propName, propPointer, requiredMap, schema) { static injectPropData(propData, propName, propPointer, requiredMap, schema) {
let propEnum;
propData = Object.assign({}, propData); propData = Object.assign({}, propData);
propData._name = propName; propData._name = propName;
propData.required = propData.required || (requiredMap && requiredMap[propName]); propData.required = propData.required || (requiredMap && requiredMap[propName]);
propData._displayType = propData.type; propData._displayType = propData.type;
propData.isDiscriminator = (schema && schema.discriminator === propName); propData.isDiscriminator = (schema && schema.discriminator === propName);
propEnum = propData.enum;
if (propData.type === 'array') { if (propData.type === 'array') {
let itemType = propData.items.type; let itemType = propData.items.type;
let itemFormat = propData.items.format; let itemFormat = propData.items.format;
propEnum = propData.items.enum;
if (itemType === 'object' || !itemType) { if (itemType === 'object' || !itemType) {
itemType = propData.items.title || 'object'; itemType = propData.items.title || 'object';
propData._pointer = propData.items._pointer propData._pointer = propData.items._pointer
@ -128,6 +132,11 @@ export default class JsonSchema extends BaseComponent {
} }
if (propData.format) propData._displayFormat = `<${propData.format}>`; if (propData.format) propData._displayFormat = `<${propData.format}>`;
if (propEnum) {
propData.enum = propEnum.map((value) => {
return {val: value, type: typeof value};
});
}
return propData; return propData;
} }

View File

@ -9,6 +9,9 @@
<span class="param-type {{param.type}}" [ngClass]="{'with-hint': param._displayTypeHint}" <span class="param-type {{param.type}}" [ngClass]="{'with-hint': param._displayTypeHint}"
title="{{param._displayTypeHint}}"> {{param._displayType}} {{param._displayFormat}}</span> title="{{param._displayTypeHint}}"> {{param._displayType}} {{param._displayFormat}}</span>
<span *ngIf="param.required" class="param-required">Required</span> <span *ngIf="param.required" class="param-required">Required</span>
<div *ngIf="param.enum" class="param-enum">
<span *ngFor="#enumItem of param.enum" class="enum-value {{enumItem.type}}"> {{enumItem.val | json}} </span>
</div>
</div> </div>
<div class="param-description" innerHtml="{{param.description | marked}}"></div> <div class="param-description" innerHtml="{{param.description | marked}}"></div>
</div> </div>