Skip to content

Commit 354b7de

Browse files
Updated client urls generation
1 parent c49ce38 commit 354b7de

File tree

6 files changed

+234
-216
lines changed

6 files changed

+234
-216
lines changed

fastapi-backend/commands/generate_openapi_schema.py

+9
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@
1313
def generate_openapi_schema(output_file):
1414
schema = app.openapi()
1515
output_path = Path(output_file)
16+
17+
for path_data in schema["paths"].values():
18+
for operation in path_data.values():
19+
tag = operation["tags"][0]
20+
operation_id = operation["operationId"]
21+
to_remove = f"{tag}-"
22+
new_operation_id = operation_id[len(to_remove) :]
23+
operation["operationId"] = new_operation_id
24+
1625
output_path.write_text(json.dumps(schema, indent=2))
1726
print(f"OpenAPI schema saved to {output_file}")
1827

fastapi-backend/src/main.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
from fastapi import Depends, FastAPI
2+
from fastapi.routing import APIRoute
23

34
from .database import User
45
from .schemas import UserCreate, UserRead, UserUpdate
56
from .users import auth_backend, current_active_user, fastapi_users, AUTH_URL_PATH
67
from fastapi.middleware.cors import CORSMiddleware
78

8-
app = FastAPI()
9+
10+
def custom_generate_unique_id(route: APIRoute):
11+
return f"{route.tags[0]}-{route.name}"
12+
13+
14+
app = FastAPI(generate_unique_id_function=custom_generate_unique_id)
915

1016
origins = [
1117
"http://localhost:3000",
@@ -48,6 +54,6 @@
4854
)
4955

5056

51-
@app.get("/authenticated-route")
57+
@app.get("/authenticated-route", tags=["custom-auth"])
5258
async def authenticated_route(user: User = Depends(current_active_user)):
5359
return {"message": f"Hello {user.email}!"}

local-shared-data/openapi.json

+86-83
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
"auth"
1212
],
1313
"summary": "Auth:Jwt.Login",
14-
"operationId": "auth_jwt_login_auth_jwt_login_post",
14+
"operationId": "auth:jwt.login",
1515
"requestBody": {
1616
"content": {
1717
"application/x-www-form-urlencoded": {
1818
"schema": {
19-
"$ref": "#/components/schemas/Body_auth_jwt_login_auth_jwt_login_post"
19+
"$ref": "#/components/schemas/login"
2020
}
2121
}
2222
},
@@ -80,7 +80,7 @@
8080
"auth"
8181
],
8282
"summary": "Auth:Jwt.Logout",
83-
"operationId": "auth_jwt_logout_auth_jwt_logout_post",
83+
"operationId": "auth:jwt.logout",
8484
"responses": {
8585
"200": {
8686
"description": "Successful Response",
@@ -107,7 +107,7 @@
107107
"auth"
108108
],
109109
"summary": "Register:Register",
110-
"operationId": "register_register_auth_register_post",
110+
"operationId": "register:register",
111111
"requestBody": {
112112
"content": {
113113
"application/json": {
@@ -175,12 +175,12 @@
175175
"auth"
176176
],
177177
"summary": "Reset:Forgot Password",
178-
"operationId": "reset_forgot_password_auth_forgot_password_post",
178+
"operationId": "reset:forgot_password",
179179
"requestBody": {
180180
"content": {
181181
"application/json": {
182182
"schema": {
183-
"$ref": "#/components/schemas/Body_reset_forgot_password_auth_forgot_password_post"
183+
"$ref": "#/components/schemas/Body_auth-reset_forgot_password"
184184
}
185185
}
186186
},
@@ -214,12 +214,12 @@
214214
"auth"
215215
],
216216
"summary": "Reset:Reset Password",
217-
"operationId": "reset_reset_password_auth_reset_password_post",
217+
"operationId": "reset:reset_password",
218218
"requestBody": {
219219
"content": {
220220
"application/json": {
221221
"schema": {
222-
"$ref": "#/components/schemas/Body_reset_reset_password_auth_reset_password_post"
222+
"$ref": "#/components/schemas/Body_auth-reset_reset_password"
223223
}
224224
}
225225
},
@@ -280,12 +280,12 @@
280280
"auth"
281281
],
282282
"summary": "Verify:Request-Token",
283-
"operationId": "verify_request_token_auth_request_verify_token_post",
283+
"operationId": "verify:request-token",
284284
"requestBody": {
285285
"content": {
286286
"application/json": {
287287
"schema": {
288-
"$ref": "#/components/schemas/Body_verify_request_token_auth_request_verify_token_post"
288+
"$ref": "#/components/schemas/Body_auth-verify_request-token"
289289
}
290290
}
291291
},
@@ -319,12 +319,12 @@
319319
"auth"
320320
],
321321
"summary": "Verify:Verify",
322-
"operationId": "verify_verify_auth_verify_post",
322+
"operationId": "verify:verify",
323323
"requestBody": {
324324
"content": {
325325
"application/json": {
326326
"schema": {
327-
"$ref": "#/components/schemas/Body_verify_verify_auth_verify_post"
327+
"$ref": "#/components/schemas/Body_auth-verify_verify"
328328
}
329329
}
330330
},
@@ -384,7 +384,7 @@
384384
"users"
385385
],
386386
"summary": "Users:Current User",
387-
"operationId": "users_current_user_users_me_get",
387+
"operationId": "users:current_user",
388388
"responses": {
389389
"200": {
390390
"description": "Successful Response",
@@ -411,7 +411,7 @@
411411
"users"
412412
],
413413
"summary": "Users:Patch Current User",
414-
"operationId": "users_patch_current_user_users_me_patch",
414+
"operationId": "users:patch_current_user",
415415
"requestBody": {
416416
"content": {
417417
"application/json": {
@@ -487,7 +487,7 @@
487487
"users"
488488
],
489489
"summary": "Users:User",
490-
"operationId": "users_user_users__id__get",
490+
"operationId": "users:user",
491491
"security": [
492492
{
493493
"OAuth2PasswordBearer": []
@@ -541,7 +541,7 @@
541541
"users"
542542
],
543543
"summary": "Users:Patch User",
544-
"operationId": "users_patch_user_users__id__patch",
544+
"operationId": "users:patch_user",
545545
"security": [
546546
{
547547
"OAuth2PasswordBearer": []
@@ -632,7 +632,7 @@
632632
"users"
633633
],
634634
"summary": "Users:Delete User",
635-
"operationId": "users_delete_user_users__id__delete",
635+
"operationId": "users:delete_user",
636636
"security": [
637637
{
638638
"OAuth2PasswordBearer": []
@@ -677,8 +677,11 @@
677677
},
678678
"/authenticated-route": {
679679
"get": {
680+
"tags": [
681+
"custom-auth"
682+
],
680683
"summary": "Authenticated Route",
681-
"operationId": "authenticated_route_authenticated_route_get",
684+
"operationId": "authenticated_route",
682685
"responses": {
683686
"200": {
684687
"description": "Successful Response",
@@ -717,64 +720,7 @@
717720
],
718721
"title": "BearerResponse"
719722
},
720-
"Body_auth_jwt_login_auth_jwt_login_post": {
721-
"properties": {
722-
"grant_type": {
723-
"anyOf": [
724-
{
725-
"type": "string",
726-
"pattern": "password"
727-
},
728-
{
729-
"type": "null"
730-
}
731-
],
732-
"title": "Grant Type"
733-
},
734-
"username": {
735-
"type": "string",
736-
"title": "Username"
737-
},
738-
"password": {
739-
"type": "string",
740-
"title": "Password"
741-
},
742-
"scope": {
743-
"type": "string",
744-
"title": "Scope",
745-
"default": ""
746-
},
747-
"client_id": {
748-
"anyOf": [
749-
{
750-
"type": "string"
751-
},
752-
{
753-
"type": "null"
754-
}
755-
],
756-
"title": "Client Id"
757-
},
758-
"client_secret": {
759-
"anyOf": [
760-
{
761-
"type": "string"
762-
},
763-
{
764-
"type": "null"
765-
}
766-
],
767-
"title": "Client Secret"
768-
}
769-
},
770-
"type": "object",
771-
"required": [
772-
"username",
773-
"password"
774-
],
775-
"title": "Body_auth_jwt_login_auth_jwt_login_post"
776-
},
777-
"Body_reset_forgot_password_auth_forgot_password_post": {
723+
"Body_auth-reset_forgot_password": {
778724
"properties": {
779725
"email": {
780726
"type": "string",
@@ -786,9 +732,9 @@
786732
"required": [
787733
"email"
788734
],
789-
"title": "Body_reset_forgot_password_auth_forgot_password_post"
735+
"title": "Body_auth-reset:forgot_password"
790736
},
791-
"Body_reset_reset_password_auth_reset_password_post": {
737+
"Body_auth-reset_reset_password": {
792738
"properties": {
793739
"token": {
794740
"type": "string",
@@ -804,9 +750,9 @@
804750
"token",
805751
"password"
806752
],
807-
"title": "Body_reset_reset_password_auth_reset_password_post"
753+
"title": "Body_auth-reset:reset_password"
808754
},
809-
"Body_verify_request_token_auth_request_verify_token_post": {
755+
"Body_auth-verify_request-token": {
810756
"properties": {
811757
"email": {
812758
"type": "string",
@@ -818,9 +764,9 @@
818764
"required": [
819765
"email"
820766
],
821-
"title": "Body_verify_request_token_auth_request_verify_token_post"
767+
"title": "Body_auth-verify:request-token"
822768
},
823-
"Body_verify_verify_auth_verify_post": {
769+
"Body_auth-verify_verify": {
824770
"properties": {
825771
"token": {
826772
"type": "string",
@@ -831,7 +777,7 @@
831777
"required": [
832778
"token"
833779
],
834-
"title": "Body_verify_verify_auth_verify_post"
780+
"title": "Body_auth-verify:verify"
835781
},
836782
"ErrorModel": {
837783
"properties": {
@@ -1053,6 +999,63 @@
1053999
"type"
10541000
],
10551001
"title": "ValidationError"
1002+
},
1003+
"login": {
1004+
"properties": {
1005+
"grant_type": {
1006+
"anyOf": [
1007+
{
1008+
"type": "string",
1009+
"pattern": "password"
1010+
},
1011+
{
1012+
"type": "null"
1013+
}
1014+
],
1015+
"title": "Grant Type"
1016+
},
1017+
"username": {
1018+
"type": "string",
1019+
"title": "Username"
1020+
},
1021+
"password": {
1022+
"type": "string",
1023+
"title": "Password"
1024+
},
1025+
"scope": {
1026+
"type": "string",
1027+
"title": "Scope",
1028+
"default": ""
1029+
},
1030+
"client_id": {
1031+
"anyOf": [
1032+
{
1033+
"type": "string"
1034+
},
1035+
{
1036+
"type": "null"
1037+
}
1038+
],
1039+
"title": "Client Id"
1040+
},
1041+
"client_secret": {
1042+
"anyOf": [
1043+
{
1044+
"type": "string"
1045+
},
1046+
{
1047+
"type": "null"
1048+
}
1049+
],
1050+
"title": "Client Secret"
1051+
}
1052+
},
1053+
"type": "object",
1054+
"required": [
1055+
"username",
1056+
"password"
1057+
],
1058+
"title": "Body_auth-auth:jwt.login"
10561059
}
10571060
},
10581061
"securitySchemes": {

0 commit comments

Comments
 (0)