OpenAPITools / OpenAPITools/openapi-generator
[BUG][typescript-axios] Description
Nobody has claimed this yet.
- 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
In multipart/form-data responseBody primitive enums are treated as complex objects and serialized as a JSON Blob instead of plaintext.
Generated output
localVarFormParams.append('type', new Blob([JSON.stringify(type)], { type: "application/json", }));
Expected output
localVarFormParams.append('type', type as any);
openapi-generator version
Current version 5.3.0
This is a regression that was introduced in 5.0.0-beta3 but worked in 5.0.0-beta2. I think it was introduced by #7816.
OpenAPI declaration file content or url
openapi: "3.0.0"
info:
version: 1.0.0
title: Swagger Petstore
description: Multi-file boilerplate for OpenAPI Specification.
license:
name: MIT
contact:
name: API Support
url: http://www.example.com/support
email: support@example.com
servers:
- url: http://petstore.swagger.io/v1
tags:
- name: pets
paths:
/pet/upload:
post:
summary: Upload pet
operationId: uploadPet
description: Upload your pet
tags:
- pets
requestBody:
content:
multipart/form-data:
schema:
type: object
required:
- type
- file
properties:
type:
$ref: "#/components/schemas/PetType"
file:
type: string
format: binary
responses:
201:
description: OK
components:
schemas:
PetType:
type: string
enum:
- Dog
- Cat
Steps to reproduce
https://replit.com/@dantman/OpenAPI-generator-typescript-axios-multipart-enum
Suggest a fix
The issue seems to be that {{^isPrimitiveType}} is used for enum types (i.e. enums are considered a complex types like type: object instead of a primitive type like the type: string they are based on.
Fixing whatever code handles isPrimitiveType to consider enums primitive could be a way to fix this.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the typescript-axios generator and the isPrimitiveType handling used for multipart/form-data responses. Reproduce the supplied OpenAPI declaration or linked Replit example, then inspect the generated append call for the enum. Done means primitive enum values are emitted as plaintext rather than JSON Blobs, with the generated output matching the expected form.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100