mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-22 16:46:34 +03:00
Display simple schema + update format display
This commit is contained in:
parent
f44ded1e86
commit
2eabd2b333
|
@ -1,5 +1,6 @@
|
||||||
<small *ng-if="errorMessage">{{errorMessage}}</small>
|
<small *ng-if="errorMessage">{{errorMessage}}</small>
|
||||||
<div class="params-wrap" [ng-class]="{'params-array': isArray}">
|
<span *ng-if="isTrivial" class="param-type param-type-trivial" [ng-class]="type">{{_displayType}}</span>
|
||||||
|
<div *ng-if="!isTrivial" class="params-wrap" [ng-class]="{'params-array': isArray}">
|
||||||
<div *ng-for="#prop of data.properties" class="param-wrap">
|
<div *ng-for="#prop of data.properties" class="param-wrap">
|
||||||
<div class="param">
|
<div class="param">
|
||||||
<div class="param-name">
|
<div class="param-name">
|
||||||
|
@ -7,7 +8,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="param-info">
|
<div class="param-info">
|
||||||
<div>
|
<div>
|
||||||
<span class="param-type" [ng-class]="prop.type">{{prop._displayType}} {{prop.format}}</span>
|
<span class="param-type" [ng-class]="prop.type">{{prop._displayType}} {{prop._displayFormat}}</span>
|
||||||
<span *ng-if="prop.isRequired" class="param-required">Required</span>
|
<span *ng-if="prop.isRequired" class="param-required">Required</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="param-description" inner-html="{{prop.description | marked}}"></div>
|
<div class="param-description" inner-html="{{prop.description | marked}}"></div>
|
||||||
|
|
|
@ -37,9 +37,9 @@ export default class JsonSchema extends BaseComponent {
|
||||||
this.joinAllOf(schema);
|
this.joinAllOf(schema);
|
||||||
|
|
||||||
if (schema.type !== 'object') {
|
if (schema.type !== 'object') {
|
||||||
// TODO
|
this.isTrivial = true;
|
||||||
this.errorMessage = 'Non-object and non-array schemas are not implemented yet';
|
this._displayType = schema.type;
|
||||||
console.warn(`${this.errorMessage}: ${schema.type}`);
|
if (schema.format) this._displayType = `${this.displayType} <${schema.format}>`;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +50,11 @@ export default class JsonSchema extends BaseComponent {
|
||||||
this.schema.required.forEach(prop => this.requiredMap[prop] = true);
|
this.schema.required.forEach(prop => this.requiredMap[prop] = true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!schema.properties) return;
|
if (!schema.properties) {
|
||||||
|
this.isTrivial = true;
|
||||||
|
this._displayType = `${schema.type} (Custom key-value pairs)`;
|
||||||
|
return;
|
||||||
|
}
|
||||||
let props = Object.keys(schema.properties).map(prop => {
|
let props = Object.keys(schema.properties).map(prop => {
|
||||||
let propData = schema.properties[prop];
|
let propData = schema.properties[prop];
|
||||||
this.injectPropData(prop, propData);
|
this.injectPropData(prop, propData);
|
||||||
|
@ -76,17 +80,21 @@ export default class JsonSchema extends BaseComponent {
|
||||||
propData._displayType = propData.type;
|
propData._displayType = propData.type;
|
||||||
if (propData.type === 'array') {
|
if (propData.type === 'array') {
|
||||||
let itemType = propData.items.type;
|
let itemType = propData.items.type;
|
||||||
|
let itemFormat = propData.items.format;
|
||||||
if (itemType === 'object') {
|
if (itemType === 'object') {
|
||||||
itemType = propData.items.title || 'object';
|
itemType = propData.items.title || 'object';
|
||||||
propData._pointer = propData.items._pointer || this.pointer + '/properties/' + prop + '/items';
|
propData._pointer = propData.items._pointer || this.pointer + '/properties/' + prop + '/items';
|
||||||
}
|
}
|
||||||
propData._displayType = `array of ${itemType}`;
|
propData._displayType = `array of ${itemType}`;
|
||||||
|
propData.format = itemFormat;
|
||||||
propData._isArray = true;
|
propData._isArray = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (propData.type === 'object') {
|
if (propData.type === 'object') {
|
||||||
propData._displayType = propData.title || 'object';
|
propData._displayType = propData.title || 'object';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (propData.format) propData._displayFormat = `<${propData.format}>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
|
|
|
@ -72,6 +72,11 @@ $sub-schema-offset: ($bullet-size/2) + $bullet-margin;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.param-type-trivial {
|
||||||
|
margin: 10px 10px 0;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
/* tree */
|
/* tree */
|
||||||
|
|
||||||
// Bullet
|
// Bullet
|
||||||
|
|
Loading…
Reference in New Issue
Block a user