@@ -7,15 +7,17 @@ async function postmanToOpenApi (input, output, { save = true }) {
77 // TODO validate?
88 const collectionFile = await readFile ( input )
99 const postmanJson = JSON . parse ( collectionFile )
10- const { item : items , info : { name : title , description } } = postmanJson
10+ const { item : items , info : { name : title , description } , variable } = postmanJson
11+ const version = getVarValue ( variable , 'version' , '1.0.0' )
1112 const paths = { }
1213
1314 for ( const item of items ) {
14- const { request : { url : { path } , method, body } , name : summary } = item
15+ const { request : { url : { path } , method, body, description } , name : summary } = item
1516 const compiledPath = '/' + path . join ( '/' )
1617 if ( ! paths [ compiledPath ] ) paths [ compiledPath ] = { }
1718 paths [ compiledPath ] [ method . toLowerCase ( ) ] = {
1819 summary,
20+ ...( description ? { description } : { } ) ,
1921 requestBody : parseBody ( body ) ,
2022 responses : {
2123 200 : {
@@ -33,7 +35,7 @@ async function postmanToOpenApi (input, output, { save = true }) {
3335 info : {
3436 title,
3537 description,
36- version : '1.0.0'
38+ version
3739 } ,
3840 paths
3941 }
@@ -66,4 +68,9 @@ function parseBody (body) {
6668 }
6769}
6870
71+ function getVarValue ( variables , name , def ) {
72+ const variable = variables . find ( ( { key } ) => key === name )
73+ return variable ? variable . value : def
74+ }
75+
6976module . exports = postmanToOpenApi
0 commit comments