From 4be7bbea030b2f5c6ae1d6afdca3a4c77a25cb22 Mon Sep 17 00:00:00 2001 From: ilkerkocatepe Date: Wed, 30 Oct 2024 23:02:30 +0300 Subject: [PATCH] [#434] fix: edits after review Signed-off-by: ilkerkocatepe --- .../openapi.json-generate-apidoc.sha256 | 2 +- documentation/book/api/index.adoc | 78 +++++++++---------- .../bridge/http/HttpAdminBridgeEndpoint.java | 12 ++- src/main/resources/openapi.json | 13 ++-- src/main/resources/openapiv2.json | 13 ++-- .../kafka/bridge/http/AdminClientIT.java | 2 +- 6 files changed, 66 insertions(+), 54 deletions(-) diff --git a/documentation/book/api/.openapi-generator/openapi.json-generate-apidoc.sha256 b/documentation/book/api/.openapi-generator/openapi.json-generate-apidoc.sha256 index 6f9941e7..1e82ad79 100644 --- a/documentation/book/api/.openapi-generator/openapi.json-generate-apidoc.sha256 +++ b/documentation/book/api/.openapi-generator/openapi.json-generate-apidoc.sha256 @@ -1 +1 @@ -e6ff5b267f241378e60e023ea1c57ccf90fd17170045b92e00e39d29bec17522 \ No newline at end of file +dff7d42e8ed3327a4f6bb31ee1538f2ce13654848528c99bade2fc1e218e4ee4 \ No newline at end of file diff --git a/documentation/book/api/index.adoc b/documentation/book/api/index.adoc index ca8cc3f2..f5fb9b1e 100644 --- a/documentation/book/api/index.adoc +++ b/documentation/book/api/index.adoc @@ -2314,8 +2314,8 @@ Creates a topic with given name, partitions count and replication factor. |=== |Name| Description| Required| Default| Pattern -| CreateTopic -| Creates a topic with given name, partitions count and replication factor. <> +| NewTopic +| Creates a topic with given name, partitions count and replication factor. <> | X | | @@ -2350,7 +2350,7 @@ Creates a topic with given name, partitions count and replication factor. | <<>> -| 422 +| 400 | Request body is null or it doesn't contain topic name. | <> @@ -3211,42 +3211,6 @@ Information about Kafka Bridge instance. -[#CreateTopic] -=== _CreateTopic_ CreateTopic - - - - -[.fields-CreateTopic] -[cols="2,1,1,2,4,1"] -|=== -| Field Name| Required| Nullable | Type| Description | Format - -| topic_name -| -| -| String -| Name of the topic to create. -| - -| partitions_count -| -| X -| Integer -| Number of partitions for the topic. -| - -| replication_factor -| -| X -| Integer -| Number of replicas for each partition. -| - -|=== - - - [#CreatedConsumer] === _CreatedConsumer_ CreatedConsumer @@ -3334,6 +3298,42 @@ Information about Kafka Bridge instance. +[#NewTopic] +=== _NewTopic_ NewTopic + + + + +[.fields-NewTopic] +[cols="2,1,1,2,4,1"] +|=== +| Field Name| Required| Nullable | Type| Description | Format + +| topic_name +| X +| +| String +| Name of the topic to create. +| + +| partitions_count +| +| X +| Integer +| Number of partitions for the topic. +| + +| replication_factor +| +| X +| Integer +| Number of replicas for each partition. +| + +|=== + + + [#OffsetCommitSeek] === _OffsetCommitSeek_ OffsetCommitSeek diff --git a/src/main/java/io/strimzi/kafka/bridge/http/HttpAdminBridgeEndpoint.java b/src/main/java/io/strimzi/kafka/bridge/http/HttpAdminBridgeEndpoint.java index b5868006..4d037676 100644 --- a/src/main/java/io/strimzi/kafka/bridge/http/HttpAdminBridgeEndpoint.java +++ b/src/main/java/io/strimzi/kafka/bridge/http/HttpAdminBridgeEndpoint.java @@ -187,7 +187,7 @@ public void doGetTopic(RoutingContext routingContext) { public void doCreateTopic(RoutingContext routingContext) { JsonObject jsonBody = routingContext.body().asJsonObject(); - if (jsonBody.isEmpty() || jsonBody.getString("topic_name").isBlank()) { + if (jsonBody.isEmpty()) { HttpBridgeError error = new HttpBridgeError( HttpResponseStatus.UNPROCESSABLE_ENTITY.code(), "Request body must be a JSON object" @@ -197,6 +197,16 @@ public void doCreateTopic(RoutingContext routingContext) { return; } + if (jsonBody.getString("topic_name").isBlank()) { + HttpBridgeError error = new HttpBridgeError( + HttpResponseStatus.UNPROCESSABLE_ENTITY.code(), + "Topic name must not be empty" + ); + HttpUtils.sendResponse(routingContext, HttpResponseStatus.UNPROCESSABLE_ENTITY.code(), + BridgeContentType.KAFKA_JSON, JsonUtils.jsonToBytes(error.toJson())); + return; + } + String topicName = jsonBody.getString("topic_name"); Optional partitionsCount = Optional.ofNullable(jsonBody.getInteger("partitions_count")); Optional replicationFactor = Optional.ofNullable(jsonBody.getInteger("replication_factor")) diff --git a/src/main/resources/openapi.json b/src/main/resources/openapi.json index aa992e44..c8bacc9c 100644 --- a/src/main/resources/openapi.json +++ b/src/main/resources/openapi.json @@ -765,7 +765,7 @@ "content": { "application/vnd.kafka.json.v2+json": { "schema": { - "$ref": "#/components/schemas/CreateTopic" + "$ref": "#/components/schemas/NewTopic" } } }, @@ -778,7 +778,7 @@ "application/vnd.kafka.v2+json": {} } }, - "422": { + "400": { "description": "Request body is null or it doesn't contain topic name.", "content": { "application/vnd.kafka.v2+json": { @@ -788,8 +788,8 @@ "examples": { "response": { "value": { - "error_code": 422, - "message": "Request body is null or it doesn't contain topic name." + "error_code": 400, + "message": "Validation error on: - provided object should contain property topic_name" } } } @@ -2240,8 +2240,8 @@ ], "nullable" : true }, - "CreateTopic": { - "title": "CreateTopic", + "NewTopic": { + "title": "NewTopic", "type": "object", "properties": { "topic_name": { @@ -2259,6 +2259,7 @@ "nullable": true } }, + "required": ["topic_name"], "additionalProperties": false, "example": { "topic_name": "my-topic", diff --git a/src/main/resources/openapiv2.json b/src/main/resources/openapiv2.json index e16fb5c0..7078aff2 100644 --- a/src/main/resources/openapiv2.json +++ b/src/main/resources/openapiv2.json @@ -705,7 +705,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/CreateTopic" + "$ref": "#/definitions/NewTopic" } } ], @@ -714,15 +714,15 @@ "description": "Created", "schema": {} }, - "422": { + "400": { "description": "Request body is null or it doesn't contain topic name.", "schema": { "$ref": "#/definitions/Error" }, "examples": { "application/vnd.kafka.v2+json": { - "error_code": 422, - "message": "Request body is null or it doesn't contain topic name." + "error_code": 400, + "message": "Validation error on: - provided object should contain property topic_name" } } } @@ -2071,8 +2071,8 @@ "null" ] }, - "CreateTopic": { - "title": "CreateTopic", + "NewTopic": { + "title": "NewTopic", "type": "object", "properties": { "topic_name": { @@ -2088,6 +2088,7 @@ "type": "integer" } }, + "required": ["topic_name"], "additionalProperties": false, "example": { "topic_name": "my-topic", diff --git a/src/test/java/io/strimzi/kafka/bridge/http/AdminClientIT.java b/src/test/java/io/strimzi/kafka/bridge/http/AdminClientIT.java index a5774b0f..bc8ae7e5 100644 --- a/src/test/java/io/strimzi/kafka/bridge/http/AdminClientIT.java +++ b/src/test/java/io/strimzi/kafka/bridge/http/AdminClientIT.java @@ -228,7 +228,7 @@ void createTopicBlankBodyTest(VertxTestContext context) { context.verify(() -> { assertThat(ar.succeeded(), is(true)); HttpResponse response = ar.result(); - assertThat(response.statusCode(), is(HttpResponseStatus.UNPROCESSABLE_ENTITY.code())); + assertThat(response.statusCode(), is(HttpResponseStatus.BAD_REQUEST.code())); }); context.completeNow(); });