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

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

Open
ekeren opened this issue Apr 30, 2024 · 2 comments
Open

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

ekeren opened this issue Apr 30, 2024 · 2 comments
Assignees
Labels
🐛 bug Something isn't working 📚 libraries Wing Libraries

Comments

@ekeren
Copy link
Collaborator

ekeren commented Apr 30, 2024

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

  • 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 Apr 30, 2024
@eladb
Copy link
Contributor

eladb commented Apr 30, 2024

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
Copy link
Collaborator Author

ekeren commented May 1, 2024

You'll notice that:

  • wing run ./src/wing/main.w
  • wing run ./src/wing/subfolder/main.w doesn't work

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();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working 📚 libraries Wing Libraries
Projects
Status: 🏗 In progress
Development

No branches or pull requests

5 participants