{"action":"created","issue":{"url":"https://api.github.com/repos/swagger-api/swagger-codegen/issues/2836","repository_url":"https://api.github.com/repos/swagger-api/swagger-codegen","labels_url":"https://api.github.com/repos/swagger-api/swagger-codegen/issues/2836/labels{/name}","comments_url":"https://api.github.com/repos/swagger-api/swagger-codegen/issues/2836/comments","events_url":"https://api.github.com/repos/swagger-api/swagger-codegen/issues/2836/events","html_url":"https://github.com/swagger-api/swagger-codegen/issues/2836","id":154364935,"number":2836,"title":"Question: Why use SplFileObject for PHP file downloads instead of returning bytes? Why call error_log each time? ","user":{"login":"nicholasareed","id":801236,"avatar_url":"https://avatars.githubusercontent.com/u/801236?v=3","gravatar_id":"","url":"https://api.github.com/users/nicholasareed","html_url":"https://github.com/nicholasareed","followers_url":"https://api.github.com/users/nicholasareed/followers","following_url":"https://api.github.com/users/nicholasareed/following{/other_user}","gists_url":"https://api.github.com/users/nicholasareed/gists{/gist_id}","starred_url":"https://api.github.com/users/nicholasareed/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nicholasareed/subscriptions","organizations_url":"https://api.github.com/users/nicholasareed/orgs","repos_url":"https://api.github.com/users/nicholasareed/repos","events_url":"https://api.github.com/users/nicholasareed/events{/privacy}","received_events_url":"https://api.github.com/users/nicholasareed/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/swagger-api/swagger-codegen/labels/Client:%20PHP","name":"Client: PHP","color":"fad8c7"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/swagger-api/swagger-codegen/milestones/9","html_url":"https://github.com/swagger-api/swagger-codegen/milestones/v2.2.0","labels_url":"https://api.github.com/repos/swagger-api/swagger-codegen/milestones/9/labels","id":1375944,"number":9,"title":"v2.2.0","description":"","creator":{"login":"fehguy","id":249413,"avatar_url":"https://avatars.githubusercontent.com/u/249413?v=3","gravatar_id":"","url":"https://api.github.com/users/fehguy","html_url":"https://github.com/fehguy","followers_url":"https://api.github.com/users/fehguy/followers","following_url":"https://api.github.com/users/fehguy/following{/other_user}","gists_url":"https://api.github.com/users/fehguy/gists{/gist_id}","starred_url":"https://api.github.com/users/fehguy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fehguy/subscriptions","organizations_url":"https://api.github.com/users/fehguy/orgs","repos_url":"https://api.github.com/users/fehguy/repos","events_url":"https://api.github.com/users/fehguy/events{/privacy}","received_events_url":"https://api.github.com/users/fehguy/received_events","type":"User","site_admin":false},"open_issues":154,"closed_issues":268,"state":"open","created_at":"2015-10-25T23:43:33Z","updated_at":"2016-05-12T15:27:29Z","due_on":null,"closed_at":null},"comments":2,"created_at":"2016-05-11T23:24:00Z","updated_at":"2016-05-12T16:13:58Z","closed_at":null,"body":"In PHP, when having a returnType mapped to `file` the SplFileObject type is used, which causes an error message from the following line: https://github.com/swagger-api/swagger-codegen/blob/50bbd9818cfb2133758ddb5697bd4b36cef62d05/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache#L271\r\n\r\nWhy is this necessary? I don't see a similar approach being taken in other languages, so why is PHP using a temporary file location instead of returning the bytes and allowing the user to create their own SplFileObject (or just file_put_contents($bytes))? If saving to an SplFileObject is the smartest way to implement the file download, then why is an error always displayed? \r\n"},"comment":{"url":"https://api.github.com/repos/swagger-api/swagger-codegen/issues/comments/218807442","html_url":"https://github.com/swagger-api/swagger-codegen/issues/2836#issuecomment-218807442","issue_url":"https://api.github.com/repos/swagger-api/swagger-codegen/issues/2836","id":218807442,"user":{"login":"nicholasareed","id":801236,"avatar_url":"https://avatars.githubusercontent.com/u/801236?v=3","gravatar_id":"","url":"https://api.github.com/users/nicholasareed","html_url":"https://github.com/nicholasareed","followers_url":"https://api.github.com/users/nicholasareed/followers","following_url":"https://api.github.com/users/nicholasareed/following{/other_user}","gists_url":"https://api.github.com/users/nicholasareed/gists{/gist_id}","starred_url":"https://api.github.com/users/nicholasareed/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nicholasareed/subscriptions","organizations_url":"https://api.github.com/users/nicholasareed/orgs","repos_url":"https://api.github.com/users/nicholasareed/repos","events_url":"https://api.github.com/users/nicholasareed/events{/privacy}","received_events_url":"https://api.github.com/users/nicholasareed/received_events","type":"User","site_admin":false},"created_at":"2016-05-12T16:13:58Z","updated_at":"2016-05-12T16:13:58Z","body":"Thanks @wing328. Using `binary` is an option, but it doesn't answer why PHP is the only language where swagger-codegen decides to use a temporary file instead of streaming the file bytes back for `file` formats. In our SDK implementations (and most others I would assume), it would be odd to switch a response type in our spec.json from `file` to `binary` for only the PHP SDK build. \r\n\r\nFor the error, it again seems an odd choice to force it upon the user when they have no recourse to actually suppress the message, even if they are moving the temporary file immediately. I can see a first-time user having trouble discerning what/where the SplFileObject points, but that seems better suited to a \"better documentation and examples\" solution than \"permanent error message.\"\r\n\r\nWe can easily work around the defaults in swagger-codegen by just commenting out the error message, or changing the typeMapping (`typeMapping.put(\"file\", \"string\")`) in PhpClientCodegen.java, but we had enough confusion around the defaults that I thought it would be good to ask. \r\n\r\n"}}