Skip to content

Write test to check openapi schema has not changed#238

Merged
callumforrester merged 6 commits intomainfrom
openapi-checks
May 25, 2023
Merged

Write test to check openapi schema has not changed#238
callumforrester merged 6 commits intomainfrom
openapi-checks

Conversation

@callumforrester
Copy link
Copy Markdown
Contributor

Changes

  • Check schema has not changed in tests
  • Write CLI command to regenerate schema
  • Delete openapi Github action (now covered by the tests)

@codecov
Copy link
Copy Markdown

codecov Bot commented May 25, 2023

Codecov Report

Merging #238 (d2fe4cf) into main (ca227d6) will decrease coverage by 0.61%.
The diff coverage is 57.14%.

@@            Coverage Diff             @@
##             main     #238      +/-   ##
==========================================
- Coverage   89.65%   89.05%   -0.61%     
==========================================
  Files          41       41              
  Lines        1257     1270      +13     
==========================================
+ Hits         1127     1131       +4     
- Misses        130      139       +9     
Impacted Files Coverage Δ
src/blueapi/cli/cli.py 85.86% <45.45%> (-5.49%) ⬇️
src/blueapi/service/openapi.py 78.57% <70.00%> (-21.43%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Copy Markdown
Contributor

@rosesyrett rosesyrett left a comment

Choose a reason for hiding this comment

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

Initially I wasn't sure I liked generate schema being a CLI command... I'm okay with it considering blueapi will be an internal service, and any schema that is generated is only used for the docs anyways so even if someone checks out the repo, makes changes to the API and generates the schema, unless they push it the actual docs wont change.

However... the tests do not actually generate the openapi schema. There are two tests:

  • test_generate_schema just checks that, if the app has a slightly different title, or description, or whatever, the generated schema returned from the get_openapi function of fastapi.openapi.utils reflects those changes.
  • test_schema_updated seems to just check that the generated schema from the current openapi.yaml file in docs matches the one in the current application.

Could the 2nd test also generate this schema if they're different? Or is that considered bad test-practise?

@callumforrester
Copy link
Copy Markdown
Contributor Author

Could the 2nd test also generate this schema if they're different? Or is that considered bad test-practise?

If we did that the test would always pass, which would mean it is not a useful test. The idea of this is: if someone has changed the API and not regenerated the schema, the CI should fail. This alerts them to the fact that they have changed the API in an "are you sure" way.

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.

2 participants