private void addResponsesToAction ( ControllerRouteModel < Raml > elem , Action action ) { // get all mimeTypes defined in @Route.produces LOGGER . debug ( "responsesMimes.size:" + elem . getResponseMimes ( ) . size ( ) ) ; List < String > mimes = new ArrayList <> ( ) ; mimes . addAll ( elem . getResponseMimes ( ) ) ; // if no mimeTypes defined, no response specifications if ( mimes . isEmpty ( ) ) { return ; } int i = 0 ; // iterate over @response.code javadoc annotation for ( String code : elem . getResponseCodes ( ) ) { LOGGER . debug ( "code:" + code ) ; // get mimeType in order of declaration, else get first String mime ; if ( mimes . size ( ) > i ) { mime = mimes . get ( i ) ; } else { mime = mimes . get ( 0 ) ; } Response resp = new Response ( ) ; // add @response.description javadoc annotation if exist if ( elem . getResponseDescriptions ( ) . size ( ) > i ) { resp . setDescription ( elem . getResponseDescriptions ( ) . get ( i ) ) ; } // add @response.body javadoc annotation if exist if ( elem . getResponseBodies ( ) . size ( ) > i ) { MimeType mimeType = new MimeType ( mime ) ; mimeType . setExample ( elem . getResponseBodies ( ) . get ( i ) . toString ( ) ) ; resp . setBody ( Collections . singletonMap ( mime , mimeType ) ) ; } action . getResponses ( ) . put ( code , resp ) ; i ++ ; } }
Add the response specification to the given action .