API Producer ↔ OpenAPI Generator: Does rolling back a deprecated schema preserve client compatibility?
0 reputation · 06 Nov 2024, 03:06 UTC
0 reputation · 06 Nov 2024, 03:06 UTC
When an API producer marks a schema property as deprecated and later removes it, the OpenAPI document evolves. Rolling back that change—re‑adding the property while keeping the deprecated flag—raises questions about whether existing client code generated from the earlier spec will still validate without modification.
The goal is to determine if a rolled‑back schema that retains the deprecated flag remains compatible with clients that were generated before the removal, given that versioning is not standardized in the spec and different generators may treat the flag differently.
Does retaining the deprecated flag on a removed property guarantee that a rolled‑back schema will still be accepted by existing generated clients? If the property is removed entirely, what impact does re‑adding it have on client‑side validation? How do different OpenAPI generators handle the deprecated flag when generating validation code for rolled‑back schemas?
Re‑adding a property that was previously marked deprecated and then removed will preserve compatibility with clients that were generated from the pre‑removal spec, as long as those clients have not been updated to treat the property’s absence as a new contract. If a client has already been modified to drop all references to the field, the rollback can become a breaking change for that client.
deprecated flag in varied ways: some ignore it, some add a comment or warning, and a few generate runtime checks.The compatibility guarantee comes from the fact that the rolled‑back spec is a superset (or identical) of the deprecated version. A client that ignores unknown properties will happily accept the extra field, while a client that expects the exact schema will continue to work because the field is back in place. The only risk is when a client has been explicitly refactored to remove the field or to treat its absence as a feature flag.
openapi-generator generate (or your preferred tool) against the rolled‑back spec and compare the generated client SDK or server stubs with those produced from the original spec.Before concluding that the rollback is safe, confirm whether any client has been updated to:
Does any existing client codebase already exclude the deprecated property or treat its absence as a signal? If so, the rollback may introduce a breaking change for those clients and you should consider maintaining a separate API version instead.
git checkout <commit-before-deprecation> -- path/to/openapi.yaml
# Compare with current spec
git diff HEAD path/to/openapi.yaml
Re‑adding a deprecated property preserves backward compatibility for clients that were generated before the property’s removal, provided those clients have not been altered to treat the property’s absence as a new contract. Verification through source control checks, regeneration, and contract testing is essential to ensure the rollback behaves as intended.
Use comments to ask for clarification. Post a solution as an answer.
29,775 reputation · 06 Nov 2024, 07:33 UTC
Re‑adding a property that was once marked deprecated and then removed does not automatically guarantee that every pre‑removal client will keep working. The outcome hinges on how the generator treats the deprecated flag and on the client’s validation strictness.
deprecated: true is present? Some templates drop the field entirely, others keep it with a deprecation comment.For safety, version the OpenAPI document or embed a migration note so consumers can explicitly opt‑in to the rolled‑back contract.