thiagobustamante / typescript-rest

This is a lightweight annotation-based expressjs extension for typescript.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problem with loadServices and swagger

alfonsoal1983 opened this issue · comments

Doing tests with the import of the services, I just realized that the swaggerGen works well with the function buildServices (passing directly to the services) but when using the function loadServices (passing the route correctly) it does not create the routes in the swagger, the routes work well but the swagger does not generate it well. Do you know why it can be @thiagobustamante ?

The swagger only shows the text:

No operations defined in spec!

Hi @alfonsoal1983 ,

Swagger generator parses the typescript file and find all classes decorated with any typescript-rest decorator to generate the docs. This parser receives an entrypoint file and follow any imports it find to search into other files too.

When you are using buildServices you need to inform the Services directly to typescript-rest, so you need to import it into your main file. When using loadServices, you do not import it.

But is possible to inform to SwaggerGen the entrypoint for the parser. You can configure it in the swagger-config.json:

{
    "swagger": {
        "yaml": false,
        "outputDirectory": "./dist",
        "entryFile": "./src/services/myService.ts",
     }
}     

I changed the parser to accept also one array of entryFiles:

{
    "swagger": {
        "yaml": false,
        "outputDirectory": "./dist",
        "entryFile": ["./src/services/myService.ts","./src/services/myService2.ts"]
     }
}     

and also glob expressions:

{
    "swagger": {
        "yaml": false,
        "outputDirectory": "./dist",
        "entryFile": "./src/services/*.ts"
     }
}     

But is not published yet to npm. I am preparing a new major version that will include some other features, like support for open api 3.0

Done. Please update typescript-rest-swagger to version 1.0.3