Skip to content

feat: support explicitly declared 304 responses on opt-in - #1463

Open
jjant wants to merge 1 commit into
oxidecomputer:mainfrom
jjant:feat/declared-not-modified
Open

jjant wants to merge 1 commit into
oxidecomputer:mainfrom
jjant:feat/declared-not-modified

Conversation

@jjant

@jjant jjant commented Nov 19, 2026 •

Copy link
Copy Markdown

Fixes #1462.

An operation can declare both a JSON 200 and a bodyless 304. The generated client currently reports the latter as UnexpectedResponse. This adds an opt-in for callers that want to revalidate a cached representation.

progenitor::generate_api!(spec = "openapi.json", conditional_responses = true);

match client.get_item(Some(etag)).await? {
    ConditionalResponse::Modified(value) => update_cache(value),
    ConditionalResponse::NotModified(response) => reuse_cache(response.headers()),
}

When enabled, the generator emits the enum only for SDKs with an explicitly declared, bodyless 304. Modified carries the existing ResponseValue<T>. NotModified carries the original HTTP response, preserving status and headers without deserializing a body. Both request styles support it. The build-script setting is with_conditional_responses(true) and the standalone generator accepts --conditional-responses.

The opt-in keeps existing generated signatures compatible. An item stream surfaces a 304 with its original headers as an error because advancing the stream requires the items and next-page token from the cached page. The generated CLI sends single-request 304s to its existing success_no_item callback.

The regression tests exercise an ETag round trip, a stale validator, a declared 404, an invalid 200 payload, the opt-in and declaration boundaries, and a 304 on a subsequent page in both SDK styles.

AI disclosure

OpenAI Codex implemented the generator changes, wrote and ran the regression tests, and drafted this pull request description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generated client treats a declared 304 Not Modified as UnexpectedResponse

1 participant