[SPRING] Generate inner enum for query and path params#13351
[SPRING] Generate inner enum for query and path params#13351Zomzog wants to merge 11 commits intoOpenAPITools:masterfrom
Conversation
|
|
||
| @Override | ||
| protected void updateModelForObject(CodegenModel m, Schema schema) { | ||
| super.updateModelForObject(m, schema); // PONY |
There was a problem hiding this comment.
Intentionally left this here?
| import javax.annotation.Generated; | ||
| {{/useJakartaEe}} | ||
|
|
||
| import static {{package}}.{{classname}}.*; |
There was a problem hiding this comment.
Would it be possible to avoid the * import and import the specific types?
For consistency, all the other imports above do not rely on *.
There was a problem hiding this comment.
I've fixed it, I don't know if I must extract this part of the template somewhere, because it's done multiple times.
| ) | ||
| ResponseEntity<List<Pet>> findPetsByTags( | ||
| @NotNull @ApiParam(value = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) List<String> tags, | ||
| @NotNull @ApiParam(value = "Tags to filter by", required = true) @Valid @RequestParam(value = "tags", required = true) List<String> tags, |
There was a problem hiding this comment.
Looks like something happened here which didn't replace with < and > properly
There was a problem hiding this comment.
Looks like a generation issue. I've just regenerate them and they are ok.
|
I think you need your other change in first to get these tests to pass - but the change looks good otherwise |
| } | ||
|
|
||
| private Map<String, String> importFromMapping(String value) { | ||
| HashMap<String, String> e = new HashMap<>(); |
There was a problem hiding this comment.
Do you really need a HashMap here?
If not it's better to use with a meaningful name:
Map<String, String> imports = new HashMap<>();
That's a good callout - a separate file where the DTOs are located is probably a better result. It will make generating the imports a little harder |
| for (final CodegenOperation operation : ops) { | ||
| if (operation.allParams.stream().anyMatch(it -> it.isEnum)) { | ||
| objs.getImports().add(importFromMapping("JsonCreator")); | ||
| objs.getImports().add(importFromMapping("JsonValue")); |
There was a problem hiding this comment.
I doubt that @JsonCreator could handle enums as request parameter for cases when value != enum contant name(i.e. AVAILABLE("available") )
You can check this comment #3337 (comment)
What I'm thinking is that you have to leverage this PR changes #13349
I mean that all these enums should be added to that configuration file
I would leave it as it is. These enums are operations/class specific. Assume situation when you have two different operations from two different controllers, they both receive parameter IMHO: there should be a rule - as long as client declare enum as global type(components -> schemas -> MyEnum) it should be in separate class, in other cases(enum for model's field or enum for operation's parameter only) it should be inner enum to class, where it should be used |
The issue is more on the client side like feign. Then you have to use an "interface enum" looks a little bit confusing. |
nope, that's a common issue. you can't declare multiple enums with same name within same package |
|
It was harder than expected because some enums are weird. |
651def2 to
6a23517
Compare
6a23517 to
8941dfb
Compare
|
|
||
| FakeApi apiInstance = new FakeApi(defaultClient); | ||
| List<String> enumHeaderStringArray = Arrays.asList("$"); // List<String> | Header parameter enum test (string array) | ||
| List<String> enumHeaderStringArray = Arrays.asList("EnumHeaderStringArrayEnum.DOLLAR"); // List<String> | Header parameter enum test (string array) |
There was a problem hiding this comment.
This doesn't seems to be correct
I've added the inner class. The static * import for the delegate was the only solution I found for importing them.
PR checklist
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.For Windows users, please run the script in Git BASH.
master(6.1.0) (minor release - breaking changes with fallbacks),7.0.x(breaking changes without fallbacks)Spring committee : @cachescrubber (2022/02) @welshm (2022/02) @MelleD (2022/02) @atextor (2022/02) @manedev79 (2022/02) @javisst (2022/02) @borsch (2022/02) @banlevente (2022/02)