Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid console view when reusing handlers in API #7203

Open
ekeren opened this issue Oct 27, 2024 · 4 comments
Open

Invalid console view when reusing handlers in API #7203

ekeren opened this issue Oct 27, 2024 · 4 comments
Labels
🐛 bug Something isn't working

Comments

@ekeren
Copy link

ekeren commented Oct 27, 2024

I tried this:

bring cloud;

let api = new cloud.Api();
let handler = inflight () => {};

api.get("/shared-handler" , handler);
api.post("/shared-handler" , handler);
api.get("/private-handler" , inflight () => {}); 
api.post("/private-handler" , inflight () => {}); 

This happened:

image

notice missing POST on shared-handler

I expected this:

image

Is there a workaround?

No response

Anything else?

No response

Wing Version

0.85.22

Node.js Version

No response

Platform(s)

No response

Community Notes

  • Please vote by adding a 👍 reaction to the issue to help us prioritize.
  • If you are interested to work on this issue, please leave a comment.
@ekeren ekeren added the 🐛 bug Something isn't working label Oct 27, 2024
@eladb
Copy link
Contributor

eladb commented Oct 27, 2024

How does this behave at runtime? Is this just a console issue?

@ekeren ekeren changed the title can reuse handler can't reuse handler Oct 29, 2024
@ekeren
Copy link
Author

ekeren commented Oct 29, 2024

bring cloud;
bring http;
bring expect;

let api = new cloud.Api();
let handler = inflight () => {return { status: 200};};

api.get("/shared-handler" , handler);
api.post("/shared-handler" , handler);
api.get("/private-handler" , inflight () => {return { status: 200};}); 
api.post("/private-handler" , inflight () => {return { status: 200};}); 

test "A" {
  expect.equal(
    http.post("{api.url}/shared-handler").status,
    http.post("{api.url}/private-handler").status
  ); 

  expect.equal(
    http.get("{api.url}/shared-handler").status,
    http.get("{api.url}/private-handler").status
  ); 
}

The test pass, so it is just a console issue

@eladb eladb changed the title can't reuse handler Invalid console view when reusing handlers in API Oct 30, 2024
@eladb
Copy link
Contributor

eladb commented Oct 30, 2024

@skyrpex can you take a quick look?

@skyrpex
Copy link
Contributor

skyrpex commented Nov 6, 2024

I think it's on the previous parts of the toolchain. I modified the example a bit:

bring cloud;

let api = new cloud.Api();
let handler = inflight () => {};

api.get("/my-shared-handler1" , handler);
api.post("/my-shared-handler2" , handler);
api.get("/my-private-handler3" , inflight () => {}); 
api.post("/my-private-handler4" , inflight () => {}); 

and then run wing compile demo/main.w -t sim, the tree.json file is missing the second shared handler (look for my-shared-handler2):

{
  "version": "tree-0.1",
  "tree": {
    "id": "root",
    "path": "root",
    "children": {
      "Default": {
        "id": "Default",
        "path": "root/Default",
        "children": {
          "Api": {
            "id": "Api",
            "path": "root/Default/Api",
            "children": {
              "Endpoint": {
                "id": "Endpoint",
                "path": "root/Default/Api/Endpoint",
                "constructInfo": {
                  "fqn": "@winglang/sdk.cloud.Endpoint",
                  "version": "0.0.0"
                },
                "display": {
                  "title": "Endpoint",
                  "description": "Api root/Default/Api",
                  "hidden": true
                }
              },
              "Policy": {
                "id": "Policy",
                "path": "root/Default/Api/Policy",
                "constructInfo": {
                  "fqn": "@winglang/sdk.sim.Policy",
                  "version": "0.0.0"
                },
                "display": {
                  "title": "Policy",
                  "description": "A simulated resource policy",
                  "hidden": true
                }
              },
              "OnRequestHandler0": {
                "id": "OnRequestHandler0",
                "path": "root/Default/Api/OnRequestHandler0",
                "constructInfo": {
                  "fqn": "@winglang/sdk.cloud.Function",
                  "version": "0.0.0"
                },
                "display": {
                  "title": "GET /my-shared-handler1",
                  "description": "A cloud function (FaaS)",
                  "sourceModule": "@winglang/sdk"
                }
              },
              "ApiEventMapping0": {
                "id": "ApiEventMapping0",
                "path": "root/Default/Api/ApiEventMapping0",
                "constructInfo": {
                  "fqn": "@winglang/sdk.std.Resource",
                  "version": "0.0.0"
                },
                "display": {
                  "hidden": true
                }
              },
              "OnRequestHandler1": {
                "id": "OnRequestHandler1",
                "path": "root/Default/Api/OnRequestHandler1",
                "constructInfo": {
                  "fqn": "@winglang/sdk.cloud.Function",
                  "version": "0.0.0"
                },
                "display": {
                  "title": "GET /my-private-handler3",
                  "description": "A cloud function (FaaS)",
                  "sourceModule": "@winglang/sdk"
                }
              },
              "ApiEventMapping1": {
                "id": "ApiEventMapping1",
                "path": "root/Default/Api/ApiEventMapping1",
                "constructInfo": {
                  "fqn": "@winglang/sdk.std.Resource",
                  "version": "0.0.0"
                },
                "display": {
                  "hidden": true
                }
              },
              "OnRequestHandler2": {
                "id": "OnRequestHandler2",
                "path": "root/Default/Api/OnRequestHandler2",
                "constructInfo": {
                  "fqn": "@winglang/sdk.cloud.Function",
                  "version": "0.0.0"
                },
                "display": {
                  "title": "POST /my-private-handler4",
                  "description": "A cloud function (FaaS)",
                  "sourceModule": "@winglang/sdk"
                }
              },
              "ApiEventMapping2": {
                "id": "ApiEventMapping2",
                "path": "root/Default/Api/ApiEventMapping2",
                "constructInfo": {
                  "fqn": "@winglang/sdk.std.Resource",
                  "version": "0.0.0"
                },
                "display": {
                  "hidden": true
                }
              }
            },
            "constructInfo": {
              "fqn": "@winglang/sdk.cloud.Api",
              "version": "0.0.0"
            },
            "display": {
              "title": "Api",
              "description": "A REST API endpoint"
            }
          },
          "$Closure1_0": {
            "id": "$Closure1_0",
            "path": "root/Default/$Closure1_0",
            "constructInfo": {
              "fqn": "@winglang/sdk.std.AutoIdResource",
              "version": "0.0.0"
            },
            "display": {
              "hidden": true
            }
          },
          "$Closure2_0": {
            "id": "$Closure2_0",
            "path": "root/Default/$Closure2_0",
            "constructInfo": {
              "fqn": "@winglang/sdk.std.AutoIdResource",
              "version": "0.0.0"
            },
            "display": {
              "hidden": true
            }
          },
          "$Closure3_0": {
            "id": "$Closure3_0",
            "path": "root/Default/$Closure3_0",
            "constructInfo": {
              "fqn": "@winglang/sdk.std.AutoIdResource",
              "version": "0.0.0"
            },
            "display": {
              "hidden": true
            }
          }
        },
        "constructInfo": {
          "fqn": "@winglang/sdk.std.Resource",
          "version": "0.0.0"
        },
        "display": {}
      },
      "ParameterRegistrar": {
        "id": "ParameterRegistrar",
        "path": "root/ParameterRegistrar",
        "constructInfo": {
          "fqn": "@winglang/sdk.platform.ParameterRegistrar",
          "version": "0.0.0"
        },
        "display": {
          "hidden": true
        }
      }
    },
    "constructInfo": {
      "fqn": "@winglang/sdk.core.App",
      "version": "0.0.0"
    },
    "display": {}
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants