File tree Expand file tree Collapse file tree 2 files changed +13
-8
lines changed
Expand file tree Collapse file tree 2 files changed +13
-8
lines changed Original file line number Diff line number Diff line change 11const fs = require ( "fs" ) ;
22
3- function importMd ( file , path ) {
4- const schema = JSON . parse ( fs . readFileSync ( file , 'utf8' ) ) ;
5- schema [ "info" ] [ "description" ] = { $ref : path } ;
6- fs . writeFileSync ( file , JSON . stringify ( schema , null , 2 ) ) ;
7- console . log ( `Add \$Ref of ${ path } to ${ file } ` ) ;
3+ function importMd ( json_file , md_folder , des_file ) {
4+ const schema = JSON . parse ( fs . readFileSync ( json_file , 'utf8' ) ) ;
5+ const description = fs . readdirSync ( md_folder ) . sort ( ) . map (
6+ ( filename ) => fs . readFileSync ( `${ md_folder } /${ filename } ` )
7+ ) . join ( "\n" ) ;
8+ fs . writeFileSync ( des_file , description , "utf8" ) ;
9+ schema [ "info" ] [ "description" ] = { $ref : des_file } ;
10+ fs . writeFileSync ( json_file , JSON . stringify ( schema , null , 2 ) ) ;
11+ console . log ( `Add \$Ref of ${ md_folder } to ${ json_file } ` ) ;
812}
913
1014module . exports = importMd ;
Original file line number Diff line number Diff line change @@ -8,16 +8,17 @@ const program = new Command();
88program
99 . name ( "postprocess" )
1010 . description ( "Postprocess an OpenAPI document for ReDoc" )
11- . version ( "0.1 .0" ) ;
11+ . version ( "0.3 .0" ) ;
1212program . command ( "deref" )
1313 . description ( "Use $RefParser to dereference a JSON schema" )
1414 . argument ( "<in-filename>" , "Input JSON file" )
1515 . argument ( "[out-filename]" , "Output JSON file. If not specified, use in-filename." )
1616 . action ( deref ) ;
1717program . command ( "importmd" )
18- . description ( "Add a markdown $Ref to JSON info.description" )
18+ . description ( "Merge markdown files in <md-folder> to a markdown <gen-file>, and import it as $ref to JSON info.description. " )
1919 . argument ( "<in-filename>" , "Target JSON file" )
20- . argument ( "<path>" , "markdown path to ref" )
20+ . argument ( "<md-folder>" , "Folder of markdown files to import" )
21+ . argument ( "<gen-md>" , "Merged markdown files" )
2122 . action ( importMd ) ;
2223program . command ( "addlogo" )
2324 . description ( "Add a logo to JSON info.x-logo" )
You can’t perform that action at this time.
0 commit comments