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

JSDoc duplicating method names is documentation API #2049

Open
BNdabwunze opened this issue Apr 5, 2023 · 1 comment
Open

JSDoc duplicating method names is documentation API #2049

BNdabwunze opened this issue Apr 5, 2023 · 1 comment

Comments

@BNdabwunze
Copy link

Input code

**
 * 
 * @memberOf module:Foo
 * @class Bar
 * 
 */
 export class Bar {
	/**
	 * 
	 * @memberOf module:Foo.Bar
	 * 
	 * @param {any} req
	 * @param {any} res
	 * @returns {RequestHandler}
	 * @description
	 * xxxxxx-xxxxxxx-xxxxxxx
	 */

JSDoc configuration

{
    "plugins": ["node_modules/better-docs/typescript"],
    "source": {
        "include":["src"],
        "includePattern": "routes.ts$",
        "excludePattern": "(^|\\/|\\\\)_"
    },
    "sourceType": "module",
    "templates": {
        "cleverLinks": true,
        "monospaceLinks": true
    },
    "opts": {
        "encoding": "utf8",
        "destination": "./docs/",
        "recurse": true,     
        "template":"./templates/api"
       
        
    }
}

JSDoc debug output

Expected behavior

I would expect only the method displaying the return values to be displayed. I suspect the both class and the module above it are generating all methods inside of them, but I can't seem to figure out why that would happen.

Current behavior

image

Your environment

Software Version
JSDoc 4.0.2
Node.js 14.20.1
npm 6.14.17
Operating system
@Zei33
Copy link

Zei33 commented Jan 2, 2024

I have a solution to this problem.

While the way you and I formatted these class comments makes complete sense, we've actually done it wrong.
I'm not sure why it's the way it is and it doesn't align with what's shown on the better-docs main page.

Instead of giving the class a description and then giving one to the constructor, you're actually supposed to attach the whole thing to the constructor and NOT to the class. Remove the comment on the class itself and then add something like this to your constructor.

class ACME {
	/** 
	 * The path to the json file that appointment IDs of sent reminders will be stored for future reference. 
	 * @type {string}
	 */
	remindersSentPath: string;

	 /**
	 * @classdesc ACME API interaction. 
	 * @description Setup an instance of the ACME class.
	 * @constructor
	 * @param {string} remindersSentPath The path to the reminder sent history json file.
	 */
	constructor(remindersSentPath: string) {
		this.remindersSentPath = remindersSentPath;
	}
}

export default ACME;

@classdesc should be the description of the class itself, but it should be included with the constructor, NOT the class definition. No idea why but this is what makes it work properly. This will also fix the duplication of the class members (see remindersSentPath in example).

Absolute pain figuring this out. Hope this saves everyone who runs into the same issue. The documentation needs to be updated to reflect this.

Side Note: If your class doesn't have a constructor, you can just do the normal comment on the class itself and it'll work fine. This only appears to be an issue if you have both a constructor and a class block comment block. You should prefer the constructor block though and just define the class information in it.

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

2 participants