OpenAPITools / OpenAPITools/openapi-generator

[BUG][TypeScript-Angular] Multipart/form-data object with file gets sent as stringified JSON

Open
#15,771 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

I have a multipart/form-data endpoint which has a picture object with a file field (binary). The problem with this is that the picture objects gets stringified as a JSON object. Is there a work around for this? I'm using openapitools to generate the models and create the services in Angular, and I'm getting an error when I try to generate:
Model FileUploadRequest not generated since it's marked as unused (due to form parameters) and 'skipFormModel' (global property) set to true (default)

openapi-generator version

I'm using the openapi-generator 6.2.1

OpenAPI declaration file content or url
"post": {
   "requestBody": {
     "content": {
       "multipart/form-data": {
         "schema": {
            "$ref": "#/components/schemas/UserRequest"
         }
       }
     },
     "required": true
  },

This is the schema for the request body:

"UserRequest": {
   "type": "object",
   "properties": {
      "picture": {
         "$ref": "#/components/schemas/FileUploadRequest"
   },

And this is the schema for the picture field.

"FileUploadRequest": {
   "type": "object",
   "description": "Serializer class for File uploads.",
   "properties": {
     "file": {
        "type": "string",
        "format": "binary",
        "writeOnly": true
     },
Generation Details

yarn openapi-generator generate -i ./swagger.json -g typescript-angular -c -c ./openapitools.config.json
which raise Model FileUploadRequest not generated since it's marked as unused (due to form parameters) and 'skipFormModel' (global property) set to true (default)

Related issues/PRs

Could not find any.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the supplied swagger.json and openapitools.config.json using the typescript-angular generator command. Start by tracing multipart/form-data handling for the nested UserRequest and FileUploadRequest schemas. Done means FileUploadRequest is generated and the picture file is sent as multipart binary data rather than stringified JSON.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, openapi, typescript
Domain
api, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.