feat: spec-level Postel's-Law tolerant readers#24
Merged
Conversation
Vendored `scripts/lib/preprocess.mjs` is in lockstep with mono's `@devhelm/openapi-tools` and runs `relaxResponseEnumsInSpec` before openapi-zod-client + openapi-typescript consume the spec. Response-DTO multi-value enums collapse to `z.string()` in `schemas.ts` and `string` in `api.ts` — so `MonitorDto.type` decodes any string, including future values added by the API after this SDK version was built. Request DTOs (CreateMonitorRequest.type, etc.) keep their literal unions for strict client-side validation. Negative tests around response-DTO enum rejection are flipped to assert tolerance (Postel's Law). Negative tests around request-DTO enum rejection are kept as-is. See `mini/runbooks/api-contract.md` § 3.1 for the cross-surface design. Coverage: 1321 / 1321 tests pass; lint + tsc clean. Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
@devhelm/sdknow decodes response-DTO multi-value enums as plainstrings —
MonitorDto.type,IncidentDto.status, etc. flow throughthe Zod schemas as
z.string()and the TS types asstring. Newenum values added by the API after this SDK version was built decode
without raising. Request DTOs keep their literal unions for strict
authoring-time validation (still enforced before the wire round-trip).
Implementation
scripts/lib/preprocess.mjs(vendored copy of mono's@devhelm/openapi-tools) callsrelaxResponseEnumsInSpecbefore thespec is consumed by
openapi-zod-client/openapi-typescript.Relaxation happens at the spec level, not as a post-processing regex.
The classifier preserves length-1 enums (discriminator tags) so sealed
union dispatch keeps working.
Negative tests around response-DTO enum rejection (
test_invalid_status,test_invalid_channel_type, …) are flipped to assert acceptance, sincethat's the new contract. Request-DTO negative tests stay strict.
Cross-surface design:
mini/runbooks/api-contract.md§ 3.1.Tests
npm run lintclean,npm run typecheckclean.Test plan
src/generated/api.ts: response DTOs (e.g.AlertChannelDto.channelType) emit as plainstring; requestDTOs (e.g.
CreateMonitorRequest.type) keep literal unions.Made with Cursor