mirror of
https://github.com/Redocly/redoc.git
synced 2024-09-21 11:18:48 +03:00
display array schema
This commit is contained in:
parent
9d096732fa
commit
f964465513
|
@ -1,5 +1,5 @@
|
||||||
<small *ng-if="errorMessage">{{errorMessage}}</small>
|
<small *ng-if="errorMessage">{{errorMessage}}</small>
|
||||||
<div class="params-wrap">
|
<div 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,13 +7,13 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="param-info">
|
<div class="param-info">
|
||||||
<div>
|
<div>
|
||||||
<span class="param-type" [ng-class]="prop.type">{{prop.type}} {{prop.format}}</span>
|
<span class="param-type" [ng-class]="prop.type">{{prop._displayType}} {{prop.format}}</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>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="param-schema" *ng-if="prop._pointer">
|
<div class="param-schema" [ng-class]="{'param-array': prop._isArray}" *ng-if="prop._pointer">
|
||||||
<json-schema pointer="{{prop._pointer}}">
|
<json-schema pointer="{{prop._pointer}}">
|
||||||
</json-schema>
|
</json-schema>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -25,11 +25,23 @@ export default class JsonSchema extends BaseComponent {
|
||||||
let schema = this.componentSchema;
|
let schema = this.componentSchema;
|
||||||
this.data = {};
|
this.data = {};
|
||||||
this.data.properties = [];
|
this.data.properties = [];
|
||||||
if (schema.type !== 'object') {
|
if (schema.type !== 'object' && schema.type !== 'array') {
|
||||||
// TODO
|
// TODO
|
||||||
this.errorMessage = 'Non-object (array-based) schemas are not implemented yet';
|
this.errorMessage = 'Non-object and non-array schemas are not implemented yet';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (schema.type === 'array') {
|
||||||
|
this._isArray = true;
|
||||||
|
this.pointer = schema.items._pointer || this.pointer;
|
||||||
|
schema = schema.items;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (schema.type === 'object') {
|
||||||
|
this.pointer = schema._pointer || this.pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!schema.properties) return;
|
if (!schema.properties) 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];
|
||||||
|
@ -53,18 +65,19 @@ export default class JsonSchema extends BaseComponent {
|
||||||
injectPropData(prop, propData) {
|
injectPropData(prop, propData) {
|
||||||
propData._name = prop;
|
propData._name = prop;
|
||||||
propData.isRequired = this.requiredMap[prop];
|
propData.isRequired = this.requiredMap[prop];
|
||||||
|
propData._displayType = propData.type;
|
||||||
if (propData.type === 'array') {
|
if (propData.type === 'array') {
|
||||||
let itemType = propData.items.type;
|
let itemType = propData.items.type;
|
||||||
if (itemType === 'object') {
|
if (itemType === 'object') {
|
||||||
itemType = propData.items.title || 'object';
|
itemType = propData.items.title || 'object';
|
||||||
propData._pointer = propData.items._pointer;
|
propData._pointer = this.pointer + '/properties/' + prop;
|
||||||
}
|
}
|
||||||
propData.type = `array of ${itemType}`;
|
propData._displayType= `array of ${itemType}`;
|
||||||
|
propData._isArray = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (propData.type === 'object') {
|
if (propData.type === 'object') {
|
||||||
propData.type = propData.title || 'object';
|
propData._displayType = propData.title || 'object';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -122,3 +122,44 @@ $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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* styles for array-schema for array */
|
||||||
|
$array-marker-font-sz: 12px;
|
||||||
|
$array-marker-line-height: 1.5;
|
||||||
|
.params-wrap.params-array:before, .params-wrap.params-array:after {
|
||||||
|
display: block;
|
||||||
|
font-weight: bold;
|
||||||
|
color: #999;
|
||||||
|
font-size: $array-marker-font-sz;
|
||||||
|
line-height: $array-marker-line-height;
|
||||||
|
}
|
||||||
|
|
||||||
|
.params-wrap.params-array:after {
|
||||||
|
content: "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
.params-wrap.params-array:before {
|
||||||
|
content: "Array [";
|
||||||
|
}
|
||||||
|
|
||||||
|
.params-wrap.params-array {
|
||||||
|
padding-left: $bullet-margin;
|
||||||
|
}
|
||||||
|
|
||||||
|
.param-schema.param-array:before {
|
||||||
|
bottom: ($array-marker-font-sz * $array-marker-line-height) / 2;
|
||||||
|
width: $bullet-margin;
|
||||||
|
border-left-style: dashed;
|
||||||
|
border-bottom: $lines-width dashed $tree-lines-color;
|
||||||
|
}
|
||||||
|
|
||||||
|
.params-wrap.params-array > .param-wrap:first-of-type > .param > .param-name:after {
|
||||||
|
content: "";
|
||||||
|
display: block;
|
||||||
|
position: absolute;
|
||||||
|
left: -$lines-width;
|
||||||
|
top: 0;
|
||||||
|
border-left: $line-border-erase;
|
||||||
|
height: ($param-name-height/2) + $cell-padding;
|
||||||
|
}
|
||||||
|
|
|
@ -79,7 +79,8 @@ export class BaseComponent {
|
||||||
* simple in-place schema dereferencing. Schema is already bundled so no need in global dereferencing.
|
* simple in-place schema dereferencing. Schema is already bundled so no need in global dereferencing.
|
||||||
* TODO: doesn't support circular references
|
* TODO: doesn't support circular references
|
||||||
*/
|
*/
|
||||||
dereference(schema = this.componentSchema) {
|
dereference(schema = Object.assign({}, this.componentSchema)) {
|
||||||
|
//schema = Object.assign({}, schema);
|
||||||
if (schema && schema.$ref) {
|
if (schema && schema.$ref) {
|
||||||
let resolved = this.schemaMgr.byPointer(schema.$ref);
|
let resolved = this.schemaMgr.byPointer(schema.$ref);
|
||||||
let baseName = JsonPointer.baseName(schema.$ref);
|
let baseName = JsonPointer.baseName(schema.$ref);
|
||||||
|
@ -96,6 +97,7 @@ export class BaseComponent {
|
||||||
this.dereference(value);
|
this.dereference(value);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
this.componentSchema = schema;
|
||||||
}
|
}
|
||||||
|
|
||||||
joinAllOf(schema = this.componentSchema) {
|
joinAllOf(schema = this.componentSchema) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user