Skip to content

Commit c753706

Browse files
Merge pull request #65 from NYCU-SDC/docs/badge
Add more examples
2 parents 3ef0f4f + 0ccf4cd commit c753706

16 files changed

Lines changed: 206 additions & 2 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Deploy API docs and mock server
1+
name: Deploy API Docs and Mock Server
22

33
on:
44
push:

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Core System API
22

3-
Core System API defined using TypeSpec
3+
[![Test Build and Format](https://github.com/NYCU-SDC/core-system-api/actions/workflows/test.yml/badge.svg)](https://github.com/NYCU-SDC/core-system-api/actions/workflows/test.yml) [![Release SDK](https://github.com/NYCU-SDC/core-system-api/actions/workflows/sdk.yml/badge.svg)](https://github.com/NYCU-SDC/core-system-api/actions/workflows/sdk.yml) [![npm version](https://badge.fury.io/js/%40nycu-sdc%2Fcore-system-sdk.svg)](https://www.npmjs.com/package/@nycu-sdc/core-system-sdk)
4+
5+
Core System API defined using TypeSpec.
46

57
```mermaid
68
flowchart TD

src/auth/models.tsp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace CoreSystem.Auth {
99
nycu: "NYCU",
1010
}
1111

12+
@example(#{ accessToken: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", expirationTime: 1735689600, refreshToken: "d290f1ee-6c54-4b01-90e6-d701748f0851" })
1213
model RefreshToken {
1314
@doc("The access token and formatted as JWT")
1415
accessToken: string;
@@ -20,11 +21,13 @@ namespace CoreSystem.Auth {
2021
refreshToken: string;
2122
}
2223

24+
@example(#{ uid: "3c5fa073-7b97-43a3-bc44-ddc98f390a08" })
2325
model InternalLoginRequest {
2426
@doc("The user ID to login as.")
2527
uid: string;
2628
}
2729

30+
@example(#{ message: "Login successful" })
2831
model InternalLoginResponse {
2932
@doc("Login status message.")
3033
message: string;

src/error/models.tsp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace CoreSystem {
22
@error
33
@doc("Problem represents a problem detail as defined in RFC 7807")
4+
@example(#{ title: "Bad Request", status: 400, type: "https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400", detail: "Invalid request parameters" })
45
model ProblemDetail {
56
@doc("The problem's title.")
67
title: string;
@@ -16,6 +17,7 @@ namespace CoreSystem {
1617
}
1718

1819
@error
20+
@example(#{ title: "Unauthorized", status: 401, type: "https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/401", detail: "Authentication credentials were missing or invalid" })
1921
model Unauthorized {
2022
title: "Unauthorized";
2123
status: 401;
@@ -24,6 +26,7 @@ namespace CoreSystem {
2426
}
2527

2628
@error
29+
@example(#{ title: "Not Found", status: 404, type: "https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/404", detail: "The requested resource was not found" })
2730
model NotFound {
2831
title: "Not Found";
2932
status: 404;
@@ -32,6 +35,7 @@ namespace CoreSystem {
3235
}
3336

3437
@error
38+
@example(#{ title: "Bad Request", status: 400, type: "https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400", detail: "The request body contains invalid data" })
3539
model BadRequest {
3640
title: "Bad Request";
3741
status: 400;

src/form/answer/models.tsp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@ namespace CoreSystem.Responses {
101101
}
102102

103103
@doc("Response model for the uploaded files and auto-created answer")
104+
@example(#{
105+
id: "a12b3c4d-5e6f-7g8h-9i0j-k1l2m3n4o5p6",
106+
answer: #{
107+
createdAt: utcDateTime.fromISO("2025-02-15T10:00:00Z"),
108+
updatedAt: utcDateTime.fromISO("2025-02-17T16:45:00Z"),
109+
responseId: "a12b3c4d-5e6f-7g8h-9i0j-k1l2m3n4o5p6",
110+
answer: #{ questionId: "ee894524-4bd8-4a64-8fd2-a53b39ca94cd", questionType: CoreSystem.Forms.QuestionTypes.shortText, value: "John Doe" },
111+
displayValue: "John Doe",
112+
},
113+
})
104114
model QuestionFilesUploadResponse {
105115
@doc("The response's unique identifier.")
106116
id: uuid;
@@ -109,6 +119,16 @@ namespace CoreSystem.Responses {
109119
answer: AnswerPayload;
110120
}
111121

122+
@example(#{
123+
id: "a12b3c4d-5e6f-7g8h-9i0j-k1l2m3n4o5p6",
124+
answer: #{
125+
createdAt: utcDateTime.fromISO("2025-02-15T10:00:00Z"),
126+
updatedAt: utcDateTime.fromISO("2025-02-17T16:45:00Z"),
127+
responseId: "a12b3c4d-5e6f-7g8h-9i0j-k1l2m3n4o5p6",
128+
answer: #{ questionId: "ee894524-4bd8-4a64-8fd2-a53b39ca94cd", questionType: CoreSystem.Forms.QuestionTypes.shortText, value: "John Doe" },
129+
displayValue: "John Doe",
130+
},
131+
})
112132
model GetQuestionResponse {
113133
@doc("Response ID that this question answer belongs to.")
114134
id: uuid;
@@ -117,6 +137,25 @@ namespace CoreSystem.Responses {
117137
}
118138

119139
@doc("Contains the question details and the corresponding answer for a specific question in a response")
140+
@example(#{
141+
question: #{
142+
id: "ee894524-4bd8-4a64-8fd2-a53b39ca94cd",
143+
sectionId: "b23f2668-c2dc-4213-88fe-eceedff46398",
144+
required: true,
145+
type: CoreSystem.Forms.QuestionTypes.shortText,
146+
title: "What's your name?",
147+
description: "Please enter your full name",
148+
createdAt: utcDateTime.fromISO("2025-01-20T10:00:00Z"),
149+
updatedAt: utcDateTime.fromISO("2025-02-01T15:30:00Z"),
150+
},
151+
payload: #{
152+
createdAt: utcDateTime.fromISO("2025-02-15T10:00:00Z"),
153+
updatedAt: utcDateTime.fromISO("2025-02-17T16:45:00Z"),
154+
responseId: "a12b3c4d-5e6f-7g8h-9i0j-k1l2m3n4o5p6",
155+
answer: #{ questionId: "ee894524-4bd8-4a64-8fd2-a53b39ca94cd", questionType: CoreSystem.Forms.QuestionTypes.shortText, value: "John Doe" },
156+
displayValue: "John Doe",
157+
},
158+
})
120159
model AnswersDetail {
121160
@doc("The question details.")
122161
question: CoreSystem.Forms.QuestionResponse;
@@ -126,6 +165,13 @@ namespace CoreSystem.Responses {
126165
}
127166

128167
@doc("Contains the details of an answer for a specific question in a response")
168+
@example(#{
169+
createdAt: utcDateTime.fromISO("2025-02-15T10:00:00Z"),
170+
updatedAt: utcDateTime.fromISO("2025-02-17T16:45:00Z"),
171+
responseId: "a12b3c4d-5e6f-7g8h-9i0j-k1l2m3n4o5p6",
172+
answer: #{ questionId: "ee894524-4bd8-4a64-8fd2-a53b39ca94cd", questionType: CoreSystem.Forms.QuestionTypes.shortText, value: "John Doe" },
173+
displayValue: "John Doe",
174+
})
129175
model AnswerPayload {
130176
@doc("The creation timestamp of the answer.")
131177
createdAt: utcDateTime;

src/form/models.tsp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace CoreSystem.Forms {
77
}
88

99
@doc("Response after uploading a cover image.")
10+
@example(#{ imageUrl: "https://example.com/images/form-cover-123.webp" })
1011
model FormCoverUploadResponse {
1112
@doc("The temporary full URL of the uploaded image.")
1213
imageUrl: string;
@@ -47,6 +48,24 @@ namespace CoreSystem.Forms {
4748
}
4849

4950
@doc("The structure of a form.")
51+
@example(#{
52+
id: "9a843aa0-8451-4e3b-b6a0-8c0e994e9040",
53+
title: "SDC 2025 Recruitment Form",
54+
description: "Join us for an exciting journey in software development!",
55+
previewMessage: "Join us for an exciting journey",
56+
status: FormStatus.published,
57+
unitId: "d26e9c90-4747-496b-9953-7e7c4f97643f",
58+
lastEditor: "3c5fa073-7b97-43a3-bc44-ddc98f390a08",
59+
deadline: utcDateTime.fromISO("2025-03-31T23:59:59Z"),
60+
publishTime: utcDateTime.fromISO("2025-02-01T00:00:00Z"),
61+
messageAfterSubmission: "Thank you for your application! We'll get back to you soon.",
62+
dressing: #{ color: "#0066cc", headerFont: "LINESeedTW", questionFont: "LINESeedTW", textFont: "LINESeedTW" },
63+
coverImage: "https://example.com/images/form-cover.webp",
64+
googleSheetUrl: "https://docs.google.com/spreadsheets/d/1ABC123/edit",
65+
visibility: FormVisibility.public,
66+
createdAt: utcDateTime.fromISO("2025-01-15T10:00:00Z"),
67+
updatedAt: utcDateTime.fromISO("2025-02-10T14:30:00Z"),
68+
})
5069
model Form {
5170
@doc("The form's unique identifier.")
5271
id: uuid;
@@ -114,6 +133,13 @@ namespace CoreSystem.Forms {
114133
}
115134

116135
@doc("A section within a form, grouping questions together.")
136+
@example(#{
137+
id: "b23f2668-c2dc-4213-88fe-eceedff46398",
138+
formId: "9a843aa0-8451-4e3b-b6a0-8c0e994e9040",
139+
title: "Personal Information",
140+
description: "Please provide your basic information",
141+
questions: #[],
142+
})
117143
model Section {
118144
@doc("Unique identifier.")
119145
id: uuid;
@@ -159,12 +185,14 @@ namespace CoreSystem.Forms {
159185
}
160186

161187
@doc("Response model for listing all sections and questions in a form.")
188+
@example(#{ sections: #[] })
162189
model ListSectionsResponse {
163190
sections: Section[];
164191
}
165192

166193
// form recipientUser
167194
@doc("The basic info of a user that can receive the form.")
195+
@example(#{ id: "3c5fa073-7b97-43a3-bc44-ddc98f390a08", name: "John Doe" })
168196
model RecipientUser {
169197
id: uuid;
170198
name: string;
@@ -181,35 +209,41 @@ namespace CoreSystem.Forms {
181209
}
182210

183211
@doc("The result of recipients selection (no duplicated).")
212+
@example(#{ recipients: #[#{ id: "3c5fa073-7b97-43a3-bc44-ddc98f390a08", name: "John Doe" }] })
184213
model RecipientSelectionResponse {
185214
recipients: RecipientUser[];
186215
}
187216

188217
@doc("Response after publishing a form.")
218+
@example(#{ visibility: FormVisibility.public })
189219
model FormPublishResponse {
190220
@doc("The visibility setting of the form. Public forms are visible to all logged-in users. Private forms require a direct link to access.")
191221
visibility: FormVisibility;
192222
}
193223

194224
@doc("Response containing the Gmail address for Google Sheet permissions.")
225+
@example(#{ email: "core-system-bot@example.com" })
195226
model GoogleSheetEmailResponse {
196227
@doc("The Gmail address that should be added to Google Sheet permissions so the system can modify the form.")
197228
email: string;
198229
}
199230

200231
@doc("Request body for verifying a Google Sheet URL.")
232+
@example(#{ googleSheetUrl: "https://docs.google.com/spreadsheets/d/1ABC123XYZ/edit" })
201233
model GoogleSheetVerifyRequest {
202234
@doc("The Google Sheet URL provided by user.")
203235
googleSheetUrl: string;
204236
}
205237

206238
@doc("Verification result for the given Google Sheet URL.")
239+
@example(#{ isValid: true })
207240
model GoogleSheetVerifyResponse {
208241
@doc("Indicates whether the Google Sheet URL is valid and accessible.")
209242
isValid: boolean;
210243
}
211244

212245
@doc("A font definition used in form dressing.")
246+
@example(#{ id: "LINESeedTW", name: "LINE Seed TW" })
213247
model Font {
214248
@doc("The unique identifier of the font.")
215249
id: string;

src/form/question/models.tsp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ namespace CoreSystem.Forms {
108108
}
109109

110110
@doc("Options for file upload questions.")
111+
@example(#{ allowedFileTypes: #[allowedFileTypes.pdf, allowedFileTypes.doc, allowedFileTypes.docx], maxFileAmount: 3, maxFileSizeLimit: 5242880 })
111112
model UploadFileOption {
112113
@doc("Allowed file types/extensions.")
113114
allowedFileTypes: allowedFileTypes[];
@@ -124,6 +125,7 @@ namespace CoreSystem.Forms {
124125
}
125126

126127
@doc("Options for linear scale and rating questions.")
128+
@example(#{ icon: "star", minVal: 1, maxVal: 5, minValueLabel: "Poor", maxValueLabel: "Excellent" })
127129
model ScaleOption {
128130
@doc("Background icon for the linear scale option.")
129131
icon?: string;
@@ -142,6 +144,7 @@ namespace CoreSystem.Forms {
142144
}
143145

144146
@doc("A choice option for creating/updating choice-based questions.")
147+
@example(#{ name: "Option A", description: "This is option A" })
145148
model ChoiceOption {
146149
@doc("The name/text of the choice option.")
147150
name: string;
@@ -151,6 +154,7 @@ namespace CoreSystem.Forms {
151154
}
152155

153156
@doc("A choice with ID and name for choice-based questions.")
157+
@example(#{ id: "f421cfc2-2b84-4da9-9629-011af609935a", name: "Backend", description: "Backend development team" })
154158
model Choice {
155159
@doc("The unique identifier of the choice.")
156160
id: uuid;
@@ -163,6 +167,7 @@ namespace CoreSystem.Forms {
163167
}
164168

165169
@doc("Options for date questions.")
170+
@example(#{ hasYear: true, hasMonth: true, hasDay: true, minDate: utcDateTime.fromISO("2025-01-01T00:00:00Z"), maxDate: utcDateTime.fromISO("2025-12-31T23:59:59Z") })
166171
model DateOption {
167172
@doc("Whether the year component is required for the date.")
168173
hasYear: boolean;
@@ -181,6 +186,16 @@ namespace CoreSystem.Forms {
181186
}
182187

183188
@doc("Response model for the detailed structure of a question.")
189+
@example(#{
190+
id: "ee894524-4bd8-4a64-8fd2-a53b39ca94cd",
191+
sectionId: "b23f2668-c2dc-4213-88fe-eceedff46398",
192+
required: true,
193+
type: QuestionTypes.shortText,
194+
title: "What's your name?",
195+
description: "Please enter your full name",
196+
createdAt: utcDateTime.fromISO("2025-01-20T10:00:00Z"),
197+
updatedAt: utcDateTime.fromISO("2025-02-01T15:30:00Z"),
198+
})
184199
model QuestionResponse {
185200
@doc("The question's unique identifier.")
186201
id: uuid;

src/form/response/models.tsp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@ using Http;
22

33
namespace CoreSystem.Responses {
44
@doc("Response model for creating a form response")
5+
@example(#{ id: "a12b3c4d-5e6f-7g8h-9i0j-k1l2m3n4o5p6" })
56
model CreateResponse {
67
@doc("The response's unique identifier.")
78
id: uuid;
89
}
910

1011
@doc("Response model for updating a form response")
12+
@example(#{
13+
id: "a12b3c4d-5e6f-7g8h-9i0j-k1l2m3n4o5p6",
14+
updatedAt: utcDateTime.fromISO("2025-02-17T16:45:00Z"),
15+
answers: #[],
16+
})
1117
model UpdateResponse {
1218
@doc("The response's unique identifier.")
1319
id: uuid;
@@ -20,6 +26,12 @@ namespace CoreSystem.Responses {
2026
}
2127

2228
@doc("Response model for a single response in list view")
29+
@example(#{
30+
id: "a12b3c4d-5e6f-7g8h-9i0j-k1l2m3n4o5p6",
31+
submittedBy: "3c5fa073-7b97-43a3-bc44-ddc98f390a08",
32+
createdAt: utcDateTime.fromISO("2025-02-15T10:00:00Z"),
33+
updatedAt: utcDateTime.fromISO("2025-02-17T16:45:00Z"),
34+
})
2335
model Response {
2436
@doc("The response's unique identifier.")
2537
id: uuid;
@@ -35,6 +47,7 @@ namespace CoreSystem.Responses {
3547
}
3648

3749
@doc("Response model for listing all responses of a form")
50+
@example(#{ formId: "9a843aa0-8451-4e3b-b6a0-8c0e994e9040", responses: #[] })
3851
model ListResponse {
3952
@doc("The form ID.")
4053
formId: uuid;
@@ -44,6 +57,12 @@ namespace CoreSystem.Responses {
4457
}
4558

4659
@doc("Response model for getting a specific form response")
60+
@example(#{
61+
id: "a12b3c4d-5e6f-7g8h-9i0j-k1l2m3n4o5p6",
62+
formId: "9a843aa0-8451-4e3b-b6a0-8c0e994e9040",
63+
progress: ResponseProgress.draft,
64+
sections: #[],
65+
})
4766
model GetFormResponse {
4867
@doc("The response's unique identifier.")
4968
id: uuid;
@@ -68,6 +87,12 @@ namespace CoreSystem.Responses {
6887
}
6988

7089
@doc("Response model for a single section in response sections view")
90+
@example(#{
91+
id: "b23f2668-c2dc-4213-88fe-eceedff46398",
92+
title: "Personal Information",
93+
progress: SectionProgress.draft,
94+
answerDetails: #[],
95+
})
7196
model ResponseSections {
7297
@doc("Unique identifier.")
7398
id: uuid;

0 commit comments

Comments
 (0)