Skip to content
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

Wip 369 doc to models #227

Merged
merged 1 commit into from
Nov 27, 2024
Merged

Wip 369 doc to models #227

merged 1 commit into from
Nov 27, 2024

Conversation

damienbfs
Copy link
Collaborator

@damienbfs damienbfs commented Nov 15, 2024

Moved documentation to pydantic models.

Redoc only shows first part of docstring (until \f character), while sphinx doc the entire docstring (see pictures).

Also added core documentation to sphinx and option to build locally.

@damienbfs damienbfs force-pushed the wip_369_doc_to_models branch 3 times, most recently from 3ed9a30 to 21083b8 Compare November 19, 2024 09:57
@PaulineMauryL
Copy link
Member

PaulineMauryL commented Nov 19, 2024

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  server/lomas_server/dp_queries
  dummy_dataset.py
  server/lomas_server/routes
  routes_admin.py
  routes_dp.py
  utils.py
  server/lomas_server/tests
  test_api.py
  test_api_diffprivlib.py
  test_api_smartnoise_synth.py
  test_dummy_generation.py
Project Total  

This report was generated by python-coverage-comment-action

@damienbfs damienbfs force-pushed the wip_369_doc_to_models branch 2 times, most recently from 2c99ddd to b774abb Compare November 19, 2024 10:40
@damienbfs damienbfs marked this pull request as ready for review November 19, 2024 10:40
@damienbfs
Copy link
Collaborator Author

image

@damienbfs
Copy link
Collaborator Author

image

@damienbfs
Copy link
Collaborator Author

image

@damienbfs damienbfs self-assigned this Nov 19, 2024


# Server error responses for DP queries
SERVER_QUERY_ERROR_RESPONSES: dict[int | str, dict[str, Any]] = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the goal of this and ...ExceptionModel exceptions versus what was there before ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows to list the possible responses that an endpoint can return:

@router.post(
    "/dummy_diffprivlib_query",
    dependencies=[Depends(server_live)],
    response_model=QueryResponse,
    responses=SERVER_QUERY_ERROR_RESPONSES,
    tags=["USER_DUMMY"],
)

The format of the dict in responses requires pydantic models. Using these also has the benefit that we can show the output model in the redoc documentation, not only for the standard response, but also for exceptions.

Comment on lines +35 to +49
class ExternalLibraryExceptionModel(LomasServerExceptionModel):
"""For exceptions from libraries external to the lomas packages."""

type: Literal[ExceptionType.EXTERNAL_LIBRARY] = ExceptionType.EXTERNAL_LIBRARY
"""Exception type."""
library: DPLibraries
"""The external library that caused the exception."""
message: str
"""Exception error message.

For exceptions from libraries external to the lomas packages.
"""


class UnauthorizedAccessExceptionModel(LomasServerExceptionModel):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aren't ExternalLibraryException and UnauthorizedAccessException always related to a query ? (just trying to understand)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure, maybe we should clarify this somewhere. How would you use them?

  • Unauthorized: every time the user does not have access?
  • ExternalLibrary: only when we catch an exception from an external library
  • ...?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is here: https://dscc-admin-ch.github.io/lomas-docs/client_errors.html
Except for InternalServerException, I think all exceptions are always directly related to queries.

@PaulineMauryL
Copy link
Member

It looks good!

…current branch.

Move endpoint documentation to pydantic models. Add responses to path operators and add models to exceptions. Modify client accordingly
Moved example queries out of default values to model configs.
Update docummentation of routes/utils methods.
Copy link
Collaborator

@LancelotMarti LancelotMarti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very clean, thanks!

@damienbfs damienbfs merged commit 5751bf0 into develop Nov 27, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants