@@ -1971,7 +1971,10 @@ extension JSONSchema: Decodable {
19711971 schema = schema. nullableSchemaObject ( )
19721972 }
19731973
1974- self = schema
1974+ // Ad-hoc vendor extension support since JSONSchema does coding keys differently.
1975+ let extensions = try Self . decodeVenderExtensions ( from: decoder)
1976+
1977+ self = schema. with ( vendorExtensions: extensions)
19751978 return
19761979 }
19771980
@@ -1988,7 +1991,10 @@ extension JSONSchema: Decodable {
19881991 schema = schema. nullableSchemaObject ( )
19891992 }
19901993
1991- self = schema
1994+ // Ad-hoc vendor extension support since JSONSchema does coding keys differently.
1995+ let extensions = try Self . decodeVenderExtensions ( from: decoder)
1996+
1997+ self = schema. with ( vendorExtensions: extensions)
19921998 return
19931999 }
19942000
@@ -2004,7 +2010,10 @@ extension JSONSchema: Decodable {
20042010 schema = schema. nullableSchemaObject ( )
20052011 }
20062012
2007- self = schema
2013+ // Ad-hoc vendor extension support since JSONSchema does coding keys differently.
2014+ let extensions = try Self . decodeVenderExtensions ( from: decoder)
2015+
2016+ self = schema. with ( vendorExtensions: extensions)
20082017 return
20092018 }
20102019
@@ -2016,8 +2025,11 @@ extension JSONSchema: Decodable {
20162025 core: coreContext
20172026 )
20182027 )
2019-
2020- self = schema
2028+
2029+ // Ad-hoc vendor extension support since JSONSchema does coding keys differently.
2030+ let extensions = try Self . decodeVenderExtensions ( from: decoder)
2031+
2032+ self = schema. with ( vendorExtensions: extensions)
20212033 return
20222034 }
20232035
@@ -2132,29 +2144,30 @@ extension JSONSchema: Decodable {
21322144
21332145 self . warnings = _warnings
21342146
2135- // Ad-hoc vendor extension support since JSONSchema does coding keys differently.
2136- let extensions : [ String : AnyCodable ]
2147+ // Ad-hoc vendor extension support since JSONSchema does coding keys differently.
2148+ let extensions = try Self . decodeVenderExtensions ( from : decoder )
21372149
2150+ self . value = value. with ( vendorExtensions: extensions)
2151+ }
2152+
2153+ private static func decodeVenderExtensions( from decoder: Decoder ) throws -> [ String : AnyCodable ] {
21382154 guard VendorExtensionsConfiguration . isEnabled else {
2139- self . value = value
2140- return
2155+ return [ : ]
21412156 }
2142-
2157+
21432158 let decoded = try AnyCodable ( from: decoder) . value
2144-
2159+
21452160 guard ( decoded as? [ Any ] ) == nil else {
21462161 throw VendorExtensionDecodingError . selfIsArrayNotDict
21472162 }
2148-
2163+
21492164 guard let decodedAny = decoded as? [ String : Any ] else {
21502165 throw VendorExtensionDecodingError . foundNonStringKeys
21512166 }
2152-
2153- extensions = decodedAny
2167+
2168+ return decodedAny
21542169 . filter { $0. key. lowercased ( ) . starts ( with: " x- " ) }
21552170 . mapValues ( AnyCodable . init)
2156-
2157- self . value = value. with ( vendorExtensions: extensions)
21582171 }
21592172
21602173 private static func decodeTypes( from container: KeyedDecodingContainer < JSONSchema . HintCodingKeys > ) throws -> [ JSONType ] {
0 commit comments