OpenAPITools / OpenAPITools/openapi-generator
[BUG] JavaSpring: Class in OpenAPI2SpringBoot.java does not fully implement interface
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
See 'secondary' bug from https://github.com/OpenAPITools/openapi-generator/issues/1164
- Have you provided a full/minimal spec to reproduce the issue?
No. Simply generate using the spring server generator to see the issue - Have you validated the input using an OpenAPI validator (example)?
No. I used the standard petstore example - What's the version of OpenAPI Generator used?
4.0.3 (but, the master code of that template still shows the problem) - Have you search for related issues/PRs?
Originally reported in https://github.com/OpenAPITools/openapi-generator/issues/1164
See description starting with:
Note: In addition to the above problem and unrelated to this there is a generated code in the generated OpenAPI2SpringBoot.java
- What's the actual output vs expected output?
When you generate the code, you will immediately see Java compile errors (I was using Eclipse and VS Code with the Java extension)
Description
The spring server generated code has compilation errors because the class does not fully implement an interface:
@bean
public WebMvcConfigurer webConfigurer() {
return new WebMvcConfigurer() {
/* @override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("")
.allowedMethods("")
.allowedHeaders("Content-Type");
} */
};
}
openapi-generator version
4.0.1. The template in the master branch does not have the entire method commented out, as this was the proposed solution.
OpenAPI declaration file content or url
Use the petstore.yaml sample
Command line used for generation
generate -g spring -i petstore.yaml -o
Steps to reproduce
Simply generate and import the project into your favourite IDE
(I can reproduce in Eclipse as well as VS Code with the Java extension added)
Related issues/PRs
See 'secondary' bug from https://github.com/OpenAPITools/openapi-generator/issues/1164
Suggest a fix
As described in the related issue, you can simply comment out the entire method (or implement the interface properly).
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 by locating the Spring server template that generates OpenAPI2SpringBoot.java, then run the documented generate command with the petstore.yaml sample. Confirm the generated Java project fails to compile because its WebMvcConfigurer implementation is incomplete; done means the generated project compiles with the interface implemented or the problematic method removed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100