Skip to content

Commit

Permalink
[strimzi#434] fix: edits after review
Browse files Browse the repository at this point in the history
Signed-off-by: ilkerkocatepe <[email protected]>
  • Loading branch information
ilkerkocatepe committed Nov 19, 2024
1 parent 1514090 commit 4be7bbe
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
e6ff5b267f241378e60e023ea1c57ccf90fd17170045b92e00e39d29bec17522
dff7d42e8ed3327a4f6bb31ee1538f2ce13654848528c99bade2fc1e218e4ee4
78 changes: 39 additions & 39 deletions documentation/book/api/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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. <<CreateTopic>>
| NewTopic
| Creates a topic with given name, partitions count and replication factor. <<NewTopic>>
| X
|
|
Expand Down Expand Up @@ -2350,7 +2350,7 @@ Creates a topic with given name, partitions count and replication factor.
| <<>>


| 422
| 400
| Request body is null or it doesn&#39;t contain topic name.
| <<Error>>

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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<Integer> partitionsCount = Optional.ofNullable(jsonBody.getInteger("partitions_count"));
Optional<Short> replicationFactor = Optional.ofNullable(jsonBody.getInteger("replication_factor"))
Expand Down
13 changes: 7 additions & 6 deletions src/main/resources/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@
"content": {
"application/vnd.kafka.json.v2+json": {
"schema": {
"$ref": "#/components/schemas/CreateTopic"
"$ref": "#/components/schemas/NewTopic"
}
}
},
Expand All @@ -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": {
Expand All @@ -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"
}
}
}
Expand Down Expand Up @@ -2240,8 +2240,8 @@
],
"nullable" : true
},
"CreateTopic": {
"title": "CreateTopic",
"NewTopic": {
"title": "NewTopic",
"type": "object",
"properties": {
"topic_name": {
Expand All @@ -2259,6 +2259,7 @@
"nullable": true
}
},
"required": ["topic_name"],
"additionalProperties": false,
"example": {
"topic_name": "my-topic",
Expand Down
13 changes: 7 additions & 6 deletions src/main/resources/openapiv2.json
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/CreateTopic"
"$ref": "#/definitions/NewTopic"
}
}
],
Expand All @@ -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"
}
}
}
Expand Down Expand Up @@ -2071,8 +2071,8 @@
"null"
]
},
"CreateTopic": {
"title": "CreateTopic",
"NewTopic": {
"title": "NewTopic",
"type": "object",
"properties": {
"topic_name": {
Expand All @@ -2088,6 +2088,7 @@
"type": "integer"
}
},
"required": ["topic_name"],
"additionalProperties": false,
"example": {
"topic_name": "my-topic",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ void createTopicBlankBodyTest(VertxTestContext context) {
context.verify(() -> {
assertThat(ar.succeeded(), is(true));
HttpResponse<JsonObject> response = ar.result();
assertThat(response.statusCode(), is(HttpResponseStatus.UNPROCESSABLE_ENTITY.code()));
assertThat(response.statusCode(), is(HttpResponseStatus.BAD_REQUEST.code()));
});
context.completeNow();
});
Expand Down

0 comments on commit 4be7bbe

Please sign in to comment.