MCPcopy
hub / github.com/dosco/graphjin / TestLoadParseErrorIsWarning

Function TestLoadParseErrorIsWarning

core/openapi/integration_test.go:260–297  ·  view source on GitHub ↗

TestLoadParseErrorIsWarning confirms a malformed spec produces a warning rather than aborting load — other specs should still be processed.

(t *testing.T)

Source from the content-addressed store, hash-verified

258// warning rather than aborting load — other specs should still be
259// processed.
260func TestLoadParseErrorIsWarning(t *testing.T) {
261 dir := t.TempDir()
262 if err := os.WriteFile(filepath.Join(dir, "bad.yaml"), []byte("not: { valid: openapi"), 0o644); err != nil {
263 t.Fatal(err)
264 }
265 if err := os.WriteFile(filepath.Join(dir, "good.yaml"), []byte(`
266openapi: 3.0.0
267info: { title: ok, version: '1' }
268paths:
269 /things:
270 get:
271 operationId: listThings
272 responses:
273 '200':
274 description: ok
275 content: { application/json: { schema: { type: object } } }
276`), 0o644); err != nil {
277 t.Fatal(err)
278 }
279
280 res, err := Load(LoaderOptions{SpecsDir: dir}, nil, nil)
281 if err != nil {
282 t.Fatal(err)
283 }
284 // Bad spec produces a warning; good spec loads successfully.
285 if len(res.Registry.Specs) != 1 {
286 t.Errorf("expected 1 spec loaded, got %d", len(res.Registry.Specs))
287 }
288 var sawBadWarning bool
289 for _, w := range res.Warnings {
290 if contains(w, "bad.yaml") {
291 sawBadWarning = true
292 }
293 }
294 if !sawBadWarning {
295 t.Errorf("expected warning mentioning bad.yaml, got %v", res.Warnings)
296 }
297}

Callers

nothing calls this directly

Calls 2

LoadFunction · 0.85
containsFunction · 0.70

Tested by

no test coverage detected