Skip to content

Commit d923836

Browse files
committed
[strimzi#434] fix: edits after review
Signed-off-by: ilkerkocatepe <[email protected]>
1 parent 9e9f096 commit d923836

File tree

6 files changed

+66
-54
lines changed

6 files changed

+66
-54
lines changed
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
e6ff5b267f241378e60e023ea1c57ccf90fd17170045b92e00e39d29bec17522
1+
dff7d42e8ed3327a4f6bb31ee1538f2ce13654848528c99bade2fc1e218e4ee4

documentation/book/api/index.adoc

+39-39
Original file line numberDiff line numberDiff line change
@@ -2314,8 +2314,8 @@ Creates a topic with given name, partitions count and replication factor.
23142314
|===
23152315
|Name| Description| Required| Default| Pattern
23162316

2317-
| CreateTopic
2318-
| Creates a topic with given name, partitions count and replication factor. <<CreateTopic>>
2317+
| NewTopic
2318+
| Creates a topic with given name, partitions count and replication factor. <<NewTopic>>
23192319
| X
23202320
|
23212321
|
@@ -2350,7 +2350,7 @@ Creates a topic with given name, partitions count and replication factor.
23502350
| <<>>
23512351

23522352

2353-
| 422
2353+
| 400
23542354
| Request body is null or it doesn&#39;t contain topic name.
23552355
| <<Error>>
23562356

@@ -3211,42 +3211,6 @@ Information about Kafka Bridge instance.
32113211

32123212

32133213

3214-
[#CreateTopic]
3215-
=== _CreateTopic_ CreateTopic
3216-
3217-
3218-
3219-
3220-
[.fields-CreateTopic]
3221-
[cols="2,1,1,2,4,1"]
3222-
|===
3223-
| Field Name| Required| Nullable | Type| Description | Format
3224-
3225-
| topic_name
3226-
|
3227-
|
3228-
| String
3229-
| Name of the topic to create.
3230-
|
3231-
3232-
| partitions_count
3233-
|
3234-
| X
3235-
| Integer
3236-
| Number of partitions for the topic.
3237-
|
3238-
3239-
| replication_factor
3240-
|
3241-
| X
3242-
| Integer
3243-
| Number of replicas for each partition.
3244-
|
3245-
3246-
|===
3247-
3248-
3249-
32503214
[#CreatedConsumer]
32513215
=== _CreatedConsumer_ CreatedConsumer
32523216

@@ -3334,6 +3298,42 @@ Information about Kafka Bridge instance.
33343298

33353299

33363300

3301+
[#NewTopic]
3302+
=== _NewTopic_ NewTopic
3303+
3304+
3305+
3306+
3307+
[.fields-NewTopic]
3308+
[cols="2,1,1,2,4,1"]
3309+
|===
3310+
| Field Name| Required| Nullable | Type| Description | Format
3311+
3312+
| topic_name
3313+
| X
3314+
|
3315+
| String
3316+
| Name of the topic to create.
3317+
|
3318+
3319+
| partitions_count
3320+
|
3321+
| X
3322+
| Integer
3323+
| Number of partitions for the topic.
3324+
|
3325+
3326+
| replication_factor
3327+
|
3328+
| X
3329+
| Integer
3330+
| Number of replicas for each partition.
3331+
|
3332+
3333+
|===
3334+
3335+
3336+
33373337
[#OffsetCommitSeek]
33383338
=== _OffsetCommitSeek_ OffsetCommitSeek
33393339

src/main/java/io/strimzi/kafka/bridge/http/HttpAdminBridgeEndpoint.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public void doGetTopic(RoutingContext routingContext) {
187187
public void doCreateTopic(RoutingContext routingContext) {
188188
JsonObject jsonBody = routingContext.body().asJsonObject();
189189

190-
if (jsonBody.isEmpty() || jsonBody.getString("topic_name").isBlank()) {
190+
if (jsonBody.isEmpty()) {
191191
HttpBridgeError error = new HttpBridgeError(
192192
HttpResponseStatus.UNPROCESSABLE_ENTITY.code(),
193193
"Request body must be a JSON object"
@@ -197,6 +197,16 @@ public void doCreateTopic(RoutingContext routingContext) {
197197
return;
198198
}
199199

200+
if (jsonBody.getString("topic_name").isBlank()) {
201+
HttpBridgeError error = new HttpBridgeError(
202+
HttpResponseStatus.UNPROCESSABLE_ENTITY.code(),
203+
"Topic name must not be empty"
204+
);
205+
HttpUtils.sendResponse(routingContext, HttpResponseStatus.UNPROCESSABLE_ENTITY.code(),
206+
BridgeContentType.KAFKA_JSON, JsonUtils.jsonToBytes(error.toJson()));
207+
return;
208+
}
209+
200210
String topicName = jsonBody.getString("topic_name");
201211
Optional<Integer> partitionsCount = Optional.ofNullable(jsonBody.getInteger("partitions_count"));
202212
Optional<Short> replicationFactor = Optional.ofNullable(jsonBody.getInteger("replication_factor"))

src/main/resources/openapi.json

+7-6
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@
765765
"content": {
766766
"application/vnd.kafka.json.v2+json": {
767767
"schema": {
768-
"$ref": "#/components/schemas/CreateTopic"
768+
"$ref": "#/components/schemas/NewTopic"
769769
}
770770
}
771771
},
@@ -778,7 +778,7 @@
778778
"application/vnd.kafka.v2+json": {}
779779
}
780780
},
781-
"422": {
781+
"400": {
782782
"description": "Request body is null or it doesn't contain topic name.",
783783
"content": {
784784
"application/vnd.kafka.v2+json": {
@@ -788,8 +788,8 @@
788788
"examples": {
789789
"response": {
790790
"value": {
791-
"error_code": 422,
792-
"message": "Request body is null or it doesn't contain topic name."
791+
"error_code": 400,
792+
"message": "Validation error on: - provided object should contain property topic_name"
793793
}
794794
}
795795
}
@@ -2240,8 +2240,8 @@
22402240
],
22412241
"nullable" : true
22422242
},
2243-
"CreateTopic": {
2244-
"title": "CreateTopic",
2243+
"NewTopic": {
2244+
"title": "NewTopic",
22452245
"type": "object",
22462246
"properties": {
22472247
"topic_name": {
@@ -2259,6 +2259,7 @@
22592259
"nullable": true
22602260
}
22612261
},
2262+
"required": ["topic_name"],
22622263
"additionalProperties": false,
22632264
"example": {
22642265
"topic_name": "my-topic",

src/main/resources/openapiv2.json

+7-6
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@
705705
"in": "body",
706706
"required": true,
707707
"schema": {
708-
"$ref": "#/definitions/CreateTopic"
708+
"$ref": "#/definitions/NewTopic"
709709
}
710710
}
711711
],
@@ -714,15 +714,15 @@
714714
"description": "Created",
715715
"schema": {}
716716
},
717-
"422": {
717+
"400": {
718718
"description": "Request body is null or it doesn't contain topic name.",
719719
"schema": {
720720
"$ref": "#/definitions/Error"
721721
},
722722
"examples": {
723723
"application/vnd.kafka.v2+json": {
724-
"error_code": 422,
725-
"message": "Request body is null or it doesn't contain topic name."
724+
"error_code": 400,
725+
"message": "Validation error on: - provided object should contain property topic_name"
726726
}
727727
}
728728
}
@@ -2071,8 +2071,8 @@
20712071
"null"
20722072
]
20732073
},
2074-
"CreateTopic": {
2075-
"title": "CreateTopic",
2074+
"NewTopic": {
2075+
"title": "NewTopic",
20762076
"type": "object",
20772077
"properties": {
20782078
"topic_name": {
@@ -2088,6 +2088,7 @@
20882088
"type": "integer"
20892089
}
20902090
},
2091+
"required": ["topic_name"],
20912092
"additionalProperties": false,
20922093
"example": {
20932094
"topic_name": "my-topic",

src/test/java/io/strimzi/kafka/bridge/http/AdminClientIT.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ void createTopicBlankBodyTest(VertxTestContext context) {
228228
context.verify(() -> {
229229
assertThat(ar.succeeded(), is(true));
230230
HttpResponse<JsonObject> response = ar.result();
231-
assertThat(response.statusCode(), is(HttpResponseStatus.UNPROCESSABLE_ENTITY.code()));
231+
assertThat(response.statusCode(), is(HttpResponseStatus.BAD_REQUEST.code()));
232232
});
233233
context.completeNow();
234234
});

0 commit comments

Comments
 (0)