Skip to content

Commit 31ed191

Browse files
committed
Issues with POST Request, application/x-www-form-urlencoded and only one parameter. Fixes #2990
1 parent ceb4a10 commit 31ed191

File tree

3 files changed

+75
-27
lines changed

3 files changed

+75
-27
lines changed

springdoc-openapi-starter-common/src/main/java/org/springdoc/core/service/GenericParameterService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ private Schema calculateRequestBodySchema(Components components, ParameterInfo p
432432
requestBodyInfo.getMergedSchema().addProperty(paramName, schemaN);
433433
schemaN = requestBodyInfo.getMergedSchema();
434434
}
435-
else if (parameterInfo.isRequestPart() || schemaN instanceof FileSchema || (schemaN!=null && schemaN.getItems() instanceof FileSchema)) {
435+
else if (parameterInfo.isRequestPart() || ParameterIn.QUERY.toString().equals(parameterInfo.getParamType()) || schemaN instanceof FileSchema || (schemaN!=null && schemaN.getItems() instanceof FileSchema)) {
436436
schemaN = new ObjectSchema().addProperty(paramName, schemaN);
437437
requestBodyInfo.setMergedSchema(schemaN);
438438
}

springdoc-openapi-starter-webmvc-api/src/test/java/test/org/springdoc/api/v31/app1/PeopleRestService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import io.swagger.v3.oas.annotations.media.Schema;
3939
import io.swagger.v3.oas.annotations.responses.ApiResponse;
4040
import io.swagger.v3.oas.annotations.tags.Tag;
41+
import jakarta.validation.constraints.NotNull;
4142

4243
import org.springframework.http.HttpStatus;
4344
import org.springframework.http.MediaType;
@@ -110,4 +111,9 @@ public ResponseEntity<String> deletePerson(
110111
}
111112
return ResponseEntity.noContent().build();
112113
}
114+
115+
@PostMapping(path = "/api/test", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
116+
public void postSingleParameter(@RequestParam(name = "test_id") @NotNull final UUID testId) {
117+
System.out.println("Received test_id: " + testId);
118+
}
113119
}

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

Lines changed: 68 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@
8787
"content": {
8888
"application/x-www-form-urlencoded": {
8989
"schema": {
90-
"required": [
91-
"firstName",
92-
"lastName"
93-
],
9490
"type": "object",
9591
"properties": {
9692
"firstName": {
@@ -101,7 +97,11 @@
10197
"type": "string",
10298
"description": "Last Name"
10399
}
104-
}
100+
},
101+
"required": [
102+
"firstName",
103+
"lastName"
104+
]
105105
}
106106
}
107107
}
@@ -210,20 +210,20 @@
210210
"in": "query",
211211
"required": true,
212212
"schema": {
213+
"type": "string",
213214
"maxLength": 6,
214-
"minLength": 4,
215-
"type": "string"
215+
"minLength": 4
216216
}
217217
},
218218
{
219219
"name": "toto",
220220
"in": "query",
221221
"required": true,
222222
"schema": {
223-
"maximum": 6,
224-
"minimum": 4,
225223
"type": "integer",
226-
"format": "int32"
224+
"format": "int32",
225+
"maximum": 6,
226+
"minimum": 4
227227
}
228228
},
229229
{
@@ -340,9 +340,9 @@
340340
"description": "number of records to skip for pagination",
341341
"required": true,
342342
"schema": {
343-
"minimum": 0,
344343
"type": "integer",
345-
"format": "int32"
344+
"format": "int32",
345+
"minimum": 0
346346
}
347347
},
348348
{
@@ -351,10 +351,10 @@
351351
"description": "maximum number of records to return",
352352
"required": true,
353353
"schema": {
354-
"maximum": 50,
355-
"minimum": 0,
356354
"type": "integer",
357-
"format": "int32"
355+
"format": "int32",
356+
"maximum": 50,
357+
"minimum": 0
358358
}
359359
}
360360
],
@@ -439,6 +439,48 @@
439439
}
440440
}
441441
},
442+
"/api/test": {
443+
"post": {
444+
"tags": [
445+
"people"
446+
],
447+
"operationId": "postSingleParameter",
448+
"requestBody": {
449+
"content": {
450+
"application/x-www-form-urlencoded": {
451+
"schema": {
452+
"type": "object",
453+
"properties": {
454+
"test_id": {
455+
"type": "string",
456+
"format": "uuid"
457+
}
458+
},
459+
"required": [
460+
"test_id"
461+
]
462+
}
463+
}
464+
},
465+
"required": true
466+
},
467+
"responses": {
468+
"500": {
469+
"description": "Internal Server Error",
470+
"content": {
471+
"application/json": {
472+
"schema": {
473+
"$ref": "#/components/schemas/ErrorMessage"
474+
}
475+
}
476+
}
477+
},
478+
"200": {
479+
"description": "OK"
480+
}
481+
}
482+
}
483+
},
442484
"/people": {
443485
"get": {
444486
"tags": [
@@ -567,12 +609,6 @@
567609
}
568610
},
569611
"InventoryItem": {
570-
"required": [
571-
"id",
572-
"manufacturer",
573-
"name",
574-
"releaseDate"
575-
],
576612
"type": "object",
577613
"properties": {
578614
"id": {
@@ -591,12 +627,15 @@
591627
"manufacturer": {
592628
"$ref": "#/components/schemas/Manufacturer"
593629
}
594-
}
630+
},
631+
"required": [
632+
"id",
633+
"manufacturer",
634+
"name",
635+
"releaseDate"
636+
]
595637
},
596638
"Manufacturer": {
597-
"required": [
598-
"name"
599-
],
600639
"type": "object",
601640
"properties": {
602641
"name": {
@@ -611,7 +650,10 @@
611650
"type": "string",
612651
"example": "408-867-5309"
613652
}
614-
}
653+
},
654+
"required": [
655+
"name"
656+
]
615657
},
616658
"ItemDTO": {
617659
"type": "object",

0 commit comments

Comments
 (0)