import { filter , groupBy , keyBy , mapValues , omit } from 'lodash' ; import { OpenAPIObject } from './interfaces' ; export class SwaggerTransformer { public normalizePaths ( denormalizedDoc ) { const roots = filter ( denormalizedDoc , ( r ) => r . root ) ; const groupedByPath = groupBy ( roots , ( { root } ) => root . path ) ; const paths = mapValues ( groupedByPath , ( routes ) => { const keyByMethod = keyBy ( routes , ( { root } ) => root . method ) ; return mapValues ( keyByMethod , ( route ) => { return { ... omit ( route . root , [ 'method' , 'path' ] ) , ... omit ( route , 'root' ) } ; } ) ; } ) ; return { paths } ; } }