Skip to content

Commit

Permalink
fix: validate OpenAPI spec (#1528)
Browse files Browse the repository at this point in the history
* init api check test

* Fix openAPI issues

Co-authored-by: Hayden <[email protected]>
  • Loading branch information
PFischbeck and hay-kot authored Aug 7, 2022
1 parent 505e594 commit 34cd6eb
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 12 deletions.
6 changes: 3 additions & 3 deletions frontend/api/class-interfaces/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ const prefix = "/api";
const routes = {
usersSelf: `${prefix}/users/self`,
passwordReset: `${prefix}/users/reset-password`,
passwordChange: `${prefix}/users/password`,
users: `${prefix}/users`,

usersIdImage: (id: string) => `${prefix}/users/${id}/image`,
usersIdResetPassword: (id: string) => `${prefix}/users/${id}/reset-password`,
usersId: (id: string) => `${prefix}/users/${id}`,
usersIdPassword: (id: string) => `${prefix}/users/${id}/password`,
usersIdFavorites: (id: string) => `${prefix}/users/${id}/favorites`,
usersIdFavoritesSlug: (id: string, slug: string) => `${prefix}/users/${id}/favorites/${slug}`,

Expand All @@ -45,8 +45,8 @@ export class UserApi extends BaseCRUDAPI<UserIn, UserOut, UserBase> {
return await this.requests.get<UserFavorites>(routes.usersIdFavorites(id));
}

async changePassword(id: string, changePassword: ChangePassword) {
return await this.requests.put(routes.usersIdPassword(id), changePassword);
async changePassword(changePassword: ChangePassword) {
return await this.requests.put(routes.passwordChange, changePassword);
}

async createAPIToken(tokenName: LongLiveTokenIn) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/pages/user/profile/edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export default defineComponent({
if (!userCopy.value?.id) {
return;
}
const { response } = await api.users.changePassword(userCopy.value.id, {
const { response } = await api.users.changePassword({
currentPassword: password.current,
newPassword: password.newOne,
});
Expand Down
1 change: 0 additions & 1 deletion mealie/routes/recipe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@
router.include_router(recipe_crud_routes.router_exports)
router.include_router(recipe_crud_routes.router)
router.include_router(comments.router, prefix=prefix, tags=["Recipe: Comments"])
router.include_router(bulk_actions.router, prefix=prefix)
router.include_router(bulk_actions.router, prefix=prefix, tags=["Recipe: Bulk Exports"])
router.include_router(shared_routes.router, prefix=prefix, tags=["Recipe: Shared"])
2 changes: 1 addition & 1 deletion mealie/routes/users/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def update_user(self, item_id: UUID4, new_data: UserBase):

return SuccessResponse.respond("User updated")

@user_router.put("/{item_id}/password")
@user_router.put("/password")
def update_password(self, password_change: ChangePassword):
"""Resets the User Password"""
if not verify_password(password_change.current_password, self.user.password):
Expand Down
12 changes: 7 additions & 5 deletions mealie/schema/user/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,13 @@ def getter_dict(cls, name_orm: User):
}

schema_extra = {
"username": "ChangeMe",
"fullName": "Change Me",
"email": "[email protected]",
"group": settings.DEFAULT_GROUP,
"admin": "false",
"example": {
"username": "ChangeMe",
"fullName": "Change Me",
"email": "[email protected]",
"group": settings.DEFAULT_GROUP,
"admin": "false",
}
}


Expand Down
93 changes: 92 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ types-requests = "^2.27.12"
types-urllib3 = "^1.26.11"
pre-commit = "^2.17.0"
types-python-dateutil = "^2.8.18"
openapi-spec-validator = "^0.4.0"


[build-system]
Expand Down
8 changes: 8 additions & 0 deletions tests/unit_tests/test_open_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from openapi_spec_validator import validate_v3_spec

from mealie.app import app


def test_validate_open_api_spec():
open_api = app.openapi()
validate_v3_spec(open_api)

0 comments on commit 34cd6eb

Please sign in to comment.