Skip to content

Commit

Permalink
Fix set site settings in swagger_ui so it function correctly.
Browse files Browse the repository at this point in the history
Prior to this fix, the swagger ui for applying site settings was not working.
  • Loading branch information
ianwallen committed Dec 24, 2024
1 parent 490e6b9 commit 37e2faf
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions services/src/main/java/org/fao/geonet/api/site/SiteApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import co.elastic.clients.elasticsearch.core.CountResponse;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
Expand Down Expand Up @@ -387,11 +388,29 @@ public List<Setting> getSettingsDetails(

@io.swagger.v3.oas.annotations.Operation(
summary = "Save settings",
description = "")
@RequestMapping(
description = "Save the provided settings.",
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
description = "Map of settings to be saved",
required = true,
content = @Content(
mediaType = MediaType.APPLICATION_FORM_URLENCODED_VALUE,
schema = @Schema(implementation = Map.class),
examples = {
@ExampleObject(
name = "Example setting",
value = "{\n \"additionalProp1\": \"string\",\n \"additionalProp2\": \"string\",\n \"additionalProp3\": \"string\"\n}"
),
@ExampleObject(
name = "Example setting selection manager max records to 1000",
value = "{\n \"system/selectionmanager/maxrecords\": \"1000\"\n}"
)
}
)
)
)
@PostMapping(
path = "/settings",
produces = MediaType.APPLICATION_JSON_VALUE,
method = RequestMethod.POST
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE
)
@PreAuthorize("hasAuthority('Administrator')")
@ResponseStatus(HttpStatus.NO_CONTENT)
Expand All @@ -400,9 +419,11 @@ public List<Setting> getSettingsDetails(
@ApiResponse(responseCode = "403", description = ApiParams.API_RESPONSE_NOT_ALLOWED_ONLY_ADMIN)
})
public void saveSettings(
@Parameter(hidden = false)
@RequestParam
Map<String, String> allRequestParams,
// Mark parameter as hidden in open api specificatin as the Operation requestBody will describe the format to be supplied
// Without this fix, the swagger ui will fail to work correctly.
@Parameter(description = "Map of settings to be saved", required = true, hidden = true)
@RequestParam
Map<String,String> allRequestParams,
HttpServletRequest request
) throws Exception {
ApplicationContext applicationContext = ApplicationContextHolder.get();
Expand Down

0 comments on commit 37e2faf

Please sign in to comment.