Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions src/api/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,38 @@ pub struct Type {

impl Type {
pub(crate) fn from_schema(name: String, s: SchemaObject) -> anyhow::Result<Self> {
let data = match s.instance_type {
Some(SingleOrVec::Single(it)) => match *it {
let instance_type = match &s.instance_type {
Some(ty) => Some(ty),
None => {
let mut result = None;

for variant in s
.subschemas
.iter()
.filter_map(|s| s.one_of.as_ref())
.flatten()
{
let Schema::Object(schema) = variant else {
bail!("unsupported: boolean oneOf schema");
};

if let Some(ty) = &schema.instance_type {
if let Some(res_ty) = result {
if res_ty != ty {
bail!("unsupported: oneOf schemas with different types");
}
} else {
result = Some(ty);
}
}
}

result
}
};

let data = match instance_type {
Some(SingleOrVec::Single(it)) => match **it {
InstanceType::Object => {
let obj = s.object.unwrap_or_default();
TypeData::from_object_schema(*obj, s.extensions, s.subschemas)?
Expand Down Expand Up @@ -126,7 +156,7 @@ impl Type {
_ => bail!("unsupported type {it:?}"),
},
Some(SingleOrVec::Vec(_)) => bail!("unsupported: multiple types"),
None => bail!("unsupported: no type"),
None => bail!("unsupported: schema without a type"),
};

let metadata = s.metadata.unwrap_or_default();
Expand Down
Loading