Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure serialisation correctly respects required and nullable fields #30

Open
crbunney opened this issue May 6, 2022 · 0 comments
Open

Comments

@crbunney
Copy link
Contributor

crbunney commented May 6, 2022

The EDR OpenAPI schema identifies some elements as required and/or nullable

We haven't been particularly rigorous in adhering to these restrictions in our initial implementation.

The implications for the core.models data models:

  • it should be possible to set nullable values to None
  • values for optional fields should default to None if not explicitly set
  • values that are not allowed to be nullable should be always set, either by an explicit argument or sensible default

The implications for serialisation are:

  • when encoding nullable fields (both optional and required), None values are serialised as JSON null values
  • when encoding non-nullable, optional fields, the field is omitted from the output if the value is None
  • non-nullable, required fields set to None would be an error, and ought not to be possible if our core.models are correctly implemented

I believe the possible options are something like

nullable=False nullable=True
required=True None not allowed in data models; always included in serialisation None allowed in data models; always included in serialisation
required=False None allowed in data models; not included in serialisation if set to None None allowed in data models; Element omitted from serialisation if set to None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant