Nswag: [C# Client] Binary string parameters not supported?

Created on 13 Dec 2018  路  9Comments  路  Source: RicoSuter/NSwag

Hi.

The OpenAPI 3 specification specifies that files can be sent in a request by declaring that a parameters is of the type string with the format binary: https://swagger.io/docs/specification/describing-request-body/file-upload/

The proposed way to send a single file is as shown below:

    requestBody:
      content:
        image/png:
          schema:
            type: string
            format: binary

When generating a C# client, I would expect to give some sort of Stream (e.g. FileStream) or a byte[], but the client wants me to supply a normal string. From what I can understand, this is not what the OpenAPI spec means with "binary string". Are strings of format binary not currently supported? Is support planned?

OpenAPI 3 help wanted NJsonSchema.CodeGeneration.CSharp NJsonSchema.CodeGeneration.TypeScript enhancement

Most helpful comment

@RSuter Ok, thank you for your quick response. Would you mind listing roughly what needs to be done to support it? I am interested in taking a look at it, but no promises.

All 9 comments

This is currently not implemented

@RSuter Ok, thank you for your quick response. Would you mind listing roughly what needs to be done to support it? I am interested in taking a look at it, but no promises.

Either here:

https://github.com/RSuter/NSwag/blob/master/src/NSwag.CodeGeneration/Models/ParameterModelBase.cs#L144

... but you also need to check how this property is handled in the liquid templates and see whether it has the correct behavior.

or here:

https://github.com/RSuter/NJsonSchema/blob/master/src/NJsonSchema.CodeGeneration.CSharp/CSharpTypeResolver.cs#L139

If the behavior is different then the existing one, add a new bool property in the model

Also the IsBody property (your case) may need a change in behavior

Thanks for your help.

I have a similar issue. I need to post multi-part binary files.
Did you solve this issue or find a workaround?
Thanks!!

@gilzig I have not found the time to implement support for this in NSwag.
My temporary solution is to build the request by hand, using Flurl (https://flurl.io/docs/fluent-http/)
and the PostMultipartAsync method.

I still would like to implement this in NSwag, but I don't think I can find the time quite yet, unfortunately.

Can I assume that this is also unimplemented for C# controllers? I see that string/binary multipart specs in openapi3 result in simple string JSON body objects in the controller code and not in any stream/IFile code?

Was this page helpful?
0 / 5 - 0 ratings