def _add_gateway_responses(self):
if not self.gateway_responses:<EOL><INDENT>return<EOL><DEDENT>if self.gateway_responses and not self.definition_body:<EOL><INDENT>raise InvalidResourceException(<EOL>self.logical_id, "<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>for responses_key, responses_value in self.gateway_responses.items():<EOL><INDENT>for response_key in responses_value.keys():<EOL><INDENT>if response_key not in GatewayResponseProperties:<EOL><INDENT>raise InvalidResourceException(<EOL>self.logical_id,<EOL>"<STR_LIT>".format(response_key, responses_key))<EOL><DEDENT><DEDENT><DEDENT>if not SwaggerEditor.is_valid(self.definition_body):<EOL><INDENT>raise InvalidResourceException(<EOL>self.logical_id, "<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>swagger_editor = SwaggerEditor(self.definition_body)<EOL>gateway_responses = {}<EOL>for response_type, response in self.gateway_responses.items():<EOL><INDENT>gateway_responses[response_type] = ApiGatewayResponse(<EOL>api_logical_id=self.logical_id,<EOL>response_parameters=response.get('<STR_LIT>', {}),<EOL>response_templates=response.get('<STR_LIT>', {}),<EOL>status_code=response.get('<STR_LIT>', None)<EOL>)<EOL><DEDENT>if gateway_responses:<EOL><INDENT>swagger_editor.add_gateway_responses(gateway_responses)<EOL><DEDENT>self.definition_body = swagger_editor.swagger<EOL>
Add Gateway Response configuration to the Swagger file, if necessary