-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change api generation #667
Changes from all commits
3f45116
ba7a2d3
58d7be2
84aac30
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
) | ||
from siarnaq.api.compete.permissions import HasTeamSubmission | ||
from siarnaq.api.compete.serializers import ( | ||
EmptySerializer, | ||
HistoricalRatingSerializer, | ||
MatchReportSerializer, | ||
MatchSerializer, | ||
|
@@ -149,8 +150,16 @@ 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 | ||
detail=False, | ||
methods=["get"], | ||
serializer_class=TournamentSubmissionSerializer, | ||
# needed so that the generated schema is not paginated | ||
pagination_class=None, | ||
) | ||
def tournament(self, request, *, episode_id): | ||
"""Retrieve the submissions used in tournaments by the current team..""" | ||
|
@@ -409,7 +418,7 @@ def report(self, request, pk=None, *, episode_id): | |
detail=True, | ||
methods=["post"], | ||
permission_classes=(IsAdminUser,), | ||
serializer_class=None, | ||
serializer_class=EmptySerializer, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spectacular errors if the serializer class is None. |
||
throttle_classes=(), | ||
) | ||
def rating_update(self, request, pk=None, *, episode_id): | ||
|
@@ -424,7 +433,7 @@ def rating_update(self, request, pk=None, *, episode_id): | |
detail=True, | ||
methods=["post"], | ||
permission_classes=(IsAdminUser,), | ||
serializer_class=None, | ||
serializer_class=EmptySerializer, | ||
throttle_classes=(), | ||
) | ||
def publish_public_bracket(self, request, pk=None, *, episode_id): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,6 +75,14 @@ def me(self, request): | |
serializer.save() | ||
return Response(serializer.data) | ||
|
||
@extend_schema( | ||
responses={ | ||
status.HTTP_200_OK: { | ||
"type": "object", | ||
"additionalProperties": {"$ref": "#/components/schemas/TeamPublic"}, | ||
} | ||
Comment on lines
+80
to
+83
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this schema dict describes the response as an object with arbitrary keys with each value conforming to the schema TeamPublic (which is generated from TeamPublicSerializer) |
||
} | ||
) | ||
@action( | ||
detail=True, | ||
permission_classes=(AllowAny,), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -510,3 +510,18 @@ 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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With this, the requests that we pass into API functiosn do not need to contain readonly fields anymore (e.g. no more passing in id:-1 to createuser) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎉🎉 |
||
# Controls which authentication methods are exposed in the schema. If not None, | ||
# will hide authentication classes that are not contained in the whitelist. | ||
# Use full import paths like | ||
# ['rest_framework.authentication.TokenAuthentication', ...]. | ||
# Empty list ([]) will hide all authentication methods. The default None shows all. | ||
"AUTHENTICATION_WHITELIST": [ | ||
"rest_framework_simplejwt.authentication.JWTAuthentication" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This gets rid of a lot of the warnings from spectacular that ask us to make an OpenApiAuthenticationExtension for GoogleCloudAuthentication. We only use JWT authentication from the frontend, so we only need that in our schema.
|
||
], | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
/node_modules | ||
/.pnp | ||
.pnp.js | ||
/types | ||
|
||
# production | ||
/build | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,12 @@ 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 | ||
|
||
:: TODO: delete the types folder before regenerating it. | ||
|
||
:: 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's original vs camelcase? does original just follow what you have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. original follows what the backend uses (aka snake_case). if the schema is generated in camelCase it doesn't work b/c the backend expects snake_case |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spectacular wasn't recognizing this as a list of tournament submissions, so I added many=True. With many=True, spectacular thought it was a paginated list, so I had to set pagination_class=None in the action decorator below