-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
Description of the problem/issue
Issue was found while using SpringDoc 2.8.14 in Spring Boot 3.5.X, I traced it back to Swagger Core, and given the history with #5005 it feels best to report it here.
Affected Version
At least 2.8.14, unsure of how far back it exists.
Steps to Reproduce
The following controller will generate the issue using SpringDoc,
@RestController
@RequestMapping("/rest")
public class GreeterController {
public static class Foo {
@Deprecated private String fizz;
public Foo(String fizz) {
this.fizz = fizz;
}
public String getFizz() {
return fizz;
}
}
public static class Bar {
private String fizz;
public Bar(String fizz) {
this.fizz = fizz;
}
public String getFizz() {
return fizz;
}
}
@PostMapping("/foo")
public String foo(@RequestBody Foo foo) {
return foo.getFizz();
}
@PostMapping("/bar")
public String bar(@RequestBody Bar bar) {
return bar.getFizz();
}
}Schema wise it generates the following,
"components": {
"schemas": {
"Foo": {
"type": "object",
"properties": {
"fizz": {
"type": "string",
"deprecated": true
}
}
},
"Bar": {
"type": "object",
"properties": {
"fizz": {
"type": "string",
"deprecated": true
}
}
},
"Descriptor": {}
}
}
Expected Behavior
#components/schemas/Bar/properties/fizz should not be deprecated.
Actual Behavior
#components/schemas/Bar/properties/fizz is deprecated.
Additional Context
This is an improper cache hit as the AnnotatedType's equals/hashcode do not check for the parent's field equality. If you populate the ModelConverterContextImpl's modelByType map with values that only different in the parent, you can observe this.
*Note, it is possible to use jakarta/javax.annotation.Nullable/Nonnull (Or any runtime annotation really) on the field being misattributed to the deprecation in order to cause a cache miss. So this isn't a major issue, but a subtle one.
Checklist
- I have searched the existing issues and this is not a duplicate. (I can see it being considered a potential continuation of others)
- I have provided sufficient information for maintainers to reproduce the issue.