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

Non-Generated WEBKNOSSOS API Client #948

Merged
merged 40 commits into from
Nov 7, 2023
Merged

Non-Generated WEBKNOSSOS API Client #948

merged 40 commits into from
Nov 7, 2023

Conversation

fm3
Copy link
Member

@fm3 fm3 commented Oct 6, 2023

Description:

  • Replaces the generated webknossos api client by a handwritten one
  • The client generation was a good idea, but did not work well in practice, in part due to incomplete swagger information by the outdated swagger-play library.
  • The handwritten client is very similar to the one used in the javascript frontend
  • It adds type-safety and holds information about which fields are optional.
  • It contains only those routes and fields that are actually used by the client. Add what’s needed
  • It also queries the versioned api routes and adds some more explanatory texts to the exceptions in failure cases.
  • The PR also refreshes the test cassettes to match the requests performed by the new client (pretty similar to before, though)

Issues:

Todos:

  • proof of concept
  • separate datastore routes
  • camelCase to snake_case for attr fields?
  • merge master
  • migrate all the routes
    • hurdles:
      • retries
      • X-Total-Count header for pagination (e.g. tasks)
      • weird format of task creation response
      • experiences are key:value dict, should not be auto_snake_cased, how to prevent that there?
  • remove the generated client and generation code
  • remove logging. version hint should go into the exception so users can catch it if they want
  • adapt and extend automated tests
  • remove pyhumps dependency (and others?)
  • refresh test cassets
  • do some manual testing
  • cleanup
  • CI
  • Document how to modify this in the future
    --
  • Updated Changelog
  • Added / Updated Tests

@fm3 fm3 self-assigned this Oct 6, 2023
@fm3 fm3 marked this pull request as ready for review November 2, 2023 16:25
@fm3 fm3 changed the title WIP: non-generated webknossos api client Non-Generated WEBKNOSSOS API Client Nov 2, 2023
@fm3 fm3 requested a review from philippotto November 2, 2023 16:25
Copy link
Member

@philippotto philippotto left a comment

Choose a reason for hiding this comment

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

Great stuff 👍 I like that the glue code got much more readable due to the better typing (which is obviously awesome in itself).

I left some small comments. Other than that, I stumbled a bit about the naming of the methods in the client. Simply retrieving something is named à la folder_tree() (without "get" or "fetch") and updating something is dataset_team_update (instead of update_team_for_dataset). You probably tried to keep the names as close as possible to the routes and only added the verbs when the method is not GET? I think, it's fine, since this layer is only a thin abstraction used by the actual model classes. Still wanted to write my thoughts down for the record..

.github/workflows/nightly.yml Outdated Show resolved Hide resolved
webknossos/tests/test_api_client.py Outdated Show resolved Hide resolved
webknossos/typecheck.sh Show resolved Hide resolved
webknossos/webknossos/administration/task.py Show resolved Hide resolved
webknossos/webknossos/client/apiclient/__init__.py Outdated Show resolved Hide resolved
webknossos/webknossos/client/apiclient/_serialization.py Outdated Show resolved Hide resolved
@fm3
Copy link
Member Author

fm3 commented Nov 6, 2023

Thanks for taking the time to read through this!

I see your point concerning the api method naming. Most names are close to what the generated client had. However, the names may not be ideal, and currently they are kind of mixed.

I think there are two possible ways to design the names:

  • (1) use verbs first (update_dataset_teams, create_tasks_from_files) (I think I’d still skip the get, though)
  • (2) use domain first (dataset_update_teams, dataset_assert_new_name_is_valid, annotation_upload, user_logged_time). This has the benefit of automated grouping by domain, which could help with auto-completion in the IDE

Most routes currently use approach 2. Depending on your opinion I could now either iron the rest out by adapting this domain first approach (originally introduced by jonathan) for the remaining few methods, or I could use the verb-first approach (with or without "get"). What do you think?

@philippotto
Copy link
Member

I think there are two possible ways to design the names:

  • (1) use verbs first (update_dataset_teams, create_tasks_from_files) (I think I’d still skip the get, though)
  • (2) use domain first (dataset_update_teams, dataset_assert_new_name_is_valid, annotation_upload, user_logged_time). This has the benefit of automated grouping by domain, which could help with auto-completion in the IDE

Most routes currently use approach 2. Depending on your opinion I could now either iron the rest out by adapting this domain first approach (originally introduced by jonathan) for the remaining few methods, or I could use the verb-first approach (with or without "get"). What do you think?

I'm fine with either way as long as it is consistent (also I'd add a comment to the module which explains the naming). So, feel free to go for (2).

@fm3 fm3 requested a review from philippotto November 6, 2023 13:45
Copy link
Member

@philippotto philippotto left a comment

Choose a reason for hiding this comment

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

🎉

@jstriebel
Copy link
Contributor

jstriebel commented Nov 6, 2023

@fm3 fm3 merged commit 00e1683 into master Nov 7, 2023
19 checks passed
@fm3 fm3 deleted the manual-client branch November 7, 2023 08:28
philippotto added a commit that referenced this pull request Apr 22, 2024
* remove openapi-python-client as it is unused since #948

* remove obsolete note about auto-generated client in contributors md

* upgrade typer to 0.12.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants