|
| 1 | +package generator |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "os" |
| 6 | + "path/filepath" |
| 7 | + "testing" |
| 8 | +) |
| 9 | + |
| 10 | +func TestGenerateClientUsesCodegenMethodName(t *testing.T) { |
| 11 | + t.Parallel() |
| 12 | + |
| 13 | + tmp := t.TempDir() |
| 14 | + specPath := filepath.Join(tmp, "openapi.json") |
| 15 | + outputDir := filepath.Join(tmp, "src", "main", "java") |
| 16 | + resourceDir := filepath.Join(tmp, "src", "main", "resources") |
| 17 | + |
| 18 | + spec := `{ |
| 19 | + "openapi": "3.0.3", |
| 20 | + "info": { |
| 21 | + "title": "test", |
| 22 | + "version": "1.0.0" |
| 23 | + }, |
| 24 | + "paths": { |
| 25 | + "/v0.1/merchants/{merchant_code}/readers/{reader_id}/terminate": { |
| 26 | + "post": { |
| 27 | + "operationId": "CreateReaderTerminate", |
| 28 | + "summary": "Terminate a Reader Checkout", |
| 29 | + "parameters": [ |
| 30 | + { |
| 31 | + "name": "merchant_code", |
| 32 | + "in": "path", |
| 33 | + "required": true, |
| 34 | + "schema": { "type": "string" } |
| 35 | + }, |
| 36 | + { |
| 37 | + "name": "reader_id", |
| 38 | + "in": "path", |
| 39 | + "required": true, |
| 40 | + "schema": { "type": "string" } |
| 41 | + } |
| 42 | + ], |
| 43 | + "responses": { |
| 44 | + "204": { |
| 45 | + "description": "Terminated" |
| 46 | + } |
| 47 | + }, |
| 48 | + "tags": ["Readers"], |
| 49 | + "x-codegen": { |
| 50 | + "method_name": "terminate_checkout" |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | + } |
| 55 | +}` |
| 56 | + if err := os.WriteFile(specPath, []byte(spec), 0o644); err != nil { |
| 57 | + t.Fatalf("write spec: %v", err) |
| 58 | + } |
| 59 | + |
| 60 | + params := Params{ |
| 61 | + SpecPath: specPath, |
| 62 | + OutputDir: outputDir, |
| 63 | + ResourceDir: resourceDir, |
| 64 | + BasePackage: "com.test.sdk", |
| 65 | + } |
| 66 | + if err := Run(context.Background(), params); err != nil { |
| 67 | + t.Fatalf("run generator: %v", err) |
| 68 | + } |
| 69 | + |
| 70 | + clientPath := filepath.Join(outputDir, "com", "test", "sdk", "clients", "ReadersClient.java") |
| 71 | + content, err := os.ReadFile(clientPath) |
| 72 | + if err != nil { |
| 73 | + t.Fatalf("read generated client: %v", err) |
| 74 | + } |
| 75 | + generated := string(content) |
| 76 | + |
| 77 | + assertContains(t, generated, "void terminateCheckout(String merchantCode, String readerId)") |
| 78 | + assertContains(t, generated, "Operation ID: CreateReaderTerminate") |
| 79 | + assertNotContains(t, generated, "createReaderTerminate") |
| 80 | +} |
0 commit comments