ahrefs / atd

Static types for JSON APIs
Other
309 stars 52 forks source link

atdpy: fix JSON representation of the option type #333

Closed mjambon closed 1 year ago

mjambon commented 1 year ago

Fixes #332

Previously, I added Python "support" for the option type by making it behave like nullable. While this is convenient on the Python programmer's side, it's incompatible with the ATD convention for representing the option type in JSON.

The solution I'm adopting here is:

Note that ATD's nullable type is still recommended to make JSON code more idiomatic and more readable when it's possible. The only problematic case is with nested nullables since Python null ambiguously represents JSON "None" and JSON ["Some", "None"]. Because of these issues, authors of APIs are advised to not use nested nullables or nested options.

PR checklist