-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenapi.yaml
More file actions
1935 lines (1826 loc) · 52.5 KB
/
openapi.yaml
File metadata and controls
1935 lines (1826 loc) · 52.5 KB
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
openapi: 3.0.0
info:
title: Servlets Development API
version: 3.5.0-rc
description: |
RPC API baseada em Jakarta Servlets.
**Esta API não segue o modelo REST.**
### Estilo Arquitetural
- **Modelo:** RPC (Remote Procedure Call)
- **Orientação:** Ações / Procedimentos
- **Transporte:** HTTP
### Autenticação
A autenticação é **stateless** e baseada exclusivamente em **cookies HTTP seguros**.
O servidor não mantém sessão em memória.
- `POST /v1/auth/login`
Emite o cookie `accessToken`
- O cliente envia o cookie automaticamente nas requisições subsequentes
- `POST /v1/auth/logout`
Invalida o cookie no cliente
Todo o estado de autenticação está contido no cookie (ex: token assinado).
contact:
name: Marcelo Feliciano
email: marcelof@tuta.io
license:
name: MIT
url: https://opensource.org/licenses/MIT
x-api-style: rpc
x-architecture: jakarta-servlets
x-state-management: stateless-cookie
x-security:
authentication: http-cookie
session-storage: none
csrf-protection: required
x-cors:
allowed-origins:
- http://localhost:3000
- http://localhost:8080
allowed-methods:
- GET
- POST
allowed-headers:
- Content-Type
- Cookie
allow-credentials: true
x-rate-limiting:
scope: per-ip
requests-per-minute: 60
burst: 10
externalDocs:
description: Repositório no GitHub
url: https://github.com/m-feliciano/javaee-framework/blob/master/README.md
servers:
- url: http://localhost:8080/api
description: Development server
tags:
- name: Auth
description: Authentication endpoints
- name: User
description: User management endpoints
- name: Category
description: Category management endpoints
- name: Product
description: Product management endpoints
- name: Inventory
description: Inventory management endpoints
- name: Activity
description: Activity logs endpoints
- name: Alert
description: Alert management endpoints
- name: Health
description: Health check endpoints
- name: Inspect
description: API inspection endpoints
x-tagGroups:
- name: Authentication & Users
tags:
- Auth
- User
- name: Catalog Management
tags:
- Category
- Product
- Inventory
- name: Monitoring & Logs
tags:
- Activity
- Alert
- Health
- Inspect
components:
securitySchemes:
cookieAuth:
type: apiKey
in: cookie
name: accessToken
description: |
**Cookie-based stateless authentication**
Flow:
1. POST /v1/auth/login → receives `Set-Cookie: accessToken`
2. Browser automatically sends cookie in subsequent requests
3. POST /v1/auth/logout → invalidates cookie
Cookie attributes:
- HttpOnly: true (prevents XSS attacks)
- Secure: true (HTTPS only in production)
- SameSite: Strict (CSRF protection)
- Path: /api
- Max-Age: 3600 (1 day)
responses:
Unauthorized:
description: Missing or invalid authentication
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
example:
message: Unauthorized access
status: 401
timestamp: "2024-12-19T10:30:00Z"
Forbidden:
description: Insufficient permissions (ADMIN role required)
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
example:
message: Access denied - ADMIN role required
status: 403
timestamp: "2024-12-19T10:30:00Z"
NotFound:
description: Resource not found
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
example:
message: Resource not found
status: 404
timestamp: "2024-12-19T10:30:00Z"
BadRequest:
description: Invalid request parameters
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
example:
message: Invalid request parameters
status: 400
timestamp: "2024-12-19T10:30:00Z"
InternalServerError:
description: Internal server error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
example:
message: Internal server error
status: 500
timestamp: "2024-12-19T10:30:00Z"
schemas:
UUID:
type: string
format: uuid
LoginRequest:
type: object
required: [login, password]
properties:
login:
type: string
format: email
minLength: 3
maxLength: 100
example: user@example.com
description: User email or username
password:
type: string
format: password
minLength: 8
maxLength: 100
example: "password123"
description: User password (minimum 8 characters)
UserCreateRequest:
type: object
required: [name, email, password]
properties:
name:
type: string
minLength: 2
maxLength: 100
example: John Doe
description: User full name
login:
type: string
format: email
example: user@example.com
description: User email address (must be unique)
password:
type: string
format: password
minLength: 8
maxLength: 100
description: User password (minimum 8 characters)
UserRequest:
type: object
properties:
id:
$ref: '#/components/schemas/UUID'
name:
type: string
login:
type: string
UserResponse:
type: object
properties:
id:
type: string
format: uuid
example: "550e8400-e29b-41d4-a716-446655440000"
description: Unique user identifier
name:
type: string
example: "John Doe"
description: User full name
login:
type: string
format: email
example: "john@example.com"
description: User email address
role:
type: string
enum: [ADMIN, USER]
example: "USER"
description: User role
createdAt:
type: string
format: date-time
example: "2024-12-19T10:30:00Z"
description: Account creation timestamp
UserProfile:
type: object
properties:
login:
type: string
format: email
example: "ana@example.com"
description: User email address
imgUrl:
type: string
format: uri
example: "https://cdn.example.com/private/users/550e8400/profile.jpg"
description: URL of the user's profile image
CategoryRequest:
type: object
properties:
id:
$ref: '#/components/schemas/UUID'
name:
type: string
minLength: 2
maxLength: 100
example: "Electronics"
description: Category name
description:
type: string
maxLength: 500
example: "Electronic devices and accessories"
description: Category description
CategoryResponse:
type: object
properties:
id:
type: string
format: uuid
example: "cat-123e4567-e89b-12d3-a456-426614174000"
description: Unique category identifier
name:
type: string
example: "Electronics"
description: Category name
description:
type: string
example: "Electronic devices and accessories"
description: Category description
ProductRequest:
type: object
properties:
id:
$ref: '#/components/schemas/UUID'
name:
type: string
minLength: 2
maxLength: 200
example: "Dell XPS 15"
description: Product name
description:
type: string
maxLength: 1000
example: "High-performance laptop with 15.6 inch display"
description: Product description
price:
type: number
format: double
minimum: 0
example: 1999.99
description: Product price (must be positive)
categoryId:
type: string
format: uuid
example: "cat-123e4567-e89b-12d3-a456-426614174000"
description: Category identifier
ProductResponse:
type: object
properties:
id:
type: string
format: uuid
example: "prod-123e4567-e89b-12d3-a456-426614174000"
description: Unique product identifier
name:
type: string
example: "Dell XPS 15"
description: Product name
description:
type: string
example: "High-performance laptop with 15.6 inch display"
description: Product description
price:
type: number
format: double
example: 1999.99
description: Product price
category:
$ref: '#/components/schemas/CategoryResponse'
InventoryRequest:
type: object
properties:
id:
type: string
productId:
type: string
quantity:
type: integer
InventoryCreateRequest:
type: object
required: [productId, quantity]
properties:
productId:
type: string
format: uuid
example: "prod-123e4567-e89b-12d3-a456-426614174000"
description: Product identifier
quantity:
type: integer
minimum: 0
example: 100
description: Stock quantity (must be non-negative)
InventoryResponse:
type: object
properties:
id:
type: string
format: uuid
example: "inv-123e4567-e89b-12d3-a456-426614174000"
description: Unique inventory identifier
product:
$ref: '#/components/schemas/ProductResponse'
quantity:
type: integer
example: 100
description: Current stock quantity
ActivityRequest:
type: object
properties:
id:
type: string
UserActivityLogResponse:
type: object
properties:
id:
type: string
format: uuid
example: "act-123e4567-e89b-12d3-a456-426614174000"
description: Unique activity log identifier
userId:
type: string
format: uuid
example: "550e8400-e29b-41d4-a716-446655440000"
description: User who performed the action
action:
type: string
enum: [CREATE, UPDATE, DELETE, LOGIN, LOGOUT]
example: "CREATE"
description: Action performed
timestamp:
type: string
format: date-time
example: "2024-12-19T10:30:00Z"
description: When the action occurred
details:
type: string
example: "Created product: Dell XPS 15"
description: Additional action details
FileUploadRequest:
type: object
properties:
file:
type: string
format: binary
PageRequest:
type: object
properties:
page:
type: integer
default: 0
minimum: 0
limit:
type: integer
default: 10
minimum: 1
maximum: 100
Pageable:
type: object
properties:
content:
type: array
items:
type: object
description: Page content (items)
totalElements:
type: integer
format: int64
example: 100
description: Total number of items across all pages
totalPages:
type: integer
example: 10
description: Total number of pages
size:
type: integer
example: 10
description: Items per page
number:
type: integer
example: 0
description: Current page number (0-indexed)
first:
type: boolean
example: true
description: Is this the first page?
last:
type: boolean
example: false
description: Is this the last page?
empty:
type: boolean
example: false
description: Is this page empty?
Query:
type: object
properties:
q:
type: string
description: Search query
ErrorResponse:
type: object
required: [message, status, timestamp]
properties:
message:
type: string
example: "Invalid request parameters"
description: Error message
status:
type: integer
example: 400
description: HTTP status code
timestamp:
type: string
format: date-time
example: "2024-12-19T10:30:00Z"
description: Error timestamp
path:
type: string
example: "/api/v1/product/create"
description: Request path that caused the error
errors:
type: array
items:
type: object
properties:
field:
type: string
message:
type: string
description: Validation errors (if applicable)
security:
- cookieAuth: []
paths:
# ==================== AUTH ENDPOINTS ====================
/v1/auth/registerPage:
get:
tags: [Auth]
summary: Forward to registration page
operationId: forwardRegister
security: []
responses:
'200':
description: Registration page
content:
text/html:
schema:
type: string
/v1/auth/form:
get:
tags: [Auth]
summary: Retrieve registration form
operationId: form
security: []
responses:
'200':
description: Registration form
content:
text/html:
schema:
type: string
/v1/auth/login:
post:
tags: [Auth]
summary: Authenticate user
description: |
Authenticates user with email/password and creates a session cookie.
**Flow:**
1. Client sends credentials
2. Server validates credentials
3. Server returns cookie
4. Client automatically sends cookie in subsequent requests
operationId: login
security: []
x-rpc-action: AuthenticateUser
x-idempotent: false
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/LoginRequest'
examples:
validUser:
summary: Valid user login
value:
login: user@example.com
password: password123
adminUser:
summary: Admin user login
value:
login: admin@example.com
password: admin123
responses:
'200':
description: Login successful
headers:
Set-Cookie:
description: Authentication cookie
schema:
type: string
example: accessToken=eyJhbGc...; Path=/api; HttpOnly; Secure; SameSite=Strict; Max-Age=3600
content:
application/json:
schema:
$ref: '#/components/schemas/UserResponse'
examples:
user:
summary: Regular user
value:
id: "550e8400-e29b-41d4-a716-446655440000"
name: "John Doe"
email: "john@example.com"
role: "USER"
createdAt: "2024-12-19T10:30:00Z"
admin:
summary: Admin user
value:
id: "550e8400-e29b-41d4-a716-446655440001"
name: "Admin User"
email: "admin@example.com"
role: "ADMIN"
createdAt: "2024-12-19T10:30:00Z"
links:
GetCurrentUser:
operationId: getCurrentUser
description: Get authenticated user info
Logout:
operationId: logout
description: Logout current user
'401':
$ref: '#/components/responses/Unauthorized'
'400':
$ref: '#/components/responses/BadRequest'
'500':
$ref: '#/components/responses/InternalServerError'
/v1/auth/logout:
post:
tags: [Auth]
summary: Logout user
operationId: logout
responses:
'200':
description: Logout successful
content:
application/json:
schema:
type: object
properties:
message:
type: string
example: Logout successful
/v2/auth/refresh-token:
post:
tags: [ Auth ]
summary: Refresh authentication token
description: |
**V2 API** - Refreshes the authentication token by issuing a new one.
**Flow:**
1. Client sends request with refresh token
2. Server validates existing token
3. Server returns new authentication
operationId: refreshToken
x-api-version: v2
x-rpc-action: RefreshAuthToken
x-requires-auth: false
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
refreshToken:
type: string
description: Refresh token
example:
refreshToken: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
responses:
'200':
description: Token refreshed successfully
content:
application/json:
schema:
type: object
properties:
token:
type: string
description: New access token
refreshToken:
type: string
description: New refresh token
example:
token: "newlyGeneratedAccessTokenValue"
refreshToken: "newlyGeneratedRefreshTokenValue"
'401':
$ref: '#/components/responses/Unauthorized'
'500':
$ref: '#/components/responses/InternalServerError'
# ==================== USER ENDPOINTS ====================
/v1/user/update:
post:
tags: [User]
summary: Update user information
operationId: updateUser
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/UserRequest'
responses:
'200':
description: User updated
content:
application/json:
schema:
$ref: '#/components/schemas/UserResponse'
/v1/user/delete:
post:
tags: [User]
summary: Delete user (ADMIN only)
description: |
Delete a user account. **Requires ADMIN role.**
**Security:**
- Only users with ADMIN role can delete users
- Returns 403 Forbidden for non-admin users
**Warning:** This action is irreversible.
operationId: deleteUser
x-rpc-action: DeleteUser
x-requires-auth: true
x-requires-role: ADMIN
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/UserRequest'
examples:
deleteUser:
summary: Delete user by ID
value:
id: "550e8400-e29b-41d4-a716-446655440000"
responses:
'200':
description: User deleted successfully
content:
application/json:
schema:
type: object
properties:
message:
type: string
example: "User deleted successfully"
'400':
$ref: '#/components/responses/BadRequest'
'401':
$ref: '#/components/responses/Unauthorized'
'403':
$ref: '#/components/responses/Forbidden'
'404':
$ref: '#/components/responses/NotFound'
'500':
$ref: '#/components/responses/InternalServerError'
/v1/user/me:
get:
tags: [User]
summary: Get current user
operationId: getCurrentUser
responses:
'200':
description: Current user information
content:
application/json:
schema:
$ref: '#/components/schemas/UserResponse'
/v1/user/profile:
get:
tags: [ User ]
summary: Get current user profile
operationId: getUserProfile
responses:
'200':
description: User profile information
content:
application/json:
schema:
$ref: '#/components/schemas/UserProfile'
/v1/user/registerUser:
post:
tags: [User]
summary: Register new user
operationId: registerUser
security: []
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/UserCreateRequest'
responses:
'201':
description: User registered
content:
application/json:
schema:
$ref: '#/components/schemas/UserResponse'
/v1/user/confirm:
get:
tags: [User]
summary: Confirm user email
operationId: confirmEmail
security: []
parameters:
- name: token
in: query
required: true
schema:
type: string
responses:
'200':
description: Email confirmed
/v1/user/email-change-confirmation:
get:
tags: [User]
summary: Confirm email change by token (sent via email)
operationId: confirmEmailChange
security: []
parameters:
- name: token
in: query
required: true
schema:
type: string
responses:
'200':
description: Email change confirmed
/v1/user/resend-confirmation:
post:
tags: [User]
summary: Resend email change confirmation by email
operationId: resendConfirmation
security: []
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/UserRequest'
responses:
'200':
description: Confirmation email resent
/v2/user/upload-photo:
post:
tags: [User]
summary: Upload user profile photo
description: |
**V2 API** - Upload user profile picture.
**Accepted formats:** JPEG, PNG, GIF
**Max file size:** 1MB
**Recommended dimensions:** 400x400px
**Example using curl:**
```bash
curl -X POST http://localhost:8080/api/v2/user/upload-photo \
-H "Cookie: accessToken=YOUR_TOKEN" \
-F "photo=@profile.jpg"
```
operationId: uploadUserPhoto
x-rpc-action: UploadUserPhoto
x-api-version: v2
x-requires-auth: true
requestBody:
required: true
content:
multipart/form-data:
schema:
type: object
required: [photo]
properties:
photo:
type: string
format: binary
description: Image file (JPEG, PNG, GIF)
encoding:
photo:
contentType: image/jpeg, image/png, image/gif
responses:
'200':
description: Photo uploaded successfully
content:
application/json:
schema:
type: object
properties:
message:
type: string
example: "Photo uploaded successfully"
photoUrl:
type: string
example: "https://cdn.example.com/users/550e8400/profile.jpg"
'400':
description: Invalid file format or size
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
example:
message: "File size exceeds 5MB limit"
status: 400
timestamp: "2024-12-19T10:30:00Z"
'401':
$ref: '#/components/responses/Unauthorized'
'500':
$ref: '#/components/responses/InternalServerError'
# ==================== CATEGORY ENDPOINTS ====================
/v1/category/new:
get:
tags: [Category]
summary: Forward to category registration page
operationId: forwardCategoryRegister
responses:
'200':
description: Category registration page
/v1/category/create:
post:
tags: [Category]
summary: Create category
operationId: createCategory
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/CategoryRequest'
responses:
'201':
description: Category created
/v1/category/list:
get:
tags: [Category]
summary: List categories
operationId: listCategories
responses:
'200':
description: List of categories
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/CategoryResponse'
/v1/category/list/{id}:
get:
tags: [Category]
summary: Get category detail
operationId: getCategoryDetail
parameters:
- name: id
in: path
required: true
schema:
type: string
format: uuid
responses:
'200':
description: Category details
content:
application/json:
schema:
$ref: '#/components/schemas/CategoryResponse'
/v1/category/delete/{id}:
post: