Skip to content

Commit

Permalink
generate types with typescript-fetch, split-request-response
Browse files Browse the repository at this point in the history
  • Loading branch information
acrantel committed Aug 24, 2023
1 parent 0de1bc1 commit ea6864a
Show file tree
Hide file tree
Showing 157 changed files with 11,331 additions and 6,655 deletions.
3 changes: 3 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ repos:
hooks:
- id: check-merge-conflict
- id: end-of-file-fixer
exclude: ^frontend2/src/utils/types
- id: mixed-line-ending
args: ["--fix=lf"]
exclude: ^frontend2/src/utils/types
- id: trailing-whitespace
exclude: ^frontend2/src/utils/types

- repo: https://github.com/dnephin/pre-commit-golang
rev: v0.5.1
Expand Down
10 changes: 7 additions & 3 deletions backend/siarnaq/api/compete/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.db.models import Exists, OuterRef, Q, Subquery
from django.utils import timezone
from drf_spectacular.utils import OpenApiParameter, OpenApiResponse, extend_schema
from rest_framework import mixins, status, viewsets
from rest_framework import mixins, serializers, status, viewsets
from rest_framework.decorators import action
from rest_framework.exceptions import APIException
from rest_framework.permissions import IsAdminUser, IsAuthenticated
Expand Down Expand Up @@ -149,6 +149,10 @@ def create(self, request, *, episode_id):
headers=headers,
)

@extend_schema(
# https://drf-spectacular.readthedocs.io/en/latest/faq.html#i-m-using-action-detail-false-but-the-response-schema-is-not-a-list
responses=TournamentSubmissionSerializer(many=True)
)
@action(
detail=False, methods=["get"], serializer_class=TournamentSubmissionSerializer
)
Expand Down Expand Up @@ -409,7 +413,7 @@ def report(self, request, pk=None, *, episode_id):
detail=True,
methods=["post"],
permission_classes=(IsAdminUser,),
serializer_class=None,
serializer_class=serializers.Serializer,
throttle_classes=(),
)
def rating_update(self, request, pk=None, *, episode_id):
Expand All @@ -424,7 +428,7 @@ def rating_update(self, request, pk=None, *, episode_id):
detail=True,
methods=["post"],
permission_classes=(IsAdminUser,),
serializer_class=None,
serializer_class=serializers.Serializer,
throttle_classes=(),
)
def publish_public_bracket(self, request, pk=None, *, episode_id):
Expand Down
4 changes: 2 additions & 2 deletions backend/siarnaq/api/teams/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.http import Http404
from django.shortcuts import get_object_or_404
from drf_spectacular.utils import extend_schema
from rest_framework import filters, mixins, status, viewsets
from rest_framework import filters, mixins, serializers, status, viewsets
from rest_framework.decorators import action
from rest_framework.permissions import IsAdminUser, IsAuthenticated
from rest_framework.response import Response
Expand Down Expand Up @@ -114,7 +114,7 @@ def me(self, request, *, episode_id):
@action(
detail=False,
methods=["post"],
serializer_class=None,
serializer_class=serializers.Serializer,
permission_classes=(IsAuthenticated, IsEpisodeAvailable),
)
def leave(self, request, *, episode_id):
Expand Down
7 changes: 7 additions & 0 deletions backend/siarnaq/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,3 +510,10 @@ def dropper(logger, method_name, event_dict):
raise structlog.DropEvent

structlog.configure(processors=[dropper])

SPECTACULAR_SETTINGS = {
# Split components into request and response parts where appropriate
# This setting is highly recommended to achieve the most accurate API
# description, however it comes at the cost of having more components.
"COMPONENT_SPLIT_REQUEST": True,
}
1 change: 0 additions & 1 deletion frontend2/.prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/node_modules
/.pnp
.pnp.js
/types

# production
/build
Expand Down
5 changes: 3 additions & 2 deletions frontend2/generate_types.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ call conda activate galaxy
echo "navigate to galaxy folder"
cd ..
echo "Generate OpenAPI 3.0 backend schema from siarnaq"
python backend/manage.py spectacular --file schema.yml
python backend/manage.py spectacular --file schema.yml --validate

:: echo "Download openapitools"
:: npm install @openapitools/openapi-generator-cli -g
:: if you have a java error, just install java 8 and reload terminal
echo "Generate typescript types from schema"
npx @openapitools/openapi-generator-cli generate -i schema.yml -o frontend2/src/utils/types -g typescript-jquery --additional-properties=modelPropertyNaming=camelCase --additional-properties=disallowAdditionalPropertiesIfNotPresent=false
npx @openapitools/openapi-generator-cli generate -i schema.yml -o frontend2/src/utils/types -g typescript-fetch --additional-properties=modelPropertyNaming=original --additional-properties=disallowAdditionalPropertiesIfNotPresent=false --additional-properties=stringEnums=true
149 changes: 85 additions & 64 deletions frontend2/src/utils/types/.openapi-generator/FILES
Original file line number Diff line number Diff line change
@@ -1,65 +1,86 @@
api/ApiApi.ts
api/api.ts
configuration.ts
git_push.sh
.openapi-generator-ignore
apis/CompeteApi.ts
apis/EpisodeApi.ts
apis/SpecsApi.ts
apis/TeamApi.ts
apis/TokenApi.ts
apis/UserApi.ts
apis/index.ts
index.ts
model/Autoscrim.ts
model/ClassRequirement.ts
model/CountryEnum.ts
model/EligibilityCriterion.ts
model/Email.ts
model/Episode.ts
model/GenderEnum.ts
model/HistoricalRating.ts
model/LanguageEnum.ts
model/Match.ts
model/MatchParticipant.ts
model/MatchReport.ts
model/ModelMap.ts
model/PaginatedClassRequirementList.ts
model/PaginatedEpisodeList.ts
model/PaginatedMatchList.ts
model/PaginatedScrimmageRequestList.ts
model/PaginatedSubmissionList.ts
model/PaginatedTeamPublicList.ts
model/PaginatedTournamentList.ts
model/PaginatedTournamentRoundList.ts
model/PasswordToken.ts
model/PatchedTeamPrivate.ts
model/PatchedUserPrivate.ts
model/PlayerOrderEnum.ts
model/ReleaseStatusEnum.ts
model/ResetToken.ts
model/SaturnInvocation.ts
model/ScrimmageRequest.ts
model/ScrimmageRequestStatusEnum.ts
model/Status526Enum.ts
model/StatusBccEnum.ts
model/StyleEnum.ts
model/Submission.ts
model/SubmissionDownload.ts
model/SubmissionReport.ts
model/TeamAvatar.ts
model/TeamCreate.ts
model/TeamJoin.ts
model/TeamPrivate.ts
model/TeamProfilePrivate.ts
model/TeamProfilePublic.ts
model/TeamPublic.ts
model/TeamReport.ts
model/TokenObtainPair.ts
model/TokenRefresh.ts
model/TokenVerify.ts
model/Tournament.ts
model/TournamentRound.ts
model/TournamentSubmission.ts
model/UserAvatar.ts
model/UserCreate.ts
model/UserPassed.ts
model/UserPrivate.ts
model/UserProfilePrivate.ts
model/UserProfilePublic.ts
model/UserPublic.ts
model/UserResume.ts
model/models.ts
variables.ts
models/AutoscrimRequest.ts
models/ClassRequirement.ts
models/CountryEnum.ts
models/EligibilityCriterion.ts
models/Email.ts
models/EmailRequest.ts
models/Episode.ts
models/GenderEnum.ts
models/HistoricalRating.ts
models/LanguageEnum.ts
models/Match.ts
models/MatchParticipant.ts
models/MatchReportRequest.ts
models/ModelMap.ts
models/PaginatedClassRequirementList.ts
models/PaginatedEpisodeList.ts
models/PaginatedMatchList.ts
models/PaginatedScrimmageRequestList.ts
models/PaginatedSubmissionList.ts
models/PaginatedTeamPublicList.ts
models/PaginatedTournamentList.ts
models/PaginatedTournamentRoundList.ts
models/PaginatedTournamentSubmissionList.ts
models/PasswordToken.ts
models/PasswordTokenRequest.ts
models/PatchedTeamPrivateRequest.ts
models/PatchedUserPrivateRequest.ts
models/PlayerOrderEnum.ts
models/ReleaseStatusEnum.ts
models/ResetToken.ts
models/ResetTokenRequest.ts
models/SaturnInvocationRequest.ts
models/ScrimmageRequest.ts
models/ScrimmageRequestRequest.ts
models/ScrimmageStatusEnum.ts
models/Status526Enum.ts
models/StatusBccEnum.ts
models/StyleEnum.ts
models/Submission.ts
models/SubmissionDownload.ts
models/SubmissionReportRequest.ts
models/SubmissionRequest.ts
models/TeamAvatarRequest.ts
models/TeamCreate.ts
models/TeamCreateRequest.ts
models/TeamJoinRequest.ts
models/TeamPrivate.ts
models/TeamPrivateRequest.ts
models/TeamProfilePrivate.ts
models/TeamProfilePrivateRequest.ts
models/TeamProfilePublic.ts
models/TeamPublic.ts
models/TeamReportRequest.ts
models/TokenObtainPair.ts
models/TokenObtainPairRequest.ts
models/TokenRefresh.ts
models/TokenRefreshRequest.ts
models/TokenVerifyRequest.ts
models/Tournament.ts
models/TournamentRound.ts
models/TournamentSubmission.ts
models/UserAvatarRequest.ts
models/UserCreate.ts
models/UserCreateRequest.ts
models/UserPassed.ts
models/UserPrivate.ts
models/UserPrivateRequest.ts
models/UserProfilePrivate.ts
models/UserProfilePrivateRequest.ts
models/UserProfilePublic.ts
models/UserProfilePublicRequest.ts
models/UserPublic.ts
models/UserPublicRequest.ts
models/UserResume.ts
models/UserResumeRequest.ts
models/index.ts
runtime.ts
2 changes: 1 addition & 1 deletion frontend2/src/utils/types/.openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.6.0
6.6.0
Loading

0 comments on commit ea6864a

Please sign in to comment.