@@ -17,14 +17,15 @@ async function postmanToOpenApi (input, output, { save = true, info = {}, defaul
1717 items . splice ( i , 1 , ...tagged )
1818 element = tagged . shift ( )
1919 }
20- const { request : { url : { path } , method, body, description } , name : summary , tag = defaultTag } = element
20+ const { request : { url : { path, query } , method, body, description } , name : summary , tag = defaultTag } = element
2121 const compiledPath = '/' + path . join ( '/' )
2222 if ( ! paths [ compiledPath ] ) paths [ compiledPath ] = { }
2323 paths [ compiledPath ] [ method . toLowerCase ( ) ] = {
2424 tags : [ tag ] ,
2525 summary,
2626 ...( description ? { description } : { } ) ,
27- requestBody : parseBody ( body ) ,
27+ ...parseBody ( body , method ) ,
28+ ...parseParams ( query ) ,
2829 responses : {
2930 200 : {
3031 description : 'Successful response' ,
@@ -50,7 +51,7 @@ async function postmanToOpenApi (input, output, { save = true, info = {}, defaul
5051}
5152
5253function compileInfo ( postmanJson , optsInfo ) {
53- const { info : { name, description : desc } , variable } = postmanJson
54+ const { info : { name, description : desc } , variable = [ ] } = postmanJson
5455 const ver = getVarValue ( variable , 'version' , '1.0.0' )
5556 const { title = name , description = desc , version = ver , termsOfService } = optsInfo
5657 return {
@@ -61,25 +62,44 @@ function compileInfo (postmanJson, optsInfo) {
6162 }
6263}
6364
64- function parseBody ( body ) {
65- if ( body . mode === 'raw' ) {
66- return {
67- content : {
65+ function parseBody ( body = { } , method ) {
66+ // Swagger validation return an error if GET has body
67+ if ( [ 'GET' ] . includes ( method ) ) return { }
68+ const { mode, raw } = body
69+ let content = { }
70+ switch ( mode ) {
71+ case 'raw' :
72+ content = {
6873 'application/json' : {
6974 schema : {
7075 type : 'object' ,
71- example : JSON . parse ( body . raw )
76+ example : JSON . parse ( raw )
7277 }
7378 }
7479 }
75- }
76- } else {
77- return {
78- content : {
80+ break
81+ case 'file' :
82+ content = {
7983 'text/plain' : { }
8084 }
81- }
85+ break
86+ default :
87+ content = { }
88+ break
8289 }
90+ return { requestBody : { content } }
91+ }
92+
93+ function parseParams ( query = [ ] ) {
94+ const parameters = query . map ( ( { key, description } ) => ( {
95+ name : key ,
96+ in : 'query' ,
97+ schema : {
98+ type : 'string'
99+ } ,
100+ ...( description ? { description } : { } )
101+ } ) )
102+ return ( parameters . length ) ? { parameters } : { }
83103}
84104
85105function getVarValue ( variables , name , def ) {
0 commit comments