pacedotdev / oto

Go driven rpc code generation tool for right now.
MIT License
805 stars 50 forks source link

Transitional Field Statuses: Allow fields to be marked 'introduced' and 'removing' in addition to 'required' and 'optional' #49

Open clord opened 1 month ago

clord commented 1 month ago

Problem

Modifying required fields in our API can lead to compatibility issues between clients and servers, especially when fields are added, removed, or have their required/optional status changed. The key challenges are:

  1. When adding a new required field, clients using older versions of the API may not include the new required field in their requests to the updated server, resulting in validation errors and failed requests.
  2. When removing a required field and a client is updated before the server, it may stop sending a field that the server still expects as required, causing processing errors on the server side.
  3. Promoting optional fields to required, or demoting required fields to optional, can create inconsistencies and unexpected behaviours if not managed carefully.

Making all fields optional is not a feasible solution because:

Proposal: Transitional Field Statuses

Implement transitional statuses for fields to manage their lifecycle without breaking existing client/servers:

becoming-required — introducing a new field that will eventually become required

becoming-optional — planning to deprecate and eventually remove an existing required field

This approach allows for a gradual transition.

Reader/Writer vs Client/Server

Please note the distinction between client/server and reader/writer. Both clients and servers write to structs, and read from structs. In this PR we draw the distinction instead between readers and writers.

matryer commented 5 days ago

@clord thanks for this - the 'required' thing in Grafana Incident is handled via the comment metadata mechanism in Oto. The templates check that field and render appropriate validation output. So I think this would be best solved in the templates themselves, and you don't need to change Oto to do it. Oto doesn't have any specific support for 'required' fields.

clord commented 5 days ago

Template changes will be required, but this request is for something between optional and required. When introducing a new field, or removing it, we want the validation of the producer to be required, but the validation of the consumer to be optional. This way, we start producing it asap, but we don't have to validate it yet on the consumer. imo, we want to break the two 'sides' of required up up so template can know which case we are in.