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

Add missing ApiQuery decorators for Swagger #1937

Merged
merged 1 commit into from
Sep 20, 2024
Merged

Conversation

iamacook
Copy link
Member

Summary

Resolves #1747

Some optional queries are currently marked a required on Swagger. This adds the missing ApiQuery decorators for said queries.

Changes

  • Add missing ApiQuery decorators where Querys are present.

@iamacook iamacook self-assigned this Sep 19, 2024
@iamacook iamacook requested a review from a team as a code owner September 19, 2024 07:50
@coveralls
Copy link

Pull Request Test Coverage Report for Build 10936715946

Details

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.05%) to 90.698%

Totals Coverage Status
Change from base Build 10906426126: 0.05%
Covered Lines: 8364
Relevant Lines: 8849

💛 - Coveralls

@PooyaRaki
Copy link
Contributor

Question: How confident are we that these were the only methods with issues, and that other methods are unaffected?

@ApiQuery({ name: 'currency', required: true, type: String })
@ApiQuery({ name: 'safes', required: true, type: String })
@ApiQuery({ name: 'trusted', required: false, type: Boolean })
@ApiQuery({ name: 'exclude_spam', required: false, type: Boolean })
@Get('safes')
async getSafeOverview(
@Query('currency') currency: string,
Copy link
Contributor

Choose a reason for hiding this comment

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

TODO: When parameters are optional, mark them as optional in the code by appending a question mark (?) to the end of the parameter name. This way, Swagger may automatically recognize the parameter as optional. e.g.

Suggested change
@Query('currency') currency: string,
@Query('currency') currency?: string,

Implementing this requires additional effort and is outside the scope of the current PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Which parameters are not marked as optional? In this case, currency is required.

Copy link
Contributor

@PooyaRaki PooyaRaki Sep 20, 2024

Choose a reason for hiding this comment

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

@iamacook I have seen some instances, but here for example excludeSpam. It has a default value though.

Copy link
Member Author

Choose a reason for hiding this comment

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

Perhaps we should reconsider usage of the default pipes, and instead assign a default value manually. This would negate the requirement of ApiQuery. I'll merge this for now and we can reconsider this later.

@iamacook
Copy link
Member Author

Question: How confident are we that these were the only methods with issues, and that other methods are unaffected?

I manually looked through every Query decorator to confirm so I am pretty confident. Regarding other Swagger definitions, I am not sure. Usage of the new SDK would highlight any.

@iamacook iamacook merged commit 8434afc into main Sep 20, 2024
18 checks passed
@iamacook iamacook deleted the swagger-query-params branch September 20, 2024 09:38
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.

Optional query parameters marked as required on Swagger
3 participants