Versioned endpoints or oneOf union: which approach offers safer rollback for OpenAPI type changes?
0 reputation · 28 May 2022, 06:12 UTC
0 reputation · 28 May 2022, 06:12 UTC
The goal is to change a field’s data type (e.g., from string to integer) in an OpenAPI 3.0+ specification while guaranteeing that a rollback to the original type can be performed without breaking existing clients.
Constraints include maintaining backward compatibility during the transition, limiting operational overhead (such as duplicate endpoints or complex validation), and ensuring that tooling (servers, clients, API gateways) correctly handles both representations. The decision must weigh the simplicity of a versioned path strategy against the flexibility of a oneOf union that accepts both old and new types.
Which strategy minimizes client‑side validation errors when rolling back? How does each approach affect API gateway routing rules and documentation consistency? What are the measurable differences in test‑suite complexity when verifying rollback safety for each option?
35275 reputation · 28 May 2022, 15:40 UTC
When you need to change a field’s data type (e.g., string → integer) and guarantee a safe rollback, the versioned endpoint strategy is the safer choice. It isolates the new schema in a distinct URL (e.g., /v2/resource) while keeping the original endpoint (/v1/resource) unchanged, so clients that still rely on the old type never see a breaking change. oneOf unions can work, but they require the server and all tooling to accept both representations simultaneously, and rolling back demands that every variant remains valid, which increases the risk of validation errors.
/v1/resource at a later date without touching the new implementation./v2/resource and keep /v1/resource unchanged./v1/resource as deprecated in the OpenAPI document and in the API gateway./v2/… to the new service and /v1/… to the legacy service./v2/resource with the original /v1/resource implementation and remove the deprecated flag.oneOf with both string and integer variants.integer variant from the union, but ensure that no client has switched to it yet.If your organization has a strict constraint that all clients must use the same URL (e.g., due to hard‑coded endpoints in legacy systems), a oneOf union might become the only viable path. In that case, you would need to confirm:
Without that information, the safest default remains versioned endpoints.
Use comments to ask for clarification. Post a solution as an answer.
35,275 reputation · 28 May 2022, 08:32 UTC
With versioned endpoints the OpenAPI document for /v1/resource never changes; rolling back just means the gateway routes traffic to the v1 backend, so any client SDK generated from that spec stays valid without regeneration. A oneOf union, however, must continue to accept both the old string and the new integer even after you decide to roll back; if you later remove the new variant from the union to reflect the rolled‑back state, clients that have already upgraded to sending integers will start receiving validation errors unless you keep the union forever, which defeats the purpose of a clean rollback.