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

Function TestClassifyExposeTopLevelOptIn

core/openapi/classifier_test.go:301–349  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

299}
300
301func TestClassifyExposeTopLevelOptIn(t *testing.T) {
302 doc := loadDoc(t, `
303openapi: 3.0.0
304info: { title: Test, version: 1.0.0 }
305paths:
306 /api/dataset/{datasetId}/users.json:
307 get:
308 operationId: exportUsers
309 parameters:
310 - { name: datasetId, in: path, required: true, schema: { type: string } }
311 responses:
312 '200':
313 description: ok
314 content:
315 application/json:
316 schema:
317 type: object
318 properties:
319 items:
320 type: array
321 items:
322 type: object
323 properties:
324 id: { type: string }
325`)
326
327 spec := &Spec{Key: "is"}
328
329 // Default: skipped.
330 ops, _ := classifyAll(spec, doc, SpecConfig{})
331 if len(ops) != 1 {
332 t.Fatalf("want 1 op, got %d", len(ops))
333 }
334 if ops[0].Mode != OpModeSkipped {
335 t.Errorf("default mode = %v, want OpModeSkipped", ops[0].Mode)
336 }
337 if !contains(ops[0].SkipReason, "expose_top_level") {
338 t.Errorf("SkipReason = %q; should mention expose_top_level", ops[0].SkipReason)
339 }
340
341 // Opt-in: classified as list (response wraps an array).
342 cfg := SpecConfig{Operations: map[string]OperationOverride{
343 "exportUsers": {ExposeTopLevel: true},
344 }}
345 ops, _ = classifyAll(spec, doc, cfg)
346 if ops[0].Mode != OpModeList {
347 t.Errorf("opt-in mode = %v, want OpModeList", ops[0].Mode)
348 }
349}
350
351func TestClassifyExposeTopLevelSingleObject(t *testing.T) {
352 doc := loadDoc(t, `

Callers

nothing calls this directly

Calls 3

loadDocFunction · 0.85
classifyAllFunction · 0.85
containsFunction · 0.70

Tested by

no test coverage detected