diff --git a/demo/swagger.yaml b/demo/swagger.yaml
index 126d919c..d00d87a2 100644
--- a/demo/swagger.yaml
+++ b/demo/swagger.yaml
@@ -676,6 +676,13 @@ definitions:
description: Category name
type: string
minLength: 1
+ sub:
+ description: test sub Category
+ type: object
+ properties:
+ prop1:
+ type: string
+ description: The best prop1
xml:
name: Category
Dog:
diff --git a/lib/components/JsonSchema/json-schema-lazy.ts b/lib/components/JsonSchema/json-schema-lazy.ts
index a50aa65b..177d0fdc 100644
--- a/lib/components/JsonSchema/json-schema-lazy.ts
+++ b/lib/components/JsonSchema/json-schema-lazy.ts
@@ -1,6 +1,6 @@
'use strict';
-import { Component, ElementRef, ViewContainerRef, OnDestroy, Input,
+import { Component, ElementRef, ViewContainerRef, OnDestroy, OnInit, Input,
AfterViewInit, ComponentFactoryResolver, Renderer } from '@angular/core';
import { JsonSchema } from './json-schema';
@@ -15,8 +15,9 @@ var cache = {};
template: '',
styles: [':host { display:none }']
})
-export class JsonSchemaLazy implements OnDestroy, AfterViewInit {
+export class JsonSchemaLazy implements OnDestroy, OnInit, AfterViewInit {
@Input() pointer: string;
+ @Input() absolutePointer: string;
@Input() auto: boolean;
@Input() isRequestSchema: boolean;
@Input() final: boolean = false;
@@ -78,6 +79,10 @@ export class JsonSchemaLazy implements OnDestroy, AfterViewInit {
Object.assign(instance, this);
}
+ ngOnInit() {
+ if (!this.absolutePointer) this.absolutePointer = this.pointer;
+ }
+
ngAfterViewInit() {
if (!this.auto && !this.disableLazy) return;
this.loadCached();
diff --git a/lib/components/JsonSchema/json-schema.html b/lib/components/JsonSchema/json-schema.html
index 028077a4..dd6441a4 100644
--- a/lib/components/JsonSchema/json-schema.html
+++ b/lib/components/JsonSchema/json-schema.html
@@ -34,6 +34,7 @@
[{{idx}}]:
@@ -92,9 +93,9 @@
-
-
+
+
|
diff --git a/lib/components/JsonSchema/json-schema.ts b/lib/components/JsonSchema/json-schema.ts
index 323cf8af..9e2058a4 100644
--- a/lib/components/JsonSchema/json-schema.ts
+++ b/lib/components/JsonSchema/json-schema.ts
@@ -1,9 +1,19 @@
'use strict';
-import { Component, Input, Renderer, ElementRef, OnInit, ChangeDetectionStrategy } from '@angular/core';
+import { Component,
+ Input,
+ Renderer,
+ ElementRef,
+ OnInit,
+ ChangeDetectionStrategy,
+ ChangeDetectorRef
+} from '@angular/core';
-import { BaseComponent, SpecManager } from '../base';
-import { SchemaNormalizer, SchemaHelper } from '../../services/index';
+import { BaseSearchableComponent, SpecManager } from '../base';
+import { SchemaNormalizer, SchemaHelper, AppStateService } from '../../services/';
+import { JsonPointer } from '../../utils/';
+import { Zippy } from '../../shared/components';
+import { JsonSchemaLazy } from './json-schema-lazy';
@Component({
selector: 'json-schema',
@@ -11,8 +21,9 @@ import { SchemaNormalizer, SchemaHelper } from '../../services/index';
styleUrls: ['./json-schema.css'],
changeDetection: ChangeDetectionStrategy.OnPush
})
-export class JsonSchema extends BaseComponent implements OnInit {
+export class JsonSchema extends BaseSearchableComponent implements OnInit {
@Input() pointer: string;
+ @Input() absolutePointer: string;
@Input() final: boolean = false;
@Input() nestOdd: boolean;
@Input() childFor: string;
@@ -25,11 +36,18 @@ export class JsonSchema extends BaseComponent implements OnInit {
properties: any;
_isArray: boolean;
normalizer: SchemaNormalizer;
- autoExpand = false;
descendants: any;
- constructor(specMgr:SpecManager, private _renderer: Renderer, private _elementRef: ElementRef) {
- super(specMgr);
+ // @ViewChildren(Zippy) childZippies: QueryList;
+ // @ViewChildren(forwardRef(() => JsonSchemaLazy)) childSchemas: QueryList;
+
+ constructor(
+ specMgr:SpecManager,
+ app: AppStateService,
+ private _renderer: Renderer,
+ private cdr: ChangeDetectorRef,
+ private _elementRef: ElementRef) {
+ super(specMgr, app);
this.normalizer = new SchemaNormalizer(specMgr);
}
@@ -78,6 +96,8 @@ export class JsonSchema extends BaseComponent implements OnInit {
init() {
if (!this.pointer) return;
+ if (!this.absolutePointer) this.absolutePointer = this.pointer;
+
this.schema = this.componentSchema;
if (!this.schema) {
throw new Error(`Can't load component schema at ${this.pointer}`);
@@ -88,6 +108,7 @@ export class JsonSchema extends BaseComponent implements OnInit {
this.schema = this.normalizer.normalize(this.schema, this.normPointer, {resolved: true});
this.schema = SchemaHelper.unwrapArray(this.schema, this.normPointer);
this._isArray = this.schema._isArray;
+ this.absolutePointer += (this._isArray ? '/items' : '');
this.initDescendants();
this.preprocessSchema();
}
@@ -114,7 +135,9 @@ export class JsonSchema extends BaseComponent implements OnInit {
return (propSchema && propSchema.type === 'object' && propSchema._pointer);
});
- this.autoExpand = this.properties && this.properties.length === 1;
+ if (this.properties.length === 1) {
+ this.properties[0].expanded = true;
+ }
}
applyStyling() {
@@ -127,6 +150,22 @@ export class JsonSchema extends BaseComponent implements OnInit {
return item.name + (item._pointer || '');
}
+ ensureSearchIsShown(ptr: string) {
+ if (ptr.startsWith(this.absolutePointer)) {
+ let props = this.properties;
+ let relative = JsonPointer.relative(this.absolutePointer, ptr);
+ let propName;
+ if (relative.length > 1 && relative[0] === 'properties') {
+ propName = relative[1];
+ }
+ let prop = props.find(p => p._name === propName);
+ if (!prop) return;
+ prop.expanded = true;
+ this.cdr.markForCheck();
+ this.cdr.detectChanges();
+ }
+ }
+
ngOnInit() {
this.preinit();
}
diff --git a/lib/components/Redoc/redoc.ts b/lib/components/Redoc/redoc.ts
index 7bbefece..6e89080f 100644
--- a/lib/components/Redoc/redoc.ts
+++ b/lib/components/Redoc/redoc.ts
@@ -15,7 +15,7 @@ import { BaseComponent } from '../base';
import * as detectScollParent from 'scrollparent';
import { SpecManager } from '../../utils/spec-manager';
-import { OptionsService, Hash, AppStateService, SchemaHelper } from '../../services/index';
+import { SearchService, OptionsService, Hash, AppStateService, SchemaHelper } from '../../services/';
import { LazyTasksService } from '../../shared/components/LazyFor/lazy-for';
@Component({
diff --git a/lib/components/ResponsesList/responses-list.html b/lib/components/ResponsesList/responses-list.html
index 8bbd42cc..d046d43e 100644
--- a/lib/components/ResponsesList/responses-list.html
+++ b/lib/components/ResponsesList/responses-list.html
@@ -1,6 +1,6 @@
+ [type]="response.type" [(open)]="response.expanded" [empty]="response.empty" (openChange)="lazySchema.load()">