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

Replace apivore with rswag for api tests #969

Merged
merged 54 commits into from May 12, 2023

Conversation

yksflip
Copy link
Member

@yksflip yksflip commented Nov 21, 2022

This PR replaces apivore with rswag.
It's still in an early stage, but I thought it would be good to share some thoughts and the progress, as it will be quite a big changeset...

  • moving to OpenAPI Spec 3.0.1
  • there is a swagger ui which is routed by default from: http://localhost:3000/api-docs/index.html
  • the swagger file moved from /docs/swagger.v1.yml to /swagger/v1/swagger.yml
  • swagger file is generated by running RAILS_ENV=test rails rswag, should this be added to the CI?

ToDo's

  • fix rubocop violations
    • config/routes.rb:1:1: C: Metrics/BlockLength: Block has too many lines. [212/210]
    • spec/support/api_helper.rb:8:9: C: RSpec/VariableName: Use snake_case for variable names.
  • rswag translation api endpoints
    • /user
      • /user/financial_overview
      • /user/financial_transactions
      • /user/group_order_articles
    • /financial_transactions
    • /orders
    • /order_articles
    • /article_categories
    • /financial_transaction_classes
    • /financial_transaction_types
    • /config
    • /navigation

@yksflip yksflip changed the title Replace apivore with rswag for api tests DRAFT: Replace apivore with rswag for api tests Nov 21, 2022
Copy link
Member

@wvengen wvengen left a comment

Choose a reason for hiding this comment

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

Ah, very very good to see this!
apivore was a big blocker for the Rails upgrade, and I think your approach is perfectly fine. Just too bad that we now have a generated file in the tree. Perhaps we'd best start with CI validating that the swagger file isn't out-of-date (either with timestamps, or by generating and detecting changes - probably the latter).

For my point of view, please continue in this direction :) 👍

@yksflip
Copy link
Member Author

yksflip commented Jan 2, 2023

thanks for your feedback!
Do we actually need to have the swagger.yaml in the tree?
We could generate it in the Dockerfile at build time and we could reference in the docs to smth like https://app.foodcoops.net/api-docs/index.html or any other demo instance.

There's one thing left:
financial_transactions_controller.rb doesn't trows an 422 Error for invalid params. See: https://github.com/foodcoops/foodsoft/pull/969/files#diff-1c933b556e77c0e5911d866a7c6fbd16b6ed8f195f40e2f079703ae4c074c03fR48
I guess this would be another issue?

Beside of that I think this rswag stuff seems to work! I know this is quite a lot to review, so I'd be happy for any ideas how we can merge this best.

@yksflip yksflip marked this pull request as ready for review January 2, 2023 13:07
@yksflip yksflip changed the title DRAFT: Replace apivore with rswag for api tests Replace apivore with rswag for api tests Jan 2, 2023
@yksflip
Copy link
Member Author

yksflip commented May 10, 2023

I've created follow-up issues for the bug in the financial_transaction controller (see todo in the spec file) and for generating the swagger.yml at build time in the Dockerfile.
I think this can be merged now.
@lentschi do you wan't to have a look first or should I just move on?
Final thoughts anyone?

@carchrae
Copy link
Contributor

i haven't reviewed this, but i'm excited to try it out some time. i would much rather have a vue.js app running as my customised front end rather than making lot of changes to haml files and then having a nightmare upgrading when a new foodsoft version comes out.

so, thank you. also, glad you are using swagger. i haven't used it in ruby, but i have used it in nodejs and java projects before.

spec/requests/api/user/financial_transactions_spec.rb Outdated Show resolved Hide resolved
.rubocop_todo.yml Outdated Show resolved Hide resolved
.rubocop_todo.yml Outdated Show resolved Hide resolved
@yksflip yksflip merged commit c67e9b5 into foodcoops:master May 12, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

5 participants