(t *testing.T)
| 299 | } |
| 300 | |
| 301 | func TestClassifyExposeTopLevelOptIn(t *testing.T) { |
| 302 | doc := loadDoc(t, ` |
| 303 | openapi: 3.0.0 |
| 304 | info: { title: Test, version: 1.0.0 } |
| 305 | paths: |
| 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 | |
| 351 | func TestClassifyExposeTopLevelSingleObject(t *testing.T) { |
| 352 | doc := loadDoc(t, ` |
nothing calls this directly
no test coverage detected