@@ -2,12 +2,13 @@ const OpenAPISampler = require('openapi-sampler');
22const _ = require ( 'lodash' ) ;
33const slugg = require ( 'slugg' ) ;
44const md = require ( 'markdown-it' ) ( ) ;
5+ const curlGenerator = require ( './curl-builder' ) ;
56
67const sharedStart = ( array ) => {
78 const A = array . concat ( ) . sort ( ) ;
8- const a1 = A [ 0 ] , a2 = A [ A . length - 1 ] , L = a1 . length ;
9+ const a1 = A [ 0 ] , a2 = A [ A . length - 1 ] , L = a1 . length ;
910 let i = 0 ;
10- while ( i < L && a1 . charAt ( i ) === a2 . charAt ( i ) ) i ++ ;
11+ while ( i < L && a1 . charAt ( i ) === a2 . charAt ( i ) ) i ++ ;
1112 return a1 . substring ( 0 , i ) ;
1213} ;
1314
@@ -63,7 +64,7 @@ const beautifySchema = (schema) => {
6364 return schema ;
6465} ;
6566
66- const beautifyOperation = ( operation , operationName , pathName ) => {
67+ const beautifyOperation = ( operation , operationName , pathName , options ) => {
6768 operation . slug = slugg ( `op-${ operationName } -${ pathName } ` ) ;
6869 operation . summaryAsHTML = mdToHTML ( operation . summary ) ;
6970 operation . descriptionAsHTML = mdToHTML ( operation . description ) ;
@@ -89,6 +90,10 @@ const beautifyOperation = (operation, operationName, pathName) => {
8990 operation . queryParams = operation . parameters . filter ( p => p . in === 'query' ) ;
9091 operation . pathParams = operation . parameters . filter ( p => p . in === 'path' ) ;
9192 operation . cookieParams = operation . parameters . filter ( p => p . in === 'cookie' ) ;
93+
94+ }
95+ if ( options . curl ) {
96+ operation . curl = curlGenerator ( operation , operationName , pathName ) ;
9297 }
9398
9499 if ( operation . responses ) {
@@ -118,7 +123,7 @@ const cleanBrackets = text => {
118123 return finalText ;
119124} ;
120125
121- module . exports = ( openapi ) => {
126+ module . exports = ( openapi , config ) => {
122127 openapi . basePath = openapi . basePath || '' ;
123128 openapi . info = openapi . info || { } ;
124129 openapi . info . descriptionAsHTML = mdToHTML ( openapi . info . description ) ;
@@ -168,7 +173,7 @@ module.exports = (openapi) => {
168173 const httpMethods = [ 'GET' , 'POST' , 'PUT' , 'DELETE' , 'PATCH' , 'COPY' , 'HEAD' , 'OPTIONS' , 'LINK' , 'UNLIK' , 'PURGE' , 'LOCK' , 'UNLOCK' , 'PROPFIND' ] ;
169174
170175 _ . each ( path , ( operation , operationName ) => {
171- if ( httpMethods . includes ( operationName . toUpperCase ( ) ) ) beautifyOperation ( operation , operationName , pathName ) ;
176+ if ( httpMethods . includes ( operationName . toUpperCase ( ) ) ) beautifyOperation ( operation , operationName , pathName , config ) ;
172177 } ) ;
173178 } ) ;
174179
0 commit comments