OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.65k stars 6.54k forks source link

[BUG] [JavaSpring]: optional parameters in delegate method signature are not wrapped in Optional<?> #1649

Open quackes opened 5 years ago

quackes commented 5 years ago
Description

When generating a spring-mvc controller from an opan api yaml with a non required parameter (required: false) the generated method annotated with request mapping annotations declared the parameter type wrapped in Optional (e.g. Optional myparam )

     @RequestMapping(value = "/search",
        produces = { "application/json" }, 
        method = RequestMethod.GET)
    default ResponseEntity<List<String>> _searchGet(@ApiParam(value = "...") @Valid @RequestParam(value = "query", required = false) Optional<String> query) {
        return searchGet(query);
    }

The method that the call is delegated to ( in this example searchGet) does not declare the parameter as Optional Type:

default ResponseEntity<List<String>> searchGet(String query) {
        return ...
    }

That results in compiler errors in the generated code!

openapi-generator version

3.3.0, master

OpenAPI declaration file content or url