Skip to content

Commit ca5fdf5

Browse files
committed
NullPointerException thrown in SchemaUtils. Fixes #3022
1 parent af6fd11 commit ca5fdf5

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/utils/SchemaUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ else if (OPENAPI_STRING_TYPE.equals(type)) {
265265
schema.setPattern(((Pattern) anno).regexp());
266266
}
267267
});
268-
if (annotatedNotNull(annotations)) {
268+
if (schema!=null && annotatedNotNull(annotations)) {
269269
String specVersion = schema.getSpecVersion().name();
270270
if (!"V30".equals(specVersion)) {
271271
schema.setNullable(false);

springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app244/HelloController.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,22 @@
2626

2727
package test.org.springdoc.api.v31.app244;
2828

29+
import io.swagger.v3.oas.annotations.Operation;
30+
import io.swagger.v3.oas.annotations.Parameter;
2931
import io.swagger.v3.oas.annotations.enums.ParameterIn;
3032
import io.swagger.v3.oas.annotations.headers.Header;
33+
import io.swagger.v3.oas.annotations.media.Content;
3134
import io.swagger.v3.oas.annotations.media.ExampleObject;
3235
import io.swagger.v3.oas.annotations.media.Schema;
3336
import io.swagger.v3.oas.annotations.responses.ApiResponse;
37+
import jakarta.validation.Valid;
38+
import jakarta.validation.constraints.NotNull;
3439

3540
import org.springframework.web.bind.annotation.GetMapping;
41+
import org.springframework.web.bind.annotation.PathVariable;
3642
import org.springframework.web.bind.annotation.PostMapping;
43+
import org.springframework.web.bind.annotation.PutMapping;
44+
import org.springframework.web.bind.annotation.RequestBody;
3745
import org.springframework.web.bind.annotation.RequestMapping;
3846
import org.springframework.web.bind.annotation.RestController;
3947

@@ -64,4 +72,18 @@ public void uploadMultipartWithBody() {
6472
void nope() {
6573
}
6674

75+
@PutMapping(value = "/{id}")
76+
@Parameter(
77+
in = ParameterIn.PATH,
78+
name = "id",
79+
description = "ID of the user to update",
80+
required = true,
81+
content = @Content(schema = @Schema(type = "integer")))
82+
@Operation(summary = "Update a user by passing the entire object")
83+
public void update(
84+
@PathVariable("id") @NotNull final String id,
85+
@Valid @RequestBody @NotNull final String user,
86+
@Parameter(hidden = true) String spec) {
87+
}
88+
6789
}

springdoc-openapi-starter-webmvc-api/src/test/resources/results/3.1.0/app244.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,45 @@
1111
}
1212
],
1313
"paths": {
14+
"/test/{id}": {
15+
"put": {
16+
"tags": [
17+
"hello-controller"
18+
],
19+
"summary": "Update a user by passing the entire object",
20+
"operationId": "update",
21+
"parameters": [
22+
{
23+
"name": "id",
24+
"in": "path",
25+
"description": "ID of the user to update",
26+
"required": true,
27+
"content": {
28+
"*/*": {
29+
"schema": {
30+
"type": "integer"
31+
}
32+
}
33+
}
34+
}
35+
],
36+
"requestBody": {
37+
"content": {
38+
"application/json": {
39+
"schema": {
40+
"type": "string"
41+
}
42+
}
43+
},
44+
"required": true
45+
},
46+
"responses": {
47+
"200": {
48+
"description": "OK"
49+
}
50+
}
51+
}
52+
},
1453
"/test": {
1554
"get": {
1655
"tags": [

0 commit comments

Comments
 (0)