From 4c923682ba940bc56e0c71fab2a444b28ace9fca Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Wed, 27 Apr 2016 22:34:27 +0300 Subject: [PATCH] Omit readonly properties in request schemas (part of #42) --- lib/components/JsonSchema/json-schema-lazy.js | 13 +++++++++---- lib/components/JsonSchema/json-schema.html | 7 ++++--- lib/components/JsonSchema/json-schema.js | 5 ++++- lib/components/ParamsList/params-list.html | 2 +- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/lib/components/JsonSchema/json-schema-lazy.js b/lib/components/JsonSchema/json-schema-lazy.js index 8992cda958..47a9862443 100644 --- a/lib/components/JsonSchema/json-schema-lazy.js +++ b/lib/components/JsonSchema/json-schema-lazy.js @@ -14,7 +14,7 @@ var cache = {}; @Component({ selector: 'json-schema-lazy', - inputs: ['pointer', 'auto'], + inputs: ['pointer', 'auto', 'skipReadOnly'], template: '', directives: [CORE_DIRECTIVES] }) @@ -38,7 +38,7 @@ export default class JsonSchemaLazy { if (this.loaded) return; if (this.pointer) { this.dcl.loadNextToLocation(JsonSchema, this.elementRef).then((compRef) => { - compRef.instance.pointer = this.pointer; + this.initComponent(compRef); // trigger change detection compRef.hostView.changeDetectorRef.detectChanges(); }); @@ -58,7 +58,7 @@ export default class JsonSchemaLazy { // FIXME: get rid of dependency on selector if ($element.querySelector('.discriminator-wrap')) { this.dcl.loadNextToLocation(JsonSchema, this.elementRef).then((compRef) => { - compRef.instance.pointer = this.pointer; + this.initComponent(compRef); compRef.hostView.changeDetectorRef.markForCheck(); }); return; @@ -68,13 +68,18 @@ export default class JsonSchemaLazy { }); } else { cache[this.pointer] = this.dcl.loadNextToLocation(JsonSchema, this.elementRef).then((compRef) => { - compRef.instance.pointer = this.pointer; + this.initComponent(compRef); compRef.hostView.changeDetectorRef.markForCheck(); return compRef; }); } } + initComponent(compRef) { + compRef.instance.pointer = this.pointer; + compRef.instance.skipReadOnly = this.skipReadOnly; + } + ngAfterViewInit() { if (!this.auto) return; this.loadCached(); diff --git a/lib/components/JsonSchema/json-schema.html b/lib/components/JsonSchema/json-schema.html index bc3fcca85d..f633f901bc 100644 --- a/lib/components/JsonSchema/json-schema.html +++ b/lib/components/JsonSchema/json-schema.html @@ -38,8 +38,8 @@ - + @@ -47,7 +47,8 @@
- +
diff --git a/lib/components/JsonSchema/json-schema.js b/lib/components/JsonSchema/json-schema.js index 3dcd549417..56facedd98 100644 --- a/lib/components/JsonSchema/json-schema.js +++ b/lib/components/JsonSchema/json-schema.js @@ -11,7 +11,7 @@ import JsonPointer from '../../utils/JsonPointer'; templateUrl: './lib/components/JsonSchema/json-schema.html', styleUrls: ['./lib/components/JsonSchema/json-schema.css'], directives: [JsonSchema, DropDown], - inputs: ['isArray', 'final', 'nestOdd', 'childFor'] + inputs: ['isArray', 'final', 'nestOdd', 'childFor', 'skipReadOnly'] }) @Reflect.metadata('parameters', [[SchemaManager], [ElementRef]]) export default class JsonSchema extends BaseComponent { @@ -105,6 +105,9 @@ export default class JsonSchema extends BaseComponent { } return propertySchema; }); + if (this.skipReadOnly) { + props = props.filter(prop => !prop.readOnly); + } // Move discriminator field to the end of properties list if (discriminatorFieldIdx > -1) { let discrProp = props.splice(discriminatorFieldIdx, 1); diff --git a/lib/components/ParamsList/params-list.html b/lib/components/ParamsList/params-list.html index faaf4a55be..bdffe020db 100644 --- a/lib/components/ParamsList/params-list.html +++ b/lib/components/ParamsList/params-list.html @@ -31,7 +31,7 @@
Request Body

- +