8 files changed +1339
-101
lines changed Original file line number Diff line number Diff line change @@ -222,6 +222,20 @@ rules.set('Transform const to singleton enum', schema => {
222
222
}
223
223
} )
224
224
225
+ // @see https://json-schema.org/understanding-json-schema/reference/combining#factoring-schemas
226
+ rules . set ( 'Propagate additionalProperties=false to all factors' , schema => {
227
+ const parent = schema [ Parent ]
228
+ if ( ! parent || parent . additionalProperties !== false ) {
229
+ return
230
+ }
231
+
232
+ if ( schema . hasOwnProperty ( 'additionalProperties' ) ) {
233
+ return
234
+ }
235
+
236
+ schema . additionalProperties = false
237
+ } )
238
+
225
239
export function normalize (
226
240
rootSchema : LinkedJSONSchema ,
227
241
dereferencedPaths : DereferencedPaths ,
Original file line number Diff line number Diff line change @@ -140,8 +140,14 @@ const matchers: Record<SchemaType, (schema: JSONSchema) => boolean> = {
140
140
}
141
141
return 'enum' in schema
142
142
} ,
143
- UNNAMED_SCHEMA ( ) {
144
- return false // Explicitly handled as the default case
143
+ UNNAMED_SCHEMA ( schema ) {
144
+ return Boolean (
145
+ ! ( '$id' in schema ) &&
146
+ ( schema . patternProperties ?. length ||
147
+ schema . properties ?. length ||
148
+ // TODO: fix the typing
149
+ ( schema . required as string [ ] ) ?. length ) ,
150
+ )
145
151
} ,
146
152
UNTYPED_ARRAY ( schema ) {
147
153
return schema . type === 'array' && ! ( 'items' in schema )
Load Diff Large diffs are not rendered by default.
Original file line number Diff line number Diff line change
1
+ export const input = {
2
+ type : 'object' ,
3
+ properties : {
4
+ a : { type : 'string' } ,
5
+ b : { type : 'string' } ,
6
+ c : { type : 'string' } ,
7
+ } ,
8
+ allOf : [
9
+ { required : [ 'a' ] } ,
10
+ {
11
+ oneOf : [ { required : [ 'b' ] } , { required : [ 'c' ] } ] ,
12
+ } ,
13
+ ] ,
14
+ additionalProperties : false ,
15
+ }
Original file line number Diff line number Diff line change
1
+ export const input = {
2
+ type : 'object' ,
3
+ properties : {
4
+ a : { type : 'string' } ,
5
+ b : { type : 'string' } ,
6
+ c : { type : 'string' } ,
7
+ } ,
8
+ allOf : [
9
+ { required : [ 'a' ] } ,
10
+ {
11
+ oneOf : [ { required : [ 'b' ] } , { required : [ 'c' ] } ] ,
12
+ } ,
13
+ ] ,
14
+ }
Original file line number Diff line number Diff line change
1
+ export const input = {
2
+ type : 'object' ,
3
+ properties : {
4
+ a : { type : 'string' } ,
5
+ b : { type : 'string' } ,
6
+ c : { type : 'string' } ,
7
+ } ,
8
+ allOf : [
9
+ { required : [ 'a' ] } ,
10
+ {
11
+ oneOf : [
12
+ { required : [ 'b' ] } ,
13
+ // Non-existent property is invalid, but it's not up to JSTT to validate this
14
+ // "An object instance is valid against this keyword if every
15
+ // item in the array is the name of a property in the instance."
16
+ // @see https://json-schema.org/draft/2020-12/json-schema-validation#name-required
17
+ { required : [ 'd' ] } ,
18
+ ] ,
19
+ } ,
20
+ ] ,
21
+ }
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ export const input = {
21
21
a : { type : 'string' } ,
22
22
} ,
23
23
additionalProperties : false ,
24
- required : [ 'a' , 'b' ] ,
24
+ required : [ 'a' ] ,
25
25
} ,
26
26
} ,
27
27
required : [ 'foo' , 'bar' ] ,
0 commit comments