@@ -13,21 +13,20 @@ import { buildJsonPointer, joinJsonPointer } from './pointer';
13
13
import { JsonSchema } from './schema' ;
14
14
15
15
export interface ReferenceResolver < ContextT > {
16
- ( ref : string , context ?: ContextT ) : { context ?: ContextT , schema ?: JsonObject } ;
16
+ ( ref : string , context ?: ContextT ) : { context ?: ContextT ; schema ?: JsonObject } ;
17
17
}
18
18
19
- function _getObjectSubSchema (
20
- schema : JsonSchema | undefined ,
21
- key : string ,
22
- ) : JsonObject | undefined {
19
+ function _getObjectSubSchema ( schema : JsonSchema | undefined , key : string ) : JsonObject | undefined {
23
20
if ( typeof schema !== 'object' || schema === null ) {
24
21
return undefined ;
25
22
}
26
23
27
24
// Is it an object schema?
28
25
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
+ ) {
31
30
return ( schema . properties as JsonObject ) [ key ] as JsonObject ;
32
31
}
33
32
if ( typeof schema . additionalProperties == 'object' ) {
@@ -51,7 +50,7 @@ function _visitJsonRecursive<ContextT>(
51
50
ptr : JsonPointer ,
52
51
schema ?: JsonSchema ,
53
52
refResolver ?: ReferenceResolver < ContextT > ,
54
- context ?: ContextT , // tslint:disable-line:no-any
53
+ context ?: ContextT ,
55
54
root ?: JsonObject | JsonArray ,
56
55
) : Observable < JsonValue > {
57
56
if ( schema === true || schema === false ) {
@@ -82,7 +81,7 @@ function _visitJsonRecursive<ContextT>(
82
81
refResolver ,
83
82
context ,
84
83
root || value ,
85
- ) . pipe ( tap < JsonValue > ( x => value [ i ] = x ) ) ;
84
+ ) . pipe ( tap < JsonValue > ( x => ( value [ i ] = x ) ) ) ;
86
85
} ) ,
87
86
ignoreElements ( ) ,
88
87
) ,
@@ -100,11 +99,18 @@ function _visitJsonRecursive<ContextT>(
100
99
refResolver ,
101
100
context ,
102
101
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
+ ) ;
104
110
} ) ,
105
111
ignoreElements ( ) ,
106
- ) ,
107
- observableOf ( value ) ,
112
+ ) ,
113
+ observableOf ( value ) ,
108
114
) ;
109
115
} else {
110
116
return observableOf ( value ) ;
@@ -133,12 +139,11 @@ export function visitJson<ContextT>(
133
139
visitor : JsonVisitor ,
134
140
schema ?: JsonSchema ,
135
141
refResolver ?: ReferenceResolver < ContextT > ,
136
- context ?: ContextT , // tslint:disable-line:no-any
142
+ context ?: ContextT ,
137
143
) : Observable < JsonValue > {
138
144
return _visitJsonRecursive ( json , visitor , buildJsonPointer ( [ ] ) , schema , refResolver , context ) ;
139
145
}
140
146
141
-
142
147
export function visitJsonSchema ( schema : JsonSchema , visitor : JsonSchemaVisitor ) {
143
148
if ( schema === false || schema === true ) {
144
149
// Nothing to visit.
0 commit comments