@@ -74,7 +74,9 @@ test('object with field of type object or null', (t) => {
74
74
75
75
try {
76
76
const value = stringify ( {
77
- prop : { str : 'string' }
77
+ prop : {
78
+ str : 'string'
79
+ }
78
80
} )
79
81
t . is ( value , '{"prop":{"str":"string"}}' )
80
82
} catch ( e ) {
@@ -96,7 +98,9 @@ test('object with field of type object or array', (t) => {
96
98
additionalProperties : true
97
99
} , {
98
100
type : 'array' ,
99
- items : { type : 'string' }
101
+ items : {
102
+ type : 'string'
103
+ }
100
104
} ]
101
105
}
102
106
}
@@ -105,7 +109,9 @@ test('object with field of type object or array', (t) => {
105
109
106
110
try {
107
111
const value = stringify ( {
108
- prop : { str : 'string' }
112
+ prop : {
113
+ str : 'string'
114
+ }
109
115
} )
110
116
t . is ( value , '{"prop":{"str":"string"}}' )
111
117
} catch ( e ) {
@@ -121,3 +127,61 @@ test('object with field of type object or array', (t) => {
121
127
t . fail ( )
122
128
}
123
129
} )
130
+
131
+ test ( 'object with field of type string and coercion disable ' , ( t ) => {
132
+ t . plan ( 1 )
133
+
134
+ const schema = {
135
+ title : 'object with field of type string' ,
136
+ type : 'object' ,
137
+ properties : {
138
+ str : {
139
+ anyOf : [ {
140
+ type : 'string'
141
+ } ]
142
+ }
143
+ }
144
+ }
145
+ const stringify = build ( schema )
146
+
147
+ try {
148
+ const value = stringify ( {
149
+ str : 1
150
+ } )
151
+ t . is ( value , '{"str":null}' )
152
+ } catch ( e ) {
153
+ t . fail ( )
154
+ }
155
+ } )
156
+
157
+ test ( 'object with field of type string and coercion enable ' , ( t ) => {
158
+ t . plan ( 1 )
159
+
160
+ const schema = {
161
+ title : 'object with field of type string' ,
162
+ type : 'object' ,
163
+ properties : {
164
+ str : {
165
+ anyOf : [ {
166
+ type : 'string'
167
+ } ]
168
+ }
169
+ }
170
+ }
171
+
172
+ const options = {
173
+ ajv : {
174
+ coerceTypes : true
175
+ }
176
+ }
177
+ const stringify = build ( schema , options )
178
+
179
+ try {
180
+ const value = stringify ( {
181
+ str : 1
182
+ } )
183
+ t . is ( value , '{"str":"1"}' )
184
+ } catch ( e ) {
185
+ t . fail ( )
186
+ }
187
+ } )
0 commit comments