ASP.NET Core Web API Interview Question #160
How can OpenAPI be used in automated API testing?
Testing, HttpClient, Integration Testing, Background Services & Deployment Senior Advanced
Quick Interview Answer
The generated OpenAPI document can be validated in CI, compared for unexpected breaking changes, or used to generate clients and test requests. This helps ensure documentation and implementation remain aligned.
Detailed Explanation
The generated OpenAPI document can be validated in CI, compared for unexpected breaking changes, or used to generate clients and test requests. This helps ensure documentation and implementation remain aligned.
OpenAPI checks do not replace behavioral tests, but they can detect accidental contract changes early.
Code Example
// CI concept:
// 1. Generate openapi.json
// 2. Validate the document
// 3. Compare against the approved contract
// 4. Fail on unintended breaking changes