-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenapi.yaml
296 lines (286 loc) · 8.49 KB
/
openapi.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# ============================================
# Setting
# ============================================
openapi: 3.0.1
info:
title: Notes Page
description: |-
This is a simple API for creating (POST), updating (PATCH), recalling
(GET) and deleting (DELETE) notes. Within this API, we use node.js, express.js and mongoDB.
This is simple project I done while at my placement at DWP.
termsOfService: https://github.com/JanOnBread/dwp-placement/tree/main#readme
license:
name: Apache 2.0
url: http://www.apache.org/licenses/LICENSE-2.0.html
version: 1.0.0
externalDocs:
description: GitHub Page
url: https://github.com/JanOnBread
servers:
- url: http://localhost:3002/
tags:
- name: Notes
description: Everything you can do with notes!
# ============================================
# Paths
# ============================================
paths:
#---------------------------------------------
# /
#---------------------------------------------
/:
# GET
get:
tags:
- Notes
summary: Shows you the main page
description: Brings you to the main page (index.html) where you can access all commands (posting, retrieving, updating and deleting) to do with the notes
operationId: getIndex
responses:
"200":
description: Successful operation
content:
application/json:
schema:
$ref: "#/components/schemas/serverMessage"
"500":
description: Error occurred when displaying index.html
content:
application/json:
schema:
$ref: "#/components/schemas/serverMessage"
#---------------------------------------------
# /notes
#---------------------------------------------
/notes:
# GET
get:
tags:
- Notes
summary: Shows you ALL notes in our MongoDB
description: Shows you all our notes stored within our database (MongoDB)
operationId: getAllNotes
responses:
"200":
description: Successful operation
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/notes"
"500":
description: Error occurred when displaying displaying all notes.
content:
application/json:
schema:
$ref: "#/components/schemas/serverMessage"
#---------------------------------------------
# POST
post:
tags:
- Notes
summary: Posts a note into our database
description: Add a new new note into our mongoDB. This post request is sent to /notes after the first "submit" button is pressed on index.html
operationId: postNotes
requestBody:
description: To create a new note
content:
application/json:
schema:
$ref: "#/components/schemas/notes"
required: true
responses:
"201":
description: Successful operation - Note is posted
content:
application/json:
schema:
$ref: "#/components/schemas/postNotes"
"400":
description: Notes field is empty
content:
application/json:
schema:
$ref: "#/components/schemas/serverMessage"
"500":
description: Note posting is unsuccessful and thus a note was not posted
content:
application/json:
schema:
$ref: "#/components/schemas/serverMessage"
#---------------------------------------------
# DELETE
delete:
tags:
- Notes
summary: Deletes all notes
description: Deletes all entries within our mongoDB when you select this option on the index.html page
operationId: delAllNotes
responses:
"200":
description: Successful operation
content:
application/json:
schema:
$ref: "#/components/schemas/serverMessage"
"500":
description: Error occurred and the no notes were deleted
content:
application/json:
schema:
$ref: "#/components/schemas/serverMessage"
#---------------------------------------------
# /notes/ {id}
#---------------------------------------------
/notes/{id}:
# GET
get:
tags:
- Notes
summary: Get a note by ID
description: Finds a note within our MongoDB with a specific ID
operationId: getNoteById
parameters:
- name: id
in: path
description: Id of the note you want to retrieve
required: true
schema:
type: integer
responses:
"200":
description: Successful operation
content:
application/json:
schema:
$ref: "#/components/schemas/submittedNotes"
"404":
description: there is no note with this id
content:
application/json:
schema:
$ref: "#/components/schemas/serverMessage"
#---------------------------------------------
# PATCH
patch:
tags:
- Notes
summary: Update a note by ID
description: Finds a note within our MongoDB based on id and update it by sending a body with a new request
operationId: patchNoteById
parameters:
- name: id
in: path
description: Id of the note you want to update
required: true
schema:
type: integer
requestBody:
description: To create a new note
content:
application/json:
schema:
$ref: "#/components/schemas/notes"
required: true
responses:
"200":
description: Successful operation
content:
application/json:
schema:
$ref: "#/components/schemas/serverMessage"
"400":
description: the notes field was empty
content:
application/json:
schema:
$ref: "#/components/schemas/serverMessage"
"404":
description: There is no note with this id
content:
application/json:
schema:
$ref: "#/components/schemas/serverMessage"
"500":
description: error occurred and the note was not updated
content:
application/json:
schema:
$ref: "#/components/schemas/serverMessage"
#---------------------------------------------
# DELETE
delete:
tags:
- Notes
summary: Delete a note by Id
description: Finds a note within our MongoDB by id then delete that note
operationId: delNoteByID
parameters:
- name: id
in: path
description: Id of the note you want to delete
required: true
schema:
type: integer
responses:
"200":
description: Successful operation
content:
application/json:
schema:
$ref: "#/components/schemas/serverMessage"
"404":
description: there is no note with this id
content:
application/json:
schema:
$ref: "#/components/schemas/serverMessage"
"500":
description: error occurred and the note was not deleted
content:
application/json:
schema:
$ref: "#/components/schemas/serverMessage"
#---------------------------------------------
# DEFINING SCHEMAS
components:
schemas:
submittedNotes:
required:
- notes
type: object
properties:
_id:
type: integer
# examples: [0]
date:
type: string
# examples: ["Thu Oct 05 2023 13:56:18 GMT+0100 (British Summer Time)"]
notes:
type: string
# examples: ["This is my first note!"]
notes:
required:
- notes
type: object
properties:
notes:
type: string
# examples: ["This is an note!"]
postNotes:
required:
- message
- id
type: object
properties:
message:
type: string
# examples: ["This is an note!"]
id:
type: integer
serverMessage:
type: object
properties:
message:
type: string