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

feat: endpoint /api/v1/strucvars/clinvar-annos/query with OpenAPI (#578) #591

Conversation

holtgrewe
Copy link
Contributor

@holtgrewe holtgrewe commented Nov 15, 2024

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new endpoint for ClinVar SV queries at /api/v1/strucvars/clinvar/query, with updated request and response structures.
    • Added OpenAPI-compliant handler for the /api/v1/genes/info endpoint, enhancing API documentation.
  • Bug Fixes

    • Removed lint suppression for better code quality in multiple handler functions.
  • Documentation

    • Enhanced OpenAPI documentation with new paths and components related to ClinVar data.
  • Chores

    • Integrated new modules for improved functionality related to ClinVar data handling.

Copy link

coderabbitai bot commented Nov 15, 2024

Walkthrough

This pull request includes several modifications across multiple files related to the handling of variant annotations and ClinVar queries. Key changes involve the restructuring of endpoints, specifically renaming the ClinVar SV query endpoint and introducing new request and response structures. The removal of lint suppression attributes in some functions is also noted, which may affect compiler warnings. Additionally, enhancements to OpenAPI documentation and the addition of new modules related to ClinVar data are implemented, improving the API's usability and clarity.

Changes

File Path Change Summary
src/server/run/annos_variant.rs Removed #[allow(clippy::option_map_unit_fn)] attribute from handle function; core logic remains unchanged.
src/server/run/clinvar_sv.rs Renamed endpoint from /clinvar-sv/query to /api/v1/strucvars/clinvar/query; introduced StrucvarsClinvarQuery struct; split handle into handle_impl and a wrapper handle; enhanced error handling and response formats.
src/server/run/genes_clinvar.rs Removed #[allow(clippy::option_map_unit_fn)] attribute from handle function; logic for processing remains unchanged.
src/server/run/genes_info.rs Added handle_with_openapi function for OpenAPI compliance; removed #[allow(clippy::option_map_unit_fn)] from handle function; enhanced error handling in the new function.
src/server/run/mod.rs Added new module clinvar_data; updated OpenAPI documentation to include new paths and components related to ClinVar; modified main function to register new ClinVar service endpoint.

Possibly related issues

Possibly related PRs

🐇 In the code we hop and play,
With endpoints changing day by day.
From ClinVar to genes, we refine,
Each function polished, all in line.
OpenAPI shines, our paths are clear,
Hooray for changes, let’s give a cheer! 🎉


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@holtgrewe holtgrewe marked this pull request as ready for review November 15, 2024 11:53
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (3)
src/server/run/clinvar_sv.rs (1)

355-355: Fix typo in error message

There's a typo in the error message: "Implementaion" should be "Implementation".

Apply the following diff:

-            .map_err(|e| CustomError::new(anyhow::anyhow!("Implementaion error: {:?}", e)))?
+            .map_err(|e| CustomError::new(anyhow::anyhow!("Implementation error: {:?}", e)))?
src/server/run/mod.rs (2)

41-41: Avoid using wildcard imports

Using wildcard imports like server::run::clinvar_data::* can lead to namespace pollution and might import unnecessary items. It's better to import only the needed components explicitly to improve code clarity and maintainability.

Consider specifying the items to import:

- server::run::clinvar_data::*,
+ server::run::clinvar_data::{ClinvarAllele, ClinvarClinicalAssertion, ClinvarTraitSet, ClinvarVariationArchive};

Replace the items with the specific components you need from clinvar_data.


125-261: Consider modularizing OpenAPI schema definitions

The addition of numerous ClinVar-related schemas makes the ApiDoc struct considerably large and harder to maintain. Organizing these schemas into separate modules or grouping them logically can improve code readability and maintainability.

Consider refactoring by:

  • Creating sub-modules for related schemas (e.g., clinvar_data::allele, clinvar_data::variation).
  • Using re-exports to simplify the components(schemas(...)) section.

This approach will help future developers navigate and update the code more efficiently.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a71d62a and f19fffa.

📒 Files selected for processing (5)
  • src/server/run/annos_variant.rs (0 hunks)
  • src/server/run/clinvar_sv.rs (5 hunks)
  • src/server/run/genes_clinvar.rs (0 hunks)
  • src/server/run/genes_info.rs (0 hunks)
  • src/server/run/mod.rs (5 hunks)
💤 Files with no reviewable changes (3)
  • src/server/run/annos_variant.rs
  • src/server/run/genes_clinvar.rs
  • src/server/run/genes_info.rs
🧰 Additional context used
🪛 GitHub Check: clippy
src/server/run/clinvar_sv.rs

[warning] 350-350: use of a fallible conversion when an infallible one could be used
warning: use of a fallible conversion when an infallible one could be used
--> src/server/run/clinvar_sv.rs:350:13
|
350 | TryInto::::try_into(query.into_inner()).map_err(|e| {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: Into::into
|
= note: converting StrucvarsClinvarQuery to Request cannot fail
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_fallible_conversions
= note: #[warn(clippy::unnecessary_fallible_conversions)] on by default


[warning] 229-229: an implementation of From is preferred since it gives you Into<_> for free where the reverse isn't true
warning: an implementation of From is preferred since it gives you Into<_> for free where the reverse isn't true
--> src/server/run/clinvar_sv.rs:229:1
|
229 | impl Into for StrucvarsClinvarQuery {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#from_over_into
help: replace the Into implementation with From<server::run::clinvar_sv::StrucvarsClinvarQuery>
|
229 ~ impl From for Request {
230 ~ fn from(val: StrucvarsClinvarQuery) -> Self {
231 | Request {
232 ~ genome_release: val.genome_release.to_string(),
233 ~ chromosome: val.chromosome,
234 ~ start: val.start,
235 ~ stop: val.stop,
236 ~ variation_types: val
237 | .variation_types
238 | .map(|v| v.into_iter().map(Into::into).collect()),
239 ~ min_overlap: val.min_overlap,
240 ~ page_no: val.page_no,
241 ~ page_size: val.page_size,
|

Comment on lines +229 to +244
impl Into<Request> for StrucvarsClinvarQuery {
fn into(self) -> Request {
Request {
genome_release: self.genome_release.to_string(),
chromosome: self.chromosome,
start: self.start,
stop: self.stop,
variation_types: self
.variation_types
.map(|v| v.into_iter().map(Into::into).collect()),
min_overlap: self.min_overlap,
page_no: self.page_no,
page_size: self.page_size,
}
}
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Prefer implementing From instead of Into for conversions

Implementing From<StrucvarsClinvarQuery> for Request is preferred since it automatically provides the Into implementation, enhancing code clarity and interoperability.

Apply the following changes:

-impl Into<Request> for StrucvarsClinvarQuery {
-    fn into(self) -> Request {
+impl From<StrucvarsClinvarQuery> for Request {
+    fn from(val: StrucvarsClinvarQuery) -> Self {
         Request {
-            genome_release: self.genome_release.to_string(),
-            chromosome: self.chromosome,
-            start: self.start,
-            stop: self.stop,
-            variation_types: self
+            genome_release: val.genome_release.to_string(),
+            chromosome: val.chromosome,
+            start: val.start,
+            stop: val.stop,
+            variation_types: val
                 .variation_types
                 .map(|v| v.into_iter().map(Into::into).collect()),
-            min_overlap: self.min_overlap,
-            page_no: self.page_no,
-            page_size: self.page_size,
+            min_overlap: val.min_overlap,
+            page_no: val.page_no,
+            page_size: val.page_size,
         }
     }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
impl Into<Request> for StrucvarsClinvarQuery {
fn into(self) -> Request {
Request {
genome_release: self.genome_release.to_string(),
chromosome: self.chromosome,
start: self.start,
stop: self.stop,
variation_types: self
.variation_types
.map(|v| v.into_iter().map(Into::into).collect()),
min_overlap: self.min_overlap,
page_no: self.page_no,
page_size: self.page_size,
}
}
}
impl From<StrucvarsClinvarQuery> for Request {
fn from(val: StrucvarsClinvarQuery) -> Self {
Request {
genome_release: val.genome_release.to_string(),
chromosome: val.chromosome,
start: val.start,
stop: val.stop,
variation_types: val
.variation_types
.map(|v| v.into_iter().map(Into::into).collect()),
min_overlap: val.min_overlap,
page_no: val.page_no,
page_size: val.page_size,
}
}
}
🧰 Tools
🪛 GitHub Check: clippy

[warning] 229-229: an implementation of From is preferred since it gives you Into<_> for free where the reverse isn't true
warning: an implementation of From is preferred since it gives you Into<_> for free where the reverse isn't true
--> src/server/run/clinvar_sv.rs:229:1
|
229 | impl Into for StrucvarsClinvarQuery {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#from_over_into
help: replace the Into implementation with From<server::run::clinvar_sv::StrucvarsClinvarQuery>
|
229 ~ impl From for Request {
230 ~ fn from(val: StrucvarsClinvarQuery) -> Self {
231 | Request {
232 ~ genome_release: val.genome_release.to_string(),
233 ~ chromosome: val.chromosome,
234 ~ start: val.start,
235 ~ stop: val.stop,
236 ~ variation_types: val
237 | .variation_types
238 | .map(|v| v.into_iter().map(Into::into).collect()),
239 ~ min_overlap: val.min_overlap,
240 ~ page_no: val.page_no,
241 ~ page_size: val.page_size,
|

Comment on lines +350 to +353
TryInto::<Request>::try_into(query.into_inner()).map_err(|e| {
CustomError::new(anyhow::anyhow!("Query conversion error: {:?}", e))
})?,
)
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Use Into instead of TryInto for infallible conversions

Since converting StrucvarsClinvarQuery to Request cannot fail, you can simplify the code by using Into::into instead of TryInto::try_into, removing unnecessary error handling.

Apply the following changes:

-            TryInto::<Request>::try_into(query.into_inner()).map_err(|e| {
-                CustomError::new(anyhow::anyhow!("Query conversion error: {:?}", e))
-            })?,
+            let request: Request = query.into_inner().into();

Update the function call accordingly:

-            handle_impl(
-                data,
-                path,
-                request,
-            )
+            handle_impl(data, path, request)

And remove the now-unnecessary error mapping.

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 GitHub Check: clippy

[warning] 350-350: use of a fallible conversion when an infallible one could be used
warning: use of a fallible conversion when an infallible one could be used
--> src/server/run/clinvar_sv.rs:350:13
|
350 | TryInto::::try_into(query.into_inner()).map_err(|e| {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: Into::into
|
= note: converting StrucvarsClinvarQuery to Request cannot fail
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_fallible_conversions
= note: #[warn(clippy::unnecessary_fallible_conversions)] on by default

@@ -140,6 +280,7 @@ pub async fn main(args: &Args, dbs: Data<WebServerData>) -> std::io::Result<()>
.service(annos_range::handle)
.service(annos_db_info::handle)
.service(clinvar_sv::handle)
.service(clinvar_sv::handle_with_openapi)
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Remove the deprecated /clinvar-sv/query endpoint registration

The code shows that handle is marked with the deprecated path /clinvar-sv/query while handle_with_openapi serves the new path /api/v1/strucvars/clinvar/query. The dual registration is intentional for backward compatibility, but the old endpoint should be removed as it's explicitly marked as deprecated in the module documentation.

  • Remove .service(clinvar_sv::handle) from src/server/run/mod.rs
🔗 Analysis chain

Verify the necessity of dual service registrations for clinvar_sv

Both clinvar_sv::handle and clinvar_sv::handle_with_openapi are registered as services. If handle_with_openapi is intended to replace handle, consider removing the original handle registration to avoid redundancy and potential conflicts.

Run the following script to check where clinvar_sv::handle is being used:

This script searches for any references to clinvar_sv::handle in the codebase outside of src/server/run/mod.rs. If there are no other references, it might be safe to remove the registration of clinvar_sv::handle.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for usages of `clinvar_sv::handle` in the codebase.

# Find all occurrences of `clinvar_sv::handle` outside of `mod.rs`.
rg -g '!src/server/run/mod.rs' 'clinvar_sv::handle'

Length of output: 51


Script:

#!/bin/bash
# Let's check the content of the mod.rs file to see both service registrations
rg -A 5 -B 5 'clinvar_sv::' src/server/run/mod.rs

Length of output: 1759


Script:

#!/bin/bash
# Let's also check the clinvar_sv module to understand the implementation
fd clinvar_sv.rs --exec cat {}

Length of output: 12771

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.

Add endpoint /api/v1/strucvars/clinvar-annos/query with OpenAPI schema
1 participant