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

Post-conditions via annotations #268

Draft
wants to merge 4 commits into
base: v4.02-release-candidate
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions examples/Org.OData.Validation.V1.PostCondition-sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"$Version": "4.0",
"$Reference": {
"https://oasis-tcs.github.io/odata-vocabularies/vocabularies/Org.OData.Validation.V1.json": {
"$Include": [
{
"$Namespace": "Org.OData.Validation.V1",
"$Alias": "Validation"
}
]
}
},
"postcondition.sample": {
"WorkerTimeSheet": {
"$Kind": "EntityType",
"ClockInDateTime": {
"$Type": "Edm.DateTimeOffset",
"$Nullable": true,
"$Precision": 0
},
"ClockOutDateTime": {
"$Type": "Edm.DateTimeOffset",
"$Nullable": true,
"$Precision": 0
}
},
"$Annotations": {
"postcondition.sample.WorkerTimeSheet": {
"@Validation.PostCondition#overtime": {
"$Gt": [
{
"$Sub": [
{
"$Path": "ClockOutDateTime"
},
{
"$Path": "ClockInDateTime"
}
]
},
"PT8H"
]
}
}
}
}
}
25 changes: 25 additions & 0 deletions examples/Org.OData.Validation.V1.PostCondition-sample.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="4.0" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx">
<edmx:Reference Uri="https://oasis-tcs.github.io/odata-vocabularies/vocabularies/Org.OData.Validation.V1.xml">
<edmx:Include Namespace="Org.OData.Validation.V1" Alias="Validation" />
</edmx:Reference>
<edmx:DataServices>
<Schema Namespace="postcondition.sample" xmlns="http://docs.oasis-open.org/odata/ns/edm">
<EntityType Name="WorkerTimeSheet">
<Property Name="ClockInDateTime" Type="Edm.DateTimeOffset" />
<Property Name="ClockOutDateTime" Type="Edm.DateTimeOffset" />
</EntityType>
<Annotations Target="postcondition.sample.WorkerTimeSheet">
<Annotation Term="Validation.PostCondition" Qualifier="overtime">
<Gt>
<Sub>
<Path>ClockOutDateTime</Path>
<Path>ClockInDateTime</Path>
</Sub>
<Duration>PT8H</Duration>
</Gt>
</Annotation>
</Annotations>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
14 changes: 14 additions & 0 deletions vocabularies/Org.OData.Validation.V1.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,20 @@
"@Core.Description": "Value MUST be a dynamic expression that evaluates to true if and only if the constraint is fulfilled"
}
},
"PostCondition": {
"$Kind": "Term",
"$Type": "Edm.PrimitiveType",
"$Nullable": true,
"$AppliesTo": [
"Property",
"NavigationProperty",
"Parameter",
"EntityType",
"ComplexType"
],
"@Core.Description": "Condition that clients can impose on the after-image of a data modification request",
"@Core.LongDescription": "The value is given as a dynamic expression in the service metadata.\nIf the payload of a data modification request provides an instance annotation\nwith this term and the same target and qualifier, the request MUST fail if the provided value\ndoes not match the dynamically expressed value in the modified data.\n\nSee [this example](../examples/Org.OData.Validation.V1.PostCondition-sample.xml).\nTo avoid posting overtime, clients include\n`{\"@Validation.PostCondition#overtime\": false}` in their insert requests."
},
"ItemsOf": {
"$Kind": "Term",
"$Collection": true,
Expand Down
23 changes: 12 additions & 11 deletions vocabularies/Org.OData.Validation.V1.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ Term|Type|Description
[AllowedValues](Org.OData.Validation.V1.xml#L94)|\[[AllowedValue](#AllowedValue)\]|<a name="AllowedValues"></a>A collection of valid values for the annotated property, parameter, or type definition
[MultipleOf](Org.OData.Validation.V1.xml#L108)|Decimal|<a name="MultipleOf"></a>The value of the annotated property, parameter, or term must be an integer multiple of this positive value. For temporal types, the value is measured in seconds.
[Constraint](Org.OData.Validation.V1.xml#L112)|[ConstraintType](#ConstraintType)|<a name="Constraint"></a>Condition that the annotation target has to fulfill
[ItemsOf](Org.OData.Validation.V1.xml#L125)|\[[ItemsOfType](#ItemsOfType)\]|<a name="ItemsOf"></a>A list of constraints describing that entities related via one navigation property MUST also be related via another, collection-valued navigation property. The same `path` value MUST NOT occur more than once.<br>Example: entity type `Customer` has navigation properties `AllOrders`, `OpenOrders`, and `ClosedOrders`. The term allows to express that items of `OpenOrders` and `ClosedOrders` are also items of the `AllOrders` navigation property, even though they are defined in an `Orders` entity set.
[OpenPropertyTypeConstraint](Org.OData.Validation.V1.xml#L143)|\[[SingleOrCollectionType](#SingleOrCollectionType)\]|<a name="OpenPropertyTypeConstraint"></a>Dynamic properties added to the annotated open structured type are restricted to the listed types.
[DerivedTypeConstraint](Org.OData.Validation.V1.xml#L147)|\[[SingleOrCollectionType](#SingleOrCollectionType)\]|<a name="DerivedTypeConstraint"></a>Values are restricted to types that are both identical to or derived from the declared type and a type listed in this collection.<br>This allows restricting values to certain sub-trees of an inheritance hierarchy, including hierarchies starting at the [Built-In Abstract Types](https://docs.oasis-open.org/odata/odata-csdl-json/v4.01/odata-csdl-json-v4.01.html#sec_BuiltInAbstractTypes). Types listed in this collection are ignored if they are not derived from the declared type of the annotated model element or would not be allowed as declared type of the annotated model element.<br/> When applied to a collection-valued element, this annotation specifies the types allowed for members of the collection without mentioning the `Collection()` wrapper. The SingleOrCollectionType may only include the `Collection()` wrapper if the annotation is applied to an element with declared type `Edm.Untyped`.
[AllowedTerms](Org.OData.Validation.V1.xml#L166)|\[[QualifiedTermName](Org.OData.Core.V1.md#QualifiedTermName)\]|<a name="AllowedTerms"></a>Annotate a term of type Edm.AnnotationPath, or a property of type Edm.AnnotationPath that is used within a structured term, to restrict the terms that can be targeted by the path.<br>The annotation path expression is intended to end in a path segment with one of the listed terms. For forward compatibility, clients should be prepared for the annotation to reference terms besides those listed.
[ApplicableTerms](Org.OData.Validation.V1.xml#L172)|\[[QualifiedTermName](Org.OData.Core.V1.md#QualifiedTermName)\]|<a name="ApplicableTerms"></a>Names of specific terms that are applicable and may be applied in the current context. This annotation does not restrict the use of other terms.
[MaxItems](Org.OData.Validation.V1.xml#L176)|Int64|<a name="MaxItems"></a>The annotated collection must have at most the specified number of items.
[MinItems](Org.OData.Validation.V1.xml#L180)|Int64|<a name="MinItems"></a>The annotated collection must have at least the specified number of items.
[PostCondition](Org.OData.Validation.V1.xml#L125)|PrimitiveType?|<a name="PostCondition"></a>Condition that clients can impose on the after-image of a data modification request<br>The value is given as a dynamic expression in the service metadata. If the payload of a data modification request provides an instance annotation with this term and the same target and qualifier, the request MUST fail if the provided value does not match the dynamically expressed value in the modified data.<br/>See [this example](../examples/Org.OData.Validation.V1.PostCondition-sample.xml). To avoid posting overtime, clients include `{"@Validation.PostCondition#overtime": false}` in their insert requests.
[ItemsOf](Org.OData.Validation.V1.xml#L139)|\[[ItemsOfType](#ItemsOfType)\]|<a name="ItemsOf"></a>A list of constraints describing that entities related via one navigation property MUST also be related via another, collection-valued navigation property. The same `path` value MUST NOT occur more than once.<br>Example: entity type `Customer` has navigation properties `AllOrders`, `OpenOrders`, and `ClosedOrders`. The term allows to express that items of `OpenOrders` and `ClosedOrders` are also items of the `AllOrders` navigation property, even though they are defined in an `Orders` entity set.
[OpenPropertyTypeConstraint](Org.OData.Validation.V1.xml#L157)|\[[SingleOrCollectionType](#SingleOrCollectionType)\]|<a name="OpenPropertyTypeConstraint"></a>Dynamic properties added to the annotated open structured type are restricted to the listed types.
[DerivedTypeConstraint](Org.OData.Validation.V1.xml#L161)|\[[SingleOrCollectionType](#SingleOrCollectionType)\]|<a name="DerivedTypeConstraint"></a>Values are restricted to types that are both identical to or derived from the declared type and a type listed in this collection.<br>This allows restricting values to certain sub-trees of an inheritance hierarchy, including hierarchies starting at the [Built-In Abstract Types](https://docs.oasis-open.org/odata/odata-csdl-json/v4.01/odata-csdl-json-v4.01.html#sec_BuiltInAbstractTypes). Types listed in this collection are ignored if they are not derived from the declared type of the annotated model element or would not be allowed as declared type of the annotated model element.<br/> When applied to a collection-valued element, this annotation specifies the types allowed for members of the collection without mentioning the `Collection()` wrapper. The SingleOrCollectionType may only include the `Collection()` wrapper if the annotation is applied to an element with declared type `Edm.Untyped`.
[AllowedTerms](Org.OData.Validation.V1.xml#L180)|\[[QualifiedTermName](Org.OData.Core.V1.md#QualifiedTermName)\]|<a name="AllowedTerms"></a>Annotate a term of type Edm.AnnotationPath, or a property of type Edm.AnnotationPath that is used within a structured term, to restrict the terms that can be targeted by the path.<br>The annotation path expression is intended to end in a path segment with one of the listed terms. For forward compatibility, clients should be prepared for the annotation to reference terms besides those listed.
[ApplicableTerms](Org.OData.Validation.V1.xml#L186)|\[[QualifiedTermName](Org.OData.Core.V1.md#QualifiedTermName)\]|<a name="ApplicableTerms"></a>Names of specific terms that are applicable and may be applied in the current context. This annotation does not restrict the use of other terms.
[MaxItems](Org.OData.Validation.V1.xml#L190)|Int64|<a name="MaxItems"></a>The annotated collection must have at most the specified number of items.
[MinItems](Org.OData.Validation.V1.xml#L194)|Int64|<a name="MinItems"></a>The annotated collection must have at least the specified number of items.

<a name="AllowedValue"></a>
## [AllowedValue](Org.OData.Validation.V1.xml#L97)
Expand All @@ -45,16 +46,16 @@ Property|Type|Description
[Condition](Org.OData.Validation.V1.xml#L120)|Boolean|Value MUST be a dynamic expression that evaluates to true if and only if the constraint is fulfilled

<a name="ItemsOfType"></a>
## [ItemsOfType](Org.OData.Validation.V1.xml#L133)
## [ItemsOfType](Org.OData.Validation.V1.xml#L147)
Entities related via the single- or collection-valued navigation property identified by `path` are also related via the collection-valued navigation property identified by `target`.

Property|Type|Description
:-------|:---|:----------
[path](Org.OData.Validation.V1.xml#L135)|NavigationPropertyPath|A path to a single- or collection-valued navigation property
[target](Org.OData.Validation.V1.xml#L138)|NavigationPropertyPath|A path to a collection-valued navigation property
[path](Org.OData.Validation.V1.xml#L149)|NavigationPropertyPath|A path to a single- or collection-valued navigation property
[target](Org.OData.Validation.V1.xml#L152)|NavigationPropertyPath|A path to a collection-valued navigation property

<a name="SingleOrCollectionType"></a>
## [SingleOrCollectionType](Org.OData.Validation.V1.xml#L162)
## [SingleOrCollectionType](Org.OData.Validation.V1.xml#L176)
**Type:** String

The qualified name of a type in scope, optionally wrapped in `Collection()` to denote a collection of instances of the type
14 changes: 14 additions & 0 deletions vocabularies/Org.OData.Validation.V1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,20 @@
</Property>
</ComplexType>

<Term Name="PostCondition" Type="Edm.PrimitiveType" Nullable="true" AppliesTo="Property NavigationProperty Parameter EntityType ComplexType">
<Annotation Term="Core.Description" String="Condition that clients can impose on the after-image of a data modification request" />
<Annotation Term="Core.LongDescription">
<String>The value is given as a dynamic expression in the service metadata.
If the payload of a data modification request provides an instance annotation
with this term and the same target and qualifier, the request MUST fail if the provided value
does not match the dynamically expressed value in the modified data.

See [this example](../examples/Org.OData.Validation.V1.PostCondition-sample.xml).
To avoid posting overtime, clients include
`{"@Validation.PostCondition#overtime": false}` in their insert requests.</String>
</Annotation>
</Term>

<Term Name="ItemsOf" Type="Collection(Validation.ItemsOfType)" Nullable="false" AppliesTo="EntityType ComplexType">
<Annotation Term="Core.Description" String="A list of constraints describing that entities related via one navigation property MUST also be related via another, collection-valued navigation property. The same `path` value MUST NOT occur more than once." />
<Annotation Term="Core.LongDescription">
Expand Down