swagger-api / swagger-api/swagger-codegen

Compilation error in generated class requestBody

Open
#8,936 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

Compilation errors in swagger generated class.

I am using swagger 3.0.0

post:
tags:
- SampleExperienceResponse
description: This api uploads photo from user
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
postion:
type: string
id:
type: string
file:
type: string
format: base64
encoding:
file:
contentType: image/png, image/jpeg, image/jpg
responses:
200:
description: Returns the applicable Modules
204:
description: No Content

This snippet in yaml creates a class Body.java. No error in yaml as per swagger editor

And inside body.java it has set file method

@JsonProperty("file")
public void setFile(String file) {
this.file = file;
}
@Override
public boolean equals(java.lang.Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
body body = (body) o;
return Objects.equals(this.postion, body.postion) &&
Objects.equals(this.Id, body.Id) &&
Objects.equals(this.file, body.file);
}

//marked in bold is the compilation error

The class name is Body and while initialization it uses as a body.

I don't have any other reference of the body in my YAML file.

Can someone please help me in understanding why it is happening.

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

Start with the OpenAPI multipart/form-data requestBody shown in the issue and inspect the generated Body.java, especially its equals method. Trace which generator template or naming step produces the invalid body reference, then verify that the generated class compiles for this input.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.