def _add_cors(self):
INVALID_ERROR = "<STR_LIT>"<EOL>if not self.cors:<EOL><INDENT>return<EOL><DEDENT>if self.cors and not self.definition_body:<EOL><INDENT>raise InvalidResourceException(self.logical_id,<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>if isinstance(self.cors, string_types) or is_instrinsic(self.cors):<EOL><INDENT>properties = CorsProperties(AllowOrigin=self.cors)<EOL><DEDENT>elif isinstance(self.cors, dict):<EOL><INDENT>if not all(key in CorsProperties._fields for key in self.cors.keys()):<EOL><INDENT>raise InvalidResourceException(self.logical_id, INVALID_ERROR)<EOL><DEDENT>properties = CorsProperties(**self.cors)<EOL><DEDENT>else:<EOL><INDENT>raise InvalidResourceException(self.logical_id, INVALID_ERROR)<EOL><DEDENT>if not SwaggerEditor.is_valid(self.definition_body):<EOL><INDENT>raise InvalidResourceException(self.logical_id, "<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>if properties.AllowCredentials is True and properties.AllowOrigin == _CORS_WILDCARD:<EOL><INDENT>raise InvalidResourceException(self.logical_id, "<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>editor = SwaggerEditor(self.definition_body)<EOL>for path in editor.iter_on_path():<EOL><INDENT>editor.add_cors(path, properties.AllowOrigin, properties.AllowHeaders, properties.AllowMethods,<EOL>max_age=properties.MaxAge, allow_credentials=properties.AllowCredentials)<EOL><DEDENT>self.definition_body = editor.swagger<EOL>
Add CORS configuration to the Swagger file, if necessary