Option 1: Parse anything that looks like a date #280
Closed
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.
This is basically it:
Before this PR, we require a key with a prefix of
time_or an exact match totimestampin order for us to attempt parsing the value a date. This is pretty bad because there is no reason to expect timestamp properties to follow this pattern — it only happened to be true in omicron for a long time. This was already a problem for other apps using this generator that did not follow this very implicit (secret, even) convention, as @augustuswm can attest.In this PR, instead of looking at the keys, we just parse as a date anything that matches a regex. This is still suboptimal, because it's easy to imagine a value happens to look like a date but which should be left as a string. For example, imagine setting a date as a description on a resource. The description is intrinsically a string and should be left as one, but this approach will cause it to be parsed as a date, even though the generated types will call it a string. This could obviously cause problems in an app.
The difficulty here is that we don't have the OpenAPI schema on hand at runtime. #279 attempts to solve this more robustly by generating code to parse as a date any fields that say
format: date-timein the OpenAPI schema. However, #279 feels so complicated that I would prefer to find a compromise solution that looks more like this PR.