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

The Azure GraphQL serverless function encountering an issue with the Cosmos DB connection, displaying an

After developing a serverless GraphQL API function using Azure functions and connecting it to Cosmos DB, I have encountered an issue with "Invalid URL" that has been puzzling me for a week. Despite running the graphql function locally without any problems, ...

Handling exceptions in Selenium

I am in the process of launching a selenium test. However, for some users, there may not be the same number of pages available. This is why I need to implement a try-catch block in my code. Unfortunately, every time he tries and the element is not found, i ...

Utilizing a Batch script to manage temporary folders in automation tests with Selenium

Frequent running of selenium tests leads to the accumulation of numerous 'anonymous-web-driver' profiles in the temp folder for Firefox and 'scoped-dirs' for Chrome. To address this issue, I devised the following batch script: @echo o ...

During rendering, the instance attempts to reference the "handleSelect" property or method which is not defined

I've incorporated the Element-UI NavMenu component into my web application to create a navigation bar using Vue.JS with TypeScript. In order to achieve this, I have created a Vue component within a directory called "navBar," which contains the follow ...

Securing your Angular application with user authentication and route guarding ensures

In the process of developing an Angular single-page application (SPA) front-end that interacts with a GraphQL endpoint, I encountered a challenge. Upon user login, I store the token in local storage and update the authentication state in my AuthService com ...

There appears to be a discrepancy in the number of elements within the jsonArray.length()

I have encountered an issue while using the org.json parser. When I retrieve a JSON array with jsonObject.getJSONArray(key), the problem arises when jsonArray.length() returns a value of 1 even though my JSON array contains 2 elements. What could be causin ...

expired: the item has either become detached from the webpage or the site has been reloaded

I am facing an issue while trying to log in using Selenium Webdriver (Java) on the website: www.tokopedia.com. I managed to input my email and password, but upon clicking the login button, it returns an error. I wonder why this is happening and what could ...

What makes Mathematics a unique object in JavaScript programming?

Recently, I've dived into learning Javascript, so pardon me if my doubts seem a bit illogical. I came across the definition for a Math object, and here is the code snippet: interface Math { /** The mathematical constant e. This is Euler's nu ...

What is the best way to simulate a constructor-created class instance in jest?

Suppose there is a class called Person which creates an instance of another class named Logger. How can we ensure that the method of Logger is being called when an instance of Person is created, as shown in the example below? // Logger.ts export default cl ...

Exploring NodeJS from a JAVA developer's perspective - Common Inquiries

Currently, I am immersed in a project that heavily relies on JSON. With approximately 90% of the server-side code being POJO.toJSON() in Java, I have decided to venture into learning NodeJS! My inquiries mainly revolve around the fact that NodeJS operates ...

Facing challenges with parsing JSON files in an Angular 2+ application

Utilizing the Angular CLI, I have configured this project with the standard folder layout. My goal is to practice reading a JSON file from src/app/assets/items.json and then using it to display these items in the HTML. items.json: { "results": [ ...

Guide on converting a material datepicker date value into the format "MM-DD-YYYY" in Angular 6

I need help formatting the date below to MM-DD-YYYY format in my Angular 6 project. I've checked out various solutions on SO and other websites, but so far, none have worked for me. Currently, I am using Material's Angular DatePicker component. ...

Prevent HTTP using AsyncValidator when the value is empty

I have developed a custom AsyncValidator to verify the uniqueness of a userName. Inspired by this tutorial, I have implemented a delay of 500ms. However, I am facing a challenge in preventing the HTTP service call if the input value does not meet a speci ...

Selenium Java encountering issue with disabling developer mode extensions error

Currently, I am using Java Selenium and encountered the following issue: System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.get("http://www.gezinomi.com/"); Error screenshot: ht ...

Efficiently Combining Objects with Rxjs

I have a specific object structure that I am working with: const myObject = { info: [ { id: 'F', pronouns: 'hers' }, { id: 'M', pronouns: 'his'} ], items:[ { name: 'John', age: 35, ...

Is there a way to utilize an AXIOS GET response from one component in a different component?

I'm having trouble getting my answer from App.tsx, as I keep getting an error saying data.map is not a function. Can anyone offer some assistance? App.tsx import React, {useState} from 'react'; import axios from "axios"; import {g ...

The property 'item' is not found within the specified type 'IntrinsicAttributes & RefAttributes<Component<{}, any, any>>'. Error code: 2322

"react": "^16.12.0", "typescript": "^4.0.3", "next": "^9.4.4" The error being raised by typescript is related to the <Item item={item} key={item.id} urlReferer={urlReferer} /> prop used ...

Generics-based conditional type that verifies entry properties

I developed a function that accepts an argument with two different architectures. I intentionally avoided enforcing rules to allow flexibility for the user, which is now causing me some headaches ...

What is the best way to combine two JSON arrays in an Android application?

After receiving a JSON response structured as follows : [{"ProjectID":1,"ProjectName":"Test","UserID":[1,3,5,7],"RSID":[2,4,6,8]}] I want to transform it into the following format : [{"ProjectID":1,"ProjectName":"Test","RS":[{"UserID":1,"RSID":2},{"User ...

Switching Facebook accounts on Firebase

I'm currently working on an Angular2 App that utilizes Firebase as its User system, with authentication providers including Email + Password, Facebook, and Google. One issue I have encountered is that when logging in with Facebook, I am unable to swi ...