Skip to content

Usage of Server.loadServices or Server.buildServices is not generating a swagger documentation #156

@perfringis

Description

@perfringis

Hi,

I'm trying to generate documentation, but something is wrong.

I have created a repository, where you can see my implementation. I'm using the same project structure/configuration as in the prepared repository. Feel free to "play around" with prepared case.

The link to a repository is here -> https://github.com/perfringis/swagger-test-repo

In the case of Server.loadServices

In my app.js file as you can see. I'm trying to use Server.loadServices(router, 'controllers/*', __dirname);

The swagger config file looks as follows:

{
  "swagger": {
    "basePath": "",
    "outputDirectory": "./dist",
    "entryFile": "./src/controllers/index.ts",
    "produces": ["application/json"],
    "ignore": ["**/node_modules/**"]
  }
}

The index.ts file in the controllers directory looks as follows:

export * from './hello-world.controller';

The hello-world.controller.ts is a just simple class implementation.

After that, I'm trying to generate documentation by running the npm/yarn run swagger command.

After running the command. Prepared swagger.json looks as follows:

{
	"basePath": "",
	"definitions": {},
	"info": {
		"license": {
			"name": "MIT"
		},
		"title": "swagger-test-repo",
		"version": "1.0.0"
	},
	"paths": {},
	"swagger": "2.0",
	"securityDefinitions": {},
	"produces": [
		"application/json"
	]
}

Looks like in the paths property, there is no information about my controllers.

In the case of Server.buildServices

This implementation is slightly different.

In app.js file, I'm using import Controllers from './controllers'; and Server.buildServices(router, ...Controllers);.

The swagger config file looks as follows:

{
  "swagger": {
    "basePath": "",
    "outputDirectory": "./dist",
    "entryFile": "./src/controllers/index.ts",
    "produces": ["application/json"],
    "ignore": ["**/node_modules/**"]
  }
}

The index.ts file in the controllers directory looks as follows:

import { HelloWorldController } from './hello-world.controller';

export default [HelloWorldController];

The hello-world.controller.ts is a just simple class implementation.

After that, I'm trying to generate documentation by running the npm/yarn run swagger command.

After running the command. Prepared swagger.json looks as follows:

{
	"basePath": "",
	"definitions": {},
	"info": {
		"license": {
			"name": "MIT"
		},
		"title": "swagger-test-repo",
		"version": "1.0.0"
	},
	"paths": {},
	"swagger": "2.0",
	"securityDefinitions": {},
	"produces": [
		"application/json"
	]
}

In both cases, generated swagger.json don't contain any information about my controllers.

In the controller class, I have added @Tags('Hello World') for experiments. But it doesn't work either.

Maybe in my configuration is something wrong. If yes, could you prepare a small example of how to correct it? I will be very grateful. Thanks in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions