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

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

Open
perfringis opened this issue Feb 27, 2023 · 0 comments

Comments

@perfringis
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant