import init from './swaggerTemplate' ; import { getPath , sortObject } from './utils' ; import { Dictionary } from 'ramda' ; /**
 * build swagger json from apiObjects
 */ const swaggerJSON = ( options = { } , apiObjects ) => { const { title , description , version , prefix = '' , swaggerOptions = { } } = options ; const swaggerJSON = init ( title , description , version , swaggerOptions ) ; const paths = { } ; Object . keys ( apiObjects ) . forEach ( ( key ) => { const value = apiObjects [ key ] ; if ( ! Object . keys ( value ) . includes ( 'request' ) ) { return ; } const { method } = value . request ; let { path } = value . request ; path = getPath ( prefix , value . prefix ? `${ value . prefix }${ path }` : path ) ; const summary = value . summary || '' ; const description = value . description || summary ; const responses = value . responses || { 200 : { description : 'success' } } ; const { query = [ ] , header = [ ] , path : pathParams = [ ] , body = [ ] , order , tags , formData = [ ] , security , deprecated } = value ; const parameters = [ ... pathParams , ... query , ... header , ... formData , ... body ] ; if ( ! paths [ path ] ) { paths [ path ] = { } ; } const consumes = formData . length > 0 ? [ 'multipart/form-data' ] : undefined ; paths [ path ] [ method ] = { consumes , summary , description , parameters , responses , tags , security , deprecated } ; if ( ! paths [ path ] . _order ) { paths [ path ] . _order = order ; } } ) ; swaggerJSON . paths = sortObject ( paths , ( path , length ) => path . _order || length , ( path ) => { const { _order , ... restOfPathData } = path ; return restOfPathData ; } ) ; return swaggerJSON ; } ; export default swaggerJSON ; export { swaggerJSON } ;