Don't show readOnly fields in request samples (fixes #59)

This commit is contained in:
Roman Hotsiy 2016-06-18 21:02:01 +03:00
parent d57b96666b
commit 54184b9f35
5 changed files with 13 additions and 10 deletions

View File

@ -1,8 +1,8 @@
<header *ngIf="data.schemaPointer || data.samples.length"> Request samples </header> <header *ngIf="data.schemaPointer || data.samples.length"> Request samples </header>
<schema-sample *ngIf="!data.samples.length" [pointer]="data.schemaPointer"> </schema-sample> <schema-sample *ngIf="!data.samples.length" [skipReadOnly]="true" [pointer]="data.schemaPointer"> </schema-sample>
<tabs *ngIf="data.samples.length" [selected] = "selectedLang" (change)=changeLangNotify($event)> <tabs *ngIf="data.samples.length" [selected] = "selectedLang" (change)=changeLangNotify($event)>
<tab tabTitle="JSON"> <tab tabTitle="JSON">
<schema-sample [pointer]="data.schemaPointer"> </schema-sample> <schema-sample [pointer]="data.schemaPointer" [skipReadOnly]="true"> </schema-sample>
</tab> </tab>
<tab *ngFor="let sample of data.samples" [tabTitle]="sample.lang"> <tab *ngFor="let sample of data.samples" [tabTitle]="sample.lang">
<pre innerHtml="{{sample.source | prism:sample.lang}}"></pre> <pre innerHtml="{{sample.source | prism:sample.lang}}"></pre>

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
import { ElementRef } from '@angular/core'; import { ElementRef, Input } from '@angular/core';
import * as OpenAPISampler from 'openapi-sampler'; import * as OpenAPISampler from 'openapi-sampler';
@ -16,6 +16,7 @@ import { JsonFormatter } from '../../utils/JsonFormatterPipe';
export class SchemaSample extends BaseComponent { export class SchemaSample extends BaseComponent {
element: any; element: any;
data: any; data: any;
@Input() skipReadOnly:boolean;
constructor(schemaMgr:SchemaManager, elementRef:ElementRef) { constructor(schemaMgr:SchemaManager, elementRef:ElementRef) {
super(schemaMgr); super(schemaMgr);
this.element = elementRef.nativeElement; this.element = elementRef.nativeElement;
@ -38,7 +39,9 @@ export class SchemaSample extends BaseComponent {
} else { } else {
this.dereference(this.componentSchema); this.dereference(this.componentSchema);
try { try {
sample = OpenAPISampler.sample(this.componentSchema); sample = OpenAPISampler.sample(this.componentSchema, {
skipReadOnly: this.skipReadOnly
});
} catch(e) { } catch(e) {
// no sample available // no sample available
} }

View File

@ -44,7 +44,7 @@
"json-pointer": "npm:json-pointer@^0.3.0", "json-pointer": "npm:json-pointer@^0.3.0",
"json-schema-ref-parser": "npm:json-schema-ref-parser@^3.1.2", "json-schema-ref-parser": "npm:json-schema-ref-parser@^3.1.2",
"marked": "npm:marked@^0.3.5", "marked": "npm:marked@^0.3.5",
"openapi-sampler": "npm:openapi-sampler@^0.1.2", "openapi-sampler": "npm:openapi-sampler@0.2.0",
"prismjs": "npm:prismjs@^1.3.0", "prismjs": "npm:prismjs@^1.3.0",
"rxjs": "npm:rxjs@5.0.0-beta.6", "rxjs": "npm:rxjs@5.0.0-beta.6",
"scrollparent": "npm:scrollparent@^0.1.0", "scrollparent": "npm:scrollparent@^0.1.0",
@ -60,7 +60,7 @@
"systemjs/plugin-json": "github:systemjs/plugin-json@^0.1.0" "systemjs/plugin-json": "github:systemjs/plugin-json@^0.1.0"
}, },
"overrides": { "overrides": {
"npm:openapi-sampler@0.1.2": { "npm:openapi-sampler@0.2.0": {
"main": "src/openapi-sampler", "main": "src/openapi-sampler",
"format": "esm" "format": "esm"
}, },
@ -123,7 +123,7 @@
"karma-sinon": "^1.0.4", "karma-sinon": "^1.0.4",
"marked": "^0.3.5", "marked": "^0.3.5",
"node-sass": "^3.7.0", "node-sass": "^3.7.0",
"openapi-sampler": "^0.1.2", "openapi-sampler": "^0.2.0",
"phantomjs-prebuilt": "^2.1.7", "phantomjs-prebuilt": "^2.1.7",
"protractor": "^3.0.0", "protractor": "^3.0.0",
"reflect-metadata": "^0.1.2", "reflect-metadata": "^0.1.2",

View File

@ -34,7 +34,7 @@ System.config({
"json-pointer": "npm:json-pointer@0.3.0", "json-pointer": "npm:json-pointer@0.3.0",
"json-schema-ref-parser": "npm:json-schema-ref-parser@3.1.2", "json-schema-ref-parser": "npm:json-schema-ref-parser@3.1.2",
"marked": "npm:marked@0.3.5", "marked": "npm:marked@0.3.5",
"openapi-sampler": "npm:openapi-sampler@0.1.2", "openapi-sampler": "npm:openapi-sampler@0.2.0",
"prismjs": "npm:prismjs@1.3.0", "prismjs": "npm:prismjs@1.3.0",
"rxjs": "npm:rxjs@5.0.0-beta.6", "rxjs": "npm:rxjs@5.0.0-beta.6",
"scrollparent": "npm:scrollparent@0.1.0", "scrollparent": "npm:scrollparent@0.1.0",
@ -641,7 +641,7 @@ System.config({
"process": "github:jspm/nodelibs-process@0.1.2", "process": "github:jspm/nodelibs-process@0.1.2",
"util": "github:jspm/nodelibs-util@0.1.0" "util": "github:jspm/nodelibs-util@0.1.0"
}, },
"npm:openapi-sampler@0.1.2": { "npm:openapi-sampler@0.2.0": {
"process": "github:jspm/nodelibs-process@0.1.2" "process": "github:jspm/nodelibs-process@0.1.2"
}, },
"npm:os-browserify@0.1.2": { "npm:os-browserify@0.1.2": {

View File

@ -1,3 +1,3 @@
declare module "openapi-sampler" { declare module "openapi-sampler" {
export function sample(schema:any):any; export function sample(schema:any, options?:any):any;
} }