Map format: duration to the runtime's RFC 3339 Duration type#2458
Conversation
Closes: #2456 A `type: string, format: duration` schema previously fell through to a plain Go string, leaving parsing and validation of the OpenAPI "duration" format entirely to the user. The default type mapping now resolves it to openapi_types.Duration, the RFC 3339 duration type added to the runtime in v1.5.0, alongside the other openapi_types formats (date, uuid, email, binary). This changes generated types for specs already using format: duration. The old behavior can be restored by explicitly mapping the format back to a plain string in the configuration file: output-options: type-mapping: string: formats: duration: type: string Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Greptile SummaryMaps the OpenAPI
Confidence Score: 4/5Safe to merge after discussion on whether the unconditional default change is the right approach for existing users. The change itself is tiny and correct — the new mapping follows the exact same pattern as Both changed files are small;
|
| Filename | Overview |
|---|---|
| pkg/codegen/typemapping.go | Adds "duration": {Type: "openapi_types.Duration"} to the default string format mapping — a one-line change that unconditionally changes generated types for any spec using format: duration. |
| pkg/codegen/typemapping_test.go | Adds a unit assertion for the new duration mapping and a TestDurationFormatMapping end-to-end string-output test; no compiled integration fixture in internal/test/schemas/ to verify the generated code actually builds against the runtime. |
Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
pkg/codegen/typemapping.go:102
**Unconditional breaking change for existing `duration` users**
Any project already using `type: string, format: duration` in its spec will silently start generating `openapi_types.Duration` instead of `string` when it upgrades — that's a type mismatch that breaks compilation without the user doing anything wrong. Per the project's stated practice (all the other conditionally-gated behavior changes in `output-options` / `compatibility`), would a new compatibility flag (e.g. `disable-legacy-duration-string`) or an explicit opt-in be more appropriate here, rather than flipping the default? The existing `type-mapping` escape hatch described in the PR description does work, but it requires users to discover and apply it after already hitting a broken build.
### Issue 2 of 2
pkg/codegen/typemapping_test.go:88-143
**Integration test belongs in `internal/test/schemas/`**
Per the project's test placement rules, regression tests for schema-to-type mapping go under `internal/test/schemas/`, not in `pkg/codegen/`. The most natural home is `internal/test/schemas/primitives/` — extending `spec.yaml` with a `format: duration` field (analogous to the existing `format: date` field) and regenerating `primitives.gen.go`. That fixture compiles the generated code against the real runtime package, giving a stronger guarantee than the string-matching approach here. A provenance comment like `# From issue-2456: duration format maps to openapi_types.Duration` keeps the traceability.
Reviews (1): Last reviewed commit: "Map format: duration to the runtime's RF..." | Re-trigger Greptile
Closes: #2456
A
type: string, format: durationschema previously fell through to a plain Go string, leaving parsing and validation of the OpenAPI "duration" format entirely to the user. The default type mapping now resolves it to openapi_types.Duration, the RFC 3339 duration type added to the runtime in v1.5.0, alongside the other openapi_types formats (date, uuid, email, binary).This changes generated types for specs already using format: duration. The old behavior can be restored by explicitly mapping the format back to a plain string in the configuration file: