F2 · Swagger Generation: springdoc /: A hand-written `openapi.yaml` is like a **photocopy that goes stale**: the developer changes the code (adds a new field, changes a status co
A hand-written `openapi.yaml` is like a **photocopy that goes stale**: the developer changes the code (adds a new field, changes a status code) but FORGETS to update the doc — over time the doc stops reflecting reality. `springdoc-openapi` (Spring/Java) and `@nestjs/swagger` (NestJS) are an **automatic photocopier** that removes this risk: you do not write the spec by hand, it is auto-generated FROM THE CODE ITSELF (from annotations/decorators) on every build — code and doc can NEVER drift apart, because the doc is a REFLECTION of the code. So why does Express (GROUP C) not have such an auto-generator library (or it requires manual setup)? Because the code does not already CONTAIN the contract as annotations/decorators: in Express, route definitions and validation rules live in separate functions, so a generator finds no fixed pattern to extract "the contract" from; in Spring/Nest, `@GetMapping`/`@Get()`, `@RequestBody`/`@Body()` already CARRY the contract structurally, and the generator READS it into a spec. For QA this difference matters: a spec generated by springdoc/`@nestjs/swagger` is architecturally HARDER to drift from the code — but as you will see in F5, "harder" does not mean impossible.
The Same Code, an Auto-Born Spec
Micro Lab: Code practice
Replace the TODO line with the critical line from the expected solution. This is not a real runtime; the goal is to reinforce writing the correct structure in a controlled way.
Step by Step: Code practice
Identify goal and input
Complete the critical line
Check output or behavior
Read the error message as evidence
Order the code reading and verification flow.
🎬 Code Changes, the Doc Updates Itself
springdoc/@nestjs/swagger
The developer adds a new `@Get('stats')` method to a controller.