From 9646607e475afd437ae82b0133d6f2ba9fcb7fe6 Mon Sep 17 00:00:00 2001 From: Florian Hotze Date: Wed, 30 Oct 2024 18:21:46 +0100 Subject: [PATCH] [rest] VoiceResource: Return answer from /interpreters endpoint & Add annotations for answer Signed-off-by: Florian Hotze --- .../core/io/rest/voice/internal/VoiceResource.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bundles/org.openhab.core.io.rest.voice/src/main/java/org/openhab/core/io/rest/voice/internal/VoiceResource.java b/bundles/org.openhab.core.io.rest.voice/src/main/java/org/openhab/core/io/rest/voice/internal/VoiceResource.java index de11bac8b12..305802f1155 100644 --- a/bundles/org.openhab.core.io.rest.voice/src/main/java/org/openhab/core/io/rest/voice/internal/VoiceResource.java +++ b/bundles/org.openhab.core.io.rest.voice/src/main/java/org/openhab/core/io/rest/voice/internal/VoiceResource.java @@ -139,8 +139,9 @@ public Response getInterpreter( @POST @Path("/interpreters/{ids: [a-zA-Z_0-9,]+}") @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.TEXT_PLAIN) @Operation(operationId = "interpretText", summary = "Sends a text to a given human language interpreter(s).", responses = { - @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = String.class))), @ApiResponse(responseCode = "404", description = "No human language interpreter was found."), @ApiResponse(responseCode = "400", description = "interpretation exception occurs") }) public Response interpret( @@ -175,8 +176,9 @@ public Response interpret( @POST @Path("/interpreters") @Consumes(MediaType.TEXT_PLAIN) + @Produces(MediaType.TEXT_PLAIN) @Operation(operationId = "interpretTextByDefaultInterpreter", summary = "Sends a text to the default human language interpreter.", responses = { - @ApiResponse(responseCode = "200", description = "OK"), + @ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = String.class))), @ApiResponse(responseCode = "404", description = "No human language interpreter was found."), @ApiResponse(responseCode = "400", description = "interpretation exception occurs") }) public Response interpret( @@ -189,8 +191,8 @@ public Response interpret( } try { - hli.interpret(locale, text); - return Response.ok(null, MediaType.TEXT_PLAIN).build(); + String answer = hli.interpret(locale, text); + return Response.ok(answer, MediaType.TEXT_PLAIN).build(); } catch (InterpretationException e) { return JSONResponse.createErrorResponse(Status.BAD_REQUEST, e.getMessage()); }