OpenAPITools / OpenAPITools/openapi-generator
No DTO exported with Axios when using POJO in multipart/form-data
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
Generating a typescript-axios client from my openapi.json file fails to produce compilable code.
My Typescript compiler outputs the following error:
Failed to compile.
TS2552: Cannot find name 'NewUserDto'. Did you mean 'UserDto'?
422 | * @throws {RequiredError}
423 | */
> 424 | createUser: async (newUser: NewUserDto, profilePicture?: File, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
| ^^^^^^^^^^
425 | // verify required parameter 'newUser' is not null or undefined
426 | assertParamExists('createUser', 'newUser', newUser)
427 | const localVarPath = `/api/users/create`;
Context
I am using springdoc to generate an openApi.json file from a SpringBoot application.
The java code of my controller method of interest is the following one:
@SecurityRequirements
@PostMapping(value = CREATE_USER_PATH, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@ResponseStatus(code = HttpStatus.CREATED)
public void createUser(@Valid @RequestPart NewUserDto newUser, @RequestPart(required = false) MultipartFile profilePicture){
this.userService.createUser(newUser, profilePicture);
}
openapi-generator version
OpenAPI declaration file content or url
{
"openapi": "3.0.1",
"info": {
"title": "OpenAPI definition",
"version": "v0"
},
"servers": [
{
"url": "http://localhost:8080",
"description": "Generated server url"
}
],
"tags": [
{
"description": "Declares the API methods dealing directly with the users.",
"name": "user-controller"
}
],
"paths": {
"/api/users/create": {
"post": {
"description": "Creates a user account.",
"operationId": "createUser",
"requestBody": {
"content": {
"multipart/form-data": {
"schema": {
"type": "object",
"properties": {
"newUser": {
"$ref": "#/components/schemas/NewUserDto"
},
"profilePicture": {
"type": "string",
"format": "binary",
"description": "The optional user profile picture."
}
},
"required": [
"newUser"
]
}
}
}
},
"responses": {
"201": {
"description": "Created"
}
},
"security": [],
"summary": "Creates a user account.",
"tags": [
"user-controller"
]
}
}
},
"components": {
"schemas": {
"NewUserDto": {
"type": "object",
"description": "The DTO used to create a new user profile.",
"properties": {
"email": {
"maxLength": 50,
"minLength": 0,
"type": "string",
"example": "marcLambert@example.com"
},
"firstName": {
"maxLength": 30,
"minLength": 1,
"type": "string",
"example": "Marc"
},
"lastName": {
"maxLength": 30,
"minLength": 1,
"type": "string",
"example": "Lambert"
},
"password": {
"maxLength": 100,
"minLength": 8,
"type": "string",
"example": "t0pSecret!"
},
"status": {
"maxLength": 100,
"minLength": 0,
"type": "string",
"example": "I am a bit special ^^"
}
},
"required": [
"email",
"firstName",
"lastName",
"password"
]
}
}
}
}
Generation Details
Steps to reproduce
$ java -jar openapi-generator-cli-6.6.0-20230415.080830-20.jar generate \
-g typescript-axios \
-i ../Desktop/openapi.json \
-o ./out/
The generated code in .out/api.ts does not compile.
Related issues/PRs
Suggest a fix
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
Run the provided Java CLI command with the supplied openapi.json and inspect the generated .out/api.ts, focusing on the multipart/form-data createUser operation. Confirm the missing NewUserDto reference and compare the generated exports; done means the typescript-axios output compiles and exposes the DTO used by createUser.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, 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