Omit readonly properties in request schemas (part of #42)

This commit is contained in:
Roman Hotsiy 2016-04-27 22:34:27 +03:00
parent 900ecaa2cc
commit 4c923682ba
4 changed files with 18 additions and 9 deletions

View File

@ -14,7 +14,7 @@ var cache = {};
@Component({ @Component({
selector: 'json-schema-lazy', selector: 'json-schema-lazy',
inputs: ['pointer', 'auto'], inputs: ['pointer', 'auto', 'skipReadOnly'],
template: '', template: '',
directives: [CORE_DIRECTIVES] directives: [CORE_DIRECTIVES]
}) })
@ -38,7 +38,7 @@ export default class JsonSchemaLazy {
if (this.loaded) return; if (this.loaded) return;
if (this.pointer) { if (this.pointer) {
this.dcl.loadNextToLocation(JsonSchema, this.elementRef).then((compRef) => { this.dcl.loadNextToLocation(JsonSchema, this.elementRef).then((compRef) => {
compRef.instance.pointer = this.pointer; this.initComponent(compRef);
// trigger change detection // trigger change detection
compRef.hostView.changeDetectorRef.detectChanges(); compRef.hostView.changeDetectorRef.detectChanges();
}); });
@ -58,7 +58,7 @@ export default class JsonSchemaLazy {
// FIXME: get rid of dependency on selector // FIXME: get rid of dependency on selector
if ($element.querySelector('.discriminator-wrap')) { if ($element.querySelector('.discriminator-wrap')) {
this.dcl.loadNextToLocation(JsonSchema, this.elementRef).then((compRef) => { this.dcl.loadNextToLocation(JsonSchema, this.elementRef).then((compRef) => {
compRef.instance.pointer = this.pointer; this.initComponent(compRef);
compRef.hostView.changeDetectorRef.markForCheck(); compRef.hostView.changeDetectorRef.markForCheck();
}); });
return; return;
@ -68,13 +68,18 @@ export default class JsonSchemaLazy {
}); });
} else { } else {
cache[this.pointer] = this.dcl.loadNextToLocation(JsonSchema, this.elementRef).then((compRef) => { cache[this.pointer] = this.dcl.loadNextToLocation(JsonSchema, this.elementRef).then((compRef) => {
compRef.instance.pointer = this.pointer; this.initComponent(compRef);
compRef.hostView.changeDetectorRef.markForCheck(); compRef.hostView.changeDetectorRef.markForCheck();
return compRef; return compRef;
}); });
} }
} }
initComponent(compRef) {
compRef.instance.pointer = this.pointer;
compRef.instance.skipReadOnly = this.skipReadOnly;
}
ngAfterViewInit() { ngAfterViewInit() {
if (!this.auto) return; if (!this.auto) return;
this.loadCached(); this.loadCached();

View File

@ -38,8 +38,8 @@
</tr> </tr>
<tr class="param-schema" [ngClass]="{'param-array': prop._isArray, 'last': last}" *ngIf="prop._pointer"> <tr class="param-schema" [ngClass]="{'param-array': prop._isArray, 'last': last}" *ngIf="prop._pointer">
<td colspan="2"> <td colspan="2">
<json-schema pointer="{{prop._pointer}}" [isArray]='prop._isArray' <json-schema class="nested-schema" pointer="{{prop._pointer}}" [isArray]='prop._isArray'
class="nested-schema" [nestOdd]="!nestOdd" [attr.nesteven]="!nestOdd"> [nestOdd]="!nestOdd" [skipReadOnly]="skipReadOnly" [attr.nesteven]="!nestOdd">
</json-schema> </json-schema>
</td> </td>
</tr> </tr>
@ -47,7 +47,8 @@
<tr *ngIf="schema.derived.length" class="param-wrap discriminator-wrap" [ngClass]="{'empty': derivedEmtpy}"> <tr *ngIf="schema.derived.length" class="param-wrap discriminator-wrap" [ngClass]="{'empty': derivedEmtpy}">
<td colspan="2"> <td colspan="2">
<div class="derived-schema" *ngFor="#derived of schema.derived" [ngClass]="{active: derived.active}"> <div class="derived-schema" *ngFor="#derived of schema.derived" [ngClass]="{active: derived.active}">
<json-schema *ngIf="!derived.empty" [childFor]="pointer" pointer="{{derived.$ref}}" [final]="derived.final" class="discriminator-part"> <json-schema class="discriminator-part" *ngIf="!derived.empty" [childFor]="pointer"
pointer="{{derived.$ref}}" [final]="derived.final" [skipReadOnly]="skipReadOnly">
</json-schema> </json-schema>
</div> </div>
</td> </td>

View File

@ -11,7 +11,7 @@ import JsonPointer from '../../utils/JsonPointer';
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, DropDown], directives: [JsonSchema, DropDown],
inputs: ['isArray', 'final', 'nestOdd', 'childFor'] inputs: ['isArray', 'final', 'nestOdd', 'childFor', 'skipReadOnly']
}) })
@Reflect.metadata('parameters', [[SchemaManager], [ElementRef]]) @Reflect.metadata('parameters', [[SchemaManager], [ElementRef]])
export default class JsonSchema extends BaseComponent { export default class JsonSchema extends BaseComponent {
@ -105,6 +105,9 @@ export default class JsonSchema extends BaseComponent {
} }
return propertySchema; return propertySchema;
}); });
if (this.skipReadOnly) {
props = props.filter(prop => !prop.readOnly);
}
// Move discriminator field to the end of properties list // Move discriminator field to the end of properties list
if (discriminatorFieldIdx > -1) { if (discriminatorFieldIdx > -1) {
let discrProp = props.splice(discriminatorFieldIdx, 1); let discrProp = props.splice(discriminatorFieldIdx, 1);

View File

@ -31,7 +31,7 @@
<div class="body-param-description" innerHtml="{{data.bodyParam.description | marked}}"></div> <div class="body-param-description" innerHtml="{{data.bodyParam.description | marked}}"></div>
<div> <div>
<br> <br>
<json-schema-lazy [auto]="true" pointer="{{data.bodyParam.pointer}}/schema"> <json-schema-lazy [skipReadOnly]="true" [auto]="true" pointer="{{data.bodyParam.pointer}}/schema">
</json-schema-lazy> </json-schema-lazy>
</div> </div>
</div> </div>