Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: plumb validation warnings into studio #1345

Merged
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
43 changes: 43 additions & 0 deletions internal/studio/studioHelpers.go
Original file line number Diff line number Diff line change
@@ -160,8 +160,12 @@ func convertSourceResultIntoSourceResponseData(sourceResult run.SourceResult, so
Line: pointer.ToInt64(int64(vErr.LineNumber)),
Type: vErr.Rule,
})
continue
}
}
for _, w := range sourceResult.LintResult.Warnings {
diagnosis = append(diagnosis, convertWarningToDiagnostic(w))
}
}

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

func convertWarningToDiagnostic(w error) components.Diagnostic {
if vErr, ok := w.(*vErrs.ValidationError); ok {
return components.Diagnostic{
Message: vErr.Message,
Severity: string(vErr.Severity),
Line: pointer.ToInt64(int64(vErr.LineNumber)),
Type: vErr.Rule,
Path: []string{vErr.Path},
}
}

if uErr, ok := w.(*vErrs.UnsupportedError); ok {
return components.Diagnostic{
Message: uErr.Message,
Line: pointer.ToInt64(int64(uErr.LineNumber)),
Severity: "warn",
Type: "Unsupported",
}
}

// TODO: Try to extract the warning type, message, and line number at a minimum
// parts := strings.Split(w.Error(), ":")
// if len(parts) == 2 {
// warnType := strings.TrimSpace(parts[0])
// message := strings.TrimSpace(parts[1])
// return components.Diagnostic{
// Message: message,
// Severity: "warn",
// Type: warnType,
// }
// }

return components.Diagnostic{
Message: w.Error(),
Severity: "warn",
Type: "Warnings",
}
}

func convertWorkflowToComponentsWorkflow(w workflow.Workflow, workingDir string) (components.Workflow, error) {
// 1. Marshal to JSON
// 2. Unmarshal to components.Workflow
2 changes: 1 addition & 1 deletion internal/validation/openapi.go
Original file line number Diff line number Diff line change
@@ -331,7 +331,7 @@ func Validate(ctx context.Context, outputLogger log.Logger, schema []byte, schem

if len(vErrs) > 0 {
status = "OpenAPI document invalid ✖"
} else if len(vErrs) > 0 {
} else if len(vWarns) > 0 {
status = "OpenAPI document valid with warnings ⚠"
}

Loading