Skip to content

Commit bef09c5

Browse files
author
bnasslahsen
committed
Payload/Request Examples no longer generated. Fixes #444
1 parent cdc3f1e commit bef09c5

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,10 @@ private void buildContent(RequestBody requestBody, MethodAttributes methodAttrib
150150
for (String value : methodAttributes.getMethodConsumes()) {
151151
io.swagger.v3.oas.models.media.MediaType mediaTypeObject = new io.swagger.v3.oas.models.media.MediaType();
152152
mediaTypeObject.setSchema(schema);
153-
if (content.get(value) != null)
153+
if (content.get(value) != null) {
154154
mediaTypeObject.setExample(content.get(value).getExample());
155+
mediaTypeObject.setExamples(content.get(value).getExamples());
156+
}
155157
content.addMediaType(value, mediaTypeObject);
156158
}
157159
requestBody.setContent(content);

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

+4-6
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,10 @@ public PropertyCustomizingConverter(Optional<List<PropertyCustomizer>> customize
4040
public Schema resolve(AnnotatedType type, ModelConverterContext context, Iterator<ModelConverter> chain) {
4141
if (chain.hasNext()) {
4242
Schema<?> resolvedSchema = chain.next().resolve(type, context, chain);
43-
if (type.isSchemaProperty()) {
44-
if(propertyCustomizers.isPresent()){
45-
List<PropertyCustomizer> propertyCustomizerList = propertyCustomizers.get() ;
46-
for(PropertyCustomizer propertyCustomizer : propertyCustomizerList)
47-
resolvedSchema = propertyCustomizer.customize(resolvedSchema, type);
48-
}
43+
if (type.isSchemaProperty() && propertyCustomizers.isPresent()) {
44+
List<PropertyCustomizer> propertyCustomizerList = propertyCustomizers.get();
45+
for (PropertyCustomizer propertyCustomizer : propertyCustomizerList)
46+
resolvedSchema = propertyCustomizer.customize(resolvedSchema, type);
4947
}
5048
return resolvedSchema;
5149
}

Diff for: springdoc-openapi-webmvc-core/src/test/java/test/org/springdoc/api/app90/HelloController.java

+22-2
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,38 @@
2121
import io.swagger.v3.oas.annotations.media.Content;
2222
import io.swagger.v3.oas.annotations.media.ExampleObject;
2323
import io.swagger.v3.oas.annotations.media.Schema;
24+
import io.swagger.v3.oas.annotations.parameters.RequestBody;
2425
import io.swagger.v3.oas.annotations.responses.ApiResponse;
2526
import io.swagger.v3.oas.annotations.responses.ApiResponses;
2627

28+
import org.springframework.http.MediaType;
2729
import org.springframework.web.bind.annotation.GetMapping;
30+
import org.springframework.web.bind.annotation.PostMapping;
2831
import org.springframework.web.bind.annotation.RestController;
2932

3033
@RestController
3134
public class HelloController {
3235

3336
@GetMapping("/test")
3437
@ApiResponses(value = { @ApiResponse(description = "successful operation", content = { @Content(examples = @ExampleObject(name = "500", ref = "#/components/examples/http500Example"), mediaType = "application/json", schema = @Schema(implementation = User.class)), @Content(mediaType = "application/xml", schema = @Schema(implementation = User.class)) }) })
35-
public void test1(String hello) {
36-
}
38+
public void test1(String hello) { }
39+
40+
@PostMapping("/test2")
41+
@RequestBody(
42+
description = "Details of the Item to be created",
43+
required = true,
44+
content = @Content(
45+
schema = @Schema(implementation = User.class),
46+
mediaType = MediaType.APPLICATION_JSON_VALUE,
47+
examples = {
48+
@ExampleObject(
49+
name = "An example request with the minimum required fields to create.",
50+
value = "min",
51+
summary = "Minimal request"),
52+
@ExampleObject(
53+
name = "An example request with all fields provided with example values.",
54+
value = "full",
55+
summary = "Full request") }))
56+
public void test2(String hello) { }
3757

3858
}

0 commit comments

Comments
 (0)