OpenAPITools / OpenAPITools/openapi-generator
[BUG][JAVA] schemaMapping not working for POST requestBody
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Hey!
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?
I have tested it with 6.2.1. - Have you searched for related issues/PRs?
- What's the actual output vs expected output?
Description
I can't get the schemaMapping to work with a POST request where I reference a object from an external package via schemaMapping.
It works flawlessly for returning objects though. See my provided examples.
openapi-generator version
6.2.1
OpenAPI declaration file content or url
paths:
/test/loadTest:
get:
tags:
- test
operationId: loadTest
responses:
200:
description: Test object
content:
application/json:
schema:
$ref: '#/components/schemas/Test'
/test/saveTest:
post:
tags:
- test
operationId: saveTest
requestBody:
description: TestToSave object
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/TestToSave'
responses:
201:
description: Created
components:
schema:
Test:
type: object
description: "external Test object"
TestToSave:
type: object
description: "external TestToSave object"
Generation Details
My schemaMappings maven configuration:
<schemaMappings>
Test=my.external.test.package.model.Test,
TestToSave=my.external.test.package.model.TestToSave,
</schemaMappings>
As you can see the saveTest(@NotNull Object body) method isn't correctly mapped to
my.external.test.package.api.model.TestToSave, even though I have set it in the schema mappings.
The weird thing is, that the schema mapping works correctly with the loadTest() method.
@ServiceInterface
@Local
public interface TestService {
/**
* @return my.test.package.api.model.Test
*/
my.external.test.package.api.model.Test loadTest() throws TestUiException;
/**
* @param body TestToSave object
*/
void saveTest(@NotNull Object body) throws TestUiException; // <-- should be my.external.test.package.api.model.TestToSave
}
Thanks!
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 supplied OpenAPI declaration and Maven schemaMappings configuration, then run generation for the Java output. Compare the generated loadTest and saveTest methods, focusing on how the requestBody schema is resolved. Done means saveTest accepts my.external.test.package.model.TestToSave instead of Object while loadTest continues to use the mapped Test type.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, backend-api-design
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100