feat(import): add deterministic OpenAPI normalized IR
This commit is contained in:
@@ -32,6 +32,8 @@ pub fn schema_from_openapi(
|
||||
let Some(value) = value else {
|
||||
return primitive(SchemaKind::String, required, description);
|
||||
};
|
||||
// NormalizedIR keeps composition typed; the legacy preview adapter retains
|
||||
// its historical first-branch projection for pending v1 jobs.
|
||||
let resolved = collapse_composition(value);
|
||||
|
||||
if let Some(values) = resolved.get("enum").and_then(Value::as_array) {
|
||||
@@ -100,6 +102,17 @@ pub fn schema_from_openapi(
|
||||
}
|
||||
}
|
||||
|
||||
fn collapse_composition(value: &Value) -> Value {
|
||||
for key in ["allOf", "oneOf", "anyOf"] {
|
||||
if let Some(items) = value.get(key).and_then(Value::as_array)
|
||||
&& let Some(first) = items.first()
|
||||
{
|
||||
return first.clone();
|
||||
}
|
||||
}
|
||||
value.clone()
|
||||
}
|
||||
|
||||
pub fn object_with_fields(description: Option<String>, fields: BTreeMap<String, Schema>) -> Schema {
|
||||
Schema {
|
||||
kind: SchemaKind::Object,
|
||||
@@ -190,14 +203,3 @@ fn text(value: &Value, key: &str) -> Option<String> {
|
||||
.and_then(Value::as_str)
|
||||
.map(ToOwned::to_owned)
|
||||
}
|
||||
|
||||
fn collapse_composition(value: &Value) -> Value {
|
||||
for key in ["allOf", "oneOf", "anyOf"] {
|
||||
if let Some(items) = value.get(key).and_then(Value::as_array)
|
||||
&& let Some(first) = items.first()
|
||||
{
|
||||
return first.clone();
|
||||
}
|
||||
}
|
||||
value.clone()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user