Skip to content

Commit 8a03bfd

Browse files
committed
Use typespec contracts
1 parent ad3ac5c commit 8a03bfd

File tree

26 files changed

+4060
-4
lines changed

26 files changed

+4060
-4
lines changed

api/src/main/java/io/kafbat/ui/mapper/DynamicConfigMapper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.kafbat.ui.mapper;
22

33
import io.kafbat.ui.model.ActionDTO;
4+
import io.kafbat.ui.model.ApplicationConfigPropertiesAuthOauth2ClientValueDTO;
45
import io.kafbat.ui.model.ApplicationConfigPropertiesAuthOauth2ResourceServerDTO;
56
import io.kafbat.ui.model.ApplicationConfigPropertiesAuthOauth2ResourceServerJwtDTO;
67
import io.kafbat.ui.model.ApplicationConfigPropertiesAuthOauth2ResourceServerOpaquetokenDTO;

api/src/test/java/io/kafbat/ui/service/mcp/McpSpecificationGeneratorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void testConvertController() {
8787
"clusterName", Map.of("type", "string"),
8888
"topicName", Map.of("type", "string"),
8989
"topicUpdate", SCHEMA_GENERATOR.generateSchema(TopicUpdateDTO.class)
90-
), List.of("clusterName", "topicName"), false, null, null)
90+
), List.of("clusterName", "topicName", "topicUpdate"), false, null, null)
9191
)
9292
);
9393
assertThat(tools).allMatch(tool ->

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ ext {
3535
release = resolveBooleanProperty("release")
3636
includeFrontend = resolveBooleanProperty("include-frontend", release)
3737
buildDockerImages = resolveBooleanProperty("build-docker-images", release)
38+
useTypeSpec = resolveBooleanProperty("typespec", false)
3839
runE2e = resolveBooleanProperty("run-e2e")
3940
}
4041

contract-typespec/api/acls.tsp

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import "@typespec/openapi";
2+
3+
using TypeSpec.Http;
4+
using OpenAPI;
5+
6+
@route("/api/clusters/{clusterName}/acls")
7+
@tag("Acls")
8+
interface AclApi {
9+
@doc("listKafkaAcls")
10+
@get
11+
@operationId("listAcls")
12+
listAcls(
13+
@path clusterName: string,
14+
@query resourceType?: KafkaAclResourceType,
15+
@query resourceName?: string,
16+
@query namePatternType?: KafkaAclNamePatternType,
17+
): KafkaAcl[];
18+
19+
@route("/csv")
20+
@doc("getAclAsCsv")
21+
@get
22+
@operationId("getAclAsCsv")
23+
getAclAsCsv(@path clusterName: string): string;
24+
25+
@route("/csv")
26+
@doc("syncAclsCsv")
27+
@post
28+
@operationId("syncAclsCsv")
29+
syncAclsCsv(@path clusterName: string, @body content: string): void | ApiBadRequestResponse;
30+
31+
@doc("createAcl")
32+
@post
33+
@operationId("createAcl")
34+
createAcl(@path clusterName: string, @body acl: KafkaAcl): void | ApiBadRequestResponse;
35+
36+
@doc("deleteAcl")
37+
@delete
38+
@operationId("deleteAcl")
39+
deleteAcl(
40+
@path clusterName: string,
41+
@body acl: KafkaAcl,
42+
): void | ApiNotFoundResponse;
43+
44+
@route("/consumer")
45+
@doc("createConsumerAcl")
46+
@post
47+
@operationId("createConsumerAcl")
48+
createConsumerAcl(
49+
@path clusterName: string,
50+
@body payload: CreateConsumerAcl,
51+
): void | ApiBadRequestResponse;
52+
53+
@route("/producer")
54+
@doc("createProducerAcl")
55+
@operationId("createProducerAcl")
56+
@post
57+
createProducerAcl(
58+
@path clusterName: string,
59+
@body payload: CreateProducerAcl,
60+
): void | ApiBadRequestResponse;
61+
62+
@route("/streamApp")
63+
@doc("createStreamAppAcl")
64+
@post
65+
@operationId("createStreamAppAcl")
66+
createStreamAppAcl(
67+
@path clusterName: string,
68+
@body payload: CreateStreamAppAcl,
69+
): void | ApiBadRequestResponse;
70+
}
71+
72+
model KafkaAcl {
73+
resourceType: KafkaAclResourceType;
74+
resourceName: string; // "*" if acl can be applied to any resource of given type
75+
namePatternType: KafkaAclNamePatternType;
76+
principal: string;
77+
host: string;
78+
operation: "UNKNOWN" | "ALL" | "READ" | "WRITE" | "CREATE" | "DELETE" | "ALTER" | "DESCRIBE" | "CLUSTER_ACTION" | "DESCRIBE_CONFIGS" | "ALTER_CONFIGS" | "IDEMPOTENT_WRITE" | "CREATE_TOKENS" | "DESCRIBE_TOKENS";
79+
permission: "ALLOW" | "DENY";
80+
}
81+
82+
enum KafkaAclResourceType {
83+
UNKNOWN,
84+
TOPIC,
85+
GROUP,
86+
CLUSTER,
87+
TRANSACTIONAL_ID,
88+
DELEGATION_TOKEN,
89+
USER,
90+
}
91+
92+
enum KafkaAclNamePatternType {
93+
MATCH,
94+
LITERAL,
95+
PREFIXED,
96+
}
97+
98+
model CreateConsumerAcl {
99+
principal: string;
100+
host: string;
101+
topics?: string[];
102+
topicsPrefix?: string;
103+
consumerGroups?: string[];
104+
consumerGroupsPrefix?: string;
105+
}
106+
107+
model CreateProducerAcl {
108+
principal: string;
109+
host: string;
110+
topics?: string[];
111+
topicsPrefix?: string;
112+
transactionalId?: string;
113+
transactionsIdPrefix?: string;
114+
idempotent?: boolean = false;
115+
}
116+
117+
model CreateStreamAppAcl {
118+
principal: string;
119+
host: string;
120+
inputTopics: string[];
121+
outputTopics: string[];
122+
applicationId: string;
123+
}

contract-typespec/api/auth.tsp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import "@typespec/openapi";
2+
3+
using TypeSpec.Http;
4+
using OpenAPI;
5+
6+
@tag("Authorization")
7+
interface AuthorizationApi {
8+
@route("/api/authorization")
9+
@doc("Get user authorization related info")
10+
@operationId("getUserAuthInfo")
11+
@get
12+
getUserAuthInfo(): AuthenticationInfo;
13+
}
14+
15+
@route("/login")
16+
@doc("Authenticate")
17+
@operationId("authenticate")
18+
@post
19+
op authenticate(@body form: LoginForm): void | Http.Response<401>;
20+
21+
model LoginForm {
22+
username: string;
23+
password: string;
24+
}
25+
26+
model AuthenticationInfo {
27+
rbacEnabled: boolean; // true if role based access control is enabled and granular permission access is required
28+
userInfo?: UserInfo;
29+
}
30+
31+
model UserInfo {
32+
username: string;
33+
permissions: UserPermission[];
34+
}
35+
36+
37+
model UserPermission {
38+
clusters: string[];
39+
resource: ResourceType;
40+
value?: string;
41+
actions: Action[];
42+
}

contract-typespec/api/brokers.tsp

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import "@typespec/openapi";
2+
3+
using TypeSpec.Http;
4+
using OpenAPI;
5+
6+
@route("/api/clusters/{clusterName}/brokers")
7+
@tag("Brokers")
8+
interface BrokersApi {
9+
@get
10+
@operationId("getBrokers")
11+
@doc("getBrokers")
12+
getBrokers(@path clusterName: string): Broker[];
13+
14+
@get
15+
@route("/{id}/configs")
16+
@operationId("getBrokerConfig")
17+
@doc("getBrokerConfig")
18+
getBrokerConfig(@path clusterName: string, @path id: int32): BrokerConfig[];
19+
20+
@put
21+
@route("/{id}/configs/{name}")
22+
@operationId("updateBrokerConfigByName")
23+
@doc("updateBrokerConfigByName")
24+
updateBrokerConfigByName(
25+
@path clusterName: string,
26+
@path id: int32,
27+
@path name: string,
28+
@body config: BrokerConfigItem,
29+
): void | ApiBadRequestResponse;
30+
31+
@get
32+
@route("/{id}/metrics")
33+
@operationId("getBrokersMetrics")
34+
@doc("getBrokersMetrics")
35+
getBrokersMetrics(@path clusterName: string, @path id: int32): BrokerMetrics;
36+
37+
@get
38+
@route("/logdirs")
39+
@operationId("getAllBrokersLogdirs")
40+
@doc("getAllBrokersLogdirs")
41+
getAllBrokersLogdirs(
42+
@path clusterName: string,
43+
@query broker?: int32[],
44+
): BrokersLogdirs[];
45+
46+
@patch(#{implicitOptionality: true})
47+
@route("/{id}/logdirs")
48+
@operationId("updateBrokerTopicPartitionLogDir")
49+
@doc("updateBrokerTopicPartitionLogDir")
50+
updateBrokerTopicPartitionLogDir(
51+
@path clusterName: string,
52+
@path id: int32,
53+
@body update: BrokerLogdirUpdate,
54+
): void | ApiBadRequestResponse;
55+
}
56+
57+
model Broker {
58+
id: int32;
59+
host?: string;
60+
port?: int32;
61+
bytesInPerSec?: float64;
62+
bytesOutPerSec?: float64;
63+
partitionsLeader?: int32;
64+
partitions?: int32;
65+
inSyncPartitions?: int32;
66+
partitionsSkew?: float64;
67+
leadersSkew?: float64;
68+
}
69+
70+
model BrokerLogdirUpdate {
71+
topic?: string;
72+
partition?: int32;
73+
logDir?: string;
74+
}
75+
76+
model BrokerConfig {
77+
name: string;
78+
value: string;
79+
source: ConfigSource;
80+
isSensitive: boolean;
81+
isReadOnly: boolean;
82+
synonyms?: ConfigSynonym[];
83+
}
84+
85+
model BrokerConfigItem {
86+
value?: string;
87+
}
88+
89+
model BrokerMetrics {
90+
segmentSize: int64;
91+
segmentCount: int32;
92+
metrics: Metric[];
93+
}
94+
95+
model BrokersLogdirs {
96+
name: string;
97+
error: string;
98+
topics: BrokerTopicLogdirs[];
99+
}
100+
101+
model BrokerTopicLogdirs {
102+
name?: string;
103+
partitions?: BrokerTopicPartitionLogdir[];
104+
}
105+
106+
model BrokerTopicPartitionLogdir extends TopicPartitionLogdir {
107+
broker?: int32;
108+
}
109+
110+
model TopicPartitionLogdir {
111+
partition?: int32;
112+
size?: int64;
113+
offsetLag?: int64;
114+
}

0 commit comments

Comments
 (0)