There seems to be an issue with the OpenAPI generator for Angular as it is not generating the multipart form data endpoint correctly. By default

Here is the endpoint that needs to be addressed:

@PostMapping(value = "/file-upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public List<FileReference> handleFileUpload(
        @RequestPart(value = "file", name = "file") MultipartFile[] file, @ApiIgnore HttpSession session) {
    return service.handleFileUpload(
            Arrays.stream(file).map(MultipartFileWithUUID::new).collect(Collectors.toList()),
            session);
}

This is how the endpoint appears in the swagger.json (swagger 2.0):

...
  "post": {
        "tags": [
          "damage-report-controller"
        ],
        "summary": "handleFileUpload",
        "operationId": "handleFileUploadUsingPOST",
        "consumes": [
          "multipart/form-data"
        ],
        "produces": [
          "application/json"
        ],
        "parameters": [
          {
            "name": "file",
            "in": "formData",
            "required": false,
            "type": "array",
            "items": {
              "type": "file"
            },
            "collectionFormat": "multi"
          }
        ],
...

Below is the function generated from the endpoint:

 public handleFileUploadUsingPOST(file?: Array<Blob> ...) {

let headers = this.defaultHeaders;

header settings etc...

        // determining the Content-Type header
        const consumes: string[] = [
            'multipart/form-data'
        ];


        const canConsumeForm = this.canConsumeForm(consumes);

        let formParams: { append(param: string, value: any): any; };
        let useForm = false;

...
        if (useForm) {
            formParams = new FormData();
        } else {
            formParams = new HttpParams({encoder: this.encoder});
        }
...
}

The error message received is 415: Unsupported media type.

Although unsure of the correct generation method, setting let useForm; to true resolved the issue. It seems that

let useForm = canConsumeForm(consumes)
since canConsumeForm returns a boolean.

What adjustments should be made for accurate generation?

Answer №1

If you happen to come across this, I wanted to share that after struggling with Swagger 2.0, I decided to switch to OpenAPI 3.0 and it resolved the issue for me.

It seems that Swagger 2.0 does not have the capability to upload an array of files, even though in my case, the issue stemmed from a misuse of existing functions within the generated service.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

SecurityClient is encountering a problem where the Http Error status is not being displayed

Currently, I am utilizing a custom Http client that is an extension of Angular 4's Http Client. export class SecurityClient extends Http { // ... } Within this client, there are methods designed to make calls to an API and handle a 401 status code by ...

Unable to open modal window in Angular 14 micro-frontend application

I've been working on a micro front end project and running into some issues with opening modal popup windows. I've tried both the Angular material and bootstrap approaches, but ran into problems with both. With Angular material, the popup window ...

Fetching DataItem from a Kendo Grid using a custom button in an Angular application

I have been working on transferring the dataItem from a Kendo grid to an Angular 6 component. Here is my setup: <kendo-grid [data]="view | async" [height]="533" (dataStateChange)="onStateChange($event)" (edit)="editHandler($even ...

How can Java enums be utilized in various scenarios?

Suppose I have the following enum class in Java, how can I access it in various ways? public enum DayOfWeek { SUNDAY(0), MONDAY(1), TUESDAY(2), WEDNESDAY(3), THURSDAY(4), FRIDAY(5), SATURDAY(6); Integer code; DayOfWe ...

Having trouble finding the "make:migration" command in Adonis 5 - any suggestions?

After reviewing the introductory documentation for Adonis Js5, I attempted to create a new API server. However, when compiling the code using "node ace serve --watch" or "node ace build --watch", I kept receiving an error stating "make:migration command no ...

Do ES6 features get transpiled into ES5 when utilized in TypeScript?

After implementing ES6 features such as template strings, arrow functions, and destructuring in a TypeScript file, I compile the code to regular JavaScript... Does the TypeScript compiler also compile the ES6 syntax, or do I need to utilize another compil ...

What is the best way to implement multiple ternary operators within HTML code?

Consider the following code snippet: It currently applies CSS classes up to red4, but I want to apply CSS classes up to red11. Additionally, the variable "size" in myData should be dynamic. For example, size could range from 0-20 // 0-100 // 0-10000, etc., ...

Error in TypeScript: The property "component" is not found on the React MUI MenuItem

I am currently working with the react mui MenuItem component and I am trying to turn a menu item into a link. Here is how I have attempted to achieve this: <MenuItem component={<Link href={`/backend/api/exam/${row.id}/result`} />} className={c ...

Utilizing mat dialog in conjunction with the bootstrap sticky top class to enhance functionality

I am encountering an issue where, upon clicking to delete an entry, a mat dialog should appear with everything else in the background greyed out. However, the problem I am facing is that when I attempt to delete an entry, the dialog appears but the sticky ...

What are the steps to convert this code into Angular syntax?

After realizing that using jQuery alongside Angular is not a good practice, I am determined to modify my code in this Angular App to eliminate the need for jQuery. Currently, I have a page that displays menu items fetched from the server and I loop throug ...

Angular CLI simplifies the process of implementing internationalization (i18n) for Angular

After diving into the Angular documentation on i18n and using the ng tool xi18n, I am truly impressed by its capabilities. However, there is one part that has me stumped. According to the documentation, when internationalizing with the AOT compiler, you ...

Preventing row click in an Angular table when a column is clicked

I want to achieve a function where clicking on a table row will expand and show extra data, but clicking on a column should perform a different action without expanding the row. To see a simplified version of the code example, please visit here <!- ...

Error: The initialization of the org.elasticsearch.common.lucene.Lucene class failed, resulting in a java.lang.NoClassDefFoundError

When attempting to write on ES using a Hadoop job, the system freezes and generates logs with the following error: Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.elasticsearch.common.lucene.Lucene. What could be causing this is ...

What steps should I take to establish a one-to-one relationship with legacy tables?

As I work on developing a web application (angular, nestjs, typeorm), I am faced with the challenge of linking two legacy user tables together within our existing system. Despite my efforts, I continue to encounter an error message related to column refere ...

How can I adjust the appearance of an HTML tag within an Angular component?

I have created an Angular component with the following definition: import { Component, Input, Output, EventEmitter } from '@angular/core'; @Component({ selector: 'rdc-dynamic-icon-button', templateUrl: './dynamic-icon-button. ...

Check if a value is present in the array with *ngIf

I'm curious about how to use the ngIf directive in a specific scenario. In my Angular application, I have dynamically generated angular material toggles, each with a unique id. I'm familiar with using ngIf to conditionally display elements on the ...

Guide on how to retrieve the information stored in an object

I am experiencing an issue with my function that retrieves data from Firebase. I am able to read the objects, but I cannot access the properties within them. Whenever I try to parse the content, an error occurs. Here is the function in question: this ...

How to access an element through the router-outlet in Angular 6?

<side-navigation [navigationTitle]="navTitle"></side-navigation> <router-outlet> </router-outlet> Within my project, I have a navigation bar located in the root component. I have set up [navigationTitle] as an @Input Decorator wit ...

Angular Universal and WebSockets: A seamless connection

I'm currently facing an issue with incorporating websockets into a server that is utilizing angular universal. It seems like express is intercepting my request before it reaches the sockets, but I could be mistaken. Upon inspecting in chrome, I encou ...

Watching for changes in a callback function - Angular 2

I'm currently working on implementing a callback function within a service class that needs to send data back to the component class. ChatComponent.ts export class ChatComponent implements OnInit { constructor( public _chatService : ChatService) ...