@@ -13,21 +13,20 @@ import { buildJsonPointer, joinJsonPointer } from './pointer';
1313import { JsonSchema } from './schema' ;
1414
1515export interface ReferenceResolver < ContextT > {
16- ( ref : string , context ?: ContextT ) : { context ?: ContextT , schema ?: JsonObject } ;
16+ ( ref : string , context ?: ContextT ) : { context ?: ContextT ; schema ?: JsonObject } ;
1717}
1818
19- function _getObjectSubSchema (
20- schema : JsonSchema | undefined ,
21- key : string ,
22- ) : JsonObject | undefined {
19+ function _getObjectSubSchema ( schema : JsonSchema | undefined , key : string ) : JsonObject | undefined {
2320 if ( typeof schema !== 'object' || schema === null ) {
2421 return undefined ;
2522 }
2623
2724 // Is it an object schema?
2825 if ( typeof schema . properties == 'object' || schema . type == 'object' ) {
29- if ( typeof schema . properties == 'object'
30- && typeof ( schema . properties as JsonObject ) [ key ] == 'object' ) {
26+ if (
27+ typeof schema . properties == 'object' &&
28+ typeof ( schema . properties as JsonObject ) [ key ] == 'object'
29+ ) {
3130 return ( schema . properties as JsonObject ) [ key ] as JsonObject ;
3231 }
3332 if ( typeof schema . additionalProperties == 'object' ) {
@@ -51,7 +50,7 @@ function _visitJsonRecursive<ContextT>(
5150 ptr : JsonPointer ,
5251 schema ?: JsonSchema ,
5352 refResolver ?: ReferenceResolver < ContextT > ,
54- context ?: ContextT , // tslint:disable-line:no-any
53+ context ?: ContextT ,
5554 root ?: JsonObject | JsonArray ,
5655) : Observable < JsonValue > {
5756 if ( schema === true || schema === false ) {
@@ -82,7 +81,7 @@ function _visitJsonRecursive<ContextT>(
8281 refResolver ,
8382 context ,
8483 root || value ,
85- ) . pipe ( tap < JsonValue > ( x => value [ i ] = x ) ) ;
84+ ) . pipe ( tap < JsonValue > ( x => ( value [ i ] = x ) ) ) ;
8685 } ) ,
8786 ignoreElements ( ) ,
8887 ) ,
@@ -100,11 +99,18 @@ function _visitJsonRecursive<ContextT>(
10099 refResolver ,
101100 context ,
102101 root || value ,
103- ) . pipe ( tap < JsonValue > ( x => value [ key ] = x ) ) ;
102+ ) . pipe (
103+ tap < JsonValue > ( x => {
104+ const descriptor = Object . getOwnPropertyDescriptor ( value , key ) ;
105+ if ( descriptor && descriptor . writable && value [ key ] !== x ) {
106+ value [ key ] = x ;
107+ }
108+ } ) ,
109+ ) ;
104110 } ) ,
105111 ignoreElements ( ) ,
106- ) ,
107- observableOf ( value ) ,
112+ ) ,
113+ observableOf ( value ) ,
108114 ) ;
109115 } else {
110116 return observableOf ( value ) ;
@@ -133,12 +139,11 @@ export function visitJson<ContextT>(
133139 visitor : JsonVisitor ,
134140 schema ?: JsonSchema ,
135141 refResolver ?: ReferenceResolver < ContextT > ,
136- context ?: ContextT , // tslint:disable-line:no-any
142+ context ?: ContextT ,
137143) : Observable < JsonValue > {
138144 return _visitJsonRecursive ( json , visitor , buildJsonPointer ( [ ] ) , schema , refResolver , context ) ;
139145}
140146
141-
142147export function visitJsonSchema ( schema : JsonSchema , visitor : JsonSchemaVisitor ) {
143148 if ( schema === false || schema === true ) {
144149 // Nothing to visit.
0 commit comments