springdoc-openapi icon indicating copy to clipboard operation
springdoc-openapi copied to clipboard

Fixed a bug that duplicate field were get for record classes

Open uc4w6c opened this issue 3 years ago • 0 comments

Describe the bug

When the argument of the MethodParameterPojoExtractor.extractFrom method is a record class, duplicate fields gets.

  1. when the argument is a class (expected)
// The ClassObject class has email, firstName, lastName fields and getters 
Stream<MethodParameter> actual = MethodParameterPojoExtractor.extractFrom(ClassObject.class);
actual.forEach(method -> System.out.println(method.getMethod().getName()));

// Below is the output result.
// getEmail
// getFirstName
// getLastName
  1. when the argument is a record (unexpected)
record RecordObject(String email, String firstName, String lastName) {}
Stream<MethodParameter> actual = MethodParameterPojoExtractor.extractFrom(RecordObject.class);
actual.forEach(method -> System.out.println(method.getMethod().getName()));

// Below is the output result.
// email
// firstName
// lastName
// email
// firstName
// lastName
// email
// firstName
// lastName

Fixes

Added filter as well as Class.

uc4w6c avatar Sep 22 '22 13:09 uc4w6c