1
votes

Versions:

  • Asp.Net 2.2
  • Swashbuckle v5.0.0 rc2

I am experiencing an issue when using NSWAG to generate my Angular client. I am using OAS 3.0. The issue is with using IFormFile as a parameter in my API.

This is my endpoint:

public async Task<object> UploadTest(IFormFile file) { }

When using OAS 3 nswag will generate the above endpoint's 'IFileFormat' parameter as a 'Blob' within the client code.

sample(body?: Blob | undefined): Observable<ObjectCommonApiResponse>;

When using OAS 2 nswag will generate the above endpoint's 'IFileFormat' parameter as a 'FileParameter' within the client code.

sample(file?: FileParameter | null | undefined): Observable<ObjectCommonApiResponse>;

Maybe I am missing something but I am not sure how to turn my file into 'Blob', which doesnt seem useful, so I can pass it into the service. On the other hand, when it's a 'FileParameter' type, using OAS 2, I can just extend the 'FileParameter' interface with my own class and send that in and it works as expected.

1
Hello @mluker, any news about this issue? - Husam Zidan
@HusamZidan nope, I ended up just v2 when generating the swagger file. - mluker

1 Answers

1
votes

This is how you could convert File array to FileParameter one in TypeScript:

const files: FileParameter[] = this.files
  ? this.files.map(i => {
    let fileParameter: FileParameter = { data: i, fileName: i.name };
    return fileParameter;
  })
  : null;