Skip to content

Commit

Permalink
Support for @JsonProperty with Javadoc Change in springdoc-openapi. F…
Browse files Browse the repository at this point in the history
…ixes #2438, #2315
  • Loading branch information
bnasslahsen committed Dec 2, 2023
1 parent 9262482 commit 1acbf20
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,17 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.introspect.SimpleMixInResolver;
import io.swagger.v3.core.converter.AnnotatedType;
import io.swagger.v3.core.converter.ModelConverter;
import io.swagger.v3.core.converter.ModelConverterContext;
import io.swagger.v3.core.converter.ModelConverterContextImpl;
import io.swagger.v3.core.util.AnnotationsUtils;
import io.swagger.v3.oas.annotations.media.SchemaProperty;
import io.swagger.v3.oas.models.media.Schema;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.reflect.FieldUtils;
Expand Down Expand Up @@ -158,7 +157,7 @@ public void setJavadocDescription(Class<?> cls, List<Field> fields, List<Propert
properties.entrySet().stream()
.filter(stringSchemaEntry -> StringUtils.isBlank(stringSchemaEntry.getValue().getDescription()))
.forEach(stringSchemaEntry -> {
Optional<Field> optionalField = fields.stream().filter(field1 -> field1.getName().equals(stringSchemaEntry.getKey())).findAny();
Optional<Field> optionalField = fields.stream().filter(field1 -> findFields(stringSchemaEntry, field1)).findAny();
optionalField.ifPresent(field -> {
String fieldJavadoc = javadocProvider.getFieldJavadoc(field);
if (StringUtils.isNotBlank(fieldJavadoc))
Expand All @@ -176,4 +175,27 @@ public void setJavadocDescription(Class<?> cls, List<Field> fields, List<Propert
}
}
}

/**
* Find fields boolean.
*
* @param stringSchemaEntry the string schema entry
* @param field the field
* @return the boolean
*/
private static boolean findFields(Entry<String, Schema> stringSchemaEntry, Field field) {
if (field.getName().equals(stringSchemaEntry.getKey())){
return true;
}
else {
JsonProperty jsonPropertyAnnotation = field.getAnnotation(JsonProperty.class);
if (jsonPropertyAnnotation != null) {
String jsonPropertyName = jsonPropertyAnnotation.value();
if (jsonPropertyName.equals(stringSchemaEntry.getKey())){
return true;
}
}
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class StudentV2 {
/**
* The Name.
*/
@JsonProperty("name")
@JsonProperty("bb")
private String name;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
"StudentV2": {
"type": "object",
"properties": {
"name": {
"bb": {
"type": "string",
"description": "The Name."
}
Expand All @@ -151,4 +151,4 @@
}
}
}
}
}

0 comments on commit 1acbf20

Please sign in to comment.