Skip to content

Commit dfca14c

Browse files
richard-lindsayfrantuma
authored andcommitted
Fix for record component annotations on fields with JsonProperty annotations
1 parent df88c8a commit dfca14c

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

modules/swagger-core/src/main/java/io/swagger/v3/core/jackson/ModelResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,7 @@ private Stream<Annotation> extractGenericTypeArgumentAnnotations(BeanPropertyDef
11121112

11131113
private Stream<Annotation> getRecordComponentAnnotations(BeanPropertyDefinition propDef) {
11141114
try {
1115-
Method accessor = propDef.getPrimaryMember().getDeclaringClass().getDeclaredMethod(propDef.getName());
1115+
Method accessor = propDef.getPrimaryMember().getDeclaringClass().getDeclaredMethod(propDef.getPrimaryMember().getName());
11161116
return getGenericTypeArgumentAnnotations(accessor.getAnnotatedReturnType());
11171117
} catch (NoSuchMethodException e) {
11181118
LOGGER.error("Accessor for record component not found");

modules/swagger-java17-support/src/test/java/io/swagger/v3/java17/resolving/JavaRecordTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.swagger.v3.java17.resolving;
22

3+
import com.fasterxml.jackson.annotation.JsonProperty;
34
import io.swagger.v3.core.converter.ModelConverters;
45
import io.swagger.v3.oas.models.media.Schema;
56
import io.swagger.v3.java17.matchers.SerializationMatchers;
@@ -117,4 +118,25 @@ public record JavaRecordWithAnnotationsOnGenericType(
117118
List<@Min(1)@Max(10000) Integer> id
118119
){
119120
}
121+
122+
@Test
123+
public void testJavaRecordWithJsonPropertyAnnotationNotMatchingFieldName() {
124+
String expectedYaml = "JavaRecordWithJsonPropertyAnnotationNotMatchingFieldName:\n" +
125+
" type: object\n" +
126+
" properties:\n" +
127+
" listOfStrings:\n" +
128+
" type: array\n" +
129+
" items:\n" +
130+
" maxLength: 5\n" +
131+
" minLength: 1\n" +
132+
" type: string";
133+
134+
Map<String, Schema> stringSchemaMap = ModelConverters.getInstance(false).readAll(JavaRecordWithJsonPropertyAnnotationNotMatchingFieldName.class);
135+
SerializationMatchers.assertEqualsToYaml(stringSchemaMap, expectedYaml);
136+
}
137+
138+
public record JavaRecordWithJsonPropertyAnnotationNotMatchingFieldName(
139+
@JsonProperty("listOfStrings") List<@Size(min = 1, max = 5)String> stringList
140+
) { }
141+
120142
}

0 commit comments

Comments
 (0)