-
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
Conversation
62c7d07
to
26a8a31
Compare
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.
comments are all things to doublecheck, etc -- no feedback that would require a second validation from me
looks good! happy if this just gets revisions and then is merged
(unless we have PRs dismiss on stale)
@@ -8,4 +8,4 @@ python backend/manage.py spectacular --file schema.yml | |||
:: 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 comment
The reason will be displayed to describe this comment to others. Learn more.
what's original vs camelcase? does original just follow what you have
sorry if i missed slack
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.
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
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.
Looks really awesome! Left a few comments about stability with future typegen runs but if those are non-issues then ship it!
this PR is blocked by #671. |
aa49de4
to
986fa3e
Compare
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.
still todo: update all references to the API in our frontend components
done!
@@ -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) |
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
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Spectacular errors if the serializer class is None.
# 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
🎉🎉
# ['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 comment
The 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.
Below is the warning that this line gets rid of:
Warning #0: MatchViewSet: could not resolve authenticator <class 'siarnaq.api.user.authentication.GoogleCloudAuthentication'>. There was no OpenApiAuthenticationExtension registered for that class. Try creating one by subclassing it. Ignoring for now.
@@ -8,4 +8,4 @@ python backend/manage.py spectacular --file schema.yml | |||
:: 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 comment
The 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
status.HTTP_200_OK: { | ||
"type": "object", | ||
"additionalProperties": {"$ref": "#/components/schemas/TeamPublic"}, | ||
} |
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.
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)
seems good, would wait for lowell though |
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.
Looks fantastic! Love the split API! Next step, implementing team ranking & ranking history!
API generation changes
Frontend API client changes
Miscellaneous:
generate-types.bat
.pre-commit-config.yaml
)review requests