Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSharp code generator - generated function's response type is string instead of byte[] #733

Closed
boazsapir opened this issue May 7, 2015 · 9 comments

Comments

@boazsapir
Copy link

I defined the response data type of a POST api request as binary, according to the Swagger spec (type="string", format="byte"):

*   @SWG\Response(response=200, description="Encrypted data", @SWG\Schema(type="string", format="byte"))

The generated CSharp API call function has "string" as return type, and therefore apiInvoker.invokeAPI() will be called instead of apiInvoker.invokeBinaryAPI().

The generated code:

   if (typeof(string) == typeof(byte[])) {

      var response = apiInvoker.invokeBinaryAPI(basePath, path, "GET", queryParams, null, headerParams, formParams);
      return ((object)response) as string;


    } else {

      var response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, BinaryData, headerParams, formParams);
      if (response != null){
         return (string) ApiInvoker.deserialize(response, typeof(string));
      }
      else {
        return null;
      }


    }
@boazsapir boazsapir changed the title CSharp code generator - string response type instead of byte[] CSharp code generator - generated function's response type is string instead of byte[] May 7, 2015
@wing328
Copy link
Contributor

wing328 commented May 8, 2015

In your example, is the HTTP response body/content encoded in base64 and you would expect the method to automatically convert the base64-encoded string to byte array using Convert.FromBase64String ?

Related discussion: OAI/OpenAPI-Specification#50

@webron webron added this to the v2.1.0 milestone May 9, 2015
@boazsapir
Copy link
Author

@wing328 in fact my response content is binary, not base64 encoded

@wing328
Copy link
Contributor

wing328 commented May 10, 2015

@boazsapir OK. RESTSharp supports sending binary data so I'll try to address the issue in the csharp_restsharp branch.

@webron
Copy link
Contributor

webron commented May 10, 2015

@boazsapir - what's the produces of your operation?

@boazsapir
Copy link
Author

           "consumes": [
                "application/octet-stream"
            ],
            "produces": [
                "application/octet-stream"
            ],

@webron
Copy link
Contributor

webron commented May 10, 2015

@boazsapir - hope you saw my comment regarding application/octet-stream and the byte format in the other thread.

@wing328
Copy link
Contributor

wing328 commented May 11, 2015

@boazsapir currently the format byte in Swagger Spec (2.0) is a base64-encoded string so there's not much I can do at the moment to change the return type to byte[]

@wing328
Copy link
Contributor

wing328 commented Jan 11, 2016

Fixed by #1864

@wing328
Copy link
Contributor

wing328 commented Jan 12, 2016

@boazsapir when you've time, please kindly help perform a test.

Closing this issue for the time being.

@wing328 wing328 closed this as completed Jan 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants