OData / OData/AspNetCoreOData

Support Omit-values prefer header

Open
#672 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature
Dominant language
C#
Stars
505
Forks
186
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source file, test, or entry point is named. Start by reviewing the OData 4.01 omit-values preference and the existing server-side extension behavior, then resolve how responses distinguish omit-values from $select, potentially using the context URL. Done means the server supports the client preference while preserving the required response semantics.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api, backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.