winglang / wing

A programming language for the cloud ☁️ A unified programming model, combining infrastructure and runtime code into one language ⚡
https://winglang.io
Other
4.6k stars 180 forks source link

tsoa service doesn't work from two different entrypoint locations #6380

Open ekeren opened 2 weeks ago

ekeren commented 2 weeks ago

I tried this:

I tried using the tsoa service from two different entrypoints (different directories).

It turns out that the folder resolution is based on the location of the entrypoint (*.main.w file)

This happened:

currently the tsoa service is dependant on the entrypoint location, which makes it impossible to work with.

I expected this:

to work the same from any place

Is there a workaround?

No response

Anything else?

No response

Wing Version

No response

Node.js Version

No response

Platform(s)

No response

Community Notes

eladb commented 2 weeks ago

I think the library should require that an absolute path and add support for __dirname as soon as possible.

And we should deprecate entrypointDir

ekeren commented 2 weeks ago

You'll notice that:

Given the following:

.
├── package.json
├── src
│   ├── controllers
│   │   └── user.ts
│   └── wing
│       ├── main.w
│       ├── my_api.w
│       └── subfolder
│           └── main.w
└── tsconfig.json

4 directories, 6 files

./package.json

{
  "name": "my-wing-app",
  "version": "0.0.0",
  "description": "A description of my Wing application",
  "author": "Your Name",
  "license": "MIT",
  "wing": true,
  "dependencies": {
    "@winglibs/tsoa": "^0.1.8"
  }
}

./tsconfig.json

{
    "compilerOptions": {
        "noEmit": true,
        "experimentalDecorators": true,
        "module": "ESNext",
        "moduleResolution": "Bundler",
        "lib": ["ESNext"],
        "target": "ESNext",
        "allowArbitraryExtensions": true,
        "allowImportingTsExtensions": false,
        "strict": true,
        "forceConsistentCasingInFileNames": true,
        "isolatedModules": true,
        "noPropertyAccessFromIndexSignature": true,
        "noUncheckedIndexedAccess": true,
        "downlevelIteration": false,
        "moduleDetection": "force"
    },
    "exclude": ["build/", "cdk.out/", "node_modules/"]
}

./src/controllers/user.ts

// src/users/usersController.ts
import {
  Body,
  Controller,
  Get,
  Path,
  Post,
  Query,
  Route,
  SuccessResponse,
} from "tsoa";

@Route("users")
export class UsersController extends Controller {
  @Get("{userId}")
  public async getUser(
    @Path() userId: number,
    @Query() name?: string
  ): Promise<string> {
    return "new UsersService().get(userId, name);"
  }

  @SuccessResponse("201", "Created") // Custom success response
  @Post()
  public async createUser(
    @Body() requestBody: number
  ): Promise<void> {
    this.setStatus(201); // set return status 201
    return;
  }
}

./src/wing/subfolder/main.w

bring "../my_api.w" as api;

new api.Service();

./src/wing/my_api.w

bring tsoa;
pub class Service {
  new() {

let service = new tsoa.Service(
  controllerPathGlobs: ["../controllers/**.ts"],
  outputDirectory: "../../build",
  routesDir: "../../build"
);
  }
}

./src/wing/main.w

bring "./my_api.w" as api;

new api.Service();