Skip to content

Commit 016ce4d

Browse files
authored
Use hey api tournament types (#1481)
1 parent ffaeb87 commit 016ce4d

34 files changed

+447
-370
lines changed

backend/cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
)
2121
from bracket.utils.db_init import sql_create_dev_db
2222
from bracket.utils.security import hash_password
23+
from openapi import openapi # noqa: F401
2324

2425
OPENAPI_JSON_PATH = "openapi/openapi.json"
2526

backend/openapi/__init__.py

Whitespace-only changes.

backend/openapi/openapi.json

Lines changed: 128 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,12 @@
5454
}
5555
},
5656
"required": [
57+
"grant_type",
5758
"username",
58-
"password"
59+
"password",
60+
"scope",
61+
"client_id",
62+
"client_secret"
5963
],
6064
"title": "Body_login_for_access_token_token_post",
6165
"type": "object"
@@ -75,6 +79,9 @@
7579
"title": "File"
7680
}
7781
},
82+
"required": [
83+
"file"
84+
],
7885
"title": "Body_update_team_logo_tournaments__tournament_id__teams__team_id__logo_post",
7986
"type": "object"
8087
},
@@ -93,6 +100,9 @@
93100
"title": "File"
94101
}
95102
},
103+
"required": [
104+
"file"
105+
],
96106
"title": "Body_upload_logo_tournaments__tournament_id__logo_post",
97107
"type": "object"
98108
},
@@ -326,6 +336,12 @@
326336
"name",
327337
"tournament_id",
328338
"active",
339+
"elo_score",
340+
"swiss_score",
341+
"wins",
342+
"draws",
343+
"losses",
344+
"logo_path",
329345
"id",
330346
"players"
331347
],
@@ -521,14 +537,25 @@
521537
},
522538
"required": [
523539
"created",
540+
"start_time",
524541
"duration_minutes",
525542
"margin_minutes",
543+
"custom_duration_minutes",
544+
"custom_margin_minutes",
545+
"position_in_schedule",
526546
"round_id",
527547
"stage_item_input1_score",
528548
"stage_item_input2_score",
549+
"court_id",
529550
"stage_item_input1_conflict",
530551
"stage_item_input2_conflict",
531-
"id"
552+
"stage_item_input1_id",
553+
"stage_item_input2_id",
554+
"stage_item_input1_winner_from_match_id",
555+
"stage_item_input2_winner_from_match_id",
556+
"id",
557+
"stage_item_input1",
558+
"stage_item_input2"
532559
],
533560
"title": "Match",
534561
"type": "object"
@@ -584,7 +611,12 @@
584611
}
585612
},
586613
"required": [
587-
"round_id"
614+
"round_id",
615+
"stage_item_input1_score",
616+
"stage_item_input2_score",
617+
"court_id",
618+
"custom_duration_minutes",
619+
"custom_margin_minutes"
588620
],
589621
"title": "MatchBody",
590622
"type": "object"
@@ -652,7 +684,12 @@
652684
}
653685
},
654686
"required": [
655-
"round_id"
687+
"round_id",
688+
"court_id",
689+
"stage_item_input1_id",
690+
"stage_item_input2_id",
691+
"stage_item_input1_winner_from_match_id",
692+
"stage_item_input2_winner_from_match_id"
656693
],
657694
"title": "MatchCreateBodyFrontend",
658695
"type": "object"
@@ -872,14 +909,26 @@
872909
},
873910
"required": [
874911
"created",
912+
"start_time",
875913
"duration_minutes",
876914
"margin_minutes",
915+
"custom_duration_minutes",
916+
"custom_margin_minutes",
917+
"position_in_schedule",
877918
"round_id",
878919
"stage_item_input1_score",
879920
"stage_item_input2_score",
921+
"court_id",
880922
"stage_item_input1_conflict",
881923
"stage_item_input2_conflict",
882-
"id"
924+
"stage_item_input1_id",
925+
"stage_item_input2_id",
926+
"stage_item_input1_winner_from_match_id",
927+
"stage_item_input2_winner_from_match_id",
928+
"id",
929+
"stage_item_input1",
930+
"stage_item_input2",
931+
"court"
883932
],
884933
"title": "MatchWithDetails",
885934
"type": "object"
@@ -1064,16 +1113,26 @@
10641113
},
10651114
"required": [
10661115
"created",
1116+
"start_time",
10671117
"duration_minutes",
10681118
"margin_minutes",
1119+
"custom_duration_minutes",
1120+
"custom_margin_minutes",
1121+
"position_in_schedule",
10691122
"round_id",
10701123
"stage_item_input1_score",
10711124
"stage_item_input2_score",
1125+
"court_id",
10721126
"stage_item_input1_conflict",
10731127
"stage_item_input2_conflict",
1128+
"stage_item_input1_id",
1129+
"stage_item_input2_id",
1130+
"stage_item_input1_winner_from_match_id",
1131+
"stage_item_input2_winner_from_match_id",
10741132
"id",
10751133
"stage_item_input1",
1076-
"stage_item_input2"
1134+
"stage_item_input2",
1135+
"court"
10771136
],
10781137
"title": "MatchWithDetailsDefinitive",
10791138
"type": "object"
@@ -1176,6 +1235,11 @@
11761235
"name",
11771236
"created",
11781237
"tournament_id",
1238+
"elo_score",
1239+
"swiss_score",
1240+
"wins",
1241+
"draws",
1242+
"losses",
11791243
"id"
11801244
],
11811245
"title": "Player",
@@ -1388,6 +1452,12 @@
13881452
"title": "Win Points"
13891453
}
13901454
},
1455+
"required": [
1456+
"win_points",
1457+
"draw_points",
1458+
"loss_points",
1459+
"add_score_points"
1460+
],
13911461
"title": "RankingCreateBody",
13921462
"type": "object"
13931463
},
@@ -1426,6 +1496,7 @@
14261496
}
14271497
},
14281498
"required": [
1499+
"name",
14291500
"stage_item_id"
14301501
],
14311502
"title": "RoundCreateBody",
@@ -1558,6 +1629,9 @@
15581629
"type": "string"
15591630
}
15601631
},
1632+
"required": [
1633+
"direction"
1634+
],
15611635
"title": "StageActivateBody",
15621636
"type": "object"
15631637
},
@@ -1576,6 +1650,9 @@
15761650
"title": "Adjust To Time"
15771651
}
15781652
},
1653+
"required": [
1654+
"adjust_to_time"
1655+
],
15791656
"title": "StageItemActivateNextBody",
15801657
"type": "object"
15811658
},
@@ -1619,8 +1696,10 @@
16191696
},
16201697
"required": [
16211698
"stage_id",
1699+
"name",
16221700
"type",
1623-
"team_count"
1701+
"team_count",
1702+
"ranking_id"
16241703
],
16251704
"title": "StageItemCreateBody",
16261705
"type": "object"
@@ -1685,9 +1764,17 @@
16851764
}
16861765
},
16871766
"required": [
1767+
"points",
1768+
"wins",
1769+
"draws",
1770+
"losses",
16881771
"id",
16891772
"slot",
1690-
"tournament_id"
1773+
"tournament_id",
1774+
"stage_item_id",
1775+
"team_id",
1776+
"winner_from_stage_item_id",
1777+
"winner_position"
16911778
],
16921779
"title": "StageItemInputEmpty",
16931780
"type": "object"
@@ -1769,10 +1856,17 @@
17691856
}
17701857
},
17711858
"required": [
1859+
"points",
1860+
"wins",
1861+
"draws",
1862+
"losses",
17721863
"id",
17731864
"slot",
17741865
"tournament_id",
1866+
"stage_item_id",
17751867
"team_id",
1868+
"winner_from_stage_item_id",
1869+
"winner_position",
17761870
"team"
17771871
],
17781872
"title": "StageItemInputFinal",
@@ -1906,9 +2000,15 @@
19062000
}
19072001
},
19082002
"required": [
2003+
"points",
2004+
"wins",
2005+
"draws",
2006+
"losses",
19092007
"id",
19102008
"slot",
19112009
"tournament_id",
2010+
"stage_item_id",
2011+
"team_id",
19122012
"winner_from_stage_item_id",
19132013
"winner_position"
19142014
],
@@ -1946,6 +2046,11 @@
19462046
"type": "null"
19472047
}
19482048
},
2049+
"required": [
2050+
"team_id",
2051+
"winner_from_stage_item_id",
2052+
"winner_position"
2053+
],
19492054
"title": "StageItemInputUpdateBodyEmpty",
19502055
"type": "object"
19512056
},
@@ -2073,6 +2178,7 @@
20732178
"created",
20742179
"type",
20752180
"team_count",
2181+
"ranking_id",
20762182
"id",
20772183
"rounds",
20782184
"inputs",
@@ -2188,6 +2294,9 @@
21882294
"type": "boolean"
21892295
}
21902296
},
2297+
"required": [
2298+
"success"
2299+
],
21912300
"title": "SuccessResponse",
21922301
"type": "object"
21932302
},
@@ -2323,6 +2432,12 @@
23232432
"name",
23242433
"tournament_id",
23252434
"active",
2435+
"elo_score",
2436+
"swiss_score",
2437+
"wins",
2438+
"draws",
2439+
"losses",
2440+
"logo_path",
23262441
"id"
23272442
],
23282443
"title": "Team",
@@ -2504,8 +2619,11 @@
25042619
"duration_minutes",
25052620
"margin_minutes",
25062621
"dashboard_public",
2622+
"dashboard_endpoint",
2623+
"logo_path",
25072624
"players_can_be_in_multiple_teams",
25082625
"auto_assign_courts",
2626+
"status",
25092627
"id"
25102628
],
25112629
"title": "Tournament",
@@ -2562,6 +2680,7 @@
25622680
"start_time",
25632681
"name",
25642682
"dashboard_public",
2683+
"dashboard_endpoint",
25652684
"players_can_be_in_multiple_teams",
25662685
"auto_assign_courts",
25672686
"duration_minutes",
@@ -2650,6 +2769,7 @@
26502769
"start_time",
26512770
"name",
26522771
"dashboard_public",
2772+
"dashboard_endpoint",
26532773
"players_can_be_in_multiple_teams",
26542774
"auto_assign_courts",
26552775
"duration_minutes",

backend/openapi/openapi.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from pydantic.json_schema import GenerateJsonSchema
2+
from pydantic_core import core_schema
3+
4+
5+
def field_is_required(
6+
self: GenerateJsonSchema,
7+
field: core_schema.ModelField | core_schema.DataclassField | core_schema.TypedDictField,
8+
total: bool,
9+
) -> bool:
10+
"""
11+
Override the default Pydantic behavior such that we mark all fields as required.
12+
Otherwise, Pydantic will mark a field as nullable and optional at the same time
13+
which causes hey-api to type fields as `field?: string | null` which is hard to work with.
14+
15+
Field can still be typed as `type: ["string", "null"]` to allow for nullable values.
16+
"""
17+
return True
18+
19+
20+
GenerateJsonSchema.field_is_required = field_is_required # type: ignore[method-assign]

backend/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ disable = [
129129
'unspecified-encoding',
130130
'unused-argument', # Gives false positives.
131131
'wrong-import-position',
132+
'unused-import', # Ruff checks this
132133
]
133134

134135
[tool.bandit]

backend/tests/unit_tests/openapi_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
from pathlib import Path
33

44
from bracket.app import app
5+
from openapi import openapi # noqa: F401
56

67

78
def test_openapi_up_to_date() -> None:
89
schema = app.openapi()
9-
assert Path("openapi/openapi.json").read_text() == json.dumps(schema, indent=2, sort_keys=True)
10+
if Path("openapi/openapi.json").read_text() != json.dumps(schema, indent=2, sort_keys=True):
11+
raise Exception("OpenAPI schema is out of date")

frontend/.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v24.3.0

0 commit comments

Comments
 (0)