diff --git a/lib/components/ResponsesList/responses-list.html b/lib/components/ResponsesList/responses-list.html
index d046d43e..23a4ae1f 100644
--- a/lib/components/ResponsesList/responses-list.html
+++ b/lib/components/ResponsesList/responses-list.html
@@ -21,6 +21,6 @@
Response Schema
+ pointer="{{response.schema ? response.pointer + '/schema' : null}}" [responseCode]="response.code">
diff --git a/lib/components/ResponsesSamples/responses-samples.html b/lib/components/ResponsesSamples/responses-samples.html
index 1b370272..7b56b1db 100644
--- a/lib/components/ResponsesSamples/responses-samples.html
+++ b/lib/components/ResponsesSamples/responses-samples.html
@@ -2,6 +2,6 @@
-
+
diff --git a/lib/components/SchemaSample/schema-sample.ts b/lib/components/SchemaSample/schema-sample.ts
index 4bbbe4d9..e0ff92b2 100644
--- a/lib/components/SchemaSample/schema-sample.ts
+++ b/lib/components/SchemaSample/schema-sample.ts
@@ -1,12 +1,15 @@
'use strict';
-import { Component, ElementRef, Input, ChangeDetectionStrategy, OnInit } from '@angular/core';
+import {Component, ElementRef, Input, ChangeDetectionStrategy, OnInit, ChangeDetectorRef} from '@angular/core';
import * as OpenAPISampler from 'openapi-sampler';
import JsonPointer from '../../utils/JsonPointer';
-import { BaseComponent, SpecManager } from '../base';
-import { SchemaNormalizer } from '../../services/schema-normalizer.service';
-import { getJsonLikeSample, getXmlLikeSample, getTextLikeSample } from '../../utils/helpers';
+import {BaseComponent, SpecManager} from '../base';
+import {SchemaNormalizer} from '../../services/schema-normalizer.service';
+import {getJsonLikeSample, getXmlLikeSample, getTextLikeSample} from '../../utils/helpers';
+
+import {Subscription} from 'rxjs/Subscription';
+import {SchemaChangerService} from "../../services/schema-changer.service";
@Component({
selector: 'schema-sample',
@@ -15,8 +18,11 @@ import { getJsonLikeSample, getXmlLikeSample, getTextLikeSample } from '../../ut
changeDetection: ChangeDetectionStrategy.OnPush
})
export class SchemaSample extends BaseComponent implements OnInit {
- @Input() pointer:string;
- @Input() skipReadOnly:boolean;
+ @Input() pointer: string;
+ @Input() skipReadOnly: boolean;
+ @Input() subscription: Subscription;
+ @Input() isRequestSample: boolean;
+ @Input() responseCode: string;
element: any;
sample: any;
@@ -24,18 +30,36 @@ export class SchemaSample extends BaseComponent implements OnInit {
textSample: string;
enableButtons: boolean = false;
- private _normalizer:SchemaNormalizer;
+ private _normalizer: SchemaNormalizer;
- constructor(specMgr:SpecManager, elementRef:ElementRef) {
+ constructor(specMgr: SpecManager,
+ elementRef: ElementRef,
+ private _schemaChanger: SchemaChangerService,
+ private _cdRef: ChangeDetectorRef) {
super(specMgr);
this.element = elementRef.nativeElement;
this._normalizer = new SchemaNormalizer(specMgr);
+ this.subscription = this._schemaChanger.selectedDescendantChanged$.subscribe(
+ descendantInfo => {
+ this.selectDescendant(descendantInfo.idx, descendantInfo.name, descendantInfo.isRequestSchema, descendantInfo.responseCode);
+ _cdRef.detectChanges();
+ });
}
init() {
+ this.selectDescendant(0, null, this.isRequestSample, this.responseCode);
+ }
+
+ selectDescendant(descendantIdx, descendantName, isRequestSchema, responseCodeIn) {
+ this.componentSchema = this.specMgr.byPointer(this.pointer || '');
+ if ((!this.componentSchema) ||
+ (isRequestSchema !== this.isRequestSample) ||
+ (responseCodeIn !== this.responseCode)) {
+ return;
+ }
this.bindEvents();
- let base:any = this.componentSchema;
+ let base: any = this.componentSchema;
let sample, xmlSample;
// got pointer not directly to the schema but e.g. to the response obj
@@ -46,8 +70,8 @@ export class SchemaSample extends BaseComponent implements OnInit {
}
// Support x-examples, allowing requests to specify an example.
- let examplePointer:string = JsonPointer.join(JsonPointer.dirName(this.pointer), 'x-examples');
- let requestExamples:any = this.specMgr.byPointer(examplePointer);
+ let examplePointer: string = JsonPointer.join(JsonPointer.dirName(this.pointer), 'x-examples');
+ let requestExamples: any = this.specMgr.byPointer(examplePointer);
if (requestExamples) {
base.examples = requestExamples;
}
@@ -55,6 +79,10 @@ export class SchemaSample extends BaseComponent implements OnInit {
this.xmlSample = base.examples && getXmlLikeSample(base.examples);
this.textSample = base.examples && getTextLikeSample(base.examples);
+ if (this.fromCache()) {
+ this.initButtons();
+ return;
+ }
let jsonLikeSample = base.examples && getJsonLikeSample(base.examples);
if (jsonLikeSample) {
sample = jsonLikeSample;
@@ -67,22 +95,23 @@ export class SchemaSample extends BaseComponent implements OnInit {
if (discriminator) {
let descendants = this.specMgr.findDerivedDefinitions(this.componentSchema._pointer || this.pointer, this.componentSchema);
if (descendants.length) {
- // TODO: sync up with dropdown
- selectedDescendant = descendants[0];
- let descSchema = this.specMgr.getDescendant(selectedDescendant, this.componentSchema);
- this.componentSchema = this._normalizer.normalize(Object.assign({}, descSchema), selectedDescendant.$ref,
- {omitParent: false});
+ selectedDescendant = descendants[descendantIdx];
+ //use this block to ignore lazy loaded dropdowns for now
+ if (descendantName == null ||
+ (selectedDescendant && selectedDescendant.name === descendantName)) {
+ let descSchema = this.specMgr.getDescendant(selectedDescendant, this.componentSchema);
+ this.componentSchema = this._normalizer.normalize(Object.assign({}, descSchema), selectedDescendant.$ref,
+ {omitParent: false});
+ } else {
+ return;
+ }
}
}
- if (this.fromCache()) {
- this.initButtons();
- return;
- }
try {
sample = OpenAPISampler.sample(this.componentSchema, {
skipReadOnly: this.skipReadOnly
});
- } catch(e) {
+ } catch (e) {
// no sample available
}
if (selectedDescendant) {
@@ -153,4 +182,8 @@ export class SchemaSample extends BaseComponent implements OnInit {
ngOnInit() {
this.preinit();
}
+
+ ngOnDestroy() {
+ this.subscription.unsubscribe();
+ }
}
diff --git a/lib/services/index.ts b/lib/services/index.ts
index 7e26d9eb..b29503f8 100644
--- a/lib/services/index.ts
+++ b/lib/services/index.ts
@@ -10,6 +10,7 @@ export * from './schema-helper.service';
export * from './warnings.service';
export * from './search.service';
+export * from './schema-changer.service';
export * from './component-parser.service';
export * from './content-projector.service';
export * from './marker.service';
diff --git a/lib/services/schema-changer.service.ts b/lib/services/schema-changer.service.ts
new file mode 100644
index 00000000..3fd3172e
--- /dev/null
+++ b/lib/services/schema-changer.service.ts
@@ -0,0 +1,20 @@
+import { Injectable } from '@angular/core';
+import { Subject } from 'rxjs/Subject';
+import {DescendantInfo} from "../utils/spec-manager";
+
+
+@Injectable()
+export class SchemaChangerService {
+
+ // Observable descendant sources
+ private selectedDescendantSource = new Subject
();
+
+ // Observable descendant streams
+ selectedDescendantChanged$ = this.selectedDescendantSource.asObservable();
+
+ // Service message commands
+ announceDescendantChange(idx: string, descendantName: string, isRequestSchema: boolean, responseCode: string) {
+ this.selectedDescendantSource.next({idx:idx, name:descendantName, isRequestSchema:isRequestSchema, responseCode:responseCode});
+ }
+
+}
\ No newline at end of file