TestOpenAPIBridgeResolve verifies the bridge translates the existing ResolverReq (parent column value as req.ID) into an OpenAPI CallParams with the join key in the right path-parameter slot.
(t *testing.T)
| 85 | // ResolverReq (parent column value as req.ID) into an OpenAPI CallParams |
| 86 | // with the join key in the right path-parameter slot. |
| 87 | func TestOpenAPIBridgeResolve(t *testing.T) { |
| 88 | srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 89 | if r.URL.Path != "/users/u-99" { |
| 90 | t.Errorf("path = %q", r.URL.Path) |
| 91 | } |
| 92 | w.Header().Set("Content-Type", "application/json") |
| 93 | _, _ = w.Write([]byte(`{"id":"u-99","name":"Test"}`)) |
| 94 | })) |
| 95 | defer srv.Close() |
| 96 | |
| 97 | op := openapi.OpDescriptor{ |
| 98 | OperationID: "getUserById", |
| 99 | Method: "GET", |
| 100 | PathTemplate: "/users/{userId}", |
| 101 | Mode: openapi.OpModeRowJoin, |
| 102 | PathParams: []openapi.ParamSpec{{Name: "userId", In: openapi.ParamInPath, Required: true}}, |
| 103 | } |
| 104 | spec := &openapi.Spec{ |
| 105 | Key: "is", |
| 106 | BaseURL: srv.URL, |
| 107 | Operations: []openapi.OpDescriptor{op}, |
| 108 | } |
| 109 | rt, err := openapi.NewSpecRuntime(spec, srv.Client()) |
| 110 | if err != nil { |
| 111 | t.Fatal(err) |
| 112 | } |
| 113 | caller, ok := rt.Caller("getUserById") |
| 114 | if !ok { |
| 115 | t.Fatal("caller not found") |
| 116 | } |
| 117 | |
| 118 | bridge := &openapiBridge{caller: caller, pathName: "userId"} |
| 119 | body, err := bridge.Resolve(context.Background(), ResolverReq{ID: "u-99"}) |
| 120 | if err != nil { |
| 121 | t.Fatal(err) |
| 122 | } |
| 123 | if string(body) != `{"id":"u-99","name":"Test"}` { |
| 124 | t.Errorf("body = %s", body) |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | // TestLoadOpenAPIIntegrationDormantWithoutSpecs confirms that a deployment |
| 129 | // with no config/specs directory boots cleanly — OpenAPI integration |