{"action":"created","issue":{"url":"https://api.github.com/repos/swagger-api/swagger-codegen/issues/8658","repository_url":"https://api.github.com/repos/swagger-api/swagger-codegen","labels_url":"https://api.github.com/repos/swagger-api/swagger-codegen/issues/8658/labels{/name}","comments_url":"https://api.github.com/repos/swagger-api/swagger-codegen/issues/8658/comments","events_url":"https://api.github.com/repos/swagger-api/swagger-codegen/issues/8658/events","html_url":"https://github.com/swagger-api/swagger-codegen/issues/8658","id":356363573,"node_id":"MDU6SXNzdWUzNTYzNjM1NzM=","number":8658,"title":"[Dart] code has compile issues when 'browserClient' = false","user":{"login":"juliusspencer","id":443032,"node_id":"MDQ6VXNlcjQ0MzAzMg==","avatar_url":"https://avatars0.githubusercontent.com/u/443032?v=4","gravatar_id":"","url":"https://api.github.com/users/juliusspencer","html_url":"https://github.com/juliusspencer","followers_url":"https://api.github.com/users/juliusspencer/followers","following_url":"https://api.github.com/users/juliusspencer/following{/other_user}","gists_url":"https://api.github.com/users/juliusspencer/gists{/gist_id}","starred_url":"https://api.github.com/users/juliusspencer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juliusspencer/subscriptions","organizations_url":"https://api.github.com/users/juliusspencer/orgs","repos_url":"https://api.github.com/users/juliusspencer/repos","events_url":"https://api.github.com/users/juliusspencer/events{/privacy}","received_events_url":"https://api.github.com/users/juliusspencer/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-09-03T05:37:24Z","updated_at":"2018-09-03T08:05:20Z","closed_at":null,"author_association":"NONE","body":"##### Description\r\n\r\nThe Dart code has a couple of issues when it is generated. I have some suggestions which work for me in Flutter.\r\n\r\n##### Swagger-codegen version\r\nVersion is 2.4.0\r\n\r\n##### Swagger declaration file content or url\r\nFile 1 with compile problems:\r\n`modules/swagger-codegen/src/main/resources/dart/auth/http_basic_auth.mustache`\r\n```\r\n    headerParams[\"Authorization\"] = \"Basic \" + **BASE64**.encode(UTF8.encode(str));\r\n```\r\n\r\nFile 2 with compile problems:\r\n`modules/swagger-codegen/src/main/resources/dart/api_client.mustache`\r\n```\r\nvar decodedJson = **JSON**.decode(json);\r\n```\r\n```\r\nserialized = **JSON**.encode(obj);\r\n```\r\n\r\n##### Command line used for generation\r\n\r\njava -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate   -i http://petstore.swagger.io/v2/swagger.json   -l dart -c flutter.config.json -o samples/client/petstore/dart\r\n\r\n##### Steps to reproduce\r\n\r\nCreate a config file:\r\n`flutter.config.json`\r\n```json\r\n{\r\n\t\"browserClient\": false\r\n}\r\n```\r\nrun the command above and the two files will have compile  errors unless the changes below are made to the mustache files.\r\n\r\n##### Suggest a fix/enhancement\r\n\r\nFile 1 to change:\r\n`modules/swagger-codegen/src/main/resources/dart/auth/http_basic_auth.mustache`\r\n\r\n```\r\n  @override\r\n  void applyToParams(List<QueryParam> queryParams, Map<String, String> headerParams) {\r\n    String str = (username == null ? \"\" : username) + \":\" + (password == null ? \"\" : password);{{#browserClient}}\r\n    headerParams[\"Authorization\"] = \"Basic \" + BASE64.encode(UTF8.encode(str));{{/browserClient}}{{^browserClient}}\r\n    headerParams[\"Authorization\"] = \"Basic \" + base64.encode(utf8.encode(str));{{/browserClient}}\r\n  }\r\n```\r\n\r\nFile 2 to change:\r\n`modules/swagger-codegen/src/main/resources/dart/api_client.mustache`\r\nChange 1:\r\n```\r\n    if (targetType == 'String') return json;\r\n\r\n{{#browserClient}}    var decodedJson = JSON.decode(json);{{/browserClient}}\r\n{{^browserClient}}    var decodedJson = jsonDecode(json);{{/browserClient}}\r\n    return _deserialize(decodedJson, targetType);\r\n  }\r\n```\r\nChange 2:\r\n```\r\n  String serialize(Object obj) {\r\n    String serialized = '';\r\n    if (obj == null) {\r\n      serialized = '';\r\n    } else {\r\n{{#browserClient}}      serialized = JSON.encode(obj);{{/browserClient}}\r\n{{^browserClient}}      serialized = json.encode(obj);{{/browserClient}}\r\n    }\r\n    return serialized;\r\n  }\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/swagger-api/swagger-codegen/issues/comments/418034736","html_url":"https://github.com/swagger-api/swagger-codegen/issues/8658#issuecomment-418034736","issue_url":"https://api.github.com/repos/swagger-api/swagger-codegen/issues/8658","id":418034736,"node_id":"MDEyOklzc3VlQ29tbWVudDQxODAzNDczNg==","user":{"login":"HugoMario","id":3266608,"node_id":"MDQ6VXNlcjMyNjY2MDg=","avatar_url":"https://avatars1.githubusercontent.com/u/3266608?v=4","gravatar_id":"","url":"https://api.github.com/users/HugoMario","html_url":"https://github.com/HugoMario","followers_url":"https://api.github.com/users/HugoMario/followers","following_url":"https://api.github.com/users/HugoMario/following{/other_user}","gists_url":"https://api.github.com/users/HugoMario/gists{/gist_id}","starred_url":"https://api.github.com/users/HugoMario/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HugoMario/subscriptions","organizations_url":"https://api.github.com/users/HugoMario/orgs","repos_url":"https://api.github.com/users/HugoMario/repos","events_url":"https://api.github.com/users/HugoMario/events{/privacy}","received_events_url":"https://api.github.com/users/HugoMario/received_events","type":"User","site_admin":false},"created_at":"2018-09-03T08:05:20Z","updated_at":"2018-09-03T08:05:20Z","author_association":"CONTRIBUTOR","body":"hello @juliusspencer , can you please propose a PR for this?"}}
{"actor":{"display_login":"HugoMario"}}