loadDoc parses an inline OpenAPI YAML/JSON document. Failures abort the test rather than returning an error so callers don't need a t.Fatal at every spec-build site.
(t *testing.T, src string)
| 11 | // test rather than returning an error so callers don't need a t.Fatal at |
| 12 | // every spec-build site. |
| 13 | func loadDoc(t *testing.T, src string) *openapi3.T { |
| 14 | t.Helper() |
| 15 | loader := openapi3.NewLoader() |
| 16 | doc, err := loader.LoadFromData([]byte(src)) |
| 17 | if err != nil { |
| 18 | t.Fatalf("load doc: %v", err) |
| 19 | } |
| 20 | if err := doc.Validate(context.Background()); err != nil { |
| 21 | // Validation failures are warnings in production code but tests |
| 22 | // should fail loudly when a fixture is malformed. |
| 23 | t.Logf("warning: doc validation: %v", err) |
| 24 | } |
| 25 | return doc |
| 26 | } |
| 27 | |
| 28 | func TestClassifySingleByID(t *testing.T) { |
| 29 | doc := loadDoc(t, ` |
no test coverage detected