Skip to content

Commit cdc3f1e

Browse files
author
bnasslahsen
committed
Return value of PropertyCustomizer is ignored. Fixes #441.
1 parent ff9b832 commit cdc3f1e

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

Diff for: springdoc-openapi-common/src/main/java/org/springdoc/core/converters/PropertyCustomizingConverter.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ public Schema resolve(AnnotatedType type, ModelConverterContext context, Iterato
4141
if (chain.hasNext()) {
4242
Schema<?> resolvedSchema = chain.next().resolve(type, context, chain);
4343
if (type.isSchemaProperty()) {
44-
propertyCustomizers.ifPresent(customizers -> customizers.forEach(customizer -> customizer.customize(resolvedSchema, type)));
44+
if(propertyCustomizers.isPresent()){
45+
List<PropertyCustomizer> propertyCustomizerList = propertyCustomizers.get() ;
46+
for(PropertyCustomizer propertyCustomizer : propertyCustomizerList)
47+
resolvedSchema = propertyCustomizer.customize(resolvedSchema, type);
48+
}
4549
}
4650
return resolvedSchema;
4751
}

Diff for: springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app70/customizer/PropertyCustomizer.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,16 @@
1919
package test.org.springdoc.api.app70.customizer;
2020

2121
import java.lang.annotation.Annotation;
22+
import java.time.Duration;
23+
import java.util.Collections;
2224
import java.util.Optional;
2325
import java.util.stream.Stream;
2426

27+
import com.fasterxml.jackson.databind.JavaType;
2528
import io.swagger.v3.core.converter.AnnotatedType;
29+
import io.swagger.v3.core.util.Json;
2630
import io.swagger.v3.oas.models.media.Schema;
31+
import io.swagger.v3.oas.models.media.StringSchema;
2732

2833
import org.springframework.stereotype.Component;
2934

@@ -41,9 +46,10 @@ public Schema customize(Schema property, AnnotatedType type) {
4146
.findFirst()
4247
.map(CustomizedProperty.class::cast);
4348

44-
propertyAnnotation
45-
.ifPresent(annotation -> property.description(property.getDescription() + ", " + annotation.addition()));
46-
49+
JavaType javaType = Json.mapper().constructType(type.getType());
50+
if (javaType.getRawClass().equals(Duration.class)) {
51+
property = new StringSchema().format("duration").properties(Collections.emptyMap());
52+
}
4753
return property;
4854
}
4955
}

Diff for: springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app70/model/ApiType.java

+5-8
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,16 @@
1818

1919
package test.org.springdoc.api.app70.model;
2020

21+
import java.time.Duration;
22+
23+
import com.fasterxml.jackson.annotation.JsonProperty;
2124
import io.swagger.v3.oas.annotations.media.Schema;
2225
import test.org.springdoc.api.app70.customizer.CustomizedProperty;
2326

2427
public class ApiType {
2528
@CustomizedProperty
2629
@Schema(description = "Test description")
27-
private String someProperty;
28-
29-
public String getSomeProperty() {
30-
return someProperty;
31-
}
30+
@JsonProperty("someProperty")
31+
private Duration someProperty;
3232

33-
public void setSomeProperty(String someProperty) {
34-
this.someProperty = someProperty;
35-
}
3633
}

Diff for: springdoc-openapi-webmvc-core/src/test/resources/results/app70.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151
"properties": {
5252
"someProperty": {
5353
"type": "string",
54-
"description": "Test description, customized property!"
54+
"properties": {},
55+
"format": "duration"
5556
}
5657
}
5758
}

0 commit comments

Comments
 (0)