Skip to content

Commit

Permalink
Fix for record component annotations on fields with JsonProperty anno…
Browse files Browse the repository at this point in the history
…tations
  • Loading branch information
richard-lindsay authored and frantuma committed Dec 9, 2024
1 parent df88c8a commit dfca14c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,7 @@ private Stream<Annotation> extractGenericTypeArgumentAnnotations(BeanPropertyDef

private Stream<Annotation> getRecordComponentAnnotations(BeanPropertyDefinition propDef) {
try {
Method accessor = propDef.getPrimaryMember().getDeclaringClass().getDeclaredMethod(propDef.getName());
Method accessor = propDef.getPrimaryMember().getDeclaringClass().getDeclaredMethod(propDef.getPrimaryMember().getName());
return getGenericTypeArgumentAnnotations(accessor.getAnnotatedReturnType());
} catch (NoSuchMethodException e) {
LOGGER.error("Accessor for record component not found");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.swagger.v3.java17.resolving;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.core.converter.ModelConverters;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.java17.matchers.SerializationMatchers;
Expand Down Expand Up @@ -117,4 +118,25 @@ public record JavaRecordWithAnnotationsOnGenericType(
List<@Min(1)@Max(10000) Integer> id
){
}

@Test
public void testJavaRecordWithJsonPropertyAnnotationNotMatchingFieldName() {
String expectedYaml = "JavaRecordWithJsonPropertyAnnotationNotMatchingFieldName:\n" +
" type: object\n" +
" properties:\n" +
" listOfStrings:\n" +
" type: array\n" +
" items:\n" +
" maxLength: 5\n" +
" minLength: 1\n" +
" type: string";

Map<String, Schema> stringSchemaMap = ModelConverters.getInstance(false).readAll(JavaRecordWithJsonPropertyAnnotationNotMatchingFieldName.class);
SerializationMatchers.assertEqualsToYaml(stringSchemaMap, expectedYaml);
}

public record JavaRecordWithJsonPropertyAnnotationNotMatchingFieldName(
@JsonProperty("listOfStrings") List<@Size(min = 1, max = 5)String> stringList
) { }

}

0 comments on commit dfca14c

Please sign in to comment.