@@ -3179,10 +3179,7 @@ export function createChecker(program: Program): Checker {
3179
3179
) {
3180
3180
const doc = extractParamDoc ( prop . parent . parent . parent , type . name ) ;
3181
3181
if ( doc ) {
3182
- type . decorators . unshift ( {
3183
- decorator : $docFromComment ,
3184
- args : [ { value : createLiteralType ( doc ) , jsValue : doc } ] ,
3185
- } ) ;
3182
+ type . decorators . unshift ( createDocFromCommentDecorator ( "self" , doc ) ) ;
3186
3183
}
3187
3184
}
3188
3185
finishType ( type ) ;
@@ -3193,6 +3190,16 @@ export function createChecker(program: Program): Checker {
3193
3190
return type ;
3194
3191
}
3195
3192
3193
+ function createDocFromCommentDecorator ( key : "self" | "returns" | "errors" , doc : string ) {
3194
+ return {
3195
+ decorator : $docFromComment ,
3196
+ args : [
3197
+ { value : createLiteralType ( key ) , jsValue : key } ,
3198
+ { value : createLiteralType ( doc ) , jsValue : doc } ,
3199
+ ] ,
3200
+ } ;
3201
+ }
3202
+
3196
3203
function isValueType ( type : Type ) : boolean {
3197
3204
if ( type === nullType ) {
3198
3205
return true ;
@@ -3439,10 +3446,16 @@ export function createChecker(program: Program): Checker {
3439
3446
// Doc comment should always be the first decorator in case an explicit @doc must override it.
3440
3447
const docComment = extractMainDoc ( targetType ) ;
3441
3448
if ( docComment ) {
3442
- decorators . unshift ( {
3443
- decorator : $docFromComment ,
3444
- args : [ { value : createLiteralType ( docComment ) , jsValue : docComment } ] ,
3445
- } ) ;
3449
+ decorators . unshift ( createDocFromCommentDecorator ( "self" , docComment ) ) ;
3450
+ }
3451
+ if ( targetType . kind === "Operation" ) {
3452
+ const returnTypesDocs = extractReturnsDocs ( targetType ) ;
3453
+ if ( returnTypesDocs . returns ) {
3454
+ decorators . unshift ( createDocFromCommentDecorator ( "returns" , returnTypesDocs . returns ) ) ;
3455
+ }
3456
+ if ( returnTypesDocs . errors ) {
3457
+ decorators . unshift ( createDocFromCommentDecorator ( "errors" , returnTypesDocs . errors ) ) ;
3458
+ }
3446
3459
}
3447
3460
return decorators ;
3448
3461
}
@@ -5827,6 +5840,30 @@ function extractMainDoc(type: Type): string | undefined {
5827
5840
return trimmed === "" ? undefined : trimmed ;
5828
5841
}
5829
5842
5843
+ function extractReturnsDocs ( type : Type ) : {
5844
+ returns : string | undefined ;
5845
+ errors : string | undefined ;
5846
+ } {
5847
+ const result : { returns : string | undefined ; errors : string | undefined } = {
5848
+ returns : undefined ,
5849
+ errors : undefined ,
5850
+ } ;
5851
+ if ( type . node ?. docs === undefined ) {
5852
+ return result ;
5853
+ }
5854
+ for ( const doc of type . node . docs ) {
5855
+ for ( const tag of doc . tags ) {
5856
+ if ( tag . kind === SyntaxKind . DocReturnsTag ) {
5857
+ result . returns = getDocContent ( tag . content ) ;
5858
+ }
5859
+ if ( tag . kind === SyntaxKind . DocErrorsTag ) {
5860
+ result . errors = getDocContent ( tag . content ) ;
5861
+ }
5862
+ }
5863
+ }
5864
+ return result ;
5865
+ }
5866
+
5830
5867
function extractParamDoc ( node : OperationStatementNode , paramName : string ) : string | undefined {
5831
5868
if ( node . docs === undefined ) {
5832
5869
return undefined ;
0 commit comments