feat: preserve nested source projects across desktop and REST

This commit is contained in:
2026-09-06 00:17:20 +03:00
parent d364d3c058
commit 4e8575bd11
32 changed files with 4283 additions and 417 deletions
+76
View File
@@ -33,6 +33,79 @@ pub struct IssueDto {
pub line: Option<usize>,
#[serde(skip_serializing_if = "Option::is_none")]
pub column: Option<usize>,
#[serde(skip_serializing_if = "Option::is_none")]
pub path: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub span: Option<SpanDto>,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub related: Vec<SourceLocationDto>,
}
#[derive(Debug, Clone, Serialize)]
pub struct SpanDto {
pub start: usize,
pub end: usize,
}
impl From<oa_core::language::Span> for SpanDto {
fn from(span: oa_core::language::Span) -> Self {
Self {
start: span.start,
end: span.end,
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct SourceLocationDto {
pub path: String,
pub span: SpanDto,
}
pub(crate) fn source_issue(issue: oa_core::source_project::SourceDiagnostic) -> IssueDto {
let diagnostic = issue.diagnostic;
IssueDto {
severity: match diagnostic.severity {
oa_core::validation::Severity::Error => "error",
oa_core::validation::Severity::Warning => "warning",
},
code: diagnostic.code,
message: diagnostic.message,
field: diagnostic.field,
object_id: diagnostic.object_id,
line: Some(diagnostic.line),
column: Some(diagnostic.column),
path: Some(issue.path),
span: Some(diagnostic.span.into()),
related: issue
.related
.into_iter()
.map(|location| SourceLocationDto {
path: location.path,
span: location.span.into(),
})
.collect(),
}
}
pub(crate) fn source_error(
diagnostics: Vec<oa_core::source_project::SourceDiagnostic>,
) -> ApiError {
let code = if diagnostics
.iter()
.any(|d| d.diagnostic.code == "model_limit")
{
"model_limit"
} else {
"invalid_source_project"
};
let mut error = ApiError::new(
StatusCode::UNPROCESSABLE_ENTITY,
code,
"Source project could not be applied.",
);
error.issues = diagnostics.into_iter().map(source_issue).collect();
error
}
impl ApiError {
@@ -106,6 +179,9 @@ pub fn issues(model: &oa_core::Project) -> Vec<IssueDto> {
object_id: issue.element,
line: None,
column: None,
path: None,
span: None,
related: vec![],
})
.collect()
}