Skip to content

Support Omit-values prefer header #672

Open
@xuzhg

Description

@xuzhg

Assemblies affected
Which assemblies and versions are known to be affected e.g. ASP.NET Core OData 8.x

Describe the bug
OData specs has the following at: http://docs.oasis-open.org/odata/odata/v4.01/cs01/part1-protocol/odata-v4.01-cs01-part1-protocol.html#_Toc505771137

 8.2.8.6 [Preference omit-values](http://docs.oasis-open.org/odata/odata/v4.01/cs01/part1-protocol/odata-v4.01-cs01-part1-protocol.html#sec_Preferenceomitvalues)
The omit-values preference specifies values that MAY be omitted from a response payload. Valid values are nulls or defaults.

If nulls is specified, then the service MAY omit properties containing null values from the response, in which case it MUST specify the Preference-Applied response header with omit-values=nulls.

If defaults is specified, then the service MAY omit properties containing default values from the response, including nulls for properties that have no other defined default value. Nulls MUST be included for properties that have a non-null default value defined. If the service omits default values it MUST specify the Preference-Applied response header with omit-values=defaults.

Properties with null or default values MUST be included in delta payloads, if modified.

The response to a POST operation MUST include any properties not set to their default value, and the response to a PUT/PATCH operation MUST include any properties whose values were changed as part of the operation.

The omit-values preference does not affect a request payload. 

To omit null value properties is a common requirement from our customers. We provide the extensions that developers can override to achieve this goal. But, it's the server-side extension. The client can't control it.

Omit-values prefer header is used for client. We should consider to support this header at server side.

Additional context
We should figure out the way that client can distinguish the "omit-values" from "$select".

For example:

~/customers?$select=Name,Age
Prefer: omit-values=nulls

So when the client receives the response payload, it should have the way to understand "the missing properties" is from $select limitation or from omit-values=nulls.

Maybe the context url can help to distinguish.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions