|
25 | 25 |
|
26 | 26 | import co.elastic.clients.elasticsearch.core.CountRequest;
|
27 | 27 | import co.elastic.clients.elasticsearch.core.CountResponse;
|
| 28 | +import com.fasterxml.jackson.core.type.TypeReference; |
| 29 | +import com.fasterxml.jackson.databind.ObjectMapper; |
28 | 30 | import io.swagger.v3.oas.annotations.Parameter;
|
29 | 31 | import io.swagger.v3.oas.annotations.media.Content;
|
| 32 | +import io.swagger.v3.oas.annotations.media.ExampleObject; |
30 | 33 | import io.swagger.v3.oas.annotations.media.Schema;
|
31 | 34 | import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
32 | 35 | import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
|
88 | 91 | import javax.servlet.http.HttpServletRequest;
|
89 | 92 | import javax.servlet.http.HttpSession;
|
90 | 93 | import java.awt.image.BufferedImage;
|
91 |
| -import java.io.File; |
92 |
| -import java.io.IOException; |
93 |
| -import java.io.InputStream; |
94 |
| -import java.io.OutputStream; |
| 94 | +import java.io.*; |
95 | 95 | import java.nio.file.DirectoryStream;
|
96 | 96 | import java.nio.file.Files;
|
97 | 97 | import java.nio.file.Path;
|
@@ -387,24 +387,67 @@ public List<Setting> getSettingsDetails(
|
387 | 387 |
|
388 | 388 | @io.swagger.v3.oas.annotations.Operation(
|
389 | 389 | summary = "Save settings",
|
390 |
| - description = "") |
391 |
| - @RequestMapping( |
| 390 | + description = "Save the provided settings.", |
| 391 | + requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody( |
| 392 | + description = "Map of settings to be saved", |
| 393 | + required = true, |
| 394 | + content = { |
| 395 | + @Content( |
| 396 | + mediaType = MediaType.APPLICATION_FORM_URLENCODED_VALUE, |
| 397 | + schema = @Schema(implementation = Map.class), |
| 398 | + examples = { |
| 399 | + @ExampleObject( |
| 400 | + name = "Example setting (application/x-www-form-urlencoded)", |
| 401 | + value = "{\n \"additionalProp1\": \"string\",\n \"additionalProp2\": \"string\",\n \"additionalProp3\": \"string\"\n}" |
| 402 | + ), |
| 403 | + @ExampleObject( |
| 404 | + name = "Example setting selection manager max records to 1000 (application/x-www-form-urlencoded)", |
| 405 | + value = "{\n \"system/selectionmanager/maxrecords\": \"1000\"\n}" |
| 406 | + ) |
| 407 | + } |
| 408 | + ), |
| 409 | + @Content( |
| 410 | + mediaType = MediaType.APPLICATION_JSON_VALUE, |
| 411 | + schema = @Schema(implementation = Map.class), |
| 412 | + examples = { |
| 413 | + @ExampleObject( |
| 414 | + name = "Example setting (application/json)", |
| 415 | + value = "{\n \"additionalProp1\": \"string\",\n \"additionalProp2\": \"string\",\n \"additionalProp3\": \"string\"\n}" |
| 416 | + ), |
| 417 | + @ExampleObject( |
| 418 | + name = "Example setting selection manager max records to 1000 (application/json)", |
| 419 | + value = "{\n \"system/selectionmanager/maxrecords\": \"1000\"\n}" |
| 420 | + ) |
| 421 | + } |
| 422 | + ) |
| 423 | + } |
| 424 | + ) |
| 425 | + ) |
| 426 | + @PostMapping( |
392 | 427 | path = "/settings",
|
393 |
| - produces = MediaType.APPLICATION_JSON_VALUE, |
394 |
| - method = RequestMethod.POST |
| 428 | + consumes = {MediaType.APPLICATION_FORM_URLENCODED_VALUE, MediaType.APPLICATION_JSON_VALUE} |
395 | 429 | )
|
396 | 430 | @PreAuthorize("hasAuthority('Administrator')")
|
397 | 431 | @ResponseStatus(HttpStatus.NO_CONTENT)
|
398 | 432 | @ApiResponses(value = {
|
399 |
| - @ApiResponse(responseCode = "204", description = "Settings saved.", content = {@Content(schema = @Schema(hidden = true))}), |
| 433 | + @ApiResponse(responseCode = "204", description = "Settings saved."), |
400 | 434 | @ApiResponse(responseCode = "403", description = ApiParams.API_RESPONSE_NOT_ALLOWED_ONLY_ADMIN)
|
401 | 435 | })
|
402 | 436 | public void saveSettings(
|
403 |
| - @Parameter(hidden = false) |
404 |
| - @RequestParam |
405 |
| - Map<String, String> allRequestParams, |
| 437 | + // Mark parameter as hidden in open api specification as the Operation requestBody(above) will describe the format to be supplied |
| 438 | + // Without this fix, the swagger ui will fail to work correctly. |
| 439 | + @Parameter(description = "Map of settings to be saved", |
| 440 | + required = true, hidden = true) |
| 441 | + @RequestParam Map<String, String> allRequestParams, |
406 | 442 | HttpServletRequest request
|
407 | 443 | ) throws Exception {
|
| 444 | + //If sent as JSON then the allRequestParams will be empty, and we need to manually load it from the request body |
| 445 | + if (MediaType.APPLICATION_JSON_VALUE.equals(request.getContentType()) && allRequestParams.isEmpty()) { |
| 446 | + BufferedReader reader = request.getReader(); |
| 447 | + ObjectMapper mapper = new ObjectMapper(); |
| 448 | + allRequestParams = mapper.readValue(reader, new TypeReference<Map<String, String>>() {}); |
| 449 | + } |
| 450 | + |
408 | 451 | ApplicationContext applicationContext = ApplicationContextHolder.get();
|
409 | 452 | String currentUuid = settingManager.getSiteId();
|
410 | 453 | String oldSiteName = settingManager.getSiteName();
|
|
0 commit comments