Skip to content

Commit

Permalink
fix: copy inherited parameter descriptions (#1303)
Browse files Browse the repository at this point in the history
Original change by @kayahr in
#788 but was deleted
before the pull request could be merged.

Fixes #787
  • Loading branch information
StephanBijzitter committed May 17, 2020
1 parent 8edb17c commit 9b586db
Show file tree
Hide file tree
Showing 3 changed files with 469 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/lib/converter/plugins/ImplementsPlugin.ts
Expand Up @@ -3,6 +3,7 @@ import { Type, ReferenceType } from '../../models/types/index';
import { Component, ConverterComponent } from '../components';
import { Converter } from '../converter';
import { Context } from '../context';
import { Comment } from '../../models/comments/comment';

/**
* A plugin that detects interface implementations of functions and
Expand Down Expand Up @@ -88,8 +89,13 @@ export class ImplementsPlugin extends ConverterComponent {
if (target instanceof SignatureReflection && target.parameters &&
source instanceof SignatureReflection && source.parameters) {
for (let index = 0, count = target.parameters.length; index < count; index++) {
if (target.parameters[index].comment) {
target.parameters[index].comment!.copyFrom(source.parameters[index].comment!);
const sourceParameter = source.parameters[index];
if (sourceParameter && sourceParameter.comment) {
const targetParameter = target.parameters[index];
if (!targetParameter.comment) {
targetParameter.comment = new Comment();
targetParameter.comment.copyFrom(sourceParameter.comment);
}
}
}
}
Expand Down
30 changes: 30 additions & 0 deletions src/test/converter/inherit-param-doc/inherit-param-doc.ts
@@ -0,0 +1,30 @@
export interface Base {
/**
* @param a - Parameter A.
* @param b - Parameter B.
*/
method1(a: number, b: string): void;
}

export class Class1 implements Base {
/** @inheritDoc */
method1(a: number, b: string): void {}
}

export class Class2 implements Base {
/**
* @inheritDoc
*
* @param a - Custom parameter A doc.
*/
method1(a: number, b: string): void {}
}

export class Class3 implements Base {
/**
* @inheritDoc
*
* @param c - Custom second parameter doc with name change.
*/
method1(a: number, c: string): void {}
}

0 comments on commit 9b586db

Please sign in to comment.