1- import { record } from 'zod' ;
21import { pkgName } from '../const' ;
32import type { OpenApi3 } from '../types/openapi' ;
43import { never } from '../utils/func' ;
@@ -24,7 +23,7 @@ import {
2423import { JsDoc } from './JsDoc' ;
2524import { Named } from './Named' ;
2625import { Schemata } from './Schemata' ;
27- import type { PrinterOptions , RequestStatusCodeMatch } from './types' ;
26+ import type { PrinterOptions , PrinterConfigs , RequestStatusCodeMatch } from './types' ;
2827
2928const allowMethods = [ 'get' , 'put' , 'post' , 'delete' , 'options' , 'head' , 'patch' , 'trace' ] ;
3029
@@ -36,6 +35,7 @@ type ResponseMatch = (statusCode: string, response: OpenApi3_Response) => boolea
3635export class Printer {
3736 named = new Named ( ) ;
3837 schemata = new Schemata ( this . named ) ;
38+ private configs : PrinterConfigs = { } ;
3939
4040 constructor (
4141 private readonly document : OpenApi3 . Document ,
@@ -76,13 +76,16 @@ export class Printer {
7676 } ) ;
7777 }
7878
79- print ( options ?: { hideInfo ?: boolean ; hideImports ?: boolean ; hideComponents ?: boolean ; hidePaths ?: boolean } ) {
79+ print ( configs ?: PrinterConfigs ) {
80+ Object . assign ( this . configs , configs ) ;
81+ const { hideInfo, hideComponents, hideImports, hidePaths } = this . configs ;
82+
8083 return [
8184 //
82- ! options ?. hideInfo && this . _printInfo ( ) ,
83- ! options ?. hideImports && this . _printImports ( ) ,
84- ! options ?. hideComponents && this . _printComponents ( ) ,
85- ! options ?. hidePaths && this . _printPaths ( ) ,
85+ ! hideInfo && this . _printInfo ( ) ,
86+ ! hideImports && this . _printImports ( ) ,
87+ ! hideComponents && this . _printComponents ( ) ,
88+ ! hidePaths && this . _printPaths ( ) ,
8689 ]
8790 . filter ( Boolean )
8891 . join ( '\n\n' ) ;
@@ -121,6 +124,8 @@ export class Printer {
121124 const { externalDocs } = this . document ;
122125 const { name, email, url } = contact || { } ;
123126 const jsDoc = new JsDoc ( ) ;
127+ const { module } = this . configs ;
128+ if ( module ) jsDoc . addComments ( { module } ) ;
124129 const extDoc = JsDoc . printExternalDoc ( externalDocs ) ;
125130 jsDoc . addComments ( {
126131 title,
@@ -249,6 +254,8 @@ export class Printer {
249254 const respType = responseArgs . toType ( 0 ) ;
250255 const jsDoc = new JsDoc ( this . document . tags ) ;
251256 const comments = JsDoc . fromOperation ( operation ) ;
257+ const { module } = this . configs ;
258+ if ( module ) jsDoc . addComments ( { module } ) ;
252259 jsDoc . addComments ( comments ) ;
253260 jsDoc . addComments ( requestArgs . toComments ( ) ) ;
254261 jsDoc . addComments ( responseArgs . toComments ( ) ) ;
0 commit comments