checkBeforeSave checks a changed response against GitHub's schema before it is saved. It returns a line saying what the check did, or an error listing the problems. A GraphQL response is checked against the query gh last sent for it, so it isn't checked until gh has sent one. With offSchema, the re
(st *state, chk *checker, name string, resp *response, offSchema bool)
| 217 | // so it's sent as stored. The line still says what the check found, because |
| 218 | // callers report off-schema values and need to know whether they really are. |
| 219 | func checkBeforeSave(st *state, chk *checker, name string, resp *response, offSchema bool) (string, error) { |
| 220 | // The checker skips responses marked off-schema, so mark it afterwards. |
| 221 | resp.OffSchema = false |
| 222 | problems, skipped, err := schemaCheck(st, chk, name, resp) |
| 223 | if err != nil { |
| 224 | return "", err |
| 225 | } |
| 226 | resp.OffSchema = offSchema |
| 227 | |
| 228 | switch { |
| 229 | case offSchema && len(problems) > 0: |
| 230 | return "Schema check: failed, saved as off-schema:\n" + strings.TrimSuffix(indentProblems(problems, " ", 0), "\n"), nil |
| 231 | case offSchema && skipped != "": |
| 232 | return "Schema check: skipped, saved as off-schema", nil |
| 233 | case offSchema: |
| 234 | return "Schema check: passed, but saved as off-schema as asked. It matches GitHub's schema, so it doesn't need --off-schema", nil |
| 235 | case len(problems) > 0: |
| 236 | return "", fmt.Errorf("the response doesn't match GitHub's schema, so it wasn't saved:\n%sFix it, or pass --off-schema to save it anyway", |
| 237 | indentProblems(problems, " ", 0)) |
| 238 | case skipped != "": |
| 239 | return skipped, nil |
| 240 | default: |
| 241 | return "Schema check: passed", nil |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | // schemaCheck checks resp against GitHub's schema. It returns the problems it |
| 246 | // found, or, when it couldn't check, a line saying why. |
no test coverage detected