Skip to content

Commit fca25c4

Browse files
authored
feat: plumb validation warnings into studio (#1345)
The studio currently displays: - ValidationErrors – Generated from rule evaluations and explicitly added errors. - Explicitly added Diagnostics – generally suggestions Both are transformed into a type (confusingly named Diagnostic) that includes key details like the message, line number, schema path, severity, and type. These diagnostics are then rendered in the studio. However, a category of validation issues visible in the CLI but missing from the studio are those logged via logging.LogWarning. This change ensures these warnings are also surfaced in the studio, providing a more consistent experience. https://github.com/user-attachments/assets/bd1cc8f7-2441-4a7f-bcc8-270c93006abf
1 parent 13f7ead commit fca25c4

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

internal/studio/studioHelpers.go

+43
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,12 @@ func convertSourceResultIntoSourceResponseData(sourceResult run.SourceResult, so
160160
Line: pointer.ToInt64(int64(vErr.LineNumber)),
161161
Type: vErr.Rule,
162162
})
163+
continue
163164
}
164165
}
166+
for _, w := range sourceResult.LintResult.Warnings {
167+
diagnosis = append(diagnosis, convertWarningToDiagnostic(w))
168+
}
165169
}
166170

167171
for t, d := range sourceResult.Diagnosis {
@@ -208,6 +212,45 @@ func convertSourceResultIntoSourceResponseData(sourceResult run.SourceResult, so
208212
}, nil
209213
}
210214

215+
func convertWarningToDiagnostic(w error) components.Diagnostic {
216+
if vErr, ok := w.(*vErrs.ValidationError); ok {
217+
return components.Diagnostic{
218+
Message: vErr.Message,
219+
Severity: string(vErr.Severity),
220+
Line: pointer.ToInt64(int64(vErr.LineNumber)),
221+
Type: vErr.Rule,
222+
Path: []string{vErr.Path},
223+
}
224+
}
225+
226+
if uErr, ok := w.(*vErrs.UnsupportedError); ok {
227+
return components.Diagnostic{
228+
Message: uErr.Message,
229+
Line: pointer.ToInt64(int64(uErr.LineNumber)),
230+
Severity: "warn",
231+
Type: "Unsupported",
232+
}
233+
}
234+
235+
// TODO: Try to extract the warning type, message, and line number at a minimum
236+
// parts := strings.Split(w.Error(), ":")
237+
// if len(parts) == 2 {
238+
// warnType := strings.TrimSpace(parts[0])
239+
// message := strings.TrimSpace(parts[1])
240+
// return components.Diagnostic{
241+
// Message: message,
242+
// Severity: "warn",
243+
// Type: warnType,
244+
// }
245+
// }
246+
247+
return components.Diagnostic{
248+
Message: w.Error(),
249+
Severity: "warn",
250+
Type: "Warnings",
251+
}
252+
}
253+
211254
func convertWorkflowToComponentsWorkflow(w workflow.Workflow, workingDir string) (components.Workflow, error) {
212255
// 1. Marshal to JSON
213256
// 2. Unmarshal to components.Workflow

internal/validation/openapi.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ func Validate(ctx context.Context, outputLogger log.Logger, schema []byte, schem
331331

332332
if len(vErrs) > 0 {
333333
status = "OpenAPI document invalid ✖"
334-
} else if len(vErrs) > 0 {
334+
} else if len(vWarns) > 0 {
335335
status = "OpenAPI document valid with warnings ⚠"
336336
}
337337

0 commit comments

Comments
 (0)