Skip to content

Commit

Permalink
Omit readonly properties in request schemas (part of #42)
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanHotsiy committed Apr 27, 2016
1 parent 900ecaa commit 4c92368
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
13 changes: 9 additions & 4 deletions lib/components/JsonSchema/json-schema-lazy.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var cache = {};

@Component({
selector: 'json-schema-lazy',
inputs: ['pointer', 'auto'],
inputs: ['pointer', 'auto', 'skipReadOnly'],
template: '',
directives: [CORE_DIRECTIVES]
})
Expand All @@ -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();
});
Expand All @@ -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;
Expand All @@ -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();
Expand Down
7 changes: 4 additions & 3 deletions lib/components/JsonSchema/json-schema.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,17 @@
</tr>
<tr class="param-schema" [ngClass]="{'param-array': prop._isArray, 'last': last}" *ngIf="prop._pointer">
<td colspan="2">
<json-schema pointer="{{prop._pointer}}" [isArray]='prop._isArray'
class="nested-schema" [nestOdd]="!nestOdd" [attr.nesteven]="!nestOdd">
<json-schema class="nested-schema" pointer="{{prop._pointer}}" [isArray]='prop._isArray'
[nestOdd]="!nestOdd" [skipReadOnly]="skipReadOnly" [attr.nesteven]="!nestOdd">
</json-schema>
</td>
</tr>
</template>
<tr *ngIf="schema.derived.length" class="param-wrap discriminator-wrap" [ngClass]="{'empty': derivedEmtpy}">
<td colspan="2">
<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>
</div>
</td>
Expand Down
5 changes: 4 additions & 1 deletion lib/components/JsonSchema/json-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/components/ParamsList/params-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ <h5 class="param-list-header" *ngIf="data.bodyParam"> Request Body </h5>
<div class="body-param-description" innerHtml="{{data.bodyParam.description | marked}}"></div>
<div>
<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>
</div>
</div>

0 comments on commit 4c92368

Please sign in to comment.