import { AnyObjectSchema , Operation , SchemaResponse , Response , Schema , BinarySchema } from "@autorest/codemodel" ; import { getLanguageMetadata } from "../utils/languageHelpers" ; import { NameType , normalizeName } from "../utils/nameUtils" ; import { isSchemaResponse } from "../utils/schemaHelpers" ; export function getResponseTypeName ( operation , response ) { const statusCode = getStatusCode ( response ) ; return normalizeName ( `${ getLanguageMetadata ( operation . language ) . name }${ statusCode }Response` , NameType . Interface ) ; } export function responseToSchemaResponse ( response ) { if ( ! isSchemaResponse ( response ) ) { let schema = ( response as any ) . binary ? new BinarySchema ( "Binary schema" ) : new AnyObjectSchema ( "AnyObject schema" ) ; return new SchemaResponse ( schema , { ... response } ) ; } else { return response ; } } param response export function getStatusCode ( response ) { if ( response . protocol . http === undefined ) { throw new Error ( "generateResponseTypes.getStatusCode: Can't extract response definition statusCode from undefined http metadata" ) ; } let statusCode = response . protocol . http ?. statusCodes [ 0 ] ; return `"${ statusCode }"` ; }