mirror of
https://github.com/Redocly/redoc.git
synced 2025-07-15 10:42:22 +03:00
JsonSchema fix issues with subschemas resolving
This commit is contained in:
parent
f964465513
commit
9979fab0ab
|
@ -1,5 +1,5 @@
|
||||||
<small *ng-if="errorMessage">{{errorMessage}}</small>
|
<small *ng-if="errorMessage">{{errorMessage}}</small>
|
||||||
<div class="params-wrap" [ng-class]="{'params-array': _isArray}">
|
<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">
|
||||||
|
@ -14,7 +14,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="param-schema" [ng-class]="{'param-array': prop._isArray}" *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}}" [is-array]='prop._isArray'>
|
||||||
</json-schema>
|
</json-schema>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -7,7 +7,8 @@ import {ElementRef} from 'angular2/angular2';
|
||||||
selector: 'json-schema',
|
selector: 'json-schema',
|
||||||
templateUrl: './lib/components/JsonSchema/json-schema.html',
|
templateUrl: './lib/components/JsonSchema/json-schema.html',
|
||||||
styleUrls: ['./lib/components/JsonSchema/json-schema.css'],
|
styleUrls: ['./lib/components/JsonSchema/json-schema.css'],
|
||||||
directives: [JsonSchema]
|
directives: [JsonSchema],
|
||||||
|
inputs: ['isArray']
|
||||||
})
|
})
|
||||||
export default class JsonSchema extends BaseComponent {
|
export default class JsonSchema extends BaseComponent {
|
||||||
constructor(schemaMgr, elementRef) {
|
constructor(schemaMgr, elementRef) {
|
||||||
|
@ -16,31 +17,38 @@ export default class JsonSchema extends BaseComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
prepareModel() {
|
prepareModel() {
|
||||||
|
this.data = {};
|
||||||
|
this.data.properties = [];
|
||||||
|
|
||||||
|
if (!this.componentSchema) {
|
||||||
|
// TODO
|
||||||
|
this.errorMessage = 'Can\'t load component schema';
|
||||||
|
console.warn(`${this.errorMessage}: ${this.pointer}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.dereference();
|
this.dereference();
|
||||||
this.joinAllOf();
|
let schema = this.componentSchema;
|
||||||
|
|
||||||
|
if (schema.type === 'array') {
|
||||||
|
this.isArray = true;
|
||||||
|
schema = schema.items;
|
||||||
|
}
|
||||||
|
this.joinAllOf(schema);
|
||||||
|
|
||||||
|
if (schema.type !== 'object') {
|
||||||
|
// TODO
|
||||||
|
this.errorMessage = 'Non-object and non-array schemas are not implemented yet';
|
||||||
|
console.warn(`${this.errorMessage}: ${schema.type}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.pointer = schema._pointer || this.pointer;
|
||||||
|
|
||||||
this.requiredMap = {};
|
this.requiredMap = {};
|
||||||
if (this.schema.required) {
|
if (this.schema.required) {
|
||||||
this.schema.required.forEach(prop => this.requiredMap[prop] = true);
|
this.schema.required.forEach(prop => this.requiredMap[prop] = true);
|
||||||
}
|
}
|
||||||
let schema = this.componentSchema;
|
|
||||||
this.data = {};
|
|
||||||
this.data.properties = [];
|
|
||||||
if (schema.type !== 'object' && schema.type !== 'array') {
|
|
||||||
// TODO
|
|
||||||
this.errorMessage = 'Non-object and non-array schemas are not implemented yet';
|
|
||||||
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 => {
|
||||||
|
@ -70,7 +78,7 @@ export default class JsonSchema extends BaseComponent {
|
||||||
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 = this.pointer + '/properties/' + prop;
|
propData._pointer = propData.items._pointer || this.pointer + '/properties/' + prop + '/items';
|
||||||
}
|
}
|
||||||
propData._displayType= `array of ${itemType}`;
|
propData._displayType= `array of ${itemType}`;
|
||||||
propData._isArray = true;
|
propData._isArray = true;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user