I'm using swaggerUI to verfy my swagger specification.
GET methods or a POST method with a body works fine, but i get problems when using a POST method with @FormParam. My server says it is missing a contenttype from the request and it is right, the generated command by SwaggerUi looks like this
curl -X POST "https://localhost:8184/authentication/password/reset?username=chrome&newPassword=11114444" -H "accept: application/json"
my swaggerUI code looks that way
/user/delete:
post:
tags:
- "Usermanagement"
summary: Löscht einen Nutzer
description: Löscht einen Nutzer anhand seines "username"
consumes:
- application/x-www-form-urlencoded
produces:
- application/json
parameters:
- in: query
name: username
type: "string"
description: Benutzername
responses:
200:
description: Nutzer wurde erfolgreich gelöscht
400:
description: Der Löschvorgang konnte nicht ausgeführt werden
whereas my server code looks like that
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.APPLICATION_JSON)
@Path("/activation")
public Response activation(@NotNull @FormParam("username") String username,
@NotNull @FormParam("active") Boolean active) {
return runWithExceptionMapper(() -> {
if (active) {
userService.activateUser(username);
} else {
userService.deactivateUser(username);
}
});
}
Server code is in general fine, it works from browser and from Postman.
I just can't figure out why swaggerUI doesn't send contenttype with the curl command or how I can force it to do so.
EDIT: I figured out that the brwoser is not sending the curl-command, but a http-request. But there is still missing content in the payload, namly content-type. Why my server doen't know what to do with the "unknown" data.
Problem is solved.
Mistake was the in-type of my parameters. Instead of query it should be formData (obviously).
Correct specification code looks like this
/user/delete:
post:
tags:
- "Usermanagement"
summary: Löscht einen Nutzer
description: Löscht einen Nutzer anhand seines "username"
consumes:
- application/x-www-form-urlencoded
produces:
- application/json
parameters:
- in: formData
name: username
type: "string"
description: Benutzername
responses:
200:
description: Nutzer wurde erfolgreich gelöscht
400:
description: Der Löschvorgang konnte nicht ausgeführt werden