@@ -92,8 +92,38 @@ pub struct Type {
9292
9393impl Type {
9494 pub ( crate ) fn from_schema ( name : String , s : SchemaObject ) -> anyhow:: Result < Self > {
95- let data = match s. instance_type {
96- Some ( SingleOrVec :: Single ( it) ) => match * it {
95+ let instance_type = match & s. instance_type {
96+ Some ( ty) => Some ( ty) ,
97+ None => {
98+ let mut result = None ;
99+
100+ for variant in s
101+ . subschemas
102+ . iter ( )
103+ . filter_map ( |s| s. one_of . as_ref ( ) )
104+ . flatten ( )
105+ {
106+ let Schema :: Object ( schema) = variant else {
107+ bail ! ( "unsupported: boolean oneOf schema" ) ;
108+ } ;
109+
110+ if let Some ( ty) = & schema. instance_type {
111+ if let Some ( res_ty) = result {
112+ if res_ty != ty {
113+ bail ! ( "unsupported: oneOf schemas with different types" ) ;
114+ }
115+ } else {
116+ result = Some ( ty) ;
117+ }
118+ }
119+ }
120+
121+ result
122+ }
123+ } ;
124+
125+ let data = match instance_type {
126+ Some ( SingleOrVec :: Single ( it) ) => match * * it {
97127 InstanceType :: Object => {
98128 let obj = s. object . unwrap_or_default ( ) ;
99129 TypeData :: from_object_schema ( * obj, s. extensions , s. subschemas ) ?
@@ -126,7 +156,7 @@ impl Type {
126156 _ => bail ! ( "unsupported type {it:?}" ) ,
127157 } ,
128158 Some ( SingleOrVec :: Vec ( _) ) => bail ! ( "unsupported: multiple types" ) ,
129- None => bail ! ( "unsupported: no type" ) ,
159+ None => bail ! ( "unsupported: schema without a type" ) ,
130160 } ;
131161
132162 let metadata = s. metadata . unwrap_or_default ( ) ;
0 commit comments