Skip to content

Ensure serialisation correctly respects required and nullable fields #30

@crbunney

Description

@crbunney

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions