Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
27pchrisl committed Apr 8, 2021
1 parent 700ab76 commit 0825210
Show file tree
Hide file tree
Showing 15 changed files with 99 additions and 38 deletions.
44 changes: 27 additions & 17 deletions src/PathSegment/Metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Flat3\Lodata\Operation\EntitySetArgument;
use Flat3\Lodata\Operation\PrimitiveArgument;
use Flat3\Lodata\ReferentialConstraint;
use Flat3\Lodata\Singleton;
use Flat3\Lodata\Type\Boolean;
use Flat3\Lodata\Type\EnumMember;
use Illuminate\Http\Request;
Expand Down Expand Up @@ -167,28 +168,29 @@ public function emitStream(Transaction $transaction): void
}

foreach (Lodata::getResources() as $resource) {
$resourceElement = null;

switch (true) {
case $resource instanceof Singleton:
// https://docs.oasis-open.org/odata/odata-csdl-xml/v4.01/odata-csdl-xml-v4.01.html#_Toc38530395
$resourceElement = $entityContainer->addChild('Singleton');
$resourceElement->addAttribute('Name', $resource->getResolvedName($namespace));
$resourceElement->addAttribute('Type', $resource->getType()->getIdentifier());
break;

case $resource instanceof EntitySet:
// http://docs.oasis-open.org/odata/odata-csdl-xml/v4.01/odata-csdl-xml-v4.01.html#sec_EntitySet
$entitySetElement = $entityContainer->addChild('EntitySet');
$entitySetElement->addAttribute('Name', $resource->getResolvedName($namespace));
$entitySetElement->addAttribute(
$resourceElement = $entityContainer->addChild('EntitySet');
$resourceElement->addAttribute('Name', $resource->getResolvedName($namespace));
$resourceElement->addAttribute(
'EntityType',
$resource->getType()->getIdentifier()
);

// https://docs.oasis-open.org/odata/odata-csdl-xml/v4.01/odata-csdl-xml-v4.01.html#_Toc38530341
if ($resource instanceof AnnotationInterface) {
/** @var Annotation $annotation */
foreach ($resource->getAnnotations() as $annotation) {
$annotation->append($entitySetElement);
}
}

// http://docs.oasis-open.org/odata/odata-csdl-xml/v4.01/odata-csdl-xml-v4.01.html#sec_NavigationPropertyBinding
/** @var NavigationBinding $binding */
foreach ($resource->getNavigationBindings() as $binding) {
$navigationPropertyBindingElement = $entitySetElement->addChild('NavigationPropertyBinding');
$navigationPropertyBindingElement = $resourceElement->addChild('NavigationPropertyBinding');
$navigationPropertyBindingElement->addAttribute(
'Path',
$binding->getPath()->getName()
Expand All @@ -202,10 +204,10 @@ public function emitStream(Transaction $transaction): void

/** @var Operation $resource */
case $resource instanceof Operation:
$operationElement = $schema->addChild($resource->getKind());
$operationElement->addAttribute('Name', $resource->getResolvedName($namespace));
$resourceElement = $schema->addChild($resource->getKind());
$resourceElement->addAttribute('Name', $resource->getResolvedName($namespace));
if ($resource->getBindingParameterName()) {
$operationElement->addAttribute('IsBound', Constants::TRUE);
$resourceElement->addAttribute('IsBound', Constants::TRUE);
}

// Ensure the binding parameter is first, if it exists. Filter out non-odata arguments.
Expand Down Expand Up @@ -233,7 +235,7 @@ public function emitStream(Transaction $transaction): void

/** @var Argument $argument */
foreach ($arguments as $argument) {
$parameterElement = $operationElement->addChild('Parameter');
$parameterElement = $resourceElement->addChild('Parameter');
$parameterElement->addAttribute('Name', $argument->getName());
$parameterElement->addAttribute('Type', $argument->getType()->getIdentifier());
$parameterElement->addAttribute(
Expand All @@ -244,7 +246,7 @@ public function emitStream(Transaction $transaction): void

$returnType = $resource->getReturnType();
if (null !== $returnType) {
$returnTypeElement = $operationElement->addChild('ReturnType');
$returnTypeElement = $resourceElement->addChild('ReturnType');

if ($resource->returnsCollection()) {
$returnTypeElement->addAttribute('Type',
Expand All @@ -267,6 +269,14 @@ public function emitStream(Transaction $transaction): void
);
break;
}

// https://docs.oasis-open.org/odata/odata-csdl-xml/v4.01/odata-csdl-xml-v4.01.html#_Toc38530341
if ($resource instanceof AnnotationInterface) {
/** @var Annotation $annotation */
foreach ($resource->getAnnotations() as $annotation) {
$annotation->append($resourceElement);
}
}
}

$schemaAnnotations = $schema->addChild('Annotations');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@
<Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="com.example.odata">
<EntityContainer Name="DefaultContainer">
<EntitySet Name="passengers" EntityType="com.example.odata.passenger">
<NavigationPropertyBinding Path="pets" Target="pets"/>
<Annotation Term="Org.OData.Capabilities.V1.DeepInsertSupport">
<Record>
<PropertyValue Property="Supported" Bool="true"/>
<PropertyValue Property="ContentIDSupported" Bool="true"/>
</Record>
</Annotation>
<NavigationPropertyBinding Path="pets" Target="pets"/>
</EntitySet>
<EntitySet Name="flights" EntityType="com.example.odata.flight">
<NavigationPropertyBinding Path="airports" Target="airports"/>
<NavigationPropertyBinding Path="passengers" Target="passengers"/>
<Annotation Term="Org.OData.Capabilities.V1.DeepInsertSupport">
<Record>
<PropertyValue Property="Supported" Bool="true"/>
<PropertyValue Property="ContentIDSupported" Bool="true"/>
</Record>
</Annotation>
<NavigationPropertyBinding Path="airports" Target="airports"/>
<NavigationPropertyBinding Path="passengers" Target="passengers"/>
</EntitySet>
<EntitySet Name="airports" EntityType="com.example.odata.airport">
<Annotation Term="Org.OData.Capabilities.V1.DeepInsertSupport">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@
<Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="com.example.odata">
<EntityContainer Name="DefaultContainer">
<EntitySet Name="passengers" EntityType="com.example.odata.passenger">
<NavigationPropertyBinding Path="pets" Target="pets"/>
<Annotation Term="Org.OData.Capabilities.V1.DeepInsertSupport">
<Record>
<PropertyValue Property="Supported" Bool="true"/>
<PropertyValue Property="ContentIDSupported" Bool="true"/>
</Record>
</Annotation>
<NavigationPropertyBinding Path="pets" Target="pets"/>
</EntitySet>
<EntitySet Name="flights" EntityType="com.example.odata.flight">
<NavigationPropertyBinding Path="airports" Target="airports"/>
<NavigationPropertyBinding Path="passengers" Target="passengers"/>
<Annotation Term="Org.OData.Capabilities.V1.DeepInsertSupport">
<Record>
<PropertyValue Property="Supported" Bool="true"/>
<PropertyValue Property="ContentIDSupported" Bool="true"/>
</Record>
</Annotation>
<NavigationPropertyBinding Path="airports" Target="airports"/>
<NavigationPropertyBinding Path="passengers" Target="passengers"/>
</EntitySet>
<EntitySet Name="airports" EntityType="com.example.odata.airport">
<Annotation Term="Org.OData.Capabilities.V1.DeepInsertSupport">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ HTTP/1.0 200 OK
content-type: application/xml

<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx" Version="4.01"><edmx:Reference Uri="https://oasis-tcs.github.io/odata-vocabularies/vocabularies/Org.OData.Core.V1.xml"><edmx:Include Namespace="Org.OData.Core.V1"/></edmx:Reference><edmx:Reference Uri="https://oasis-tcs.github.io/odata-vocabularies/vocabularies/Org.OData.Capabilities.V1.xml"><edmx:Include Namespace="Org.OData.Capabilities.V1"/></edmx:Reference><edmx:DataServices><Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="com.example.odata"><EntityContainer Name="DefaultContainer"><EntitySet Name="passengers" EntityType="com.example.odata.passenger"><Annotation Term="Org.OData.Capabilities.V1.DeepInsertSupport"><Record><PropertyValue Property="Supported" Bool="true"/><PropertyValue Property="ContentIDSupported" Bool="true"/></Record></Annotation><NavigationPropertyBinding Path="pets" Target="pets"/></EntitySet><EntitySet Name="flights" EntityType="com.example.odata.flight"><Annotation Term="Org.OData.Capabilities.V1.DeepInsertSupport"><Record><PropertyValue Property="Supported" Bool="true"/><PropertyValue Property="ContentIDSupported" Bool="true"/></Record></Annotation><NavigationPropertyBinding Path="airports" Target="airports"/><NavigationPropertyBinding Path="passengers" Target="passengers"/></EntitySet><EntitySet Name="airports" EntityType="com.example.odata.airport"><Annotation Term="Org.OData.Capabilities.V1.DeepInsertSupport"><Record><PropertyValue Property="Supported" Bool="true"/><PropertyValue Property="ContentIDSupported" Bool="true"/></Record></Annotation></EntitySet><EntitySet Name="pets" EntityType="com.example.odata.pet"><Annotation Term="Org.OData.Capabilities.V1.DeepInsertSupport"><Record><PropertyValue Property="Supported" Bool="true"/><PropertyValue Property="ContentIDSupported" Bool="true"/></Record></Annotation></EntitySet></EntityContainer><EntityType Name="passenger"><Key><PropertyRef Name="id"/></Key><Property Name="id" Type="Edm.Int32" Nullable="false"/><Property Name="name" Type="Edm.String" Nullable="true"/><Property Name="flight_id" Type="Edm.Int32" Nullable="true"/><NavigationProperty Name="pets" Type="Collection(com.example.odata.pet)" Nullable="true"><ReferentialConstraint Property="id" ReferencedProperty="passenger_id"/></NavigationProperty></EntityType><EntityType Name="flight"><Key><PropertyRef Name="id"/></Key><Property Name="id" Type="Edm.Int32" Nullable="false"/><Property Name="origin" Type="Edm.String" Nullable="true"/><Property Name="destination" Type="Edm.String" Nullable="true"/><Property Name="gate" Type="Edm.Int32" Nullable="true"/><Property Name="duration" Type="Edm.Duration" Nullable="true"/><NavigationProperty Name="airports" Type="Collection(com.example.odata.airport)" Nullable="true"><ReferentialConstraint Property="origin" ReferencedProperty="code"/><ReferentialConstraint Property="destination" ReferencedProperty="code"/></NavigationProperty><NavigationProperty Name="passengers" Type="Collection(com.example.odata.passenger)" Nullable="true"><ReferentialConstraint Property="id" ReferencedProperty="flight_id"/></NavigationProperty></EntityType><EntityType Name="airport"><Key><PropertyRef Name="id"/></Key><Property Name="id" Type="Edm.Int32" Nullable="false"/><Property Name="name" Type="Edm.String" Nullable="true"/><Property Name="code" Type="Edm.String" Nullable="true"/><Property Name="construction_date" Type="Edm.Date" Nullable="true"/><Property Name="open_time" Type="Edm.TimeOfDay" Nullable="true"/><Property Name="sam_datetime" Type="Edm.DateTimeOffset" Nullable="true"/><Property Name="review_score" Type="Edm.Decimal" Nullable="true"/><Property Name="is_big" Type="Edm.Boolean" Nullable="true"/></EntityType><EntityType Name="pet"><Key><PropertyRef Name="id"/></Key><Property Name="id" Type="Edm.Int32" Nullable="false"/><Property Name="name" Type="Edm.String" Nullable="true"/><Property Name="type" Type="Edm.String" Nullable="true"/><Property Name="passenger_id" Type="Edm.Int32" Nullable="true"/></EntityType><Annotations Target="com.example.odata.DefaultContainer"><Annotation Term="Org.OData.Core.V1.ConventionalIDs" Bool="true"/><Annotation Term="Org.OData.Core.V1.DefaultNamespace" Bool="true"/><Annotation Term="Org.OData.Core.V1.DereferencableIDs" Bool="true"/><Annotation Term="Org.OData.Core.V1.ODataVersions" String="4.01"/><Annotation Term="Org.OData.Capabilities.V1.AsynchronousRequestsSupported" Bool="true"/><Annotation Term="Org.OData.Capabilities.V1.CallbackSupported"><Collection/></Annotation><Annotation Term="Org.OData.Capabilities.V1.ConformanceLevel" EnumMember="Org.OData.Capabilities.V1.ConformanceLevelType/Advanced"/><Annotation Term="Org.OData.Capabilities.V1.SupportedFormats"><Collection><String>application/json;odata.metadata=full;IEEE754Compatible=true;odata.streaming=true</String><String>application/json;odata.metadata=minimal;IEEE754Compatible=true;odata.streaming=true</String><String>application/json;odata.metadata=none;IEEE754Compatible=true;odata.streaming=true</String></Collection></Annotation></Annotations></Schema></edmx:DataServices></edmx:Edmx>
<edmx:Edmx xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx" Version="4.01"><edmx:Reference Uri="https://oasis-tcs.github.io/odata-vocabularies/vocabularies/Org.OData.Core.V1.xml"><edmx:Include Namespace="Org.OData.Core.V1"/></edmx:Reference><edmx:Reference Uri="https://oasis-tcs.github.io/odata-vocabularies/vocabularies/Org.OData.Capabilities.V1.xml"><edmx:Include Namespace="Org.OData.Capabilities.V1"/></edmx:Reference><edmx:DataServices><Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="com.example.odata"><EntityContainer Name="DefaultContainer"><EntitySet Name="passengers" EntityType="com.example.odata.passenger"><NavigationPropertyBinding Path="pets" Target="pets"/><Annotation Term="Org.OData.Capabilities.V1.DeepInsertSupport"><Record><PropertyValue Property="Supported" Bool="true"/><PropertyValue Property="ContentIDSupported" Bool="true"/></Record></Annotation></EntitySet><EntitySet Name="flights" EntityType="com.example.odata.flight"><NavigationPropertyBinding Path="airports" Target="airports"/><NavigationPropertyBinding Path="passengers" Target="passengers"/><Annotation Term="Org.OData.Capabilities.V1.DeepInsertSupport"><Record><PropertyValue Property="Supported" Bool="true"/><PropertyValue Property="ContentIDSupported" Bool="true"/></Record></Annotation></EntitySet><EntitySet Name="airports" EntityType="com.example.odata.airport"><Annotation Term="Org.OData.Capabilities.V1.DeepInsertSupport"><Record><PropertyValue Property="Supported" Bool="true"/><PropertyValue Property="ContentIDSupported" Bool="true"/></Record></Annotation></EntitySet><EntitySet Name="pets" EntityType="com.example.odata.pet"><Annotation Term="Org.OData.Capabilities.V1.DeepInsertSupport"><Record><PropertyValue Property="Supported" Bool="true"/><PropertyValue Property="ContentIDSupported" Bool="true"/></Record></Annotation></EntitySet></EntityContainer><EntityType Name="passenger"><Key><PropertyRef Name="id"/></Key><Property Name="id" Type="Edm.Int32" Nullable="false"/><Property Name="name" Type="Edm.String" Nullable="true"/><Property Name="flight_id" Type="Edm.Int32" Nullable="true"/><NavigationProperty Name="pets" Type="Collection(com.example.odata.pet)" Nullable="true"><ReferentialConstraint Property="id" ReferencedProperty="passenger_id"/></NavigationProperty></EntityType><EntityType Name="flight"><Key><PropertyRef Name="id"/></Key><Property Name="id" Type="Edm.Int32" Nullable="false"/><Property Name="origin" Type="Edm.String" Nullable="true"/><Property Name="destination" Type="Edm.String" Nullable="true"/><Property Name="gate" Type="Edm.Int32" Nullable="true"/><Property Name="duration" Type="Edm.Duration" Nullable="true"/><NavigationProperty Name="airports" Type="Collection(com.example.odata.airport)" Nullable="true"><ReferentialConstraint Property="origin" ReferencedProperty="code"/><ReferentialConstraint Property="destination" ReferencedProperty="code"/></NavigationProperty><NavigationProperty Name="passengers" Type="Collection(com.example.odata.passenger)" Nullable="true"><ReferentialConstraint Property="id" ReferencedProperty="flight_id"/></NavigationProperty></EntityType><EntityType Name="airport"><Key><PropertyRef Name="id"/></Key><Property Name="id" Type="Edm.Int32" Nullable="false"/><Property Name="name" Type="Edm.String" Nullable="true"/><Property Name="code" Type="Edm.String" Nullable="true"/><Property Name="construction_date" Type="Edm.Date" Nullable="true"/><Property Name="open_time" Type="Edm.TimeOfDay" Nullable="true"/><Property Name="sam_datetime" Type="Edm.DateTimeOffset" Nullable="true"/><Property Name="review_score" Type="Edm.Decimal" Nullable="true"/><Property Name="is_big" Type="Edm.Boolean" Nullable="true"/></EntityType><EntityType Name="pet"><Key><PropertyRef Name="id"/></Key><Property Name="id" Type="Edm.Int32" Nullable="false"/><Property Name="name" Type="Edm.String" Nullable="true"/><Property Name="type" Type="Edm.String" Nullable="true"/><Property Name="passenger_id" Type="Edm.Int32" Nullable="true"/></EntityType><Annotations Target="com.example.odata.DefaultContainer"><Annotation Term="Org.OData.Core.V1.ConventionalIDs" Bool="true"/><Annotation Term="Org.OData.Core.V1.DefaultNamespace" Bool="true"/><Annotation Term="Org.OData.Core.V1.DereferencableIDs" Bool="true"/><Annotation Term="Org.OData.Core.V1.ODataVersions" String="4.01"/><Annotation Term="Org.OData.Capabilities.V1.AsynchronousRequestsSupported" Bool="true"/><Annotation Term="Org.OData.Capabilities.V1.CallbackSupported"><Collection/></Annotation><Annotation Term="Org.OData.Capabilities.V1.ConformanceLevel" EnumMember="Org.OData.Capabilities.V1.ConformanceLevelType/Advanced"/><Annotation Term="Org.OData.Capabilities.V1.SupportedFormats"><Collection><String>application/json;odata.metadata=full;IEEE754Compatible=true;odata.streaming=true</String><String>application/json;odata.metadata=minimal;IEEE754Compatible=true;odata.streaming=true</String><String>application/json;odata.metadata=none;IEEE754Compatible=true;odata.streaming=true</String></Collection></Annotation></Annotations></Schema></edmx:DataServices></edmx:Edmx>

--00000000-0000-0000-0000-000000000001
content-type: application/http
Expand Down
Loading

0 comments on commit 0825210

Please sign in to comment.