import { PathLike , readFileSync } from 'fs' ; import path from 'path' ; import { SwaggerMetadata , SwaggerPath } from './swagger-types' ; internal export function readSwaggerFile ( swaggerPath ) { const swaggerFile = readFileSync ( path . resolve ( swaggerPath . toString ( ) ) , { encoding : 'utf-8' } ) ; return parseSwaggerFile ( swaggerFile ) ; } function parseSwaggerFile ( swaggerFile ) { const swaggerMetaData = JSON . parse ( swaggerFile ) ; swaggerMetaData . definitions = swaggerMetaData . definitions || swaggerMetaData ?. components ?. schemas ; return swaggerMetaData ; } internal export function swaggerDefinitionForFunctionImport ( originalName , httpMethod , swaggerMetadata ) { if ( swaggerMetadata ) { const paths = swaggerMetadata . paths ; const entryPath = Object . keys ( paths ) . find ( p => p === `/${ originalName }` ) ; if ( entryPath ) { const key = Object . keys ( paths [ entryPath ] ) . find ( k => k . toLowerCase ( ) === httpMethod . toLowerCase ( ) ) ; if ( key ) { return paths [ entryPath ] [ key ] ; } } } }