Skip to content

Commit 921c422

Browse files
committed
feat: move executables into bin dir and gen openapi doc
1 parent 203a59f commit 921c422

File tree

7 files changed

+256
-3
lines changed

7 files changed

+256
-3
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
[package]
22
name = "codecraft-server"
33
description = "CodeCraft Backend Server"
4-
version = "0.1.0"
4+
version = "0.2.0"
55
edition = "2021"
66

7+
default-run = "codecraft-server"
8+
79
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
10+
811
[lib]
912
name = "codecraft"
1013
path = "src/lib.rs"
1114

15+
[[bin]]
16+
name = "codecraft-server"
17+
path = "src/bin/codecraft-server.rs"
18+
19+
[[bin]]
20+
name = "openapi-generator"
21+
path = "src/bin/openapi-generator.rs"
22+
1223
[dependencies]
1324
anyhow = "1.0.98"
1425
axum = { version = "0.8.4" }

justfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@ check:
3232
just clippy
3333
just test
3434

35+
# Generate OpenAPI documentation
36+
openapi:
37+
cargo run --bin openapi-generator > openapi.json
38+
3539
# Run all commend in the local environment
3640
all:
3741
just clean
3842
just check
3943
just build
44+
just openapi

openapi.json

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
{
2+
"openapi": "3.1.0",
3+
"info": {
4+
"title": "codecraft-server",
5+
"description": "CodeCraft Backend Server",
6+
"license": {
7+
"name": ""
8+
},
9+
"version": "0.2.0"
10+
},
11+
"paths": {
12+
"/v1/workflows": {
13+
"post": {
14+
"tags": [
15+
"Workflows"
16+
],
17+
"summary": "Create a workflow.",
18+
"operationId": "create",
19+
"requestBody": {
20+
"description": "Create workflow request",
21+
"content": {
22+
"application/json": {
23+
"schema": {
24+
"type": "object",
25+
"required": [
26+
"repo"
27+
],
28+
"properties": {
29+
"branch": {
30+
"type": [
31+
"string",
32+
"null"
33+
],
34+
"description": "Git branch, eg. master or main"
35+
},
36+
"repo": {
37+
"type": "string",
38+
"description": "Source code repository"
39+
},
40+
"rev": {
41+
"type": [
42+
"string",
43+
"null"
44+
],
45+
"description": "A commit hash like rev = \"4c59b707\", or a named reference exposed by\nthe remote repository such as rev = \"refs/pull/493/head\". What references\nare available varies by where the repo is hosted."
46+
},
47+
"tag": {
48+
"type": [
49+
"string",
50+
"null"
51+
],
52+
"description": "Git tag, eg. v1.0"
53+
}
54+
}
55+
}
56+
}
57+
},
58+
"required": true
59+
},
60+
"responses": {
61+
"201": {
62+
"description": "Workflow created successfully",
63+
"content": {
64+
"application/json": {
65+
"schema": {
66+
"$ref": "#/components/schemas/WorkflowResponse"
67+
}
68+
}
69+
}
70+
}
71+
}
72+
}
73+
},
74+
"/v1/workflows/{id}": {
75+
"post": {
76+
"tags": [
77+
"Workflows"
78+
],
79+
"summary": "Get a workflow.",
80+
"operationId": "get",
81+
"parameters": [
82+
{
83+
"name": "id",
84+
"in": "path",
85+
"description": "The id of workflow",
86+
"required": true,
87+
"schema": {
88+
"type": "string",
89+
"format": "uuid"
90+
}
91+
}
92+
],
93+
"responses": {
94+
"204": {
95+
"description": "Workflow started successfully"
96+
},
97+
"404": {
98+
"description": "Workflow not found"
99+
},
100+
"500": {
101+
"description": "Failed to start workflow"
102+
}
103+
}
104+
},
105+
"delete": {
106+
"tags": [
107+
"Workflows"
108+
],
109+
"summary": "Delete a workflow.",
110+
"operationId": "delete",
111+
"parameters": [
112+
{
113+
"name": "id",
114+
"in": "path",
115+
"description": "The id of workflow",
116+
"required": true,
117+
"schema": {
118+
"type": "string",
119+
"format": "uuid"
120+
}
121+
}
122+
],
123+
"responses": {
124+
"204": {
125+
"description": "Workflow deleted successfully"
126+
},
127+
"404": {
128+
"description": "Workflow not found"
129+
},
130+
"500": {
131+
"description": "Failed to delete workflow"
132+
}
133+
}
134+
}
135+
}
136+
},
137+
"components": {
138+
"schemas": {
139+
"CreateWorkflowRequest": {
140+
"type": "object",
141+
"required": [
142+
"repo"
143+
],
144+
"properties": {
145+
"branch": {
146+
"type": [
147+
"string",
148+
"null"
149+
],
150+
"description": "Git branch, eg. master or main"
151+
},
152+
"repo": {
153+
"type": "string",
154+
"description": "Source code repository"
155+
},
156+
"rev": {
157+
"type": [
158+
"string",
159+
"null"
160+
],
161+
"description": "A commit hash like rev = \"4c59b707\", or a named reference exposed by\nthe remote repository such as rev = \"refs/pull/493/head\". What references\nare available varies by where the repo is hosted."
162+
},
163+
"tag": {
164+
"type": [
165+
"string",
166+
"null"
167+
],
168+
"description": "Git tag, eg. v1.0"
169+
}
170+
}
171+
},
172+
"WorkflowResponse": {
173+
"type": "object",
174+
"required": [
175+
"repo"
176+
],
177+
"properties": {
178+
"branch": {
179+
"type": [
180+
"string",
181+
"null"
182+
],
183+
"description": "Git branch, eg. master or main"
184+
},
185+
"repo": {
186+
"type": "string",
187+
"description": "Source code repository"
188+
},
189+
"rev": {
190+
"type": [
191+
"string",
192+
"null"
193+
],
194+
"description": "A commit hash like rev = \"4c59b707\", or a named reference exposed by\nthe remote repository such as rev = \"refs/pull/493/head\". What references\nare available varies by where the repo is hosted."
195+
},
196+
"tag": {
197+
"type": [
198+
"string",
199+
"null"
200+
],
201+
"description": "Git tag, eg. v1.0"
202+
}
203+
}
204+
}
205+
}
206+
},
207+
"tags": [
208+
{
209+
"name": "Workflows",
210+
"description": "The Workflow Service Handlers"
211+
}
212+
]
213+
}
File renamed without changes.

src/bin/openapi-generator.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (c) wangeguo. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
use codecraft::swagger::ApiDoc;
16+
use utoipa::OpenApi;
17+
18+
fn main() {
19+
let openapi = ApiDoc::openapi();
20+
let json = serde_json::to_string_pretty(&openapi).unwrap();
21+
22+
// Print the OpenAPI document to stdout
23+
println!("{}", json);
24+
}

src/swagger.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use crate::{handlers, requests, responses};
3434
(name = "Workflows", description = "The Workflow Service Handlers"),
3535
),
3636
)]
37-
struct ApiDoc;
37+
pub struct ApiDoc;
3838

3939
pub fn build() -> SwaggerUi {
4040
SwaggerUi::new("/swagger").url("/openapi.json", ApiDoc::openapi())

0 commit comments

Comments
 (0)