oasis-tcs / odata-specs

OASIS OData TC: Markdown sources for OData specification drafts. https://github.com/oasis-tcs/odata-specs
https://oasis-tcs.github.io/odata-specs/
Other
6 stars 2 forks source link

Formally define OData Metamodel #288

Open ralfhandl opened 3 months ago

ralfhandl commented 3 months ago

Various aspects of OData seem unclear or redundant. A formal UML model for the OData metamodel can be used to clarify and simplify OData.

The existing metamodel defined by 'MetadataService.xml' contains much of what is needed, but has some issues, such as:

The included proposal started from scratch out of a need to understand several concepts, including the semantics of Singletons and EntitySets. It needs to be rationalized with the existing 'MetadataService.xml' . It is preliminary and needs review and refinement. It is expressed in CSDL XML. (See https://www.oasis-open.org/apps/org/workgroup/odata/download.php/60420/OdataMetamodel.xml.) UML diagrams are provided that illustrate this proposal. (See: https://www.oasis-open.org/apps/org/workgroup/odata/download.php/60421/OdataMetamodel.pdf)

An advantage of the UML model is that it expresses the Odata metamodel in precise terms. Constraints and requirements on the various elements of the model are expressed normatively using the UML model together with UML Object Constraing Language (OCL) statements. An added Term supports this.

The various schema definition languages CSDL XML, CSDL JSON, and others should conform to the OData metamodel.

Imported from ODATA-1062

HeikoTheissen commented 3 months ago

A PropertyRef does not simply refer to a structural property, because the same structural property (Name in the example) can be reached via different paths by different PropertyRefs.

<EntityType Name="Employee">
  <Key>
    <PropertyRef Name="Name"/>
  </Key>
  <Property Name="Name" Type="Edm.String" Nullable="false"/>
</EntityType>
<EntityType Name="ReportingLine">
  <Key>
    <PropertyRef Name="ReportsTo/Name" Alias="Manager"/>
    <PropertyRef Name="DirectReport/Name" Alias="Subordinate"/>
  </Key>
  <NavigationProperty Name="ReportsTo" Type="self.Employee"/>
  <NavigationProperty Name="DirectReport" Type="self.Employee"/>
</EntityType>

A PropertyRef is expressed as a sequences of references to model elements, that last of which is a structural property. Similarly, the final segment of a NavigationPropertyBinding is a navigation property, and the final segment of an external annotation target is any model element. Such references can be expressed in YAML:

$Version: '4.0'
Org.OData.Core.V1:
  Description: &Core.Description
    $Kind: Term
    $Annotations:
      - term: *Core.Description
        value: A brief description of a model element
example.StructuralProperty:
  Employee: &Employee
    $Kind: EntityType
    Name: &Name
    $Key:
      - finalSegmentStructuralProperty: *Name
  ReportingLine: &ReportingLine
    $Kind: EntityType
    ReportsTo: &ReportsTo
      $Kind: NavigationProperty
      $Type: *Employee
    DirectReport: &DirectReport
      $Kind: NavigationProperty
      $Type: *Employee
    $Key:
      - nonFinalSegments: [*ReportsTo]
        finalSegmentStructuralProperty: *Name
        alias: Manager
      - nonFinalSegments: [*DirectReport]
        finalSegmentStructuralProperty: *Name
        alias: Subordinate
  container: &container
    $Kind: EntityContainer
    Employees: &Employees
      $Collection: true
      $Type: *Employee
      $NavigationPropertyBinding:
        - finalSegmentNavigationProperty: *ReportsTo
          target: *Employees
        - finalSegmentNavigationProperty: *DirectReport
          target: *Employees
  $Annotations:
    - target: [*Employee]
      term: *Core.Description
      value: Party to a contractual agreement regarding employment
$EntityContainer: *container

Or they can be expressed in CSDL XML through additional ID attributes, see oasis-tcs/odata-openapi#291.

chrisspre commented 2 months ago

About the comment from March 22.

the standard says : "The value of Name is a path expression leading to a primitive property. The names of the properties in the path are joined together by forward slashes."

the meta model would specify that it is a path starting with the containing EntityType followed by a sequence of Properties or NavigationProperties (connected via their referenced types) and ending in a PrimitiveType.

In pseudo PGQL: (EntityType) --> (Property) [ – /Type/ -> (:EntityType|ComplexType) --> (Property) ]* – /Type/ -> (PrimititveType)

the paths are visualized in the graph visualization through colored graph-paths

image

chrisspre commented 2 months ago

About the comment from March 22.

the standard says : "The value of Name is a path expression leading to a primitive property. The names of the properties in the path are joined together by forward slashes."

the meta model would specify that it is a path starting with the containing EntityType followed by a sequence of Properties or NavigationProperties (via their types) and ending in a PrimitiveType.

In pseudo PGQL: (EntityType) --> (Property) [ – /Type/ -> (:EntityType|ComplexType) --> (Property) ]* – /Type/ -> (PrimititveType)

the paths are visualized in the graph visualization through colored graph-paths

image