Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for record component annotations on fields with JsonProperty annotations #4795

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
) { }

}
Loading