DevNet Associate (DEVASC) v1.0Understanding and Using APIsHard
A network automation team is developing a CI/CD pipeline. As part of the API testing phase, they need to ensure that the API documentation is always synchronized with the actual API implementation. Which of the following approaches is most effective for automatically verifying API documentation accuracy?
- AUsing a tool like Postman to send requests defined in the documentation and assert against expected responses.
- BGenerating API documentation from code annotations and validating it against predefined templates.
- CImplementing contract testing where generated client stubs are tested against the server-side API implementation.
- DManually comparing the documentation to API responses after each deployment.
Show answer & explanationAnswer & explanation
Correct answer: C. Implementing contract testing where generated client stubs are tested against the server-side API implementation.
Contract testing (specifically consumer-driven contract testing) is highly effective for ensuring API documentation (contract) matches implementation. It involves defining a shared contract and then testing both the consumer (client) and provider (API) against that contract, flagging discrepancies automatically in the CI/CD pipeline.
Why the other options are wrong
- A. While Postman can test the API, it primarily validates the API's behavior against a set of expectations, not directly the documentation's accuracy against the *implementation's contract*. It's a form of integration testing, not contract testing.
- B. Generating docs from code helps with consistency but doesn't verify that the *generated* documentation accurately reflects the *runtime behavior* of the API.
- D. Manual comparison is impractical and error-prone in a CI/CD pipeline.
API Contract Testing
A testing approach where an explicit 'contract' (often derived from API documentation like OpenAPI) is defined between an API producer and consumer, and both sides are tested to ensure they adhere to this contract.
- Ensures API documentation matches actual implementation.
- Prevents breaking changes between API versions.
- Automated in CI/CD pipelines to catch discrepancies early.
Memory trick: Docs Must Match Code, Contract Testing Makes It So.