Compare commits

...

7 commits

Author SHA1 Message Date
Sam Xu bc405aa8ac Make all test passed 2019-06-27 17:06:02 -07:00
Sam Xu 4d8264dfb1 ok 2019-06-26 17:35:48 -07:00
Sam Xu f6470b0df7 ok 2019-06-25 13:04:59 -07:00
Sam Xu 08ded1e66d Modify at home 2019-06-25 00:10:05 -07:00
Sam Xu 0abc9e5db5 ok 2019-06-24 17:32:52 -07:00
Sam Xu 00c2262da4 Ok2 2019-06-21 16:57:43 -07:00
Sam Xu 2ea2d243cd Ok 2019-06-20 17:32:30 -07:00
158 changed files with 23442 additions and 4291 deletions

454
docs/csdl/capabilities.xml Normal file
View file

@ -0,0 +1,454 @@
<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="4.0"
xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx">
<edmx:DataServices>
<Schema Namespace="microsoft.graph"
xmlns="http://docs.oasis-open.org/odata/ns/edm">
<Annotations Target="microsoft.graph.GraphService/users">
<Annotation Term="Org.Graph.Vocabulary.InsertRestrictions">
<Record>
<PropertyValue Property="CustomHeaders">
<Collection>
<Record>
<PropertyValue Property="Name" String="Authorization" />
<PropertyValue Property="Description" />
<PropertyValue Property="Required" Bool="false" />
</Record>
<Record>
<PropertyValue Property="Name" String="Content-Type" />
<PropertyValue Property="Description" />
<PropertyValue Property="Required" Bool="false" />
</Record>
</Collection>
</PropertyValue>
<PropertyValue Property="CustomQueryOptions"/>
<PropertyValue Property="Permission">
<Record>
<PropertyValue Property="Scheme" String="DelegatedWork" />
<PropertyValue Property="Scopes">
<Collection>
<Record>
<PropertyValue Property="Scope" String="User.ReadWrite.All"/>
<!--
* , [PROPERTY NAME], - list
"*" denotes all properties are accessible
"Property name" used to provide access to specific properties
"-" sign prepended to property name used to exclude specific properties
Absense of the PropertyValue denotes all properties are accessible using that scope.
-->
<PropertyValue Property="RestrictedProperties">
<string>-mailboxSettings</string>
</PropertyValue>
</Record>
<Record>
<PropertyValue Property="Scope" String="MailboxSettings.ReadWrite"/>
<PropertyValue Property="RestrictedProperties">
<string>mailboxSettings</string>
</PropertyValue>
</Record>
<Record>
<PropertyValue Property="Scope" String="Directory.ReadWrite.All"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="Directory.AccessAsUser.All"/>
</Record>
</Collection>
</PropertyValue>
</Record>
<Record>
<PropertyValue Property="Scheme" String="Application" />
<PropertyValue Property="Scopes">
<Collection>
<Record>
<PropertyValue Property="Scope" String="Directory.ReadWrite.All"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="MailboxSettings.ReadWrite"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="Directory.AccessAsUser.All"/>
</Record>
</Collection>
</PropertyValue>
</Record>
</PropertyValue>
</Record>
</Annotation>
<Annotation Term="Org.Graph.Vocabulary.UpdateRestrictions">
<Record>
<PropertyValue Property="CustomHeaders">
<Collection>
<Record>
<PropertyValue Property="Name" String="Authorization" />
<PropertyValue Property="Description" />
<PropertyValue Property="Required" Bool="false" />
</Record>
<Record>
<PropertyValue Property="Name" String="Content-Type" />
<PropertyValue Property="Description" />
<PropertyValue Property="Required" Bool="false" />
</Record>
</Collection>
</PropertyValue>
<PropertyValue Property="Permission">
<Record>
<PropertyValue Property="Scheme" String="DelegatedWork" />
<PropertyValue Property="Scopes">
<Collection>
<Record>
<PropertyValue Property="Scope" String="User.ReadWrite"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="User.ReadWrite.All"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="Directory.ReadWrite.All"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="Directory.AccessAsUser.All"/>
</Record>
</Collection>
</PropertyValue>
</Record>
<Record>
<PropertyValue Property="Scheme" String="DelegatedPersonal" />
<PropertyValue Property="Scopes">
<Collection>
<Record>
<PropertyValue Property="Scope" String="User.ReadWrite"/>
</Record>
</Collection>
</PropertyValue>
</Record>
<Record>
<PropertyValue Property="Scheme" String="Application" />
<PropertyValue Property="Scopes">
<Collection>
<Record>
<PropertyValue Property="Scope" String="User.ReadWrite.All"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="Directory.ReadWrite.All"/>
</Record>
</Collection>
</PropertyValue>
</Record>
</PropertyValue>
</Record>
</Annotation>
<!-- Read restrictions :select restrictions and then props to filter, expand, etc. -->
<Annotation Term="Org.Graph.Vocabulary.ReadRestrictions">
<Record>
<PropertyValue Property="CustomHeaders">
<Collection>
<Record>
<PropertyValue Property="Name" String="Authorization" />
<PropertyValue Property="Description" />
<PropertyValue Property="Required" Bool="false" />
</Record>
<Record>
<PropertyValue Property="Name" String="Content-Type" />
<PropertyValue Property="Description" />
<PropertyValue Property="Required" Bool="false" />
</Record>
</Collection>
</PropertyValue>
<PropertyValue Property="Permission">
<Collection>
<Record>
<PropertyValue Property="Scheme" String="DelegatedWork" />
<PropertyValue Property="Scopes">
<Collection>
<Record>
<PropertyValue Property="Scope" String="User.Read"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="User.ReadWrite"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="User.ReadBasic.All"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="User.Read.All"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="User.ReadWrite.All"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="Directory.Read.All"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="Directory.ReadWrite.All"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="Directory.AccessAsUser.All"/>
</Record>
</Collection>
</PropertyValue>
</Record>
<Record>
<PropertyValue Property="Scheme" String="Application" />
<PropertyValue Property="Scopes">
<Collection>
<Record>
<PropertyValue Property="Scope" String="User.Read"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="User.ReadWrite"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="User.ReadWrite.All"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="Directory.Read.All"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="Directory.ReadWrite.All"/>
</Record>
</Collection>
</PropertyValue>
</Record>
</Collection>
</PropertyValue>
<PropertValue Property="ReadByKeyRestrictions">
<Record>
<PropertyValue Property="Permission">
<Collection>
<Record>
<PropertyValue Property="Scheme" String="DelegatedWork" />
<PropertyValue Property="Scopes">
<Collection>
<Record>
<PropertyValue Property="Scope" String="User.Read"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="User.ReadWrite"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="User.ReadBasic.All"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="User.Read.All"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="User.ReadWrite.All"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="Directory.Read.All"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="Directory.ReadWrite.All"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="Directory.AccessAsUser.All"/>
</Record>
</Collection>
</PropertyValue>
</Record>
<Record>
<PropertyValue Property="Scheme" String="DelegatedPersonal" />
<PropertyValue Property="Scopes">
<Collection>
<Record>
<PropertyValue Property="Scope" String="User.Read"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="User.ReadWrite"/>
</Record>
</Collection>
</PropertyValue>
</Record>
<Record>
<PropertyValue Property="Scheme" String="Application" />
<PropertyValue Property="Scopes">
<Collection>
<Record>
<PropertyValue Property="Scope" String="User.Read.All"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="User.ReadWrite.All"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="Directory.Read.All"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="Directory.ReadWrite.All"/>
</Record>
</Collection>
</PropertyValue>
</Record>
</Collection>
</PropertyValue>
</Record>
</PropertValue>
</Record>
</Annotation>
<Annotation Term="Org.Graph.Vocabulary.DeleteRestrictions">
<Record>
<PropertyValue Property="CustomHeaders">
<Collection>
<Record>
<PropertyValue Property="Name" String="Authorization" />
<PropertyValue Property="Description" />
<PropertyValue Property="Required" Bool="false" />
</Record>
</Collection>
</PropertyValue>
<PropertyValue Property="Permission">
<Record>
<PropertyValue Property="Scheme" String="DelegatedWork" />
<PropertyValue Property="Scopes">
<Collection>
<Record>
<PropertyValue Property="Scope" String="Directory.AccessAsUser.All"/>
</Record>
</Collection>
</PropertyValue>
</Record>
<Record>
<PropertyValue Property="Scheme" String="Application" />
<PropertyValue Property="Scopes">
<Collection>
<Record>
<PropertyValue Property="Scope" String="User.ReadWrite.All"/>
</Record>
</Collection>
</PropertyValue>
</Record>
</PropertyValue>
</Record>
</Annotation>
</Annotations>
<!-- annoations on actions/functions -->
<Annotations Target="microsoft.graph.reminderView(microsoft.graph.user, Edm.String, Edm.String)">
<!-- for a path that looks like "GET /users/{id | userPrincipalName}/reminderView(startDateTime=startDateTime-value,endDateTime=endDateTime-value)" -->
<Annotation Term="Org.Graph.Vocabulary.OperationRestrictions">
<Collection>
<Record>
<PropertyValue Property="QualifiedOperationName" String="reminderView" />
<PropertyValue Property="Permission">
<Record>
<PropertyValue Property="Scheme" String="DelegatedWork" />
<PropertyValue Property="Scopes">
<Collection>
<Record>
<PropertyValue Property="Scope" String="Calendars.Read" />
</Record>
<Record>
<PropertyValue Property="Scope" String="Calendars.ReadWrite" />
</Record>
</Collection>
</PropertyValue>
</Record>
<Record>
<PropertyValue Property="Scheme" String="DelegatedPersonal" />
<PropertyValue Property="Scopes">
<Collection>
<Record>
<PropertyValue Property="Scope" String="Calendars.Read" />
</Record>
<Record>
<PropertyValue Property="Scope" String="Calendars.ReadWrite" />
</Record>
</Collection>
</PropertyValue>
</Record>
<Record>
<PropertyValue Property="Scheme" String="Application" />
<PropertyValue Property="Scopes">
<Collection>
<Record>
<PropertyValue Property="Scope" String="Calendars.Read" />
</Record>
<Record>
<PropertyValue Property="Scope" String="Calendars.ReadWrite" />
</Record>
</Collection>
</PropertyValue>
</Record>
</PropertyValue>
</Record>
</Collection>
</Annotation>
</Annotations>
<!-- Annotating container with Auth Schemes that contain all the scopes applicable per that security scheme. Graph has 3 security schemes, DelegatedWork, DelegatedPersonal, Application -->
<Annotations Target="microsoft.graph.GraphService">
<Annotation Term="Auth.Authorizations">
<Collection>
<Record Type="Org.OData.Authorization.V1.OAuth2Implicit">
<PropertyValue Property="Name" String="DelegatedWork"/>
<PropertyValue Property="AuthorizationUrl" String="https://graph.microsoft.com" />
<PropertyValue Property="RefreshUrl" String="https://refreshUrl" />
<PropertyValue Property="Scopes">
<Collection>
<Record>
<PropertyValue Property="Scope" String="User.ReadAll"/>
<PropertyValue Property="Description" String="Read all user data"/>
<PropertyValue Property="Grant" String="User"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="User.WriteAll"/>
<PropertyValue Property="Description" String="Write all user data"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="Directory.ReadAll"/>
<PropertyValue Property="Description" String="Write to directory"/>
<PropertyValue Property="Grant" String="Admin"/>
</Record>
</Collection>
</PropertyValue>
</Record>
<Record Type="Org.OData.Authorization.V1.OAuth2Implicit">
<PropertyValue Property="Name" String="DelegatedPersonal"/>
<PropertyValue Property="AuthorizationUrl" String="https://graph.microsoft.com" />
<PropertyValue Property="RefreshUrl" String="https://refreshUrl" />
<PropertyValue Property="Scopes">
<Collection>
<Record>
<PropertyValue Property="Scope" String="User.ReadAll"/>
<PropertyValue Property="Description" String="Read all user data"/>
<PropertyValue Property="Grant" String="User"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="User.WriteAll"/>
<PropertyValue Property="Description" String="Write all user data"/>
<PropertyValue Property="Grant" String="User"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="Directory.ReadAll"/>
<PropertyValue Property="Description" String="Write to directory"/>
<PropertyValue Property="Grant" String="User"/>
</Record>
</Collection>
</PropertyValue>
</Record>
<Record Type="Org.OData.Authorization.V1.OAuth2Implicit">
<PropertyValue Property="Name" String="Application"/>
<PropertyValue Property="AuthorizationUrl" String="https://graph.microsoft.com" />
<PropertyValue Property="RefreshUrl" String="https://refreshUrl" />
<PropertyValue Property="Scopes">
<Collection>
<Record>
<PropertyValue Property="Scope" String="User.ReadAll"/>
<PropertyValue Property="Description" String="Read all user data"/>
<PropertyValue Property="Grant" String="Admin"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="User.WriteAll"/>
<PropertyValue Property="Description" String="Write all user data"/>
<PropertyValue Property="Grant" String="Admin"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="Directory.ReadAll"/>
<PropertyValue Property="Description" String="Write to directory"/>
<PropertyValue Property="Grant" String="Admin"/>
</Record>
</Collection>
</PropertyValue>
</Record>
</Collection>
</Annotation>
</Annotations>
</Schema>
</edmx:DataServices>
</edmx:Edmx>

16267
docs/csdl/graph1.0_updated.xml Normal file

File diff suppressed because it is too large Load diff

View file

@ -2,6 +2,451 @@
<edmx:Edmx xmlns:ags="http://aggregator.microsoft.com/internal" Version="4.0" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx">
<edmx:DataServices>
<Schema Namespace="microsoft.graph" xmlns="http://docs.oasis-open.org/odata/ns/edm">
<Annotations Target="microsoft.graph.GraphService/users">
<Annotation Term="Org.Graph.Vocabulary.InsertRestrictions">
<Record>
<PropertyValue Property="CustomHeaders">
<Collection>
<Record>
<PropertyValue Property="Name" String="Authorization" />
<PropertyValue Property="Description" />
<PropertyValue Property="Required" Bool="false" />
</Record>
<Record>
<PropertyValue Property="Name" String="Content-Type" />
<PropertyValue Property="Description" />
<PropertyValue Property="Required" Bool="false" />
</Record>
</Collection>
</PropertyValue>
<PropertyValue Property="CustomQueryOptions"/>
<PropertyValue Property="Permission">
<Record>
<PropertyValue Property="Scheme" String="DelegatedWork" />
<PropertyValue Property="Scopes">
<Collection>
<Record>
<PropertyValue Property="Scope" String="User.ReadWrite.All"/>
<!--
* , [PROPERTY NAME], - list
"*" denotes all properties are accessible
"Property name" used to provide access to specific properties
"-" sign prepended to property name used to exclude specific properties
Absense of the PropertyValue denotes all properties are accessible using that scope.
-->
<PropertyValue Property="RestrictedProperties">
<string>-mailboxSettings</string>
</PropertyValue>
</Record>
<Record>
<PropertyValue Property="Scope" String="MailboxSettings.ReadWrite"/>
<PropertyValue Property="RestrictedProperties">
<string>mailboxSettings</string>
</PropertyValue>
</Record>
<Record>
<PropertyValue Property="Scope" String="Directory.ReadWrite.All"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="Directory.AccessAsUser.All"/>
</Record>
</Collection>
</PropertyValue>
</Record>
<Record>
<PropertyValue Property="Scheme" String="Application" />
<PropertyValue Property="Scopes">
<Collection>
<Record>
<PropertyValue Property="Scope" String="Directory.ReadWrite.All"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="MailboxSettings.ReadWrite"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="Directory.AccessAsUser.All"/>
</Record>
</Collection>
</PropertyValue>
</Record>
</PropertyValue>
</Record>
</Annotation>
<Annotation Term="Org.Graph.Vocabulary.UpdateRestrictions">
<Record>
<PropertyValue Property="CustomHeaders">
<Collection>
<Record>
<PropertyValue Property="Name" String="Authorization" />
<PropertyValue Property="Description" />
<PropertyValue Property="Required" Bool="false" />
</Record>
<Record>
<PropertyValue Property="Name" String="Content-Type" />
<PropertyValue Property="Description" />
<PropertyValue Property="Required" Bool="false" />
</Record>
</Collection>
</PropertyValue>
<PropertyValue Property="Permission">
<Record>
<PropertyValue Property="Scheme" String="DelegatedWork" />
<PropertyValue Property="Scopes">
<Collection>
<Record>
<PropertyValue Property="Scope" String="User.ReadWrite"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="User.ReadWrite.All"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="Directory.ReadWrite.All"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="Directory.AccessAsUser.All"/>
</Record>
</Collection>
</PropertyValue>
</Record>
<Record>
<PropertyValue Property="Scheme" String="DelegatedPersonal" />
<PropertyValue Property="Scopes">
<Collection>
<Record>
<PropertyValue Property="Scope" String="User.ReadWrite"/>
</Record>
</Collection>
</PropertyValue>
</Record>
<Record>
<PropertyValue Property="Scheme" String="Application" />
<PropertyValue Property="Scopes">
<Collection>
<Record>
<PropertyValue Property="Scope" String="User.ReadWrite.All"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="Directory.ReadWrite.All"/>
</Record>
</Collection>
</PropertyValue>
</Record>
</PropertyValue>
</Record>
</Annotation>
<!-- Read restrictions :select restrictions and then props to filter, expand, etc. -->
<Annotation Term="Org.Graph.Vocabulary.ReadRestrictions">
<Record>
<PropertyValue Property="CustomHeaders">
<Collection>
<Record>
<PropertyValue Property="Name" String="Authorization" />
<PropertyValue Property="Description" />
<PropertyValue Property="Required" Bool="false" />
</Record>
<Record>
<PropertyValue Property="Name" String="Content-Type" />
<PropertyValue Property="Description" />
<PropertyValue Property="Required" Bool="false" />
</Record>
</Collection>
</PropertyValue>
<PropertyValue Property="Permission">
<Collection>
<Record>
<PropertyValue Property="Scheme" String="DelegatedWork" />
<PropertyValue Property="Scopes">
<Collection>
<Record>
<PropertyValue Property="Scope" String="User.Read"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="User.ReadWrite"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="User.ReadBasic.All"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="User.Read.All"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="User.ReadWrite.All"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="Directory.Read.All"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="Directory.ReadWrite.All"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="Directory.AccessAsUser.All"/>
</Record>
</Collection>
</PropertyValue>
</Record>
<Record>
<PropertyValue Property="Scheme" String="Application" />
<PropertyValue Property="Scopes">
<Collection>
<Record>
<PropertyValue Property="Scope" String="User.Read"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="User.ReadWrite"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="User.ReadWrite.All"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="Directory.Read.All"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="Directory.ReadWrite.All"/>
</Record>
</Collection>
</PropertyValue>
</Record>
</Collection>
</PropertyValue>
<PropertValue Property="ReadByKeyRestrictions">
<Record>
<PropertyValue Property="Permission">
<Collection>
<Record>
<PropertyValue Property="Scheme" String="DelegatedWork" />
<PropertyValue Property="Scopes">
<Collection>
<Record>
<PropertyValue Property="Scope" String="User.Read"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="User.ReadWrite"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="User.ReadBasic.All"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="User.Read.All"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="User.ReadWrite.All"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="Directory.Read.All"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="Directory.ReadWrite.All"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="Directory.AccessAsUser.All"/>
</Record>
</Collection>
</PropertyValue>
</Record>
<Record>
<PropertyValue Property="Scheme" String="DelegatedPersonal" />
<PropertyValue Property="Scopes">
<Collection>
<Record>
<PropertyValue Property="Scope" String="User.Read"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="User.ReadWrite"/>
</Record>
</Collection>
</PropertyValue>
</Record>
<Record>
<PropertyValue Property="Scheme" String="Application" />
<PropertyValue Property="Scopes">
<Collection>
<Record>
<PropertyValue Property="Scope" String="User.Read.All"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="User.ReadWrite.All"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="Directory.Read.All"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="Directory.ReadWrite.All"/>
</Record>
</Collection>
</PropertyValue>
</Record>
</Collection>
</PropertyValue>
</Record>
</PropertValue>
</Record>
</Annotation>
<Annotation Term="Org.Graph.Vocabulary.DeleteRestrictions">
<Record>
<PropertyValue Property="CustomHeaders">
<Collection>
<Record>
<PropertyValue Property="Name" String="Authorization" />
<PropertyValue Property="Description" />
<PropertyValue Property="Required" Bool="false" />
</Record>
</Collection>
</PropertyValue>
<PropertyValue Property="Permission">
<Record>
<PropertyValue Property="Scheme" String="DelegatedWork" />
<PropertyValue Property="Scopes">
<Collection>
<Record>
<PropertyValue Property="Scope" String="Directory.AccessAsUser.All"/>
</Record>
</Collection>
</PropertyValue>
</Record>
<Record>
<PropertyValue Property="Scheme" String="Application" />
<PropertyValue Property="Scopes">
<Collection>
<Record>
<PropertyValue Property="Scope" String="User.ReadWrite.All"/>
</Record>
</Collection>
</PropertyValue>
</Record>
</PropertyValue>
</Record>
</Annotation>
</Annotations>
<!-- annoations on actions/functions -->
<Annotations Target="microsoft.graph.reminderView(microsoft.graph.user, Edm.String, Edm.String)">
<!-- for a path that looks like "GET /users/{id | userPrincipalName}/reminderView(startDateTime=startDateTime-value,endDateTime=endDateTime-value)" -->
<Annotation Term="Org.Graph.Vocabulary.OperationRestrictions">
<Collection>
<Record>
<PropertyValue Property="QualifiedOperationName" String="reminderView" />
<PropertyValue Property="Permission">
<Record>
<PropertyValue Property="Scheme" String="DelegatedWork" />
<PropertyValue Property="Scopes">
<Collection>
<Record>
<PropertyValue Property="Scope" String="Calendars.Read" />
</Record>
<Record>
<PropertyValue Property="Scope" String="Calendars.ReadWrite" />
</Record>
</Collection>
</PropertyValue>
</Record>
<Record>
<PropertyValue Property="Scheme" String="DelegatedPersonal" />
<PropertyValue Property="Scopes">
<Collection>
<Record>
<PropertyValue Property="Scope" String="Calendars.Read" />
</Record>
<Record>
<PropertyValue Property="Scope" String="Calendars.ReadWrite" />
</Record>
</Collection>
</PropertyValue>
</Record>
<Record>
<PropertyValue Property="Scheme" String="Application" />
<PropertyValue Property="Scopes">
<Collection>
<Record>
<PropertyValue Property="Scope" String="Calendars.Read" />
</Record>
<Record>
<PropertyValue Property="Scope" String="Calendars.ReadWrite" />
</Record>
</Collection>
</PropertyValue>
</Record>
</PropertyValue>
</Record>
</Collection>
</Annotation>
</Annotations>
<!-- Annotating container with Auth Schemes that contain all the scopes applicable per that security scheme. Graph has 3 security schemes, DelegatedWork, DelegatedPersonal, Application -->
<Annotations Target="microsoft.graph.GraphService">
<Annotation Term="Auth.Authorizations">
<Collection>
<Record Type="Org.OData.Authorization.V1.OAuth2Implicit">
<PropertyValue Property="Name" String="DelegatedWork"/>
<PropertyValue Property="AuthorizationUrl" String="https://graph.microsoft.com" />
<PropertyValue Property="RefreshUrl" String="https://refreshUrl" />
<PropertyValue Property="Scopes">
<Collection>
<Record>
<PropertyValue Property="Scope" String="User.ReadAll"/>
<PropertyValue Property="Description" String="Read all user data"/>
<PropertyValue Property="Grant" String="User"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="User.WriteAll"/>
<PropertyValue Property="Description" String="Write all user data"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="Directory.ReadAll"/>
<PropertyValue Property="Description" String="Write to directory"/>
<PropertyValue Property="Grant" String="Admin"/>
</Record>
</Collection>
</PropertyValue>
</Record>
<Record Type="Org.OData.Authorization.V1.OAuth2Implicit">
<PropertyValue Property="Name" String="DelegatedPersonal"/>
<PropertyValue Property="AuthorizationUrl" String="https://graph.microsoft.com" />
<PropertyValue Property="RefreshUrl" String="https://refreshUrl" />
<PropertyValue Property="Scopes">
<Collection>
<Record>
<PropertyValue Property="Scope" String="User.ReadAll"/>
<PropertyValue Property="Description" String="Read all user data"/>
<PropertyValue Property="Grant" String="User"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="User.WriteAll"/>
<PropertyValue Property="Description" String="Write all user data"/>
<PropertyValue Property="Grant" String="User"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="Directory.ReadAll"/>
<PropertyValue Property="Description" String="Write to directory"/>
<PropertyValue Property="Grant" String="User"/>
</Record>
</Collection>
</PropertyValue>
</Record>
<Record Type="Org.OData.Authorization.V1.OAuth2Implicit">
<PropertyValue Property="Name" String="Application"/>
<PropertyValue Property="AuthorizationUrl" String="https://graph.microsoft.com" />
<PropertyValue Property="RefreshUrl" String="https://refreshUrl" />
<PropertyValue Property="Scopes">
<Collection>
<Record>
<PropertyValue Property="Scope" String="User.ReadAll"/>
<PropertyValue Property="Description" String="Read all user data"/>
<PropertyValue Property="Grant" String="Admin"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="User.WriteAll"/>
<PropertyValue Property="Description" String="Write all user data"/>
<PropertyValue Property="Grant" String="Admin"/>
</Record>
<Record>
<PropertyValue Property="Scope" String="Directory.ReadAll"/>
<PropertyValue Property="Description" String="Write to directory"/>
<PropertyValue Property="Grant" String="Admin"/>
</Record>
</Collection>
</PropertyValue>
</Record>
</Collection>
</Annotation>
</Annotations>
<EnumType Name="timeZoneStandard">
<Member Name="windows" Value="0" />
<Member Name="iana" Value="1" />

View file

@ -1,76 +0,0 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
namespace Microsoft.OpenApi.OData.Annotations
{
/// <summary>
/// Org.OData.Core.V1.Example
/// </summary>
internal abstract class Example
{
/// <summary>
/// Description.
/// </summary>
public string Description { get; set; }
/// <summary>
/// Init the <see cref="Example"/>.
/// </summary>
/// <param name="record">The input record.</param>
public virtual void Init(IEdmRecordExpression record)
{
Utils.CheckArgumentNull(record, nameof(record));
// Description
Description = record.GetString("Description");
}
/// <summary>
/// Creat the corresponding example object.
/// </summary>
/// <param name="record">The input record.</param>
/// <returns>The created example object.</returns>
public static Example CreateExample(IEdmRecordExpression record)
{
if (record == null || record.DeclaredType == null)
{
return null;
}
IEdmComplexType complexType = record.DeclaredType.Definition as IEdmComplexType;
if (complexType == null)
{
return null;
}
Example example = null;
switch (complexType.FullTypeName())
{
case "Org.OData.Core.V1.ExternalExample":
example = new ExternalExample();
break;
case "Org.OData.Core.V1.InlineExample":
example = new InlineExample();
break;
default:
break;
}
if (example != null)
{
example.Init(record);
}
return example;
}
}
}

View file

@ -1,84 +0,0 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
using System.Collections.Generic;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Authorizations;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
namespace Microsoft.OpenApi.OData.Annotations
{
/// <summary>
/// Org.OData.Core.V1.HttpRequest
/// </summary>
internal class HttpRequest
{
/// <summary>
/// The description.
/// </summary>
public string Description { get; set; }
/// <summary>
/// The MethodDescription.
/// </summary>
public string MethodDescription { get; set; }
/// <summary>
/// The MethodType.
/// </summary>
public string MethodType { get; set; }
/// <summary>
/// The Custom Query Options.
/// </summary>
public IList<CustomParameter> CustomQueryOptions { get; set; }
/// <summary>
/// The custom Headers.
/// </summary>
public IList<CustomParameter> CustomHeaders { get; set; }
/// <summary>
/// The http responses.
/// </summary>
public IList<HttpResponse> HttpResponses { get; set; }
/// <summary>
/// The security sechems.
/// </summary>
public IList<SecurityScheme> SecuritySchemes { get; set; }
/// <summary>
/// Init the <see cref="HttpRequest"/>.
/// </summary>
/// <param name="record">The input record.</param>
public virtual void Init(IEdmRecordExpression record)
{
Utils.CheckArgumentNull(record, nameof(record));
// Description.
Description = record.GetString("Description");
// MethodDescription.
MethodDescription = record.GetString("MethodDescription");
// MethodType.
MethodType = record.GetString("MethodType");
// CustomQueryOptions
CustomQueryOptions = record.GetCollection<CustomParameter>("CustomQueryOptions", (s, r) => s.Init(r as IEdmRecordExpression));
// CustomHeaders
CustomHeaders = record.GetCollection<CustomParameter>("CustomHeaders", (s, r) => s.Init(r as IEdmRecordExpression));
// HttpResponses
HttpResponses = record.GetCollection<HttpResponse>("HttpResponses", (s, r) => s.Init(r as IEdmRecordExpression));
// SecuritySchemes
SecuritySchemes = record.GetCollection<SecurityScheme>("SecuritySchemes", (s, r) => s.Init(r as IEdmRecordExpression));
}
}
}

View file

@ -1,120 +0,0 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
using System.Collections.Generic;
using System.Linq;
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
namespace Microsoft.OpenApi.OData.Annotations
{
/// <summary>
/// Org.OData.Core.V1.HttpRequests provider
/// </summary>
internal class HttpRequestProvider
{
/// <summary>
/// Annotatable: EntitySet Singleton ActionImport FunctionImport Action Function
/// Collection(Core.HttpRequest)
/// </summary>
private IDictionary<IEdmVocabularyAnnotatable, IList<HttpRequest>> _requests
= new Dictionary<IEdmVocabularyAnnotatable, IList<HttpRequest>>();
/// <summary>
/// Gets the Edm model.
/// </summary>
public IEdmModel Model { get; }
/// <summary>
/// Gets the Edm Term.
/// </summary>
public IEdmTerm Term { get; }
/// <summary>
/// Initializes a new instance of <see cref="HttpRequestProvider"/> class.
/// </summary>
/// <param name="model">The Edm model.</param>
public HttpRequestProvider(IEdmModel model)
{
Utils.CheckArgumentNull(model, nameof(model));
Term = model.FindTerm("Org.OData.Core.V1.HttpRequests");
Model = model;
}
/// <summary>
/// Gets Org.OData.Core.V1.HttpRequest.
/// </summary>
/// <param name="target">The target.</param>
/// <param name="method">The request method.</param>
/// <returns>The Org.OData.Core.V1.HttpRequest or null.</returns>
public HttpRequest GetHttpRequest(IEdmVocabularyAnnotatable target, string method)
{
Utils.CheckArgumentNull(target, nameof(target));
Utils.CheckArgumentNull(method, nameof(method));
var requests = GetHttpRequests(target);
return requests?.FirstOrDefault(e => string.Equals(e.MethodType, method, System.StringComparison.OrdinalIgnoreCase));
}
/// <summary>
/// Gets the collection of Org.OData.Core.V1.HttpRequest for a given <see cref="IEdmVocabularyAnnotatable"/>.
/// </summary>
/// <param name="target">The target.</param>
/// <returns>The collection of Org.OData.Core.V1.HttpRequest</returns>
public IEnumerable<HttpRequest> GetHttpRequests(IEdmVocabularyAnnotatable target)
{
Utils.CheckArgumentNull(target, nameof(target));
if (Term == null)
{
return null;
}
// Search the cache.
if (_requests.TryGetValue(target, out IList<HttpRequest> value))
{
return value;
}
IEdmVocabularyAnnotation annotation = Model.GetVocabularyAnnotation(target, Term);
if (annotation == null)
{
IEdmNavigationSource navigationSource = target as IEdmNavigationSource;
// if not, search the entity type.
if (navigationSource != null)
{
IEdmEntityType entityType = navigationSource.EntityType();
annotation = Model.GetVocabularyAnnotation(entityType, Term);
}
}
if (annotation == null ||
annotation.Value == null ||
annotation.Value.ExpressionKind != EdmExpressionKind.Collection)
{
_requests[target] = null;
return null;
}
IEdmCollectionExpression collection = (IEdmCollectionExpression)annotation.Value;
var httpRequests = new List<HttpRequest>();
foreach (var item in collection.Elements)
{
IEdmRecordExpression record = (IEdmRecordExpression)item;
HttpRequest newRequest = new HttpRequest();
newRequest.Init(record);
httpRequests.Add(newRequest);
}
_requests[target] = httpRequests;
return httpRequests;
}
}
}

View file

@ -1,57 +0,0 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
using System.Collections.Generic;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Edm;
namespace Microsoft.OpenApi.OData.Annotations
{
/// <summary>
/// The Org.OData.Core.v1.HttpResponse
/// </summary>
internal class HttpResponse
{
/// <summary>
/// Description.
/// </summary>
public string Description { get; set; }
/// <summary>
/// ResponseCode
/// </summary>
public string ResponseCode { get; set; }
/// <summary>
/// Examples
/// </summary>
public IEnumerable<Example> Examples { get; set; }
/// <summary>
/// Int the <see cref="HttpResponse"/>.
/// </summary>
/// <param name="record">The input record.</param>
public void Init(IEdmRecordExpression record)
{
// ResponseCode
ResponseCode = record.GetString("ResponseCode");
// Description
Description = record.GetString("Description");
// Examples
Examples = record.GetCollection("Examples", r =>
{
IEdmRecordExpression itemRecord = r as IEdmRecordExpression;
if (itemRecord != null)
{
return Example.CreateExample(itemRecord);
}
return null;
});
}
}
}

View file

@ -1,33 +0,0 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Edm;
namespace Microsoft.OpenApi.OData.Annotations
{
/// <summary>
/// Complex type Org.OData.Core.V1.InlineExample
/// </summary>
internal class InlineExample : Example
{
/// <summary>
/// InlineValue
/// </summary>
public string InlineValue { get; set; }
/// <summary>
/// Init the <see cref="InlineExample"/>.
/// </summary>
/// <param name="record">The record.</param>
public override void Init(IEdmRecordExpression record)
{
base.Init(record);
// InlineValue
InlineValue = record.GetString("InlineValue");
}
}
}

View file

@ -1,102 +0,0 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
using System.Collections.Generic;
using System.Linq;
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
namespace Microsoft.OpenApi.OData.Authorizations
{
/// <summary>
/// The default 'Org.OData.Core.V1.Authorization' provider.
/// </summary>
internal class AuthorizationProvider
{
/// <summary>
/// Annotatable: EntitySet Singleton ActionImport FunctionImport Action Function
/// Collection(Core.HttpRequest)
/// </summary>
private IDictionary<IEdmVocabularyAnnotatable, IEnumerable<Authorization>> _authorizations
= new Dictionary<IEdmVocabularyAnnotatable, IEnumerable<Authorization>>();
/// <summary>
/// Gets the Edm model.
/// </summary>
public IEdmModel Model { get; }
/// <summary>
/// Gets the Edm Term.
/// </summary>
public IEdmTerm Term { get; }
/// <summary>
/// Initializes a new instance of <see cref="AuthorizationProvider"/> class.
/// </summary>
/// <param name="model">The Edm model.</param>
public AuthorizationProvider(IEdmModel model)
{
Utils.CheckArgumentNull(model, nameof(model));
Term = model.FindTerm(AuthorizationConstants.Authorizations);
Model = model;
}
/// <summary>
/// Gets the <see cref="Authorization"/> collections for a given target in the given Edm model.
/// </summary>
/// <param name="target">The Edm target.</param>
/// <returns>The <see cref="Authorization"/> collections.</returns>
public virtual IEnumerable<Authorization> GetAuthorizations(IEdmVocabularyAnnotatable target)
{
Utils.CheckArgumentNull(target, nameof(target));
if (_authorizations.TryGetValue(target, out IEnumerable<Authorization> value))
{
return value;
}
if (Term == null)
{
return Enumerable.Empty<Authorization>();
}
value = RetrieveAuthorizations(target);
_authorizations[target] = value;
return value;
}
/// <summary>
/// Create the corresponding Authorization object.
/// </summary>
/// <param name="record">The input record.</param>
/// <returns>The created <see cref="Authorization"/> object.</returns>
private IEnumerable<Authorization> RetrieveAuthorizations(IEdmVocabularyAnnotatable target)
{
IEdmVocabularyAnnotation annotation = Model.GetVocabularyAnnotation(target, Term);
if (annotation != null && annotation.Value != null && annotation.Value.ExpressionKind == EdmExpressionKind.Collection)
{
IEdmCollectionExpression collection = (IEdmCollectionExpression)annotation.Value;
foreach (var item in collection.Elements)
{
IEdmRecordExpression record = item as IEdmRecordExpression;
if (record == null || record.DeclaredType == null)
{
continue;
}
Authorization auth = Authorization.CreateAuthorization(record);
if (auth != null)
{
yield return auth;
}
}
}
}
}
}

View file

@ -1,93 +0,0 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
namespace Microsoft.OpenApi.OData.Capabilities
{
/// <summary>
/// Constant values for Capabilities Vocabulary
/// </summary>
internal class CapabilitiesConstants
{
/// <summary>
/// The namespace of Capabilities annotation.
/// </summary>
public const string Namespace = "Org.OData.Capabilities.V1";
/// <summary>
/// Org.OData.Capabilities.V1.ChangeTracking
/// </summary>
public const string ChangeTracking = Namespace + ".ChangeTracking";
/// <summary>
/// Org.OData.Capabilities.V1.FilterRestrictions
/// </summary>
public const string FilterRestrictions = Namespace + ".FilterRestrictions";
/// <summary>
/// Org.OData.Capabilities.V1.SortRestrictions
/// </summary>
public const string SortRestrictions = Namespace + ".SortRestrictions";
/// <summary>
/// Org.OData.Capabilities.V1.NavigationRestrictions
/// </summary>
public const string NavigationRestrictions = Namespace + ".NavigationRestrictions";
/// <summary>
/// Org.OData.Capabilities.V1.SearchRestrictions
/// </summary>
public const string SearchRestrictions = Namespace + ".SearchRestrictions";
/// <summary>
/// Org.OData.Capabilities.V1.CountRestrictions
/// </summary>
public const string CountRestrictions = Namespace + ".CountRestrictions";
/// <summary>
/// Org.OData.Capabilities.V1.ExpandRestrictions
/// </summary>
public const string ExpandRestrictions = Namespace + ".ExpandRestrictions";
/// <summary>
/// Org.OData.Capabilities.V1.DeleteRestrictions
/// </summary>
public const string DeleteRestrictions = Namespace + ".DeleteRestrictions";
/// <summary>
/// Org.OData.Capabilities.V1.DeleteRestrictions
/// </summary>
public const string UpdateRestrictions = Namespace + ".UpdateRestrictions";
/// <summary>
/// Org.OData.Capabilities.V1.InsertRestrictions
/// </summary>
public const string InsertRestrictions = Namespace + ".InsertRestrictions";
/// <summary>
/// Org.OData.Capabilities.V1.TopSupported
/// </summary>
public const string TopSupported = Namespace + ".TopSupported";
/// <summary>
/// Org.OData.Capabilities.V1.SkipSupported
/// </summary>
public const string SkipSupported = Namespace + ".SkipSupported";
/// <summary>
/// Org.OData.Capabilities.V1.BatchSupported
/// </summary>
public const string BatchSupported = Namespace + ".BatchSupported";
/// <summary>
/// Org.OData.Capabilities.V1.IndexableByKey
/// </summary>
public const string IndexableByKey = Namespace + ".IndexableByKey";
/// <summary>
/// Org.OData.Capabilities.V1.KeyAsSegmentSupported
/// </summary>
public const string KeyAsSegmentSupported = Namespace + ".KeyAsSegmentSupported";
}
}

View file

@ -1,327 +0,0 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Properties;
namespace Microsoft.OpenApi.OData.Capabilities
{
/// <summary>
/// The class provides the functionality for the capabilities annotation.
/// </summary>
internal static class CapabilitiesExtensions
{
private static IDictionary<IEdmVocabularyAnnotatable, IDictionary<CapabilitesTermKind, ICapablitiesRestrictions>> _capabilitesRestrictions;
private static IEdmModel _savedModel = null;
private static object _objectLock = new object();
/// <summary>
/// Gets Org.OData.Capabilities.V1.SearchRestrictions.
/// </summary>
/// <param name="model">The Edm model.</param>
/// <param name="target">The target.</param>
/// <returns>The Org.OData.Capabilities.V1.SearchRestrictions or null.</returns>
public static SearchRestrictions GetSearchRestrictions(this IEdmModel model, IEdmVocabularyAnnotatable target)
{
return model.GetCapabilities(target, CapabilitesTermKind.SearchRestrictions) as SearchRestrictions;
}
/// <summary>
/// Gets Org.OData.Capabilities.V1.FilterRestrictions.
/// </summary>
/// <param name="model">The Edm model.</param>
/// <param name="target">The target.</param>
/// <returns>The Org.OData.Capabilities.V1.FilterRestrictions or null.</returns>
public static FilterRestrictions GetFilterRestrictions(this IEdmModel model, IEdmVocabularyAnnotatable target)
{
return model.GetCapabilities(target, CapabilitesTermKind.FilterRestrictions) as FilterRestrictions;
}
/// <summary>
/// Gets Org.OData.Capabilities.V1.NavigationRestrictions.
/// </summary>
/// <param name="model">The Edm model.</param>
/// <param name="target">The target.</param>
/// <returns>The Org.OData.Capabilities.V1.NavigationRestrictions or null.</returns>
public static NavigationRestrictions GetNavigationRestrictions(this IEdmModel model, IEdmVocabularyAnnotatable target)
{
return model.GetCapabilities(target, CapabilitesTermKind.NavigationRestrictions) as NavigationRestrictions;
}
/// <summary>
/// Gets Org.OData.Capabilities.V1.ExpandRestrictions.
/// </summary>
/// <param name="model">The Edm model.</param>
/// <param name="target">The target.</param>
/// <returns>The Org.OData.Capabilities.V1.ExpandRestrictions or null.</returns>
public static ExpandRestrictions GetExpandRestrictions(this IEdmModel model, IEdmVocabularyAnnotatable target)
{
return model.GetCapabilities(target, CapabilitesTermKind.ExpandRestrictions) as ExpandRestrictions;
}
/// <summary>
/// Gets Org.OData.Capabilities.V1.DeleteRestrictions.
/// </summary>
/// <param name="model">The Edm model.</param>
/// <param name="target">The target.</param>
/// <returns>The Org.OData.Capabilities.V1.DeleteRestrictions or null.</returns>
public static DeleteRestrictions GetDeleteRestrictions(this IEdmModel model, IEdmVocabularyAnnotatable target)
{
return model.GetCapabilities(target, CapabilitesTermKind.DeleteRestrictions) as DeleteRestrictions;
}
/// <summary>
/// Gets Org.OData.Capabilities.V1.UpdateRestrictions.
/// </summary>
/// <param name="model">The Edm model.</param>
/// <param name="target">The target.</param>
/// <returns>The Org.OData.Capabilities.V1.UpdateRestrictions or null.</returns>
public static UpdateRestrictions GetUpdateRestrictions(this IEdmModel model, IEdmVocabularyAnnotatable target)
{
return model.GetCapabilities(target, CapabilitesTermKind.UpdateRestrictions) as UpdateRestrictions;
}
/// <summary>
/// Gets Org.OData.Capabilities.V1.InsertRestrictions.
/// </summary>
/// <param name="model">The Edm model.</param>
/// <param name="target">The target.</param>
/// <returns>The Org.OData.Capabilities.V1.InsertRestrictions or null.</returns>
public static InsertRestrictions GetInsertRestrictions(this IEdmModel model, IEdmVocabularyAnnotatable target)
{
return model.GetCapabilities(target, CapabilitesTermKind.InsertRestrictions) as InsertRestrictions;
}
/// <summary>
/// Gets Org.OData.Capabilities.V1.SortRestrictions.
/// </summary>
/// <param name="model">The Edm model.</param>
/// <param name="target">The target.</param>
/// <returns>The Org.OData.Capabilities.V1.SortRestrictions or null.</returns>
public static SortRestrictions GetSortRestrictions(this IEdmModel model, IEdmVocabularyAnnotatable target)
{
return model.GetCapabilities(target, CapabilitesTermKind.SortRestrictions) as SortRestrictions;
}
/// <summary>
/// Gets Org.OData.Capabilities.V1.CountRestrictions.
/// </summary>
/// <param name="model">The Edm model.</param>
/// <param name="target">The target.</param>
/// <returns>The Org.OData.Capabilities.V1.CountRestrictions or null.</returns>
public static CountRestrictions GetCountRestrictions(this IEdmModel model, IEdmVocabularyAnnotatable target)
{
return model.GetCapabilities(target, CapabilitesTermKind.CountRestrictions) as CountRestrictions;
}
/// <summary>
/// Gets Org.OData.Capabilities.V1.BatchSupported.
/// </summary>
/// <param name="model">The Edm model.</param>
/// <param name="target">The target.</param>
/// <returns>The Org.OData.Capabilities.V1.BatchSupported or null.</returns>
public static BatchSupported GetBatchSupported(this IEdmModel model, IEdmVocabularyAnnotatable target)
{
return model.GetCapabilities(target, CapabilitesTermKind.BatchSupported) as BatchSupported;
}
/// <summary>
/// Gets Org.OData.Capabilities.V1.SkipSupported.
/// </summary>
/// <param name="model">The Edm model.</param>
/// <param name="target">The target.</param>
/// <returns>The Org.OData.Capabilities.V1.SkipSupported or null.</returns>
public static SkipSupported GetSkipSupported(this IEdmModel model, IEdmVocabularyAnnotatable target)
{
return model.GetCapabilities(target, CapabilitesTermKind.SkipSupported) as SkipSupported;
}
/// <summary>
/// Gets Org.OData.Capabilities.V1.TopSupported.
/// </summary>
/// <param name="model">The Edm model.</param>
/// <param name="target">The target.</param>
/// <returns>The Org.OData.Capabilities.V1.TopSupported or null.</returns>
public static TopSupported GetTopSupported(this IEdmModel model, IEdmVocabularyAnnotatable target)
{
return model.GetCapabilities(target, CapabilitesTermKind.TopSupported) as TopSupported;
}
/// <summary>
/// Gets Org.OData.Capabilities.V1.KeyAsSegmentSupported.
/// </summary>
/// <param name="model">The Edm model.</param>
/// <param name="target">The target.</param>
/// <returns>The Org.OData.Capabilities.V1.KeyAsSegmentSupported or null.</returns>
public static KeyAsSegmentSupported GetKeyAsSegmentSupported(this IEdmModel model, IEdmVocabularyAnnotatable target)
{
return model.GetCapabilities(target, CapabilitesTermKind.KeyAsSegmentSupported) as KeyAsSegmentSupported;
}
/// <summary>
/// Gets Org.OData.Capabilities.V1.IndexableByKey.
/// </summary>
/// <param name="model">The Edm model.</param>
/// <param name="target">The target.</param>
/// <returns>The Org.OData.Capabilities.V1.IndexableByKey or null.</returns>
public static IndexableByKey GetIndexableByKey(this IEdmModel model, IEdmVocabularyAnnotatable target)
{
return model.GetCapabilities(target, CapabilitesTermKind.IndexableByKey) as IndexableByKey;
}
/// <summary>
/// Create the capabiliites restriction
/// </summary>
/// <param name="model">The Edm model.</param>
/// <param name="target">The Target.</param>
/// <param name="kind">The Capabiliites kind.</param>
/// <returns>The <see cref="ICapablitiesRestrictions"/>.</returns>
public static ICapablitiesRestrictions CreateCapabilitesRestrictions(this IEdmModel model, IEdmVocabularyAnnotatable target, CapabilitesTermKind kind)
{
Debug.Assert(model != null);
Debug.Assert(target != null);
ICapablitiesRestrictions capabilitiesRestrictions = null;
switch(kind)
{
case CapabilitesTermKind.DeleteRestrictions: // DeleteRestrictions
capabilitiesRestrictions = new DeleteRestrictions();
break;
case CapabilitesTermKind.UpdateRestrictions: // UpdateRestrictions
capabilitiesRestrictions = new UpdateRestrictions();
break;
case CapabilitesTermKind.InsertRestrictions: // InsertRestrictions
capabilitiesRestrictions = new InsertRestrictions();
break;
case CapabilitesTermKind.SearchRestrictions: // SearchRestrictions
capabilitiesRestrictions = new SearchRestrictions();
break;
case CapabilitesTermKind.ExpandRestrictions: // ExpandRestrictions
capabilitiesRestrictions = new ExpandRestrictions();
break;
case CapabilitesTermKind.SortRestrictions: // SortRestrictions
capabilitiesRestrictions = new SortRestrictions();
break;
case CapabilitesTermKind.FilterRestrictions: // FilterRestrictions
capabilitiesRestrictions = new FilterRestrictions();
break;
case CapabilitesTermKind.NavigationRestrictions: // NavigationRestrictions
capabilitiesRestrictions = new NavigationRestrictions();
break;
case CapabilitesTermKind.CountRestrictions: // CountRestrictions
capabilitiesRestrictions = new CountRestrictions();
break;
case CapabilitesTermKind.BatchSupported: // BatchSupported
capabilitiesRestrictions = new BatchSupported();
break;
case CapabilitesTermKind.SkipSupported: // SkipSupported
capabilitiesRestrictions = new SkipSupported();
break;
case CapabilitesTermKind.TopSupported: // TopSupported
capabilitiesRestrictions = new TopSupported();
break;
case CapabilitesTermKind.KeyAsSegmentSupported: // KeyAsSegmentSupported
capabilitiesRestrictions = new KeyAsSegmentSupported();
break;
case CapabilitesTermKind.IndexableByKey: // IndexableByKey
capabilitiesRestrictions = new IndexableByKey();
break;
case CapabilitesTermKind.ChangeTracking: // ChangeTracking
case CapabilitesTermKind.CrossJoinSupported: // CrossJoinSupported
case CapabilitesTermKind.CallbackSupported: // CallbackSupported
case CapabilitesTermKind.FilterFunctions: // FilterFunctions
case CapabilitesTermKind.BatchContinueOnErrorSupported: // BatchContinueOnErrorSupported
case CapabilitesTermKind.AsynchronousRequestsSupported: // AsynchronousRequestsSupported
case CapabilitesTermKind.Isolation: // Isolation
case CapabilitesTermKind.AcceptableEncodings: // AcceptableEncodings
case CapabilitesTermKind.SupportedFormats: // SupportedFormats
default:
throw Error.NotSupported(String.Format(SRResource.CapabilitiesKindNotSupported, kind));
}
// load the annotation value
if (!capabilitiesRestrictions.Load(model, target))
{
return null;
}
return capabilitiesRestrictions;
}
/// <summary>
/// Gets the capablities from the <see cref="IEdmModel"/> for the given <see cref="IEdmVocabularyAnnotatable"/>.
/// </summary>
/// <param name="model">The Edm model.</param>
/// <param name="target">The target.</param>
/// <param name="kind">Thye Capabilites kind.</param>
/// <returns>The capabilities restrictions or null.</returns>
private static ICapablitiesRestrictions GetCapabilities(this IEdmModel model, IEdmVocabularyAnnotatable target, CapabilitesTermKind kind)
{
if (model == null || target == null)
{
return null;
}
lock (_objectLock)
{
if (!ReferenceEquals(_savedModel, model))
{
if (_capabilitesRestrictions != null)
{
_capabilitesRestrictions.Clear();
}
_savedModel = model;
}
if (_capabilitesRestrictions == null)
{
_capabilitesRestrictions = new Dictionary<IEdmVocabularyAnnotatable, IDictionary<CapabilitesTermKind, ICapablitiesRestrictions>>();
}
ICapablitiesRestrictions restriction;
if (_capabilitesRestrictions.TryGetValue(target, out IDictionary<CapabilitesTermKind, ICapablitiesRestrictions> value))
{
// Here means we visited target before and we are sure that the value is not null.
if (value.TryGetValue(kind, out restriction))
{
return restriction;
}
else
{
restriction = CreateCapabilitesRestrictions(model, target, kind);
value[kind] = restriction;
return restriction;
}
}
// It's first time to query this target, create new dictionary and restriction.
value = new Dictionary<CapabilitesTermKind, ICapablitiesRestrictions>();
_capabilitesRestrictions[target] = value;
restriction = CreateCapabilitesRestrictions(model, target, kind);
value[kind] = restriction;
return restriction;
}
}
}
}

View file

@ -1,57 +0,0 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
namespace Microsoft.OpenApi.OData.Capabilities
{
/// <summary>
/// The base class of Capabilities
/// </summary>
internal abstract class CapabilitiesRestrictions : ICapablitiesRestrictions
{
/// <summary>
/// The Capablities Kind.
/// </summary>
public abstract CapabilitesTermKind Kind { get; }
/// <summary>
/// Load the annotation value.
/// </summary>
/// <param name="model">The Edm model.</param>
/// <param name="target">The target.</param>
/// <returns>True/False</returns>
public virtual bool Load(IEdmModel model, IEdmVocabularyAnnotatable target)
{
Utils.CheckArgumentNull(model, nameof(model));
Utils.CheckArgumentNull(target, nameof(target));
string termQualifiedName = CapabilitiesConstants.Namespace + "." + Kind.ToString();
IEdmVocabularyAnnotation annotation = model.GetVocabularyAnnotation(target, termQualifiedName);
if (annotation == null)
{
IEdmNavigationSource navigationSource = target as IEdmNavigationSource;
// if not, search the entity type.
if (navigationSource != null)
{
IEdmEntityType entityType = navigationSource.EntityType();
annotation = model.GetVocabularyAnnotation(entityType, termQualifiedName);
}
}
return Initialize(annotation);
}
/// <summary>
/// Initialize the capabilities with the vocabulary annotation.
/// </summary>
/// <param name="annotation">The input vocabulary annotation.</param>
protected abstract bool Initialize(IEdmVocabularyAnnotation annotation);
}
}

View file

@ -1,163 +0,0 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
namespace Microsoft.OpenApi.OData.Capabilities
{
/// <summary>
/// The Enum kind for Capabiliites annotation
/// </summary>
internal enum CapabilitesTermKind
{
/// <summary>
/// Media types of supported formats, including format parameters
/// </summary>
SupportedFormats,
/// <summary>
/// List of acceptable compression methods for ($batch) requests, e.g. gzip
/// </summary>
AcceptableEncodings,
/// <summary>
/// Supports key values according to OData URL conventions
/// </summary>
IndexableByKey,
/// <summary>
/// Supported odata.isolation levels
/// </summary>
Isolation,
/// <summary>
/// Supports key as segment
/// </summary>
KeyAsSegmentSupported,
/// <summary>
/// Supports $top
/// </summary>
TopSupported,
/// <summary>
/// Supports $skip
/// </summary>
SkipSupported,
/// <summary>
/// Service supports the asynchronous request preference
/// </summary>
AsynchronousRequestsSupported,
/// <summary>
/// Supports $batch requests
/// </summary>
BatchSupported,
/// <summary>
/// Service supports the continue on error preference
/// </summary>
BatchContinueOnErrorSupported,
/// <summary>
/// List of functions supported in $filter
/// </summary>
FilterFunctions,
/// <summary>
/// Supports callbacks for the specified protocols
/// </summary>
CallbackSupported,
/// <summary>
/// Supports cross joins for the entity sets in this container
/// </summary>
CrossJoinSupported,
/// <summary>
/// Change tracking capabilities of this service or entity set
/// </summary>
ChangeTracking,
/// <summary>
/// Restrictions on /$count path suffix and $count=true system query option
/// </summary>
CountRestrictions,
/// <summary>
/// Restrictions on navigating properties according to OData URL conventions
/// </summary>
NavigationRestrictions,
/// <summary>
/// Restrictions on $filter expressions
/// </summary>
FilterRestrictions,
/// <summary>
/// Restrictions on $orderby expressions
/// </summary>
SortRestrictions,
/// <summary>
/// Restrictions on $expand expressions
/// </summary>
ExpandRestrictions,
/// <summary>
/// Restrictions on $search expressions
/// </summary>
SearchRestrictions,
/// <summary>
/// Restrictions on insert operations
/// </summary>
InsertRestrictions,
/// <summary>
/// Deep Insert Support of the annotated resource (the whole service, an entity set, or a collection-valued resource
/// </summary>
DeepInsertSupport,
/// <summary>
/// Restrictions on update operations
/// </summary>
UpdateRestrictions,
/// <summary>
/// Deep Update Support of the annotated resource (the whole service, an entity set, or a collection-valued resource)
/// </summary>
DeepUpdateSupported,
/// <summary>
/// Restrictions on delete operations
/// </summary>
DeleteRestrictions,
/// <summary>
/// Describes restrictions on operations applied to collection-valued structural properties.
/// </summary>
CollectionPropertyRestrictions,
/// <summary>
/// Restrictions for function or action operation.
/// </summary>
OperationRestrictions,
/// <summary>
/// Restrictions for retrieving a collection of entities, retrieving a singleton instance, invoking a function
/// </summary>
ReadRestrictions,
/// <summary>
/// Custom headers that are supported/required for the annotated resource
/// </summary>
CustomHeaders,
/// <summary>
/// Custom query options that are supported/required for the annotated resource
/// </summary>
CustomQueryOptions
}
}

View file

@ -1,31 +0,0 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
using System.Collections.Generic;
using Microsoft.OData.Edm.Vocabularies;
namespace Microsoft.OpenApi.OData.Capabilities
{
/// <summary>
/// Term: Org.OData.Capabilities.V1.CustomHeaders
/// </summary>
internal class CustomHeaders : CapabilitiesRestrictions
{
/// <summary>
/// The Term type kind.
/// </summary>
public override CapabilitesTermKind Kind => CapabilitesTermKind.CustomHeaders;
/// <summary>
/// Collection(Capabilities.CustomParameter)
/// </summary>
public IList<CustomParameter> Parameters { get; private set; }
protected override bool Initialize(IEdmVocabularyAnnotation annotation)
{
throw new System.NotImplementedException();
}
}
}

View file

@ -1,40 +0,0 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
using System.Collections.Generic;
namespace Microsoft.OpenApi.OData.Capabilities
{
/// <summary>
/// Complex type: Org.OData.Capabilities.V1.CustomParameter
/// </summary>
internal class CustomParameter
{
/// <summary>
/// Gets/sets the name of the custom parameter.
/// </summary>
public string Name { get; set; }
/// <summary>
/// Gets/sets the description of the custom parameter.
/// </summary>
public string Description { get; set; }
/// <summary>
/// Gets/sets the documentationURL of the custom parameter.
/// </summary>
public string DocumentationURL { get; set; }
/// <summary>
/// Gets/sets the reuired of the custom parameter. true: parameter is required, false or not specified: parameter is optional.
/// </summary>
public bool Required { get; set; }
/// <summary>
/// Gets the list of scopes that can provide access to the resource.
/// </summary>s
public IList<PrimitiveExampleValue> Scopes { get; set; }
}
}

View file

@ -1,31 +0,0 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
using System.Collections.Generic;
using Microsoft.OData.Edm.Vocabularies;
namespace Microsoft.OpenApi.OData.Capabilities
{
/// <summary>
/// Term: Org.OData.Capabilities.V1.CustomQueryOptions
/// </summary>
internal class CustomQueryOptions : CapabilitiesRestrictions
{
/// <summary>
/// The Term type kind.
/// </summary>
public override CapabilitesTermKind Kind => CapabilitesTermKind.CustomQueryOptions;
/// <summary>
/// Collection(Capabilities.CustomParameter)
/// </summary>
public IList<CustomParameter> Parameters { get; private set; }
protected override bool Initialize(IEdmVocabularyAnnotation annotation)
{
throw new System.NotImplementedException();
}
}
}

View file

@ -1,29 +0,0 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Vocabularies;
namespace Microsoft.OpenApi.OData.Capabilities
{
/// <summary>
/// Interface for the capabilities restrictions
/// </summary>
internal interface ICapablitiesRestrictions
{
/// <summary>
/// The Capablities Kind.
/// </summary>
CapabilitesTermKind Kind { get; }
/// <summary>
/// Load the annotation value.
/// </summary>
/// <param name="model">The Edm model.</param>
/// <param name="target">The target.</param>
/// <returns>True/False</returns>
bool Load(IEdmModel model, IEdmVocabularyAnnotatable target);
}
}

View file

@ -1,43 +0,0 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
namespace Microsoft.OpenApi.OData.Capabilities
{
/// <summary>
/// Complex type: Org.OData.Capabilities.V1.ModificationQueryOptionsType
/// </summary>
internal class ModificationQueryOptionsType
{
/// <summary>
/// Gets/sets the $expand with modification requests.
/// </summary>
public bool ExpandSupported { get; private set; }
/// <summary>
/// Gets/sets the $select with modification requests.
/// </summary>
public bool SelectSupported { get; private set; }
/// <summary>
/// Gets/sets the $compute with modification requests.
/// </summary>
public bool ComputeSupported { get; private set; }
/// <summary>
/// Gets/sets the $filter with modification requests.
/// </summary>
public bool FilterSupported { get; private set; }
/// <summary>
/// Gets/sets the $search with modification requests.
/// </summary>
public bool SearchSupported { get; private set; }
/// <summary>
/// Gets/sets the $sort with modification requests.
/// </summary>
public bool SortSupported { get; private set; }
}
}

View file

@ -1,96 +0,0 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
using System.Collections.Generic;
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Vocabularies;
namespace Microsoft.OpenApi.OData.Capabilities
{
internal abstract class ReadRestrictionsBase
{
/// <summary>
/// Get the Entities can be retrieved.
/// </summary>
public bool? Readable { get; private set; }
/// <summary>
/// Gets the List of required scopes to invoke an action or function
/// </summary>
public PermissionType Permission { get; private set; }
/// <summary>
/// Gets the Supported or required custom headers.
/// </summary>
public IList<CustomParameter> CustomHeaders { get; private set; }
/// <summary>
/// Gets the Supported or required custom query options.
/// </summary>
public IList<CustomParameter> CustomQueryOptions { get; private set; }
}
/// <summary>
/// Restrictions for retrieving an entity by key
/// </summary>
internal class ReadByKeyRestrictionsType : ReadRestrictionsBase
{
}
/// <summary>
/// Restrictions for retrieving an entity by key
/// </summary>
internal class ReadRestrictionsType : ReadRestrictionsBase
{
/// <summary>
/// Gets the Restrictions for retrieving an entity by key.
/// Only valid when applied to a collection. If a property of `ReadByKeyRestrictions`
/// is not specified, the corresponding property value of `ReadRestrictions` applies.
/// </summary>
public ReadByKeyRestrictionsType ReadByKeyRestrictions { get; private set; }
}
/// <summary>
/// Org.OData.Capabilities.V1.ReadRestrictions
/// </summary>
internal class ReadRestrictions : CapabilitiesRestrictions
{
/// <summary>
/// The Term type name.
/// </summary>
public override CapabilitesTermKind Kind => CapabilitesTermKind.ReadRestrictions;
/// <summary>
/// Gets the List of required scopes to invoke an action or function.
/// </summary>
public PermissionType Permission { get; private set; }
/// <summary>
/// Gets the Supported or required custom headers.
/// </summary>
public IList<CustomParameter> CustomHeaders { get; private set; }
/// <summary>
/// Gets the Supported or required custom query options.
/// </summary>
public IList<CustomParameter> CustomQueryOptions { get; private set; }
protected override bool Initialize(IEdmVocabularyAnnotation annotation)
{
if (annotation == null ||
annotation.Value == null ||
annotation.Value.ExpressionKind != EdmExpressionKind.Record)
{
return false;
}
IEdmRecordExpression record = (IEdmRecordExpression)annotation.Value;
return true;
}
}
}

View file

@ -1,144 +0,0 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Common;
namespace Microsoft.OpenApi.OData.Capabilities
{
/// <summary>
/// Extension methods for <see cref="IEdmRecordExpression"/>
/// </summary>
internal static class RecordExpressionExtensions
{
/// <summary>
/// Get the boolean value from the record using the given property name.
/// </summary>
/// <param name="record">The record expression.</param>
/// <param name="propertyName">The property name.</param>
/// <returns>The boolean value or null.</returns>
public static bool? GetBoolean(this IEdmRecordExpression record, string propertyName)
{
Utils.CheckArgumentNull(record, nameof(record));
Utils.CheckArgumentNull(propertyName, nameof(propertyName));
if (record.Properties != null)
{
IEdmPropertyConstructor property = record.Properties.FirstOrDefault(e => e.Name == propertyName);
if (property != null)
{
IEdmBooleanConstantExpression value = property.Value as IEdmBooleanConstantExpression;
if (value != null)
{
return value.Value;
}
}
}
return null;
}
/// <summary>
/// Get the Enum value from the record using the given property name.
/// </summary>
/// <typeparam name="T">The output enum type.</typeparam>
/// <param name="record">The record expression.</param>
/// <param name="propertyName">The property name.</param>
/// <returns>The Enum value or null.</returns>
public static T? GetEnum<T>(this IEdmRecordExpression record, string propertyName)
where T : struct
{
Utils.CheckArgumentNull(record, nameof(record));
Utils.CheckArgumentNull(propertyName, nameof(propertyName));
if (record.Properties != null)
{
IEdmPropertyConstructor property = record.Properties.FirstOrDefault(e => e.Name == propertyName);
if (property != null)
{
IEdmEnumMemberExpression value = property.Value as IEdmEnumMemberExpression;
if (value != null && value.EnumMembers != null && value.EnumMembers.Any())
{
IEdmEnumMember member = value.EnumMembers.First();
T result;
if (Enum.TryParse(member.Name, out result))
{
return result;
}
}
}
}
return null;
}
/// <summary>
/// Get the property path from the record using the given property name.
/// </summary>
/// <param name="record">The record expression.</param>
/// <param name="propertyName">The property name.</param>
/// <returns>The property path or null.</returns>
public static string GetPropertyPath(this IEdmRecordExpression record, string propertyName)
{
Utils.CheckArgumentNull(record, nameof(record));
Utils.CheckArgumentNull(propertyName, nameof(propertyName));
if (record.Properties != null)
{
IEdmPropertyConstructor property = record.Properties.FirstOrDefault(e => e.Name == propertyName);
if (property != null)
{
IEdmPathExpression value = property.Value as IEdmPathExpression;
if (value != null)
{
return value.Path;
}
}
}
return null;
}
/// <summary>
/// Get the collection of property path from the record using the given property name.
/// </summary>
/// <param name="record">The record expression.</param>
/// <param name="propertyName">The property name.</param>
/// <returns>The collection of property path or null.</returns>
public static IList<string> GetCollectionPropertyPath(this IEdmRecordExpression record, string propertyName)
{
Utils.CheckArgumentNull(record, nameof(record));
Utils.CheckArgumentNull(propertyName, nameof(propertyName));
if (record.Properties != null)
{
IEdmPropertyConstructor property = record.Properties.FirstOrDefault(e => e.Name == propertyName);
if (property != null)
{
IEdmCollectionExpression value = property.Value as IEdmCollectionExpression;
if (value != null && value.Elements != null)
{
IList<string> properties = new List<string>();
foreach (var a in value.Elements.Select(e => e as IEdmPathExpression))
{
properties.Add(a.Path);
}
if (properties.Any())
{
return properties;
}
}
}
}
return null;
}
}
}

View file

@ -1,46 +0,0 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Vocabularies;
namespace Microsoft.OpenApi.OData.Capabilities
{
/// <summary>
/// Base class the supported restrictions.
/// </summary>
internal abstract class SupportedRestrictions : CapabilitiesRestrictions
{
/// <summary>
/// Get the Supported boolean value.
/// </summary>
public bool? Supported { get; protected set; }
/// <summary>
/// Test the target supports the corresponding restriction.
/// </summary>
/// <returns>True/false.</returns>
public bool IsSupported => Supported == null || Supported.Value == true;
protected override bool Initialize(IEdmVocabularyAnnotation annotation)
{
if (annotation == null ||
annotation.Value == null ||
annotation.Value.ExpressionKind != EdmExpressionKind.BooleanConstant)
{
return false;
}
// supported
IEdmBooleanConstantExpression boolConstant = (IEdmBooleanConstantExpression)annotation.Value;
if (boolConstant != null)
{
Supported = boolConstant.Value;
}
return true;
}
}
}

View file

@ -4,6 +4,7 @@
// ------------------------------------------------------------
using System;
using Microsoft.OpenApi.OData.Vocabulary;
namespace Microsoft.OpenApi.OData.Common
{
@ -12,6 +13,23 @@ namespace Microsoft.OpenApi.OData.Common
/// </summary>
public static class Utils
{
/// <summary>
/// Get the term qualified name when using the type of <typeparamref name="T"/>
/// </summary>
/// <typeparam name="T">The type of the term.</typeparam>
/// <returns>The qualified name.</returns>
public static string GetTermQualifiedName<T>()
{
object[] attributes = typeof(T).GetCustomAttributes(typeof(TermAttribute), false);
if (attributes == null && attributes.Length == 0)
{
return null;
}
TermAttribute term = (TermAttribute)attributes[0];
return term.QualifiedName;
}
/// <summary>
/// Upper the first character of the string.
/// </summary>

View file

@ -1,18 +0,0 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
namespace Microsoft.OpenApi.OData.Capabilities
{
/// <summary>
/// Complex type: Org.OData.Capabilities.V1.ComplexExampleValue.
/// </summary>
internal class ComplexExampleValue : ExampleValue
{
/// <summary>
/// Gets the Example value for the custom parameter
/// </summary>
public object Value { get; private set; }
}
}

View file

@ -1,18 +0,0 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
namespace Microsoft.OpenApi.OData.Capabilities
{
/// <summary>
/// Complex type: Org.OData.Capabilities.V1.EntityExampleValue.
/// </summary>
internal class EntityExampleValue : ExampleValue
{
/// <summary>
/// Gets the Example value for the custom parameter
/// </summary>
public object Value { get; private set; }
}
}

View file

@ -1,18 +0,0 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
namespace Microsoft.OpenApi.OData.Capabilities
{
/// <summary>
/// Complex type: Org.OData.Capabilities.V1.ExternalExampleValue.
/// </summary>
internal class ExternalExampleValue : ExampleValue
{
/// <summary>
/// Gets the Url reference to the value in its literal format
/// </summary>
public string ExternalValue { get; set; }
}
}

View file

@ -3,64 +3,295 @@
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Vocabulary;
using Microsoft.OpenApi.OData.Vocabulary.Authorization;
namespace Microsoft.OpenApi.OData.Edm
{
/// <summary>
/// Vocabulary Annotation Extension methods for <see cref="IEdmModel"/>
/// </summary>
public static class EdmAnnotationExtensions
internal static class EdmVocabularyAnnotationExtensions
{
private static IDictionary<IEdmVocabularyAnnotatable, IDictionary<string, object>> _cachedAnnotations;
private static IEdmModel _savedModel = null; // if diffenent model, the cache will be cleaned.
private static object _objectLock = new object();
/// <summary>
/// Gets the vocabulary annotations from a target annotatable.
/// Gets the boolean term value for the given <see cref="IEdmVocabularyAnnotatable"/>.
/// </summary>
/// <param name="model">The model referenced to.</param>
/// <param name="target">The target Annotatable to find annotation</param>
/// <returns>The annotations or null.</returns>
public static IEnumerable<IEdmVocabularyAnnotation> GetVocabularyAnnotations(this IEdmModel model,
IEdmVocabularyAnnotatable target, string qualifiedName)
/// <param name="model">The Edm model.</param>
/// <param name="target">The Edm target.</param>
/// <param name="qualifiedName">The Term qualified name.</param>
/// <returns>Null or the boolean value for this annotation.</returns>
public static bool? GetBoolean(this IEdmModel model, IEdmVocabularyAnnotatable target, string qualifiedName)
{
Utils.CheckArgumentNull(model, nameof(model));
Utils.CheckArgumentNull(target, nameof(target));
Utils.CheckArgumentNull(qualifiedName, nameof(qualifiedName));
IEdmTerm term = model.FindTerm(qualifiedName);
if (term != null)
return GetOrAddCached(model, target, qualifiedName, () =>
{
return model.FindVocabularyAnnotations<IEdmVocabularyAnnotation>(target, term);
}
bool? value = null;
IEdmTerm term = model.FindTerm(qualifiedName);
if (term != null)
{
value = model.GetBoolean(target, term);
if (value != null)
{
return value;
}
else
{
// Note: Graph has a lot of annotations applied to the type, not to the navigation source.
// Here's a work around to retrieve these annotations from type if we can't find it from navigation source.
// It's the same reason for belows
IEdmNavigationSource navigationSource = target as IEdmNavigationSource;
if (navigationSource != null)
{
IEdmEntityType entityType = navigationSource.EntityType();
value = model.GetBoolean(entityType, term);
}
}
}
return Enumerable.Empty<IEdmVocabularyAnnotation>();
return value;
});
}
/// <summary>
/// Gets the vocabulary annotation from a target annotatable.
/// Gets the string term value for the given <see cref="IEdmVocabularyAnnotatable"/>.
/// </summary>
/// <param name="model">The model referenced to.</param>
/// <param name="target">The target Annotatable to find annotation</param>
/// <returns>The annotation or null.</returns>
public static IEdmVocabularyAnnotation GetVocabularyAnnotation(this IEdmModel model, IEdmVocabularyAnnotatable target, string qualifiedName)
/// <param name="model">The Edm model.</param>
/// <param name="target">The Edm target.</param>
/// <param name="qualifiedName">The Term qualified name.</param>
/// <returns>Null or the string value for this annotation.</returns>
public static string GetString(this IEdmModel model, IEdmVocabularyAnnotatable target, string qualifiedName)
{
Utils.CheckArgumentNull(model, nameof(model));
Utils.CheckArgumentNull(target, nameof(target));
Utils.CheckArgumentNull(qualifiedName, nameof(qualifiedName));
IEdmTerm term = model.FindTerm(qualifiedName);
if (term != null)
return GetOrAddCached(model, target, qualifiedName, () =>
{
IEdmVocabularyAnnotation annotation = model.FindVocabularyAnnotations<IEdmVocabularyAnnotation>(target, term).FirstOrDefault();
if (annotation != null)
string value = null;
IEdmTerm term = model.FindTerm(qualifiedName);
if (term != null)
{
return annotation;
value = model.GetString(target, term);
if (value != null)
{
return value;
}
else
{
IEdmNavigationSource navigationSource = target as IEdmNavigationSource;
if (navigationSource != null)
{
IEdmEntityType entityType = navigationSource.EntityType();
value = model.GetString(entityType, term);
}
}
}
}
return null;
return value;
});
}
/// <summary>
/// Gets the record value (a complex type) for the given <see cref="IEdmVocabularyAnnotatable"/>.
/// </summary>
/// <typeparam name="T">The CLR mapping type.</typeparam>
/// <typeparam name="T">The CLR mapping type.</typeparam>
/// <param name="model">The Edm model.</param>
/// <returns>Null or the record value (a complex type) for this annotation.</returns>
public static T GetRecord<T>(this IEdmModel model, IEdmVocabularyAnnotatable target)
where T : IRecord, new()
{
string qualifiedName = Utils.GetTermQualifiedName<T>();
return model.GetRecord<T>(target, qualifiedName);
}
/// <summary>
/// Gets the record value (a complex type) for the given <see cref="IEdmVocabularyAnnotatable"/>.
/// </summary>
/// <typeparam name="T">The CLR mapping type.</typeparam>
/// <param name="model">The Edm model.</param>
/// <param name="target">The Edm target.</param>
/// <param name="qualifiedName">The Term qualified name.</param>
/// <returns>Null or the record value (a complex type) for this annotation.</returns>
public static T GetRecord<T>(this IEdmModel model, IEdmVocabularyAnnotatable target, string qualifiedName)
where T : IRecord, new()
{
Utils.CheckArgumentNull(model, nameof(model));
Utils.CheckArgumentNull(target, nameof(target));
Utils.CheckArgumentNull(qualifiedName, nameof(qualifiedName));
return GetOrAddCached(model, target, qualifiedName, () =>
{
T value = default;
IEdmTerm term = model.FindTerm(qualifiedName);
if (term != null)
{
value = model.GetRecord<T>(target, term);
if (value != null)
{
return value;
}
else
{
IEdmNavigationSource navigationSource = target as IEdmNavigationSource;
if (navigationSource != null)
{
IEdmEntityType entityType = navigationSource.EntityType();
value = model.GetRecord<T>(entityType, term);
}
}
}
return value;
});
}
/// <summary>
/// Gets the collection of string term value for the given <see cref="IEdmVocabularyAnnotatable"/>.
/// </summary>
/// <param name="model">The Edm model.</param>
/// <param name="target">The Edm target.</param>
/// <param name="qualifiedName">The Term qualified name.</param>
/// <returns>Null or the collection of string value for this annotation.</returns>
public static IEnumerable<string> GetCollection(this IEdmModel model, IEdmVocabularyAnnotatable target, string qualifiedName)
{
Utils.CheckArgumentNull(model, nameof(model));
Utils.CheckArgumentNull(target, nameof(target));
Utils.CheckArgumentNull(qualifiedName, nameof(qualifiedName));
return GetOrAddCached(model, target, qualifiedName, () =>
{
IEnumerable<string> value = null;
IEdmTerm term = model.FindTerm(qualifiedName);
if (term != null)
{
value = model.GetCollection(target, term);
if (value != null)
{
return value;
}
else
{
IEdmNavigationSource navigationSource = target as IEdmNavigationSource;
if (navigationSource != null)
{
IEdmEntityType entityType = navigationSource.EntityType();
value = model.GetCollection(entityType, term);
}
}
}
return value;
});
}
/// <summary>
/// Gets the collection of record value (a complex type) for the given <see cref="IEdmVocabularyAnnotatable"/>.
/// </summary>
/// <typeparam name="T">The CLR mapping type.</typeparam>
/// <param name="model">The Edm model.</param>
/// <param name="target">The Edm target.</param>
/// <returns>Null or the colllection of record value (a complex type) for this annotation.</returns>
public static IEnumerable<T> GetCollection<T>(this IEdmModel model, IEdmVocabularyAnnotatable target)
where T : IRecord, new()
{
Utils.CheckArgumentNull(model, nameof(model));
Utils.CheckArgumentNull(target, nameof(target));
string qualifiedName = Utils.GetTermQualifiedName<T>();
return GetCollection<T>(model, target, qualifiedName);
}
/// <summary>
/// Gets the collection of record value (a complex type) for the given <see cref="IEdmVocabularyAnnotatable"/>.
/// </summary>
/// <typeparam name="T">The CLR mapping type.</typeparam>
/// <param name="model">The Edm model.</param>
/// <param name="target">The Edm target.</param>
/// <param name="qualifiedName">The Term qualified name.</param>
/// <returns>Null or the colllection of record value (a complex type) for this annotation.</returns>
public static IEnumerable<T> GetCollection<T>(this IEdmModel model, IEdmVocabularyAnnotatable target, string qualifiedName)
where T : IRecord, new()
{
Utils.CheckArgumentNull(model, nameof(model));
Utils.CheckArgumentNull(target, nameof(target));
Utils.CheckArgumentNull(qualifiedName, nameof(qualifiedName));
return GetOrAddCached(model, target, qualifiedName, () =>
{
IEnumerable<T> value = null;
IEdmTerm term = model.FindTerm(qualifiedName);
if (term != null)
{
value = model.GetCollection<T>(target, term);
if (value != null)
{
return value;
}
else
{
IEdmNavigationSource navigationSource = target as IEdmNavigationSource;
if (navigationSource != null)
{
IEdmEntityType entityType = navigationSource.EntityType();
value = model.GetCollection<T>(entityType, term);
}
}
}
return value;
});
}
/// <summary>
/// Create the corresponding Authorization object.
/// </summary>
/// <param name="record">The input record.</param>
/// <returns>The created <see cref="Authorization"/> object.</returns>
public static IEnumerable<Authorization> GetAuthorizations(this IEdmModel model, IEdmVocabularyAnnotatable target)
{
Utils.CheckArgumentNull(model, nameof(model));
Utils.CheckArgumentNull(target, nameof(target));
return GetOrAddCached(model, target, AuthorizationConstants.Authorizations, () =>
{
IEdmTerm term = model.FindTerm(AuthorizationConstants.Authorizations);
if (term != null)
{
IEdmVocabularyAnnotation annotation = model.FindVocabularyAnnotations<IEdmVocabularyAnnotation>(target, term).FirstOrDefault();
if (annotation != null && annotation.Value != null && annotation.Value.ExpressionKind == EdmExpressionKind.Collection)
{
IEdmCollectionExpression collection = (IEdmCollectionExpression)annotation.Value;
if (collection.Elements != null)
{
return collection.Elements.Select(e =>
{
Debug.Assert(e.ExpressionKind == EdmExpressionKind.Record);
IEdmRecordExpression recordExpression = (IEdmRecordExpression)e;
Authorization auth = Authorization.CreateAuthorization(recordExpression);
return auth;
});
}
}
}
return null;
});
}
/// <summary>
@ -83,5 +314,199 @@ namespace Microsoft.OpenApi.OData.Edm
return null;
}
private static T GetOrAddCached<T>(this IEdmModel model, IEdmVocabularyAnnotatable target, string qualifiedName, Func<T> createFunc)
{
if (model == null || target == null)
{
return default;
}
lock (_objectLock)
{
if (!ReferenceEquals(_savedModel, model))
{
if (_cachedAnnotations != null)
{
_cachedAnnotations.Clear();
}
_savedModel = model;
}
if (_cachedAnnotations == null)
{
_cachedAnnotations = new Dictionary<IEdmVocabularyAnnotatable, IDictionary<string, object>>();
}
object restriction;
if (_cachedAnnotations.TryGetValue(target, out IDictionary<string, object> value))
{
// Here means we visited target before and we are sure that the value is not null.
if (value.TryGetValue(qualifiedName, out restriction))
{
T ret = (T)restriction;
return ret;
}
else
{
T ret = createFunc();
value[qualifiedName] = ret;
return ret;
}
}
// It's first time to query this target, create new dictionary and restriction.
value = new Dictionary<string, object>();
_cachedAnnotations[target] = value;
T newAnnotation = createFunc();
value[qualifiedName] = newAnnotation;
return newAnnotation;
}
}
private static bool? GetBoolean(this IEdmModel model, IEdmVocabularyAnnotatable target, IEdmTerm term)
{
Debug.Assert(model != null);
Debug.Assert(target != null);
Debug.Assert(term != null);
IEdmVocabularyAnnotation annotation = model.FindVocabularyAnnotations<IEdmVocabularyAnnotation>(target, term).FirstOrDefault();
if (annotation != null && annotation.Value != null && annotation.Value.ExpressionKind == EdmExpressionKind.BooleanConstant)
{
IEdmBooleanConstantExpression boolConstant = (IEdmBooleanConstantExpression)annotation.Value;
if (boolConstant != null)
{
return boolConstant.Value;
}
}
return null;
}
private static string GetString(this IEdmModel model, IEdmVocabularyAnnotatable target, IEdmTerm term)
{
Debug.Assert(model != null);
Debug.Assert(target != null);
Debug.Assert(term != null);
IEdmVocabularyAnnotation annotation = model.FindVocabularyAnnotations<IEdmVocabularyAnnotation>(target, term).FirstOrDefault();
if (annotation != null && annotation.Value != null && annotation.Value.ExpressionKind == EdmExpressionKind.StringConstant)
{
IEdmStringConstantExpression stringConstant = (IEdmStringConstantExpression)annotation.Value;
return stringConstant.Value;
}
return null;
}
private static IEnumerable<string> GetCollection(this IEdmModel model, IEdmVocabularyAnnotatable target, IEdmTerm term)
{
Debug.Assert(model != null);
Debug.Assert(target != null);
Debug.Assert(term != null);
IEdmVocabularyAnnotation annotation = model.FindVocabularyAnnotations<IEdmVocabularyAnnotation>(target, term).FirstOrDefault();
if (annotation != null && annotation.Value != null && annotation.Value.ExpressionKind == EdmExpressionKind.Collection)
{
IEdmCollectionExpression collection = (IEdmCollectionExpression)annotation.Value;
if (collection.Elements != null)
{
return collection.Elements.Select(e => ((IEdmStringConstantExpression)e).Value);
}
}
return null;
}
private static T GetRecord<T>(this IEdmModel model, IEdmVocabularyAnnotatable target, IEdmTerm term)
where T : IRecord, new()
{
Debug.Assert(model != null);
Debug.Assert(target != null);
Debug.Assert(term != null);
IEdmVocabularyAnnotation annotation = model.FindVocabularyAnnotations<IEdmVocabularyAnnotation>(target, term).FirstOrDefault();
if (annotation != null && annotation.Value != null && annotation.Value.ExpressionKind == EdmExpressionKind.Record)
{
IEdmRecordExpression recordExpression = (IEdmRecordExpression)annotation.Value;
T newRecord = new T();
newRecord.Initialize(recordExpression);
return newRecord;
}
return default;
}
private static IEnumerable<T> GetCollection<T>(this IEdmModel model, IEdmVocabularyAnnotatable target, IEdmTerm term)
where T : IRecord, new()
{
Debug.Assert(model != null);
Debug.Assert(target != null);
Debug.Assert(term != null);
IEdmVocabularyAnnotation annotation = model.FindVocabularyAnnotations<IEdmVocabularyAnnotation>(target, term).FirstOrDefault();
if (annotation != null && annotation.Value != null && annotation.Value.ExpressionKind == EdmExpressionKind.Collection)
{
IEdmCollectionExpression collection = (IEdmCollectionExpression)annotation.Value;
if (collection.Elements != null)
{
return collection.Elements.Select(e =>
{
Debug.Assert(e.ExpressionKind == EdmExpressionKind.Record);
IEdmRecordExpression recordExpression = (IEdmRecordExpression)e;
T newRecord = new T();
newRecord.Initialize(recordExpression);
return newRecord;
});
}
}
return null;
}
private static Type GetTypeInfo<T>(string fullTypeName) where T : IRecord
{
object[] attributes = typeof(T).GetCustomAttributes(typeof(SubTypeAttribute), false);
SubTypeAttribute subType = attributes.OfType<SubTypeAttribute>().FirstOrDefault(s => s.FullName == fullTypeName);
if (subType == null)
{
return typeof(T);
}
return subType.Type;
#if false
foreach (var item in collection.Elements)
{
Debug.Assert(item.ExpressionKind == EdmExpressionKind.Record);
IEdmRecordExpression record = (IEdmRecordExpression)item;
if (record.DeclaredType == null)
{
T newRecord = new T();
newRecord.Initialize(record);
yield return newRecord;
}
else
{
IEdmComplexType complexType = record.DeclaredType.Definition as IEdmComplexType;
Debug.Assert(complexType != null);
string fullTypeName = complexType.FullTypeName();
Type subType = GetTypeInfo<T>(fullTypeName);
IRecord sub = Activator.CreateInstance(subType) as IRecord;
Debug.Assert(typeof(T).IsAssignableFrom(subType));
sub.Initialize(record);
yield return (T)sub;
}
}
// return Activator.CreateInstance(subType.Type) as T2;
#endif
}
}
}

View file

@ -6,15 +6,12 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.OData.Annotations;
using Microsoft.OpenApi.OData.Authorizations;
using Microsoft.OpenApi.OData.Capabilities;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Generator;
using Microsoft.OpenApi.OData.Operation;
using Microsoft.OpenApi.OData.PathItem;
using Microsoft.OpenApi.OData.Vocabulary.Capabilities;
namespace Microsoft.OpenApi.OData.Edm
{
@ -25,8 +22,6 @@ namespace Microsoft.OpenApi.OData.Edm
{
private IEnumerable<ODataPath> _allPaths;
private IODataPathProvider _pathProvider;
private HttpRequestProvider _httpRequestProvider;
private AuthorizationProvider _authorizationProvider;
/// <summary>
/// Initializes a new instance of <see cref="ODataContext"/> class.
@ -54,8 +49,6 @@ namespace Microsoft.OpenApi.OData.Edm
OperationHanderProvider = new OperationHandlerProvider();
PathItemHanderProvider = new PathItemHandlerProvider();
_authorizationProvider = new AuthorizationProvider(model);
_httpRequestProvider = new HttpRequestProvider(model);
_pathProvider = new ODataPathProvider();
if (settings.EnableKeyAsSegment != null)
@ -68,10 +61,10 @@ namespace Microsoft.OpenApi.OData.Edm
KeyAsSegment = false;
if (model.EntityContainer != null)
{
var keyAsSegment = model.GetKeyAsSegmentSupported(model.EntityContainer);
var keyAsSegment = model.GetBoolean(model.EntityContainer, CapabilitiesConstants.KeyAsSegmentSupported);
if (keyAsSegment != null)
{
KeyAsSegment = keyAsSegment.IsSupported;
KeyAsSegment = keyAsSegment.Value;
}
}
}
@ -139,27 +132,6 @@ namespace Microsoft.OpenApi.OData.Edm
/// </summary>
public IList<OpenApiTag> Tags { get; private set; }
/// <summary>
/// Find the Org.OData.Core.V1.HttpRequest for a given target.
/// </summary>
/// <param name="target">The target.</param>
/// <param name="method">The method name.</param>
/// <returns>The <see cref="HttpRequest"/> or null.</returns>
public HttpRequest FindRequest(IEdmVocabularyAnnotatable target, string method)
{
return _httpRequestProvider?.GetHttpRequest(target, method);
}
/// <summary>
/// Gets the <see cref="Authorization"/> collections for a given target in the given Edm model.
/// </summary>
/// <param name="target">The Edm target.</param>
/// <returns>The <see cref="Authorization"/> collections.</returns>
public IEnumerable<Authorization> GetAuthorizations(IEdmVocabularyAnnotatable target)
{
return _authorizationProvider?.GetAuthorizations(target);
}
/// <summary>
/// Append tag.
/// </summary>

View file

@ -29,7 +29,7 @@ namespace Microsoft.OpenApi.OData.Edm
public override ODataSegmentKind Kind => ODataSegmentKind.TypeCast;
/// <inheritdoc />
public override string Name { get => EntityType.Name; }
public override string Name { get => EntityType.FullTypeName(); }
/// <inheritdoc />
public override string GetPathItemName(OpenApiConvertSettings settings) => EntityType.FullTypeName();

View file

@ -9,6 +9,7 @@ using System.Linq;
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Vocabulary;
namespace Microsoft.OpenApi.OData.Edm
{
@ -17,6 +18,33 @@ namespace Microsoft.OpenApi.OData.Edm
/// </summary>
internal static class RecordExpressionExtensions
{
/// <summary>
/// Get the integer value from the record using the given property name.
/// </summary>
/// <param name="record">The record expression.</param>
/// <param name="propertyName">The property name.</param>
/// <returns>The integer value or null.</returns>
public static long? GetInteger(this IEdmRecordExpression record, string propertyName)
{
Utils.CheckArgumentNull(record, nameof(record));
Utils.CheckArgumentNull(propertyName, nameof(propertyName));
if (record.Properties != null)
{
IEdmPropertyConstructor property = record.Properties.FirstOrDefault(e => e.Name == propertyName);
if (property != null)
{
IEdmIntegerConstantExpression value = property.Value as IEdmIntegerConstantExpression;
if (value != null)
{
return value.Value;
}
}
}
return null;
}
/// <summary>
/// Gets the string value of a property in the given record expression.
/// </summary>
@ -105,6 +133,35 @@ namespace Microsoft.OpenApi.OData.Edm
return null;
}
/// <summary>
/// Get the collection of <typeparamref name="T"/> from the record using the given property name.
/// </summary>
/// <typeparam name="T">The element type.</typeparam>
/// <param name="record">The record expression.</param>
/// <param name="propertyName">The property name.</param>
/// <param name="elementAction">The element action.</param>
/// <returns>The collection or null.</returns>
public static T GetRecord<T>(this IEdmRecordExpression record, string propertyName)
where T : IRecord, new()
{
Utils.CheckArgumentNull(record, nameof(record));
Utils.CheckArgumentNull(propertyName, nameof(propertyName));
IEdmPropertyConstructor property = record.Properties.FirstOrDefault(e => e.Name == propertyName);
if (property != null)
{
IEdmRecordExpression recordValue = property.Value as IEdmRecordExpression;
if (recordValue != null)
{
T a = new T();
a.Initialize(recordValue);
return a;
}
}
return default;
}
/// <summary>
/// Get the property path from the record using the given property name.
/// </summary>
@ -152,9 +209,9 @@ namespace Microsoft.OpenApi.OData.Edm
if (value != null && value.Elements != null)
{
IList<string> properties = new List<string>();
foreach (var a in value.Elements.Select(e => e as IEdmPathExpression))
foreach (var path in value.Elements.Select(e => e as IEdmPathExpression))
{
properties.Add(a.Path);
properties.Add(path.Path);
}
if (properties.Any())
@ -168,6 +225,8 @@ namespace Microsoft.OpenApi.OData.Edm
return null;
}
/// <summary>
/// Get the collection of <typeparamref name="T"/> from the record using the given property name.
/// </summary>
@ -176,8 +235,8 @@ namespace Microsoft.OpenApi.OData.Edm
/// <param name="propertyName">The property name.</param>
/// <param name="elementAction">The element action.</param>
/// <returns>The collection or null.</returns>
public static IList<T> GetCollection<T>(this IEdmRecordExpression record, string propertyName, Action<T, IEdmExpression> elementAction)
where T: new()
public static IList<T> GetCollection<T>(this IEdmRecordExpression record, string propertyName, Action<T, IEdmRecordExpression> elementAction)
where T: class, new()
{
Utils.CheckArgumentNull(record, nameof(record));
Utils.CheckArgumentNull(propertyName, nameof(propertyName));
@ -189,7 +248,7 @@ namespace Microsoft.OpenApi.OData.Edm
if (collection != null && collection.Elements != null)
{
IList<T> items = new List<T>();
foreach (var item in collection.Elements)
foreach (IEdmRecordExpression item in collection.Elements.OfType<IEdmRecordExpression>())
{
T a = new T();
elementAction(a, item);
@ -258,5 +317,40 @@ namespace Microsoft.OpenApi.OData.Edm
return null;
}
/// <summary>
/// Get the collection of <typeparamref name="T"/> from the record using the given property name.
/// </summary>
/// <typeparam name="T">The element type.</typeparam>
/// <param name="record">The record expression.</param>
/// <param name="propertyName">The property name.</param>
/// <param name="elementAction">The element action.</param>
/// <returns>The collection or null.</returns>
public static IList<T> GetCollection<T>(this IEdmRecordExpression record, string propertyName)
where T : IRecord, new()
{
Utils.CheckArgumentNull(record, nameof(record));
Utils.CheckArgumentNull(propertyName, nameof(propertyName));
IEdmPropertyConstructor property = record.Properties.FirstOrDefault(e => e.Name == propertyName);
if (property != null)
{
IEdmCollectionExpression collection = property.Value as IEdmCollectionExpression;
if (collection != null && collection.Elements != null)
{
IList<T> items = new List<T>();
foreach (IEdmRecordExpression item in collection.Elements.OfType<IEdmRecordExpression>())
{
T a = new T();
a.Initialize(item);
items.Add(a);
}
return items;
}
}
return null;
}
}
}

View file

@ -9,9 +9,10 @@ using Microsoft.OData.Edm;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Capabilities;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Edm;
using Microsoft.OpenApi.OData.Vocabulary;
using Microsoft.OpenApi.OData.Vocabulary.Capabilities;
namespace Microsoft.OpenApi.OData.Generator
{
@ -178,8 +179,8 @@ namespace Microsoft.OpenApi.OData.Generator
Utils.CheckArgumentNull(context, nameof(context));
Utils.CheckArgumentNull(target, nameof(target));
TopSupported top = context.Model.GetTopSupported(target);
if (top == null || top.IsSupported)
bool? top = context.Model.GetTopSupported(target);
if (top == null || top.Value)
{
return new OpenApiParameter
{
@ -201,8 +202,8 @@ namespace Microsoft.OpenApi.OData.Generator
Utils.CheckArgumentNull(context, nameof(context));
Utils.CheckArgumentNull(target, nameof(target));
SkipSupported skip = context.Model.GetSkipSupported(target);
if (skip == null || skip.IsSupported)
bool? skip = context.Model.GetSkipSupported(target);
if (skip == null || skip.Value)
{
return new OpenApiParameter
{
@ -224,7 +225,7 @@ namespace Microsoft.OpenApi.OData.Generator
Utils.CheckArgumentNull(context, nameof(context));
Utils.CheckArgumentNull(target, nameof(target));
SearchRestrictions search = context.Model.GetSearchRestrictions(target);
SearchRestrictionsType search = context.Model.GetRecord<SearchRestrictionsType>(target, CapabilitiesConstants.SearchRestrictions);
if (search == null || search.IsSearchable)
{
return new OpenApiParameter
@ -247,7 +248,7 @@ namespace Microsoft.OpenApi.OData.Generator
Utils.CheckArgumentNull(context, nameof(context));
Utils.CheckArgumentNull(target, nameof(target));
CountRestrictions count = context.Model.GetCountRestrictions(target);
CountRestrictionsType count = context.Model.GetRecord<CountRestrictionsType>(target, CapabilitiesConstants.CountRestrictions);
if (count == null || count.IsCountable)
{
return new OpenApiParameter
@ -270,7 +271,7 @@ namespace Microsoft.OpenApi.OData.Generator
Utils.CheckArgumentNull(context, nameof(context));
Utils.CheckArgumentNull(target, nameof(target));
FilterRestrictions filter = context.Model.GetFilterRestrictions(target);
FilterRestrictionsType filter = context.Model.GetRecord<FilterRestrictionsType>(target, CapabilitiesConstants.FilterRestrictions);
if (filter == null || filter.IsFilterable)
{
return new OpenApiParameter
@ -318,7 +319,7 @@ namespace Microsoft.OpenApi.OData.Generator
Utils.CheckArgumentNull(target, nameof(target));
Utils.CheckArgumentNull(entityType, nameof(entityType));
SortRestrictions sort = context.Model.GetSortRestrictions(target);
SortRestrictionsType sort = context.Model.GetRecord<SortRestrictionsType>(target, CapabilitiesConstants.SortRestrictions);
if (sort != null && !sort.IsSortable)
{
return null;
@ -407,7 +408,7 @@ namespace Microsoft.OpenApi.OData.Generator
Utils.CheckArgumentNull(target, nameof(target));
Utils.CheckArgumentNull(entityType, nameof(entityType));
NavigationRestrictions navigation = context.Model.GetNavigationRestrictions(target);
NavigationRestrictionsType navigation = context.Model.GetRecord<NavigationRestrictionsType>(target, CapabilitiesConstants.NavigationRestrictions);
if (navigation != null && !navigation.IsNavigable)
{
return null;
@ -486,7 +487,7 @@ namespace Microsoft.OpenApi.OData.Generator
Utils.CheckArgumentNull(target, nameof(target));
Utils.CheckArgumentNull(entityType, nameof(entityType));
ExpandRestrictions expand = context.Model.GetExpandRestrictions(target);
ExpandRestrictionsType expand = context.Model.GetRecord<ExpandRestrictionsType>(target, CapabilitiesConstants.ExpandRestrictions);
if (expand != null && !expand.IsExpandable)
{
return null;

View file

@ -3,11 +3,13 @@
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
using System.Linq;
using System.Collections.Generic;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Authorizations;
using Microsoft.OpenApi.OData.Edm;
using Microsoft.OpenApi.OData.Vocabulary.Authorization;
using Microsoft.OpenApi.OData.Vocabulary.Capabilities;
namespace Microsoft.OpenApi.OData.Generator
{
@ -47,5 +49,37 @@ namespace Microsoft.OpenApi.OData.Generator
}
}
}
/// <summary>
/// Create the list of <see cref="OpenApiSecurityRequirement"/> object.
/// </summary>
/// <param name="context">The OData to Open API context.</param>
/// <param name="securitySchemes">The securitySchemes.</param>
/// <returns>The created <see cref="OpenApiSecurityRequirement"/> collection.</returns>
public static IEnumerable<OpenApiSecurityRequirement> CreateSecurityRequirements(this ODataContext context,
IList<PermissionType> permissions)
{
Utils.CheckArgumentNull(context, nameof(context));
if (permissions != null)
{
foreach (PermissionType permission in permissions)
{
yield return new OpenApiSecurityRequirement
{
[
new OpenApiSecurityScheme
{
Reference = new OpenApiReference
{
Type = ReferenceType.SecurityScheme,
Id = permission.Scheme.Authorization
}
}
] = new List<string>(permission.Scopes?.Select(c => c.Scope) ?? new List<string>())
};
}
}
}
}
}

View file

@ -8,9 +8,9 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.OData.Authorizations;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
using Microsoft.OpenApi.OData.Vocabulary.Authorization;
namespace Microsoft.OpenApi.OData.Generator
{
@ -35,7 +35,12 @@ namespace Microsoft.OpenApi.OData.Generator
}
IDictionary<string, OpenApiSecurityScheme> securitySchemes = new Dictionary<string, OpenApiSecurityScheme>();
var authorizations = context.GetAuthorizations(context.EntityContainer);
var authorizations = context.Model.GetAuthorizations(context.EntityContainer);
if (authorizations == null)
{
return securitySchemes;
}
foreach (var authorization in authorizations)
{
OpenApiSecurityScheme scheme = new OpenApiSecurityScheme

View file

@ -0,0 +1,137 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
using System;
using System.Linq;
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Properties;
namespace Microsoft.OpenApi.OData
{
/// <summary>
/// Extension methods for <see cref="IEdmExpression"/>.
/// </summary>
internal static class IEdmExpressionExtensions
{
/// <summary>
/// Convert an <see cref="IEdmExpression"/> to a <see cref="ODataValue"/>
/// </summary>
/// <param name="expression">The <see cref="IEdmExpression"/>.</param>
/// <returns>The null or <see cref="ODataValue"/>.</returns>
public static ODataValue Convert(this IEdmExpression expression)
{
if (expression == null)
{
return null;
}
switch (expression.ExpressionKind)
{
case EdmExpressionKind.BinaryConstant:
IEdmBinaryConstantExpression binaryConstant = (IEdmBinaryConstantExpression)expression;
return new ODataPrimitiveValue(binaryConstant.Value)
{
TypeReference = EdmCoreModel.Instance.GetBinary(false)
};
case EdmExpressionKind.BooleanConstant:
IEdmBooleanConstantExpression booleanConstant = (IEdmBooleanConstantExpression)expression;
return new ODataPrimitiveValue(booleanConstant.Value)
{
TypeReference = EdmCoreModel.Instance.GetBoolean(false)
};
case EdmExpressionKind.DateTimeOffsetConstant:
IEdmDateTimeOffsetConstantExpression dateTimeOffsetConstant = (IEdmDateTimeOffsetConstantExpression)expression;
return new ODataPrimitiveValue(dateTimeOffsetConstant.Value)
{
TypeReference = EdmCoreModel.Instance.GetDateTimeOffset(false)
};
case EdmExpressionKind.DecimalConstant:
IEdmDecimalConstantExpression decimalConstant = (IEdmDecimalConstantExpression)expression;
return new ODataPrimitiveValue(decimalConstant.Value)
{
TypeReference = EdmCoreModel.Instance.GetDecimal(false)
};
case EdmExpressionKind.FloatingConstant:
IEdmFloatingConstantExpression floatConstant = (IEdmFloatingConstantExpression)expression;
return new ODataPrimitiveValue(floatConstant.Value)
{
TypeReference = EdmCoreModel.Instance.GetDouble(false)
};
case EdmExpressionKind.GuidConstant:
IEdmGuidConstantExpression guidConstant = (IEdmGuidConstantExpression)expression;
return new ODataPrimitiveValue(guidConstant.Value)
{
TypeReference = EdmCoreModel.Instance.GetGuid(false)
};
case EdmExpressionKind.IntegerConstant:
IEdmIntegerConstantExpression integerConstant = (IEdmIntegerConstantExpression)expression;
return new ODataPrimitiveValue(integerConstant.Value)
{
TypeReference = EdmCoreModel.Instance.GetInt64(false)
};
case EdmExpressionKind.StringConstant:
IEdmStringConstantExpression stringConstant = (IEdmStringConstantExpression)expression;
return new ODataPrimitiveValue(stringConstant.Value)
{
TypeReference = EdmCoreModel.Instance.GetString(false)
};
case EdmExpressionKind.DurationConstant:
IEdmDurationConstantExpression durationConstant = (IEdmDurationConstantExpression)expression;
return new ODataPrimitiveValue(durationConstant.Value)
{
TypeReference = EdmCoreModel.Instance.GetDuration(false)
};
case EdmExpressionKind.TimeOfDayConstant:
IEdmTimeOfDayConstantExpression timeOfDayConstant = (IEdmTimeOfDayConstantExpression)expression;
return new ODataPrimitiveValue(timeOfDayConstant.Value)
{
TypeReference = EdmCoreModel.Instance.GetTimeOfDay(false)
};
case EdmExpressionKind.DateConstant:
IEdmDateConstantExpression dateConstant = (IEdmDateConstantExpression)expression;
return new ODataPrimitiveValue(dateConstant.Value)
{
TypeReference = EdmCoreModel.Instance.GetDate(false)
};
case EdmExpressionKind.Record:
IEdmRecordExpression recordExpression = (IEdmRecordExpression)expression;
return new ODataResourceValue
{
TypeReference = recordExpression.DeclaredType,
Properties = recordExpression.Properties.ToDictionary(p => p.Name, p => p.Value.Convert())
};
case EdmExpressionKind.Collection:
IEdmCollectionExpression collectionExpression = (IEdmCollectionExpression)expression;
ODataCollectValue collectionValue = new ODataCollectValue
{
TypeReference = collectionExpression.DeclaredType
};
collectionValue.Elements = collectionExpression.Elements.Select(e => e.Convert()).ToList();
return collectionValue;
case EdmExpressionKind.Path:
case EdmExpressionKind.PropertyPath:
case EdmExpressionKind.NavigationPropertyPath:
case EdmExpressionKind.EnumMember:
default:
throw new NotSupportedException(String.Format(SRResource.NotSupportedEdmExpressionKind, expression.ExpressionKind));
}
}
}
}

View file

@ -3,16 +3,15 @@
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
namespace Microsoft.OpenApi.OData.Capabilities
using System.Collections.Generic;
namespace Microsoft.OpenApi.OData
{
/// <summary>
/// Org.OData.Capabilities.V1.TopSupported
/// Represents an OData value.
/// </summary>
internal class TopSupported : SupportedRestrictions
internal class ODataCollectValue : ODataValue
{
/// <summary>
/// The Term type Kind.
/// </summary>
public override CapabilitesTermKind Kind => CapabilitesTermKind.TopSupported;
public IList<ODataValue> Elements { get; set; }
}
}

View file

@ -3,16 +3,12 @@
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
namespace Microsoft.OpenApi.OData.Capabilities
namespace Microsoft.OpenApi.OData
{
/// <summary>
/// Org.OData.Capabilities.V1.SkipSupported
/// Represents an OData complex value.
/// </summary>
internal class SkipSupported : SupportedRestrictions
internal class ODataComplexValue : ODataResourceValue
{
/// <summary>
/// The Term type kind.
/// </summary>
public override CapabilitesTermKind Kind => CapabilitesTermKind.SkipSupported;
}
}

View file

@ -3,16 +3,12 @@
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
namespace Microsoft.OpenApi.OData.Capabilities
namespace Microsoft.OpenApi.OData
{
/// <summary>
/// Org.OData.Capabilities.V1.BatchSupported
/// Represents an OData entity value.
/// </summary>
internal class BatchSupported : SupportedRestrictions
internal class ODataEntityValue : ODataResourceValue
{
/// <summary>
/// The Term type kind.
/// </summary>
public override CapabilitesTermKind Kind => CapabilitesTermKind.BatchSupported;
}
}

View file

@ -3,16 +3,26 @@
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
namespace Microsoft.OpenApi.OData.Capabilities
namespace Microsoft.OpenApi.OData
{
/// <summary>
/// Complex type: Org.OData.Capabilities.V1.PrimitiveExampleValue.
/// Represents an OData primitive value.
/// </summary>
internal class PrimitiveExampleValue : ExampleValue
internal class ODataPrimitiveValue : ODataValue
{
public ODataPrimitiveValue(object value)
{
Value = value;
}
/// <summary>
/// Gets the Example value for the custom parameter
/// Gets the underlying CLR object wrapped by this <see cref="ODataPrimitiveValue"/>.
/// </summary>
public object Value { get; private set; }
public override string ToString()
{
return Value.ToString();
}
}
}

View file

@ -3,16 +3,18 @@
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
namespace Microsoft.OpenApi.OData.Capabilities
using System.Collections.Generic;
namespace Microsoft.OpenApi.OData
{
/// <summary>
/// Org.OData.Capabilities.V1.KeyAsSegmentSupported
/// Represents an OData resource value (complex or entity).
/// </summary>
internal class KeyAsSegmentSupported : SupportedRestrictions
internal class ODataResourceValue : ODataValue
{
/// <summary>
/// The Term type kind.
/// Gets or sets the properties.
/// </summary>
public override CapabilitesTermKind Kind => CapabilitesTermKind.KeyAsSegmentSupported;
public IDictionary<string, ODataValue> Properties { get; set; }
}
}

View file

@ -3,16 +3,18 @@
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
namespace Microsoft.OpenApi.OData.Capabilities
using Microsoft.OData.Edm;
namespace Microsoft.OpenApi.OData
{
/// <summary>
/// Complex type: Org.OData.Capabilities.V1.ExampleValue.
/// Represents an OData value.
/// </summary>
internal class ExampleValue
internal abstract class ODataValue
{
/// <summary>
/// Gets the description of the example value.
/// Gets or set the type reference of this value.
/// </summary>
public string Desciption { get; private set; }
public IEdmTypeReference TypeReference { get; set; }
}
}

View file

@ -31,8 +31,6 @@ namespace Microsoft.OpenApi.OData.Operation
ODataOperationImportSegment operationImportSegment = path.LastSegment as ODataOperationImportSegment;
EdmOperationImport = operationImportSegment.OperationImport;
Request = Context.FindRequest(EdmOperationImport, OperationType.ToString());
}
/// <inheritdoc/>

View file

@ -13,6 +13,7 @@ using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
using Microsoft.OpenApi.OData.Generator;
using Microsoft.OpenApi.OData.Vocabulary.Capabilities;
namespace Microsoft.OpenApi.OData.Operation
{
@ -49,8 +50,6 @@ namespace Microsoft.OpenApi.OData.Operation
EdmOperation = operationSegment.Operation;
HasTypeCast = path.Segments.Any(s => s is ODataTypeCastSegment);
Request = Context.FindRequest(EdmOperation, OperationType.ToString());
}
/// <inheritdoc/>
@ -151,5 +150,45 @@ namespace Microsoft.OpenApi.OData.Operation
base.SetResponses(operation);
}
/// <inheritdoc/>
protected override void SetSecurity(OpenApiOperation operation)
{
IEnumerable<OperationRestrictionType> restrictions = Context.Model.GetCollection<OperationRestrictionType>(EdmOperation, CapabilitiesConstants.OperationRestrictions);
if (restrictions == null || !restrictions.Any())
{
return;
}
// TODO: how to use the collection?
OperationRestrictionType operationRestriction = restrictions.First();
// the Permission should be collection, however current ODL supports the single permission.
// Will update after ODL change.
operation.Security = Context.CreateSecurityRequirements(new[] { operationRestriction.Permission.Scheme }).ToList();
}
/// <inheritdoc/>
protected override void AppendCustomParameters(OpenApiOperation operation)
{
IEnumerable<OperationRestrictionType> restrictions = Context.Model.GetCollection<OperationRestrictionType>(EdmOperation, CapabilitiesConstants.OperationRestrictions);
if (restrictions == null || !restrictions.Any())
{
return;
}
// TODO: how to use the collection?
OperationRestrictionType operationRestriction = restrictions.First();
if (operationRestriction.CustomHeaders != null)
{
AppendCustomParameters(operation.Parameters, operationRestriction.CustomHeaders, ParameterLocation.Header);
}
if (operationRestriction.CustomQueryOptions != null)
{
AppendCustomParameters(operation.Parameters, operationRestriction.CustomQueryOptions, ParameterLocation.Query);
}
}
}
}

View file

@ -3,10 +3,13 @@
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
using System.Linq;
using Microsoft.OData.Edm;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
using Microsoft.OpenApi.OData.Generator;
using Microsoft.OpenApi.OData.Vocabulary.Capabilities;
namespace Microsoft.OpenApi.OData.Operation
{
@ -64,5 +67,37 @@ namespace Microsoft.OpenApi.OData.Operation
base.SetResponses(operation);
}
protected override void SetSecurity(OpenApiOperation operation)
{
DeleteRestrictionsType delete = Context.Model.GetRecord<DeleteRestrictionsType>(EntitySet, CapabilitiesConstants.DeleteRestrictions);
if (delete == null || delete.Permission == null)
{
return;
}
// the Permission should be collection, however current ODL supports the single permission.
// Will update after ODL change.
operation.Security = Context.CreateSecurityRequirements(new[] { delete.Permission.Scheme }).ToList();
}
protected override void AppendCustomParameters(OpenApiOperation operation)
{
DeleteRestrictionsType delete = Context.Model.GetRecord< DeleteRestrictionsType>(EntitySet, CapabilitiesConstants.DeleteRestrictions);
if (delete == null)
{
return;
}
if (delete.CustomHeaders != null)
{
AppendCustomParameters(operation.Parameters, delete.CustomHeaders, ParameterLocation.Header);
}
if (delete.CustomQueryOptions != null)
{
AppendCustomParameters(operation.Parameters, delete.CustomQueryOptions, ParameterLocation.Query);
}
}
}
}

View file

@ -4,10 +4,13 @@
// ------------------------------------------------------------
using System.Collections.Generic;
using System.Linq;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OData.Edm;
using Microsoft.OpenApi.OData.Generator;
using Microsoft.OpenApi.OData.Vocabulary.Capabilities;
using Microsoft.OpenApi.OData.Edm;
namespace Microsoft.OpenApi.OData.Operation
{
@ -92,5 +95,54 @@ namespace Microsoft.OpenApi.OData.Operation
base.SetResponses(operation);
}
protected override void SetSecurity(OpenApiOperation operation)
{
ReadRestrictionsType read = Context.Model.GetRecord<ReadRestrictionsType>(EntitySet, CapabilitiesConstants.ReadRestrictions);
if (read == null)
{
return;
}
ReadRestrictionsBase readBase = read;
if (read.ReadByKeyRestrictions != null)
{
readBase = read.ReadByKeyRestrictions;
}
if (readBase == null && readBase.Permission == null)
{
return;
}
// the Permission should be collection, however current ODL supports the single permission.
// Will update after ODL change.
operation.Security = Context.CreateSecurityRequirements(new[] { readBase.Permission.Scheme }).ToList();
}
protected override void AppendCustomParameters(OpenApiOperation operation)
{
ReadRestrictionsType read = Context.Model.GetRecord<ReadRestrictionsType>(EntitySet, CapabilitiesConstants.ReadRestrictions);
if (read == null)
{
return;
}
ReadRestrictionsBase readBase = read;
if (read.ReadByKeyRestrictions != null)
{
readBase = read.ReadByKeyRestrictions;
}
if (readBase.CustomHeaders != null)
{
AppendCustomParameters(operation.Parameters, readBase.CustomHeaders, ParameterLocation.Header);
}
if (readBase.CustomQueryOptions != null)
{
AppendCustomParameters(operation.Parameters, readBase.CustomQueryOptions, ParameterLocation.Query);
}
}
}
}

View file

@ -4,10 +4,13 @@
// ------------------------------------------------------------
using System.Collections.Generic;
using System.Linq;
using Microsoft.OData.Edm;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
using Microsoft.OpenApi.OData.Generator;
using Microsoft.OpenApi.OData.Vocabulary.Capabilities;
namespace Microsoft.OpenApi.OData.Operation
{
@ -76,5 +79,37 @@ namespace Microsoft.OpenApi.OData.Operation
base.SetResponses(operation);
}
protected override void SetSecurity(OpenApiOperation operation)
{
UpdateRestrictionsType update = Context.Model.GetRecord<UpdateRestrictionsType>(EntitySet, CapabilitiesConstants.UpdateRestrictions);
if (update == null || update.Permission == null)
{
return;
}
// the Permission should be collection, however current ODL supports the single permission.
// Will update after ODL change.
operation.Security = Context.CreateSecurityRequirements(new[] { update.Permission.Scheme }).ToList();
}
protected override void AppendCustomParameters(OpenApiOperation operation)
{
UpdateRestrictionsType update = Context.Model.GetRecord<UpdateRestrictionsType>(EntitySet, CapabilitiesConstants.UpdateRestrictions);
if (update == null)
{
return;
}
if (update.CustomHeaders != null)
{
AppendCustomParameters(operation.Parameters, update.CustomHeaders, ParameterLocation.Header);
}
if (update.CustomQueryOptions != null)
{
AppendCustomParameters(operation.Parameters, update.CustomQueryOptions, ParameterLocation.Query);
}
}
}
}

View file

@ -4,10 +4,13 @@
// ------------------------------------------------------------
using System.Collections.Generic;
using System.Linq;
using Microsoft.OData.Edm;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
using Microsoft.OpenApi.OData.Generator;
using Microsoft.OpenApi.OData.Vocabulary.Capabilities;
namespace Microsoft.OpenApi.OData.Operation
{
@ -158,5 +161,37 @@ namespace Microsoft.OpenApi.OData.Operation
base.SetResponses(operation);
}
protected override void SetSecurity(OpenApiOperation operation)
{
ReadRestrictionsType read = Context.Model.GetRecord<ReadRestrictionsType>(EntitySet, CapabilitiesConstants.ReadRestrictions);
if (read == null || read.Permission == null)
{
return;
}
// the Permission should be collection, however current ODL supports the single permission.
// Will update after ODL change.
operation.Security = Context.CreateSecurityRequirements(new[] { read.Permission.Scheme }).ToList();
}
protected override void AppendCustomParameters(OpenApiOperation operation)
{
ReadRestrictionsType read = Context.Model.GetRecord<ReadRestrictionsType>(EntitySet, CapabilitiesConstants.ReadRestrictions);
if (read == null)
{
return;
}
if (read.CustomHeaders != null)
{
AppendCustomParameters(operation.Parameters, read.CustomHeaders, ParameterLocation.Header);
}
if (read.CustomQueryOptions != null)
{
AppendCustomParameters(operation.Parameters, read.CustomQueryOptions, ParameterLocation.Query);
}
}
}
}

View file

@ -30,8 +30,6 @@ namespace Microsoft.OpenApi.OData.Operation
ODataNavigationSourceSegment navigationSourceSegment = path.FirstSegment as ODataNavigationSourceSegment;
EntitySet = navigationSourceSegment.NavigationSource as IEdmEntitySet;
Request = Context.FindRequest(EntitySet, OperationType.ToString());
}
/// <inheritdoc/>

View file

@ -4,10 +4,13 @@
// ------------------------------------------------------------
using System.Collections.Generic;
using System.Linq;
using Microsoft.OData.Edm;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
using Microsoft.OpenApi.OData.Generator;
using Microsoft.OpenApi.OData.Vocabulary.Capabilities;
namespace Microsoft.OpenApi.OData.Operation
{
@ -102,5 +105,37 @@ namespace Microsoft.OpenApi.OData.Operation
base.SetResponses(operation);
}
protected override void SetSecurity(OpenApiOperation operation)
{
InsertRestrictionsType insert = Context.Model.GetRecord<InsertRestrictionsType>(EntitySet, CapabilitiesConstants.InsertRestrictions);
if (insert == null || insert.Permission == null)
{
return;
}
// the Permission should be collection, however current ODL supports the single permission.
// Will update after ODL change.
operation.Security = Context.CreateSecurityRequirements(new[] { insert.Permission.Scheme }).ToList();
}
protected override void AppendCustomParameters(OpenApiOperation operation)
{
InsertRestrictionsType insert = Context.Model.GetRecord<InsertRestrictionsType>(EntitySet, CapabilitiesConstants.InsertRestrictions);
if (insert == null)
{
return;
}
if (insert.CustomQueryOptions != null)
{
AppendCustomParameters(operation.Parameters, insert.CustomQueryOptions, ParameterLocation.Query);
}
if (insert.CustomHeaders != null)
{
AppendCustomParameters(operation.Parameters, insert.CustomHeaders, ParameterLocation.Header);
}
}
}
}

View file

@ -7,10 +7,10 @@ using System.Collections.Generic;
using System.Linq;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.OData.Annotations;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
using Microsoft.OpenApi.OData.Generator;
using Microsoft.OpenApi.OData.Vocabulary.Capabilities;
namespace Microsoft.OpenApi.OData.Operation
{
@ -68,12 +68,6 @@ namespace Microsoft.OpenApi.OData.Operation
/// </summary>
protected ODataPath Path { get; private set; }
/// <summary>
/// Gets/sets the <see cref="HttpRequest"/>.
/// That will be set in the initialize method.
/// </summary>
protected HttpRequest Request { get; set; }
/// <summary>
/// Initialize the handler.
/// It should be call ahead of in derived class.
@ -88,33 +82,21 @@ namespace Microsoft.OpenApi.OData.Operation
/// </summary>
/// <param name="operation">The <see cref="OpenApiOperation"/>.</param>
protected virtual void SetBasicInfo(OpenApiOperation operation)
{
if (Request != null && Request.Description != null)
{
operation.Summary = Request.Description;
}
}
{ }
/// <summary>
/// Set the security information for <see cref="OpenApiOperation"/>.
/// </summary>
/// <param name="operation">The <see cref="OpenApiOperation"/>.</param>
protected virtual void SetSecurity(OpenApiOperation operation)
{
if (Request != null)
{
operation.Security = Context.CreateSecurityRequirements(Request.SecuritySchemes).ToList();
}
}
{ }
/// <summary>
/// Set the responses information for <see cref="OpenApiOperation"/>.
/// </summary>
/// <param name="operation">The <see cref="OpenApiOperation"/>.</param>
protected virtual void SetResponses(OpenApiOperation operation)
{
AppendHttpResponses(operation);
}
{ }
/// <summary>
/// Set the request body information for <see cref="OpenApiOperation"/>.
@ -168,91 +150,26 @@ namespace Microsoft.OpenApi.OData.Operation
/// <param name="request">The <see cref="HttpRequest"/>.</param>
protected virtual void AppendCustomParameters(OpenApiOperation operation)
{
if (Request == null)
{
return;
}
if (operation.Parameters == null)
{
operation.Parameters = new List<OpenApiParameter>();
}
if (Request.CustomQueryOptions != null)
{
AppendCustomParameters(operation.Parameters, Request.CustomQueryOptions, ParameterLocation.Query);
}
if (Request.CustomHeaders != null)
{
AppendCustomParameters(operation.Parameters, Request.CustomHeaders, ParameterLocation.Header);
}
}
/// <summary>
/// Set the <see cref="HttpRequest"/> annotation for the response.
/// Set the addition annotation for the response.
/// </summary>
/// <param name="operation">The operation.</param>
/// <param name="request">The <see cref="HttpRequest"/>.</param>
protected virtual void AppendHttpResponses(OpenApiOperation operation)
{
if (Request == null || Request.HttpResponses == null || !Request.HttpResponses.Any())
{
return;
}
foreach(var httpResponse in Request.HttpResponses)
{
if (operation.Responses.TryGetValue(httpResponse.ResponseCode, out OpenApiResponse response))
{
if (httpResponse.Description != null)
{
response.Description = httpResponse.Description;
}
if (httpResponse.Examples != null)
{
int index = 1;
foreach (var example in httpResponse.Examples)
{
OpenApiExample ex = new OpenApiExample
{
Description = example.Description
};
if (example is ExternalExample)
{
var externalExample = (ExternalExample)example;
ex.Value = new OpenApiString(externalExample.ExternalValue ?? "N/A");
}
else
{
var inlineExample = (InlineExample)example;
ex.Value = new OpenApiString(inlineExample.InlineValue ?? "N/A");
}
if (ex.Description != null)
{
if (response.Content.TryGetValue(ex.Description, out OpenApiMediaType mediaType))
{
mediaType.Examples.Add("example-" + index++, ex);
}
}
}
}
}
}
}
/// <summary>
/// Sets the custom parameters.
/// </summary>
/// <param name="parameters">The parameters.</param>
/// <param name="headers">The custom parameters.</param>
/// <param name="customParameters">The custom parameters.</param>
/// <param name="location">The parameter location.</param>
private static void AppendCustomParameters(IList<OpenApiParameter> parameters, IList<CustomParameter> headers, ParameterLocation location)
protected static void AppendCustomParameters(IList<OpenApiParameter> parameters, IList<CustomParameter> customParameters, ParameterLocation location)
{
foreach (var param in headers)
foreach (var param in customParameters)
{
OpenApiParameter parameter = new OpenApiParameter
{
@ -268,7 +185,7 @@ namespace Microsoft.OpenApi.OData.Operation
if (param.DocumentationURL != null)
{
parameter.Example = new OpenApiString(param.DocumentationURL?? "N/A");
parameter.Example = new OpenApiString(param.DocumentationURL ?? "N/A");
}
if (param.ExampleValues != null)
@ -282,16 +199,8 @@ namespace Microsoft.OpenApi.OData.Operation
Description = example.Description
};
if (example is ExternalExample)
{
var externalExample = (ExternalExample)example;
ex.Value = new OpenApiString(externalExample.ExternalValue ?? "N/A");
}
else
{
var inlineExample = (InlineExample)example;
ex.Value = new OpenApiString(inlineExample.InlineValue ?? "N/A");
}
// maybe call convert to Uri literal
ex.Value = new OpenApiString(example.Value.ToString());
parameter.Examples.Add("example-" + index++, ex);
}

View file

@ -3,9 +3,9 @@
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
using System.Collections.Generic;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.OData.Edm;
using System.Collections.Generic;
namespace Microsoft.OpenApi.OData.Operation
{

View file

@ -4,10 +4,13 @@
// ------------------------------------------------------------
using System.Collections.Generic;
using System.Linq;
using Microsoft.OData.Edm;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
using Microsoft.OpenApi.OData.Generator;
using Microsoft.OpenApi.OData.Vocabulary.Capabilities;
namespace Microsoft.OpenApi.OData.Operation
{
@ -92,5 +95,39 @@ namespace Microsoft.OpenApi.OData.Operation
base.SetResponses(operation);
}
/// <inheritdoc/>
protected override void SetSecurity(OpenApiOperation operation)
{
ReadRestrictionsType read = Context.Model.GetRecord<ReadRestrictionsType>(Singleton, CapabilitiesConstants.ReadRestrictions);
if (read == null || read.Permission == null)
{
return;
}
// the Permission should be collection, however current ODL supports the single permission.
// Will update after ODL change.
operation.Security = Context.CreateSecurityRequirements(new[] { read.Permission.Scheme }).ToList();
}
/// <inheritdoc/>
protected override void AppendCustomParameters(OpenApiOperation operation)
{
ReadRestrictionsType read = Context.Model.GetRecord<ReadRestrictionsType>(Singleton, CapabilitiesConstants.ReadRestrictions);
if (read == null)
{
return;
}
if (read.CustomHeaders != null)
{
AppendCustomParameters(operation.Parameters, read.CustomHeaders, ParameterLocation.Header);
}
if (read.CustomQueryOptions != null)
{
AppendCustomParameters(operation.Parameters, read.CustomQueryOptions, ParameterLocation.Query);
}
}
}
}

View file

@ -30,8 +30,6 @@ namespace Microsoft.OpenApi.OData.Operation
ODataNavigationSourceSegment navigationSourceSegment = path.FirstSegment as ODataNavigationSourceSegment;
Singleton = navigationSourceSegment.NavigationSource as IEdmSingleton;
Request = context.FindRequest(Singleton, OperationType.ToString());
}
/// <inheritdoc/>

View file

@ -4,10 +4,13 @@
// ------------------------------------------------------------
using System.Collections.Generic;
using System.Linq;
using Microsoft.OData.Edm;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
using Microsoft.OpenApi.OData.Generator;
using Microsoft.OpenApi.OData.Vocabulary.Capabilities;
namespace Microsoft.OpenApi.OData.Operation
{
@ -76,5 +79,39 @@ namespace Microsoft.OpenApi.OData.Operation
base.SetResponses(operation);
}
/// <inheritdoc/>
protected override void SetSecurity(OpenApiOperation operation)
{
UpdateRestrictionsType update = Context.Model.GetRecord<UpdateRestrictionsType>(Singleton, CapabilitiesConstants.UpdateRestrictions);
if (update == null || update.Permission == null)
{
return;
}
// the Permission should be collection, however current ODL supports the single permission.
// Will update after ODL change.
operation.Security = Context.CreateSecurityRequirements(new[] { update.Permission }).ToList();
}
/// <inheritdoc/>
protected override void AppendCustomParameters(OpenApiOperation operation)
{
UpdateRestrictionsType update = Context.Model.GetRecord<UpdateRestrictionsType>(Singleton, CapabilitiesConstants.UpdateRestrictions);
if (update == null)
{
return;
}
if (update.CustomHeaders != null)
{
AppendCustomParameters(operation.Parameters, update.CustomHeaders, ParameterLocation.Header);
}
if (update.CustomQueryOptions != null)
{
AppendCustomParameters(operation.Parameters, update.CustomQueryOptions, ParameterLocation.Query);
}
}
}
}

View file

@ -4,8 +4,8 @@
// ------------------------------------------------------------
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.OData.Capabilities;
using Microsoft.OpenApi.OData.Edm;
using Microsoft.OpenApi.OData.Vocabulary.Capabilities;
namespace Microsoft.OpenApi.OData.PathItem
{
@ -20,19 +20,22 @@ namespace Microsoft.OpenApi.OData.PathItem
/// <inheritdoc/>
protected override void SetOperations(OpenApiPathItem item)
{
IndexableByKey index = Context.Model.GetIndexableByKey(EntitySet);
if (index == null || index.IsSupported)
ReadRestrictionsType read = Context.Model.GetRecord<ReadRestrictionsType>(EntitySet);
if (read == null ||
(read.ReadByKeyRestrictions == null && read.IsReadable) ||
(read.ReadByKeyRestrictions != null && read.ReadByKeyRestrictions.IsReadable))
{
// If we don't have Read by key read restriction, we should check the set read restrction.
AddOperation(item, OperationType.Get);
}
UpdateRestrictions update = Context.Model.GetUpdateRestrictions(EntitySet);
UpdateRestrictionsType update = Context.Model.GetRecord<UpdateRestrictionsType>(EntitySet);
if (update == null || update.IsUpdatable)
{
AddOperation(item, OperationType.Patch);
}
DeleteRestrictions delete = Context.Model.GetDeleteRestrictions(EntitySet);
DeleteRestrictionsType delete = Context.Model.GetRecord<DeleteRestrictionsType>(EntitySet);
if (delete == null || delete.IsDeletable)
{
AddOperation(item, OperationType.Delete);

View file

@ -6,7 +6,7 @@
using Microsoft.OData.Edm;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.OData.Edm;
using Microsoft.OpenApi.OData.Capabilities;
using Microsoft.OpenApi.OData.Vocabulary.Capabilities;
namespace Microsoft.OpenApi.OData.PathItem
{
@ -26,13 +26,13 @@ namespace Microsoft.OpenApi.OData.PathItem
/// <inheritdoc/>
protected override void SetOperations(OpenApiPathItem item)
{
NavigationRestrictions navigation = Context.Model.GetNavigationRestrictions(EntitySet);
if (navigation == null || navigation.IsNavigable)
ReadRestrictionsType read = Context.Model.GetRecord<ReadRestrictionsType>(EntitySet);
if (read == null || read.IsReadable)
{
AddOperation(item, OperationType.Get);
}
InsertRestrictions insert = Context.Model.GetInsertRestrictions(EntitySet);
InsertRestrictionsType insert = Context.Model.GetRecord<InsertRestrictionsType>(EntitySet);
if (insert == null || insert.IsInsertable)
{
AddOperation(item, OperationType.Post);

View file

@ -8,11 +8,11 @@ using System.Linq;
using System.Collections.Generic;
using Microsoft.OData.Edm;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.OData.Capabilities;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
using Microsoft.OpenApi.Any;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Vocabulary.Capabilities;
namespace Microsoft.OpenApi.OData.PathItem
{
@ -49,12 +49,18 @@ namespace Microsoft.OpenApi.OData.PathItem
target = NavigationSource as IEdmSingleton;
}
NavigationRestrictionsType navigation = Context.Model.GetRecord<NavigationRestrictionsType>(target, CapabilitiesConstants.NavigationRestrictions);
if (navigation != null && navigation.Navigability != null && navigation.Navigability.Value == NavigationType.None)
{
// This check should be done when retrieve the path, but, here is for verification.
return;
}
string navigationPropertyPath = String.Join("/",
Path.Segments.OfType<ODataNavigationPropertySegment>().Select(e => e.NavigationProperty.Name));
Path.Segments.Where(s => !(s is ODataKeySegment || s is ODataNavigationSourceSegment)).Select(e => e.Name));
// contaiment: Get / (Post - Collection | Patch - Single)
// non-containment: only Get
NavigationRestrictions navigation = Context.Model.GetNavigationRestrictions(target);
if (navigation == null || !navigation.IsRestrictedProperty(navigationPropertyPath))
{
AddOperation(item, OperationType.Get);
@ -67,7 +73,7 @@ namespace Microsoft.OpenApi.OData.PathItem
if (LastSegmentIsKeySegment)
{
// Need to check this scenario is valid or not?
UpdateRestrictions update = Context.Model.GetUpdateRestrictions(target);
UpdateRestrictionsType update = Context.Model.GetRecord<UpdateRestrictionsType>(target, CapabilitiesConstants.UpdateRestrictions);
if (update == null || !update.IsNonUpdatableNavigationProperty(navigationPropertyPath))
{
AddOperation(item, OperationType.Patch);
@ -75,7 +81,7 @@ namespace Microsoft.OpenApi.OData.PathItem
}
else
{
InsertRestrictions insert = Context.Model.GetInsertRestrictions(target);
InsertRestrictionsType insert = Context.Model.GetRecord<InsertRestrictionsType>(target, CapabilitiesConstants.InsertRestrictions);
if (insert == null || !insert.IsNonInsertableNavigationProperty(navigationPropertyPath))
{
AddOperation(item, OperationType.Post);
@ -84,7 +90,7 @@ namespace Microsoft.OpenApi.OData.PathItem
}
else
{
UpdateRestrictions update = Context.Model.GetUpdateRestrictions(target);
UpdateRestrictionsType update = Context.Model.GetRecord<UpdateRestrictionsType>(target, CapabilitiesConstants.UpdateRestrictions);
if (update == null || !update.IsNonUpdatableNavigationProperty(navigationPropertyPath))
{
AddOperation(item, OperationType.Patch);

View file

@ -6,6 +6,7 @@
using Microsoft.OData.Edm;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.OData.Edm;
using Microsoft.OpenApi.OData.Vocabulary.Capabilities;
namespace Microsoft.OpenApi.OData.PathItem
{
@ -39,7 +40,13 @@ namespace Microsoft.OpenApi.OData.PathItem
// resource path of the function import prepended with a forward slash, and whose value is a Path
// Item Object containing the keyword get with an Operation Object as value that describes
// how to invoke the function import.
AddOperation(item, OperationType.Get);
// so far, <Term Name="ReadRestrictions" Type="Capabilities.ReadRestrictionsType" AppliesTo="EntitySet Singleton FunctionImport">
ReadRestrictionsType read = Context.Model.GetRecord<ReadRestrictionsType>(EdmOperationImport, CapabilitiesConstants.ReadRestrictions);
if (read == null || read.IsReadable)
{
AddOperation(item, OperationType.Get);
}
}
}

View file

@ -81,7 +81,7 @@ namespace Microsoft.OpenApi.OData.PathItem
/// </summary>
/// <param name="item">The path item.</param>
/// <param name="operationType">The operatin type.</param>
protected void AddOperation(OpenApiPathItem item, OperationType operationType)
protected virtual void AddOperation(OpenApiPathItem item, OperationType operationType)
{
IOperationHandlerProvider provider = Context.OperationHanderProvider;
IOperationHandler operationHander = provider.GetHandler(Path.Kind, operationType);

View file

@ -33,7 +33,7 @@ namespace Microsoft.OpenApi.OData.PathItem
// Edm OperationImport
{ ODataPathKind.OperationImport, new OperationImportPathItemHandler() },
// Edm OperationImport
// Unknown
{ ODataPathKind.Unknown, null },
};

View file

@ -5,8 +5,8 @@
using Microsoft.OData.Edm;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.OData.Capabilities;
using Microsoft.OpenApi.OData.Edm;
using Microsoft.OpenApi.OData.Vocabulary.Capabilities;
namespace Microsoft.OpenApi.OData.PathItem
{
@ -27,14 +27,14 @@ namespace Microsoft.OpenApi.OData.PathItem
protected override void SetOperations(OpenApiPathItem item)
{
// Retrieve a singleton.
NavigationRestrictions navigation = Context.Model.GetNavigationRestrictions(Singleton);
if (navigation == null || navigation.IsNavigable)
ReadRestrictionsType read = Context.Model.GetRecord<ReadRestrictionsType>(Singleton);
if (read == null || read.IsReadable)
{
AddOperation(item, OperationType.Get);
}
// Update a singleton
UpdateRestrictions update = Context.Model.GetUpdateRestrictions(Singleton);
UpdateRestrictionsType update = Context.Model.GetRecord<UpdateRestrictionsType>(Singleton);
if (update == null || update.IsUpdatable)
{
AddOperation(item, OperationType.Patch);

View file

@ -19,7 +19,7 @@ namespace Microsoft.OpenApi.OData.Properties {
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class SRResource {
@ -105,6 +105,15 @@ namespace Microsoft.OpenApi.OData.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Not supported {0} Edm expression kind..
/// </summary>
internal static string NotSupportedEdmExpressionKind {
get {
return ResourceManager.GetString("NotSupportedEdmExpressionKind", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Not supported {0} Edm type kind..
/// </summary>

View file

@ -132,6 +132,9 @@
<data name="InvalidPathKindForPathItemHandler" xml:space="preserve">
<value>The '{0}' path item handler can't process path kind '{1}'.</value>
</data>
<data name="NotSupportedEdmExpressionKind" xml:space="preserve">
<value>Not supported {0} Edm expression kind.</value>
</data>
<data name="NotSupportedEdmTypeKind" xml:space="preserve">
<value>Not supported {0} Edm type kind.</value>
</data>

View file

@ -7,7 +7,7 @@ using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.OData.Edm;
namespace Microsoft.OpenApi.OData.Authorizations
namespace Microsoft.OpenApi.OData.Vocabulary.Authorization
{
/// <summary>
/// Enum type KeyLocation
@ -31,7 +31,7 @@ namespace Microsoft.OpenApi.OData.Authorizations
}
/// <summary>
/// Complex type 'Org.OData.Core.V1.ApiKey'
/// Complex type: 'Org.OData.Authorization.V1.ApiKey'
/// </summary>
internal class ApiKey : Authorization
{
@ -54,10 +54,10 @@ namespace Microsoft.OpenApi.OData.Authorizations
/// Init <see cref="ApiKey"/>.
/// </summary>
/// <param name="record">the input record.</param>
public override void Init(IEdmRecordExpression record)
public override void Initialize(IEdmRecordExpression record)
{
// base checked.
base.Init(record);
base.Initialize(record);
// KeyName.
KeyName = record.GetString("KeyName");

View file

@ -12,12 +12,13 @@ using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
using Microsoft.OpenApi.OData.Properties;
namespace Microsoft.OpenApi.OData.Authorizations
namespace Microsoft.OpenApi.OData.Vocabulary.Authorization
{
/// <summary>
/// Abstract complex type 'Org.OData.Core.V1.Authorization'
/// Abstract complex type: 'Org.OData.Authorization.V1.Authorization'
/// </summary>
internal abstract class Authorization
[Term("Org.OData.Authorization.Authorizations")]
internal abstract class Authorization : IRecord
{
/// <summary>
/// Name that can be used to reference the authorization flow.
@ -38,7 +39,7 @@ namespace Microsoft.OpenApi.OData.Authorizations
/// Init the <see cref="Authorization"/>.
/// </summary>
/// <param name="record">The corresponding record.</param>
public virtual void Init(IEdmRecordExpression record)
public virtual void Initialize(IEdmRecordExpression record)
{
Utils.CheckArgumentNull(record, nameof(record));
@ -67,7 +68,7 @@ namespace Microsoft.OpenApi.OData.Authorizations
return null;
}
Authorization auth = null;
Authorization auth;
switch (complexType.FullTypeName())
{
case AuthorizationConstants.OpenIDConnect: // OpenIDConnect
@ -105,7 +106,7 @@ namespace Microsoft.OpenApi.OData.Authorizations
if (auth != null)
{
auth.Init(record);
auth.Initialize(record);
}
return auth;

View file

@ -3,7 +3,7 @@
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
namespace Microsoft.OpenApi.OData.Authorizations
namespace Microsoft.OpenApi.OData.Vocabulary.Authorization
{
/// <summary>
/// Constant values for Authorization Vocabulary

View file

@ -7,12 +7,12 @@ using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
namespace Microsoft.OpenApi.OData.Authorizations
namespace Microsoft.OpenApi.OData.Vocabulary.Authorization
{
/// <summary>
/// Complex type 'Org.OData.Core.V1.AuthorizationScope'
/// Complex type: 'Org.OData.Authorization.V1.AuthorizationScope'
/// </summary>
internal class AuthorizationScope
internal class AuthorizationScope : IRecord
{
/// <summary>
/// Scope name.
@ -34,7 +34,7 @@ namespace Microsoft.OpenApi.OData.Authorizations
/// Init the <see cref="AuthorizationScope"/>.
/// </summary>
/// <param name="record">The corresponding record.</param>
public virtual void Init(IEdmRecordExpression record)
public virtual void Initialize(IEdmRecordExpression record)
{
Utils.CheckArgumentNull(record, nameof(record));

View file

@ -7,10 +7,10 @@ using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.OData.Edm;
namespace Microsoft.OpenApi.OData.Authorizations
namespace Microsoft.OpenApi.OData.Vocabulary.Authorization
{
/// <summary>
/// Complex type 'Org.OData.Core.V1.Http'
/// Complex type 'Org.OData.Authorization.V1.Http'
/// </summary>
internal class Http : Authorization
{
@ -33,10 +33,10 @@ namespace Microsoft.OpenApi.OData.Authorizations
/// Init <see cref="Http"/>.
/// </summary>
/// <param name="record">the input record.</param>
public override void Init(IEdmRecordExpression record)
public override void Initialize(IEdmRecordExpression record)
{
// base checked.
base.Init(record);
base.Initialize(record);
// Scheme
Scheme = record.GetString("Scheme");

View file

@ -6,10 +6,10 @@
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Edm;
namespace Microsoft.OpenApi.OData.Authorizations
namespace Microsoft.OpenApi.OData.Vocabulary.Authorization
{
/// <summary>
/// Complex type 'Org.OData.Core.V1.OAuth2AuthCode'.
/// Complex type 'Org.OData.Authorization.V1.OAuth2AuthCode'.
/// </summary>
internal class OAuth2AuthCode : OAuthAuthorization
{
@ -32,10 +32,10 @@ namespace Microsoft.OpenApi.OData.Authorizations
/// Init <see cref="OAuth2AuthCode"/>.
/// </summary>
/// <param name="record">the input record.</param>
public override void Init(IEdmRecordExpression record)
public override void Initialize(IEdmRecordExpression record)
{
// base checked.
base.Init(record);
base.Initialize(record);
// AuthorizationUrl
AuthorizationUrl = record.GetString("AuthorizationUrl");

View file

@ -6,10 +6,10 @@
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Edm;
namespace Microsoft.OpenApi.OData.Authorizations
namespace Microsoft.OpenApi.OData.Vocabulary.Authorization
{
/// <summary>
/// Complex type 'Org.OData.Core.V1.OAuth2ClientCredentials'
/// Complex type 'Org.OData.Authorization.V1.OAuth2ClientCredentials'
/// </summary>
internal class OAuth2ClientCredentials : OAuthAuthorization
{
@ -27,10 +27,10 @@ namespace Microsoft.OpenApi.OData.Authorizations
/// Init <see cref="OAuth2ClientCredentials"/>.
/// </summary>
/// <param name="record">the input record.</param>
public override void Init(IEdmRecordExpression record)
public override void Initialize(IEdmRecordExpression record)
{
// base checked.
base.Init(record);
base.Initialize(record);
// TokenUrl
TokenUrl = record.GetString("TokenUrl");

View file

@ -6,10 +6,10 @@
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Edm;
namespace Microsoft.OpenApi.OData.Authorizations
namespace Microsoft.OpenApi.OData.Vocabulary.Authorization
{
/// <summary>
/// Complex type 'Org.OData.Core.V1.OAuth2Implicit'
/// Complex type 'Org.OData.Authorization.V1.OAuth2Implicit'
/// </summary>
internal class OAuth2Implicit : OAuthAuthorization
{
@ -27,10 +27,10 @@ namespace Microsoft.OpenApi.OData.Authorizations
/// Init <see cref="OAuth2Implicit"/>.
/// </summary>
/// <param name="record">the input record.</param>
public override void Init(IEdmRecordExpression record)
public override void Initialize(IEdmRecordExpression record)
{
// base checked.
base.Init(record);
base.Initialize(record);
// AuthorizationUrl
AuthorizationUrl = record.GetString("AuthorizationUrl");

View file

@ -6,10 +6,10 @@
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Edm;
namespace Microsoft.OpenApi.OData.Authorizations
namespace Microsoft.OpenApi.OData.Vocabulary.Authorization
{
/// <summary>
/// Complex type 'Org.OData.Core.V1.OAuth2Password'
/// Complex type 'Org.OData.Authorization.V1.OAuth2Password'
/// </summary>
internal class OAuth2Password : OAuthAuthorization
{
@ -27,10 +27,10 @@ namespace Microsoft.OpenApi.OData.Authorizations
/// Init <see cref="OAuth2Password"/>.
/// </summary>
/// <param name="record">the input record.</param>
public override void Init(IEdmRecordExpression record)
public override void Initialize(IEdmRecordExpression record)
{
// base checked.
base.Init(record);
base.Initialize(record);
// TokenUrl
TokenUrl = record.GetString("TokenUrl");

View file

@ -8,7 +8,7 @@ using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.OData.Edm;
namespace Microsoft.OpenApi.OData.Authorizations
namespace Microsoft.OpenApi.OData.Vocabulary.Authorization
{
/// <summary>
/// OAuth2 type kind.
@ -37,7 +37,7 @@ namespace Microsoft.OpenApi.OData.Authorizations
}
/// <summary>
/// Abstract complex type 'Org.OData.Core.V1.OAuthAuthorization'
/// Abstract complex type 'Org.OData.Authorization.V1.OAuthAuthorization'
/// </summary>
internal abstract class OAuthAuthorization : Authorization
{
@ -65,13 +65,13 @@ namespace Microsoft.OpenApi.OData.Authorizations
/// Init <see cref="OAuthAuthorization"/>.
/// </summary>
/// <param name="record">the input record.</param>
public override void Init(IEdmRecordExpression record)
public override void Initialize(IEdmRecordExpression record)
{
// base checked.
base.Init(record);
base.Initialize(record);
// Scopes
Scopes = record.GetCollection<AuthorizationScope>("Scopes", (s, item) => s.Init(item as IEdmRecordExpression));
Scopes = record.GetCollection<AuthorizationScope>("Scopes");
// RefreshUrl
RefreshUrl = record.GetString("RefreshUrl");

View file

@ -7,10 +7,10 @@ using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.OData.Edm;
namespace Microsoft.OpenApi.OData.Authorizations
namespace Microsoft.OpenApi.OData.Vocabulary.Authorization
{
/// <summary>
/// Complex type 'Org.OData.Core.V1.OpenIDConnect'
/// Complex type: Org.OData.Authorization.V1.OpenIDConnect
/// </summary>
internal class OpenIDConnect : Authorization
{
@ -29,10 +29,10 @@ namespace Microsoft.OpenApi.OData.Authorizations
/// Init <see cref="OpenIDConnect"/>.
/// </summary>
/// <param name="record">the input record.</param>
public override void Init(IEdmRecordExpression record)
public override void Initialize(IEdmRecordExpression record)
{
// base checked.
base.Init(record);
base.Initialize(record);
// IssuerUrl
IssuerUrl = record.GetString("IssuerUrl");

View file

@ -8,12 +8,13 @@ using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
namespace Microsoft.OpenApi.OData.Authorizations
namespace Microsoft.OpenApi.OData.Vocabulary.Authorization
{
/// <summary>
/// Complex type Org.OData.Core.V1.SecurityScheme
/// Complex type: Org.OData.Authorization.V1.SecurityScheme
/// </summary>
internal class SecurityScheme
[Term("Org.OData.Authorization.V1.SecuritySchemes")]
internal class SecurityScheme : IRecord
{
/// <summary>
/// The name of a required authorization scheme.
@ -29,7 +30,7 @@ namespace Microsoft.OpenApi.OData.Authorizations
/// Init the <see cref="SecurityScheme"/>.
/// </summary>
/// <param name="record">The input record.</param>
public void Init(IEdmRecordExpression record)
public void Initialize(IEdmRecordExpression record)
{
Utils.CheckArgumentNull(record, nameof(record));

View file

@ -0,0 +1,98 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
namespace Microsoft.OpenApi.OData.Vocabulary.Capabilities
{
/// <summary>
/// Term name of the Capabilities Vocabulary
/// </summary>
internal class CapabilitiesConstants
{
/// <summary>
/// Org.OData.Capabilities.V1.ReadRestrictions
/// </summary>
public const string ReadRestrictions = "Org.OData.Capabilities.V1.ReadRestrictions";
/// <summary>
/// Org.OData.Capabilities.V1.ChangeTracking
/// </summary>
public const string ChangeTracking = "Org.OData.Capabilities.V1.ChangeTracking";
/// <summary>
/// Org.OData.Capabilities.V1.FilterRestrictions
/// </summary>
public const string FilterRestrictions = "Org.OData.Capabilities.V1.FilterRestrictions";
/// <summary>
/// Org.OData.Capabilities.V1.SortRestrictions
/// </summary>
public const string SortRestrictions = "Org.OData.Capabilities.V1.SortRestrictions";
/// <summary>
/// Org.OData.Capabilities.V1.NavigationRestrictions
/// </summary>
public const string NavigationRestrictions = "Org.OData.Capabilities.V1.NavigationRestrictions";
/// <summary>
/// Org.OData.Capabilities.V1.SearchRestrictions
/// </summary>
public const string SearchRestrictions = "Org.OData.Capabilities.V1.SearchRestrictions";
/// <summary>
/// Org.OData.Capabilities.V1.CountRestrictions
/// </summary>
public const string CountRestrictions = "Org.OData.Capabilities.V1.CountRestrictions";
/// <summary>
/// Org.OData.Capabilities.V1.ExpandRestrictions
/// </summary>
public const string ExpandRestrictions = "Org.OData.Capabilities.V1.ExpandRestrictions";
/// <summary>
/// Org.OData.Capabilities.V1.DeleteRestrictions
/// </summary>
public const string DeleteRestrictions = "Org.OData.Capabilities.V1.DeleteRestrictions";
/// <summary>
/// Org.OData.Capabilities.V1.DeleteRestrictions
/// </summary>
public const string UpdateRestrictions = "Org.OData.Capabilities.V1.UpdateRestrictions";
/// <summary>
/// Org.OData.Capabilities.V1.InsertRestrictions
/// </summary>
public const string InsertRestrictions = "Org.OData.Capabilities.V1.InsertRestrictions";
/// <summary>
/// Org.OData.Capabilities.V1.TopSupported
/// </summary>
public const string TopSupported = "Org.OData.Capabilities.V1.TopSupported";
/// <summary>
/// Org.OData.Capabilities.V1.SkipSupported
/// </summary>
public const string SkipSupported = "Org.OData.Capabilities.V1.SkipSupported";
/// <summary>
/// Term: Org.OData.Capabilities.V1.BatchSupported
/// </summary>
public const string BatchSupported = "Org.OData.Capabilities.V1.BatchSupported";
/// <summary>
/// Term: rg.OData.Capabilities.V1.OperationRestrictions
/// </summary>
public const string OperationRestrictions = "Org.OData.Capabilities.V1.OperationRestrictions";
/// <summary>
/// Org.OData.Capabilities.V1.IndexableByKey
/// </summary>
public const string IndexableByKey = "Org.OData.Capabilities.V1.IndexableByKey";
/// <summary>
/// Org.OData.Capabilities.V1.KeyAsSegmentSupported
/// </summary>
public const string KeyAsSegmentSupported = "Org.OData.Capabilities.V1.KeyAsSegmentSupported";
}
}

View file

@ -4,21 +4,18 @@
// ------------------------------------------------------------
using System.Collections.Generic;
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
namespace Microsoft.OpenApi.OData.Capabilities
namespace Microsoft.OpenApi.OData.Vocabulary.Capabilities
{
/// <summary>
/// Org.OData.Capabilities.V1.CollectionPropertyRestrictions
/// Complex Type: Org.OData.Capabilities.V1.CollectionPropertyRestrictionsType
/// </summary>
internal class CollectionPropertyRestrictions : CapabilitiesRestrictions
[Term("Org.OData.Capabilities.V1.CollectionPropertyRestrictions")]
internal class CollectionPropertyRestrictionsType : IRecord
{
/// <summary>
/// The Term type kind.
/// </summary>
public override CapabilitesTermKind Kind => CapabilitesTermKind.CollectionPropertyRestrictions;
/// <summary>
/// Gets the Restricted Collection-valued property.
/// </summary>
@ -32,17 +29,17 @@ namespace Microsoft.OpenApi.OData.Capabilities
/// <summary>
/// Gets Restrictions on filter expressions.
/// </summary>
public FilterRestrictions FilterRestrictions { get; private set; }
public FilterRestrictionsType FilterRestrictions { get; private set; }
/// <summary>
/// Gets Restrictions on search expressions.
/// </summary>
public SearchRestrictions SearchRestrictions { get; private set; }
public SearchRestrictionsType SearchRestrictions { get; private set; }
/// <summary>
/// Gets Restrictions on orderby expressions.
/// </summary>
public SortRestrictions SortRestrictions { get; private set; }
public SortRestrictionsType SortRestrictions { get; private set; }
/// <summary>
/// Gets Supports $top.
@ -74,21 +71,46 @@ namespace Microsoft.OpenApi.OData.Capabilities
/// </summary>
public bool? Deletable { get; private set; }
protected override bool Initialize(IEdmVocabularyAnnotation annotation)
/// <summary>
/// Init the <see cref="CollectionPropertyRestrictionsType"/>.
/// </summary>
/// <param name="record">The input record.</param>
public virtual void Initialize(IEdmRecordExpression record)
{
if (annotation == null ||
annotation.Value == null ||
annotation.Value.ExpressionKind != EdmExpressionKind.Record)
{
return false;
}
Utils.CheckArgumentNull(record, nameof(record));
IEdmRecordExpression record = (IEdmRecordExpression)annotation.Value;
// CollectionProperty
CollectionProperty = record.GetPropertyPath("CollectionProperty");
// FilterFunctions
FilterFunctions = record.GetCollection("FilterFunctions");
// FilterRestrictions
FilterRestrictions = record.GetRecord<FilterRestrictionsType>("FilterRestrictions");
// SearchRestrictions
SearchRestrictions = record.GetRecord<SearchRestrictionsType>("SearchRestrictions");
// SortRestrictions
SortRestrictions = record.GetRecord<SortRestrictionsType>("SortRestrictions");
// TopSupported
TopSupported = record.GetBoolean("TopSupported");
// SkipSupported
SkipSupported = record.GetBoolean("SkipSupported");
// SelectSupport
SelectSupport = record.GetRecord<SelectSupportType>("SelectSupport");
// Insertable
Insertable = record.GetBoolean("Insertable");
// Updatable
Updatable = record.GetBoolean("Updatable");
// Deletable
Deletable = record.GetBoolean("Deletable");
return true;
}
}
}

View file

@ -5,21 +5,18 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
namespace Microsoft.OpenApi.OData.Capabilities
namespace Microsoft.OpenApi.OData.Vocabulary.Capabilities
{
/// <summary>
/// Org.OData.Capabilities.V1.CountRestrictions
/// Complex Type: Org.OData.Capabilities.V1.CountRestrictionsType
/// </summary>
internal class CountRestrictions : CapabilitiesRestrictions
[Term("Org.OData.Capabilities.V1.CountRestrictions")]
internal class CountRestrictionsType : IRecord
{
/// <summary>
/// The Term type kind.
/// </summary>
public override CapabilitesTermKind Kind => CapabilitesTermKind.CountRestrictions;
/// <summary>
/// Gets the Countable value.
/// </summary>
@ -63,16 +60,13 @@ namespace Microsoft.OpenApi.OData.Capabilities
false;
}
protected override bool Initialize(IEdmVocabularyAnnotation annotation)
/// <summary>
/// Init the <see cref="CountRestrictionsType"/>.
/// </summary>
/// <param name="record">The input record.</param>
public virtual void Initialize(IEdmRecordExpression record)
{
if (annotation == null ||
annotation.Value == null ||
annotation.Value.ExpressionKind != EdmExpressionKind.Record)
{
return false;
}
IEdmRecordExpression record = (IEdmRecordExpression)annotation.Value;
Utils.CheckArgumentNull(record, nameof(record));
// Countable
Countable = record.GetBoolean("Countable");
@ -82,8 +76,6 @@ namespace Microsoft.OpenApi.OData.Capabilities
// NonCountableNavigationProperties
NonCountableNavigationProperties = record.GetCollectionPropertyPath("NonCountableNavigationProperties");
return true;
}
}
}

View file

@ -7,44 +7,47 @@ using System.Collections.Generic;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
using Microsoft.OpenApi.OData.Vocabulary.Core;
namespace Microsoft.OpenApi.OData.Annotations
namespace Microsoft.OpenApi.OData.Vocabulary.Capabilities
{
/// <summary>
/// Complex type Org.OData.Core.V1.CustomParameter
/// Complex type: Org.OData.Capabilities.V1.CustomParameter
/// </summary>
internal class CustomParameter
// [Term("Org.OData.Capabilities.V1.CustomHeaders")]
// [Term("Org.OData.Capabilities.V1.CustomQueryOptions")]
internal class CustomParameter : IRecord
{
/// <summary>
/// The Name.
/// Gets/sets the name of the custom parameter.
/// </summary>
public string Name { get; set; }
/// <summary>
/// The Description.
/// Gets/sets the description of the custom parameter.
/// </summary>
public string Description { get; set; }
/// <summary>
/// The DocumentationURL.
/// Gets/sets the documentationURL of the custom parameter.
/// </summary>
public string DocumentationURL { get; set; }
/// <summary>
/// The Required.
/// Gets/sets the reuired of the custom parameter. true: parameter is required, false or not specified: parameter is optional.
/// </summary>
public bool? Required { get; set; }
/// <summary>
/// The ExampleValues.
/// </summary>
public IEnumerable<Example> ExampleValues { get; set; }
/// Gets the list of scopes that can provide access to the resource.
/// </summary>s
public IList<PrimitiveExampleValue> ExampleValues { get; set; }
/// <summary>
/// Init the <see cref="CustomParameter"/>
/// Init the <see cref="CustomParameter"/>.
/// </summary>
/// <param name="record">The input record.</param>
public virtual void Init(IEdmRecordExpression record)
public void Initialize(IEdmRecordExpression record)
{
Utils.CheckArgumentNull(record, nameof(record));
@ -61,16 +64,7 @@ namespace Microsoft.OpenApi.OData.Annotations
Required = record.GetBoolean("Required");
// ExampleValues
ExampleValues = record.GetCollection("ExampleValues", r =>
{
IEdmRecordExpression itemRecord = r as IEdmRecordExpression;
if (itemRecord != null)
{
return Example.CreateExample(itemRecord);
}
return null;
});
ExampleValues = record.GetCollection<PrimitiveExampleValue>("ExampleValues");
}
}
}

View file

@ -3,44 +3,41 @@
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
namespace Microsoft.OpenApi.OData.Capabilities
namespace Microsoft.OpenApi.OData.Vocabulary.Capabilities
{
/// <summary>
/// Org.OData.Capabilities.V1.DeepInsertSupport
/// Complex Type: Org.OData.Capabilities.V1.DeepInsertSupport
/// </summary>
internal class DeepInsertSupported : SupportedRestrictions
[Term("Org.OData.Capabilities.V1.DeepInsertSupport")]
internal class DeepInsertSupportType : IRecord
{
/// <summary>
/// The Term type kind.
/// Gets Annotation target supports deep inserts
/// </summary>
public override CapabilitesTermKind Kind => CapabilitesTermKind.DeepInsertSupport;
public bool? Supported { get; private set; }
/// <summary>
/// Gets Annotation target supports accepting and returning nested entities annotated with the `Core.ContentID` instance annotation.
/// </summary>
public bool? ContentIDSupported { get; private set; }
protected override bool Initialize(IEdmVocabularyAnnotation annotation)
/// <summary>
/// Init the <see cref="DeepInsertSupportType"/>.
/// </summary>
/// <param name="record">The input record.</param>
public void Initialize(IEdmRecordExpression record)
{
if (annotation == null ||
annotation.Value == null ||
annotation.Value.ExpressionKind != EdmExpressionKind.Record)
{
return false;
}
IEdmRecordExpression record = (IEdmRecordExpression)annotation.Value;
Utils.CheckArgumentNull(record, nameof(record));
// Supported
Supported = record.GetBoolean("Supported");
// NonInsertableNavigationProperties
ContentIDSupported = record.GetBoolean("ContentIDSupported");
return true;
}
}
}

View file

@ -3,44 +3,41 @@
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
namespace Microsoft.OpenApi.OData.Capabilities
namespace Microsoft.OpenApi.OData.Vocabulary.Capabilities
{
/// <summary>
/// Org.OData.Capabilities.V1.DeepUpdateSupported
/// Complex Type: Org.OData.Capabilities.V1.DeepUpdateSupportType
/// </summary>
internal class DeepUpdateSupported : SupportedRestrictions
[Term("Org.OData.Capabilities.V1.DeepUpdateSupport")]
internal class DeepUpdateSupportType : IRecord
{
/// <summary>
/// The Term type kind.
/// Gets Annotation target supports deep updates
/// </summary>
public override CapabilitesTermKind Kind => CapabilitesTermKind.DeepUpdateSupported;
public bool? Supported { get; private set; }
/// <summary>
/// Gets Annotation target supports accepting and returning nested entities annotated with the `Core.ContentID` instance annotation.
/// </summary>
public bool? ContentIDSupported { get; private set; }
protected override bool Initialize(IEdmVocabularyAnnotation annotation)
/// <summary>
/// Init the <see cref="DeepUpdateSupportType"/>.
/// </summary>
/// <param name="record">The input record.</param>
public void Initialize(IEdmRecordExpression record)
{
if (annotation == null ||
annotation.Value == null ||
annotation.Value.ExpressionKind != EdmExpressionKind.Record)
{
return false;
}
IEdmRecordExpression record = (IEdmRecordExpression)annotation.Value;
Utils.CheckArgumentNull(record, nameof(record));
// Supported
Supported = record.GetBoolean("Supported");
// NonInsertableNavigationProperties
ContentIDSupported = record.GetBoolean("ContentIDSupported");
return true;
}
}
}

View file

@ -5,21 +5,18 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
namespace Microsoft.OpenApi.OData.Capabilities
namespace Microsoft.OpenApi.OData.Vocabulary.Capabilities
{
/// <summary>
/// Org.OData.Capabilities.V1.DeleteRestrictions
/// Complex Type: Org.OData.Capabilities.V1.DeleteRestrictionsType
/// </summary>
internal class DeleteRestrictions : CapabilitiesRestrictions
[Term("Org.OData.Capabilities.V1.DeleteRestrictions")]
internal class DeleteRestrictionsType : IRecord
{
/// <summary>
/// The Term type kind.
/// </summary>
public override CapabilitesTermKind Kind => CapabilitesTermKind.DeleteRestrictions;
/// <summary>
/// Gets the Deletable value.
/// </summary>
@ -40,16 +37,16 @@ namespace Microsoft.OpenApi.OData.Capabilities
/// </summary>
public PermissionType Permission { get; private set; }
/// <summary>
/// Gets the Support for query options with insert requests.
/// </summary>
public ModificationQueryOptionsType QueryOptions { get; private set; }
/// <summary>
/// Gets the Supported or required custom headers.
/// </summary>
public IList<CustomParameter> CustomHeaders { get; private set; }
/// <summary>
/// Gets the Supported or required custom query options.
/// </summary>
public IList<CustomParameter> CustomQueryOptions { get; private set; }
/// <summary>
/// Test the target supports delete.
/// </summary>
@ -68,16 +65,13 @@ namespace Microsoft.OpenApi.OData.Capabilities
false;
}
protected override bool Initialize(IEdmVocabularyAnnotation annotation)
/// <summary>
/// Init the <see cref="DeleteRestrictionsType"/>.
/// </summary>
/// <param name="record">The input record.</param>
public void Initialize(IEdmRecordExpression record)
{
if (annotation == null ||
annotation.Value == null ||
annotation.Value.ExpressionKind != EdmExpressionKind.Record)
{
return false;
}
IEdmRecordExpression record = (IEdmRecordExpression)annotation.Value;
Utils.CheckArgumentNull(record, nameof(record));
// Deletable
Deletable = record.GetBoolean("Deletable");
@ -85,7 +79,17 @@ namespace Microsoft.OpenApi.OData.Capabilities
// NonDeletableNavigationProperties
NonDeletableNavigationProperties = record.GetCollectionPropertyPath("NonDeletableNavigationProperties");
return true;
// MaxLevels
MaxLevels = (int?)record.GetInteger("MaxLevels");
// Permission
Permission = record.GetRecord<PermissionType>("Permission");
// CustomHeaders
CustomHeaders = record.GetCollection<CustomParameter>("CustomHeaders");
// CustomQueryOptions
CustomQueryOptions = record.GetCollection<CustomParameter>("CustomQueryOptions");
}
}
}

View file

@ -5,21 +5,18 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
namespace Microsoft.OpenApi.OData.Capabilities
namespace Microsoft.OpenApi.OData.Vocabulary.Capabilities
{
/// <summary>
/// Org.OData.Capabilities.V1.ExpandRestrictions
/// </summary>
internal class ExpandRestrictions : CapabilitiesRestrictions
[Term("Org.OData.Capabilities.V1.ExpandRestrictions")]
internal class ExpandRestrictionsType : IRecord
{
/// <summary>
/// The Term type kind.
/// </summary>
public override CapabilitesTermKind Kind => CapabilitesTermKind.ExpandRestrictions;
/// <summary>
/// Gets the Expandable value.
/// </summary>
@ -33,7 +30,7 @@ namespace Microsoft.OpenApi.OData.Capabilities
/// <summary>
/// Gets the maximum number of levels that can be expanded in a expand expression.
/// </summary>
public int? MaxLevles { get; private set; }
public long? MaxLevels { get; private set; }
/// <summary>
/// Test the target supports $expand.
@ -51,16 +48,9 @@ namespace Microsoft.OpenApi.OData.Capabilities
return NonExpandableProperties != null ? NonExpandableProperties.Any(a => a == navigationPropertyPath) : false;
}
protected override bool Initialize(IEdmVocabularyAnnotation annotation)
public void Initialize(IEdmRecordExpression record)
{
if (annotation == null ||
annotation.Value == null ||
annotation.Value.ExpressionKind != EdmExpressionKind.Record)
{
return false;
}
IEdmRecordExpression record = (IEdmRecordExpression)annotation.Value;
Utils.CheckArgumentNull(record, nameof(record));
// Expandable
Expandable = record.GetBoolean("Expandable");
@ -68,7 +58,8 @@ namespace Microsoft.OpenApi.OData.Capabilities
// NonExpandableProperties
NonExpandableProperties = record.GetCollectionPropertyPath("NonExpandableProperties");
return true;
// MaxLevels
MaxLevels = record.GetInteger("MaxLevels");
}
}
}

View file

@ -0,0 +1,44 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
namespace Microsoft.OpenApi.OData.Vocabulary.Capabilities
{
/// <summary>
/// Complex Type: Org.OData.Capabilities.V1.FilterExpressionRestrictionType
/// </summary>
internal class FilterExpressionRestrictionType : IRecord
{
/// <summary>
/// Gets the Path to the restricted property.
/// </summary>
public string Property { get; private set; }
/// <summary>
/// Gets the RequiresFilter value.
/// <Property Name="AllowedExpressions" Type="Capabilities.FilterExpressionType">
/// <TypeDefinition Name="FilterExpressionType" UnderlyingType="Edm.String">
/// </summary>
public string AllowedExpressions { get; private set; }
/// <summary>
/// Init the <see cref="FilterExpressionRestrictionType"/>.
/// </summary>
/// <param name="record">The input record.</param>
public void Initialize(IEdmRecordExpression record)
{
Utils.CheckArgumentNull(record, nameof(record));
// Property
Property = record.GetPropertyPath("Property");
// AllowedExpressions
AllowedExpressions = record.GetString("AllowedExpressions");
}
}
}

View file

@ -5,21 +5,18 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
namespace Microsoft.OpenApi.OData.Capabilities
namespace Microsoft.OpenApi.OData.Vocabulary.Capabilities
{
/// <summary>
/// Org.OData.Capabilities.V1.FilterRestrictions
/// Complex Type: Org.OData.Capabilities.V1.FilterRestrictionsType
/// </summary>
internal class FilterRestrictions : CapabilitiesRestrictions
[Term("Org.OData.Capabilities.V1.FilterRestrictions")]
internal class FilterRestrictionsType : IRecord
{
/// <summary>
/// The Term type kind.
/// </summary>
public override CapabilitesTermKind Kind => CapabilitesTermKind.FilterRestrictions;
/// <summary>
/// Gets the Filterable value.
/// </summary>
@ -40,6 +37,17 @@ namespace Microsoft.OpenApi.OData.Capabilities
/// </summary>
public IList<string> NonFilterableProperties { get; private set; }
/// <summary>
/// Gets The maximum number of levels (including recursion) that can be traversed in a filter expression. A value of -1 indicates there is no restriction.
/// </summary>
public long? MaxLevels { get; private set; }
/// <summary>
/// Gets These properties only allow a subset of filter expressions.
/// A valid filter expression for a single property can be enclosed in parentheses and combined by `and` with valid expressions for other properties.
/// </summary>
public IList<FilterExpressionRestrictionType> FilterExpressionRestrictions { get; private set; }
/// <summary>
/// Test the target supports filter.
/// </summary>
@ -66,16 +74,13 @@ namespace Microsoft.OpenApi.OData.Capabilities
return NonFilterableProperties != null ? NonFilterableProperties.Any(a => a == propertyPath) : false;
}
protected override bool Initialize(IEdmVocabularyAnnotation annotation)
/// <summary>
/// Init the <see cref="FilterRestrictionsType"/>.
/// </summary>
/// <param name="record">The input record.</param>
public void Initialize(IEdmRecordExpression record)
{
if (annotation == null ||
annotation.Value == null ||
annotation.Value.ExpressionKind != EdmExpressionKind.Record)
{
return false;
}
IEdmRecordExpression record = (IEdmRecordExpression)annotation.Value;
Utils.CheckArgumentNull(record, nameof(record));
// Filterable
Filterable = record.GetBoolean("Filterable");
@ -89,7 +94,11 @@ namespace Microsoft.OpenApi.OData.Capabilities
// NonFilterableProperties
NonFilterableProperties = record.GetCollectionPropertyPath("NonFilterableProperties");
return true;
// MaxLevels
MaxLevels = record.GetInteger("MaxLevels");
// FilterExpressionRestrictions
FilterExpressionRestrictions = record.GetCollection<FilterExpressionRestrictionType>("FilterExpressionRestrictions");
}
}
}

View file

@ -5,21 +5,18 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
namespace Microsoft.OpenApi.OData.Capabilities
namespace Microsoft.OpenApi.OData.Vocabulary.Capabilities
{
/// <summary>
/// Org.OData.Capabilities.V1.InsertRestrictions
/// Complex Type: Org.OData.Capabilities.V1.InsertRestrictionsType
/// </summary>
internal class InsertRestrictions : CapabilitiesRestrictions
[Term("Org.OData.Capabilities.V1.InsertRestrictions")]
internal class InsertRestrictionsType : IRecord
{
/// <summary>
/// The Term type kind.
/// </summary>
public override CapabilitesTermKind Kind => CapabilitesTermKind.InsertRestrictions;
/// <summary>
/// Gets the Insertable value.
/// </summary>
@ -38,7 +35,7 @@ namespace Microsoft.OpenApi.OData.Capabilities
/// <summary>
/// Gets the maximum number of navigation properties that can be traversed.
/// </summary>
public int? MaxLevels { get; private set; }
public long? MaxLevels { get; private set; }
/// <summary>
/// Gets the required scopes to perform the insert.
@ -78,16 +75,13 @@ namespace Microsoft.OpenApi.OData.Capabilities
false;
}
protected override bool Initialize(IEdmVocabularyAnnotation annotation)
/// <summary>
/// Initialize the capabilities with the vocabulary annotation.
/// </summary>
/// <param name="annotation">The input vocabulary annotation.</param>
public void Initialize(IEdmRecordExpression record)
{
if (annotation == null ||
annotation.Value == null ||
annotation.Value.ExpressionKind != EdmExpressionKind.Record)
{
return false;
}
IEdmRecordExpression record = (IEdmRecordExpression)annotation.Value;
Utils.CheckArgumentNull(record, nameof(record));
// Insertable
Insertable = record.GetBoolean("Insertable");
@ -95,7 +89,20 @@ namespace Microsoft.OpenApi.OData.Capabilities
// NonInsertableNavigationProperties
NonInsertableNavigationProperties = record.GetCollectionPropertyPath("NonInsertableNavigationProperties");
return true;
// MaxLevels
MaxLevels = record.GetInteger("MaxLevels");
// Permission
Permission = record.GetRecord<PermissionType>("Permission");
// QueryOptions
QueryOptions = record.GetRecord<ModificationQueryOptionsType>("QueryOptions");
// CustomHeaders
CustomHeaders = record.GetCollection<CustomParameter>("CustomHeaders");
// CustomHeaders
CustomQueryOptions = record.GetCollection<CustomParameter>("CustomQueryOptions");
}
}
}

View file

@ -0,0 +1,75 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
namespace Microsoft.OpenApi.OData.Vocabulary.Capabilities
{
/// <summary>
/// Complex type: Org.OData.Capabilities.V1.ModificationQueryOptionsType
/// </summary>
[Term("Org.OData.Capabilities.V1.ModificationQueryOptions")]
internal class ModificationQueryOptionsType : IRecord
{
/// <summary>
/// Gets/sets the $expand with modification requests.
/// </summary>
public bool? ExpandSupported { get; private set; }
/// <summary>
/// Gets/sets the $select with modification requests.
/// </summary>
public bool? SelectSupported { get; private set; }
/// <summary>
/// Gets/sets the $compute with modification requests.
/// </summary>
public bool? ComputeSupported { get; private set; }
/// <summary>
/// Gets/sets the $filter with modification requests.
/// </summary>
public bool? FilterSupported { get; private set; }
/// <summary>
/// Gets/sets the $search with modification requests.
/// </summary>
public bool? SearchSupported { get; private set; }
/// <summary>
/// Gets/sets the $sort with modification requests.
/// </summary>
public bool? SortSupported { get; private set; }
/// <summary>
/// Init the <see cref="ModificationQueryOptionsType"/>.
/// </summary>
/// <param name="record">The input record.</param>
public void Initialize(IEdmRecordExpression record)
{
Utils.CheckArgumentNull(record, nameof(record));
// ExpandSupported
ExpandSupported = record.GetBoolean("ExpandSupported");
// SelectSupported
SelectSupported = record.GetBoolean("SelectSupported");
// ComputeSupported
ComputeSupported = record.GetBoolean("ComputeSupported");
// FilterSupported
FilterSupported = record.GetBoolean("FilterSupported");
// SearchSupported
SearchSupported = record.GetBoolean("SearchSupported");
// SortSupported
SortSupported = record.GetBoolean("SortSupported");
}
}
}

View file

@ -5,10 +5,11 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
namespace Microsoft.OpenApi.OData.Capabilities
namespace Microsoft.OpenApi.OData.Vocabulary.Capabilities
{
/// <summary>
/// Enumerates the navigation type can apply on navigation restrictions.
@ -32,9 +33,9 @@ namespace Microsoft.OpenApi.OData.Capabilities
}
/// <summary>
/// Complex type name = NavigationPropertyRestriction
/// Complex Type: Org.OData.Capabilities.V1.NavigationPropertyRestriction
/// </summary>
internal class NavigationPropertyRestriction
internal class NavigationPropertyRestriction : IRecord
{
/// <summary>
/// Navigation properties can be navigated
@ -54,17 +55,17 @@ namespace Microsoft.OpenApi.OData.Capabilities
/// <summary>
/// Restrictions on filter expressions.
/// </summary>
public FilterRestrictions FilterRestrictions { get; set; }
public FilterRestrictionsType FilterRestrictions { get; set; }
/// <summary>
/// Restrictions on search expressions.
/// </summary>
public SearchRestrictions SearchRestrictions { get; set; }
public SearchRestrictionsType SearchRestrictions { get; set; }
/// <summary>
/// Restrictions on orderby expressions.
/// </summary>
public SortRestrictions SortRestrictions { get; set; }
public SortRestrictionsType SortRestrictions { get; set; }
/// <summary>
/// Supports $top.
@ -89,27 +90,27 @@ namespace Microsoft.OpenApi.OData.Capabilities
/// <summary>
/// Restrictions on insert operations.
/// </summary>
public InsertRestrictions InsertRestrictions { get; set; }
public InsertRestrictionsType InsertRestrictions { get; set; }
/// <summary>
/// Deep Insert Support of the annotated resource (the whole service, an entity set, or a collection-valued resource).
/// </summary>
public DeepInsertSupported DeepInsertSupport { get; set; }
public DeepInsertSupportType DeepInsertSupport { get; set; }
/// <summary>
/// Restrictions on update operations.
/// </summary>
public UpdateRestrictions UpdateRestrictions { get; set; }
public UpdateRestrictionsType UpdateRestrictions { get; set; }
/// <summary>
/// Deep Update Support of the annotated resource (the whole service, an entity set, or a collection-valued resource).
/// </summary>
public DeepUpdateSupported DeepUpdateSupport { get; set; }
public DeepUpdateSupportType DeepUpdateSupport { get; set; }
/// <summary>
/// Restrictions on delete operations.
/// </summary>
public DeleteRestrictions DeleteRestrictions { get; set; }
public DeleteRestrictionsType DeleteRestrictions { get; set; }
/// <summary>
/// Data modification (including insert) along this navigation property requires the use of ETags.
@ -119,19 +120,75 @@ namespace Microsoft.OpenApi.OData.Capabilities
/// <summary>
/// Restrictions for retrieving entities.
/// </summary>
public ReadRestrictions ReadRestrictions { get; set; }
public ReadRestrictionsType ReadRestrictions { get; set; }
/// <summary>
/// Init the <see cref="NavigationPropertyRestriction"/>.
/// </summary>
/// <param name="record">The input record.</param>
public void Initialize(IEdmRecordExpression record)
{
Utils.CheckArgumentNull(record, nameof(record));
// NavigationProperty
NavigationProperty = record.GetPropertyPath("NavigationProperty"); // maybe call "GetNavigationPropertyPath
// Navigability
Navigability = record.GetEnum<NavigationType>("Navigability");
// FilterFunctions
FilterFunctions = record.GetCollection("FilterFunctions");
// FilterRestrictions
FilterRestrictions = record.GetRecord<FilterRestrictionsType>("FilterRestrictions");
// SearchRestrictions
SearchRestrictions = record.GetRecord<SearchRestrictionsType>("SearchRestrictions");
// SortRestrictions
SortRestrictions = record.GetRecord<SortRestrictionsType>("SortRestrictions");
// TopSupported
TopSupported = record.GetBoolean("TopSupported");
// SkipSupported
SkipSupported = record.GetBoolean("SkipSupported");
// SelectSupport
SelectSupport = record.GetRecord<SelectSupportType>("SelectSupport");
// IndexableByKey
IndexableByKey = record.GetBoolean("IndexableByKey");
// InsertRestrictions
InsertRestrictions = record.GetRecord<InsertRestrictionsType>("InsertRestrictions");
// DeepInsertSupport
DeepInsertSupport = record.GetRecord<DeepInsertSupportType>("DeepInsertSupport");
// UpdateRestrictions
UpdateRestrictions = record.GetRecord<UpdateRestrictionsType>("UpdateRestrictions");
// DeepUpdateSupport
DeepUpdateSupport = record.GetRecord<DeepUpdateSupportType>("DeepUpdateSupport");
// DeleteRestrictions
DeleteRestrictions = record.GetRecord<DeleteRestrictionsType>("DeleteRestrictions");
// IndexableByKey
OptimisticConcurrencyControl = record.GetBoolean("OptimisticConcurrencyControl");
// ReadRestrictions
ReadRestrictions = record.GetRecord<ReadRestrictionsType>("ReadRestrictions");
}
}
/// <summary>
/// Org.OData.Capabilities.V1.NavigationRestrictions
/// Complex Type: Org.OData.Capabilities.V1.NavigationRestrictionsType
/// </summary>
internal class NavigationRestrictions : CapabilitiesRestrictions
[Term("Org.OData.Capabilities.V1.NavigationRestrictions")]
internal class NavigationRestrictionsType : IRecord
{
/// <summary>
/// The Term type name.
/// </summary>
public override CapabilitesTermKind Kind => CapabilitesTermKind.NavigationRestrictions;
/// <summary>
/// Gets the Navigability value.
/// </summary>
@ -160,54 +217,19 @@ namespace Microsoft.OpenApi.OData.Capabilities
false;
}
protected override bool Initialize(IEdmVocabularyAnnotation annotation)
/// <summary>
/// Init the <see cref="NavigationRestrictionsType"/>.
/// </summary>
/// <param name="record">The input record.</param>
public void Initialize(IEdmRecordExpression record)
{
if (annotation == null ||
annotation.Value == null ||
annotation.Value.ExpressionKind != EdmExpressionKind.Record)
{
return false;
}
IEdmRecordExpression record = (IEdmRecordExpression)annotation.Value;
Utils.CheckArgumentNull(record, nameof(record));
// Navigability
Navigability = record.GetEnum<NavigationType>("Navigability");
// RestrictedProperties
RestrictedProperties = GetRestrictedProperties(record);
return true;
}
private static IList<NavigationPropertyRestriction> GetRestrictedProperties(IEdmRecordExpression record)
{
if (record != null && record.Properties != null)
{
IEdmPropertyConstructor property = record.Properties.FirstOrDefault(p => p.Name == "RestrictedProperties");
if (property != null)
{
IEdmCollectionExpression value = property.Value as IEdmCollectionExpression;
if (value != null && value.Elements != null)
{
IList<NavigationPropertyRestriction> restrictedProperties = new List<NavigationPropertyRestriction>();
foreach (var item in value.Elements.OfType<IEdmRecordExpression>())
{
NavigationPropertyRestriction restriction = new NavigationPropertyRestriction();
restriction.Navigability = item.GetEnum<NavigationType>("Navigability");
restriction.NavigationProperty = item.GetPropertyPath("NavigationProperty");
restrictedProperties.Add(restriction);
}
if (restrictedProperties.Any())
{
return restrictedProperties;
}
}
}
}
return null;
RestrictedProperties = record.GetCollection<NavigationPropertyRestriction>("RestrictedProperties");
}
}
}

View file

@ -4,21 +4,19 @@
// ------------------------------------------------------------
using System.Collections.Generic;
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
namespace Microsoft.OpenApi.OData.Capabilities
namespace Microsoft.OpenApi.OData.Vocabulary.Capabilities
{
/// <summary>
/// Org.OData.Capabilities.V1.OperationRestrictions
/// Complex Type: Org.OData.Capabilities.V1.OperationRestrictionType
/// Be note: in ODL 7.6, it's named as "OperationRestriction", after that, it will be changed as "OperationRestrictionType"
/// </summary>
internal class OperationRestrictions : CapabilitiesRestrictions
[Term("Org.OData.Capabilities.V1.OperationRestrictions")]
internal class OperationRestrictionType : IRecord
{
/// <summary>
/// The Term type name.
/// </summary>
public override CapabilitesTermKind Kind => CapabilitesTermKind.OperationRestrictions;
/// <summary>
/// Gets the List of required scopes to invoke an action or function.
/// </summary>
@ -34,19 +32,22 @@ namespace Microsoft.OpenApi.OData.Capabilities
/// </summary>
public IList<CustomParameter> CustomQueryOptions { get; private set; }
protected override bool Initialize(IEdmVocabularyAnnotation annotation)
/// <summary>
/// Init the <see cref="SearchRestrictionsType"/>.
/// </summary>
/// <param name="record">The input record.</param>
public void Initialize(IEdmRecordExpression record)
{
if (annotation == null ||
annotation.Value == null ||
annotation.Value.ExpressionKind != EdmExpressionKind.Record)
{
return false;
}
Utils.CheckArgumentNull(record, nameof(record));
IEdmRecordExpression record = (IEdmRecordExpression)annotation.Value;
// Permission
Permission = record.GetRecord<PermissionType>("Permission");
// CustomHeaders
CustomHeaders = record.GetCollection<CustomParameter>("CustomHeaders");
return true;
// CustomQueryOptions
CustomQueryOptions = record.GetCollection<CustomParameter>("CustomQueryOptions");
}
}
}

View file

@ -4,27 +4,18 @@
// ------------------------------------------------------------
using System.Collections.Generic;
using Microsoft.OpenApi.OData.Authorizations;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
using Microsoft.OpenApi.OData.Vocabulary.Authorization;
namespace Microsoft.OpenApi.OData.Capabilities
namespace Microsoft.OpenApi.OData.Vocabulary.Capabilities
{
/// <summary>
/// Complex type: Org.OData.Capabilities.V1.PermissionType
/// </summary>
internal class PermissionType
internal class PermissionType : IRecord
{
/// <summary>
/// Initializes a new instance of <see cref="PermissionType"/> class.
/// </summary>
/// <param name="scheme">The Auth flow scheme name.</param>
/// <param name="scopes">List of scopes that can provide access to the resource.</param>
public PermissionType(SecurityScheme scheme, IEnumerable<ScopeType> scopes)
{
Scheme = scheme ?? throw Error.ArgumentNull(nameof(scheme));
Scopes = scopes ?? throw Error.ArgumentNull(nameof(scopes));
}
/// <summary>
/// Gets the auth flow scheme name.
/// </summary>
@ -34,5 +25,20 @@ namespace Microsoft.OpenApi.OData.Capabilities
/// Gets the list of scopes that can provide access to the resource.
/// </summary>
public IEnumerable<ScopeType> Scopes { get; private set; }
/// <summary>
/// Init the <see cref="PermissionType"/>.
/// </summary>
/// <param name="record">The input record.</param>
public void Initialize(IEdmRecordExpression record)
{
Utils.CheckArgumentNull(record, nameof(record));
// Scheme
Scheme = record.GetRecord<SecurityScheme>("Scheme");
// Scopes
Scopes = record.GetCollection<ScopeType>("Scopes");
}
}
}

View file

@ -0,0 +1,99 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
using System.Collections.Generic;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
namespace Microsoft.OpenApi.OData.Vocabulary.Capabilities
{
/// <summary>
/// Complex Type: Org.OData.Capabilities.V1.ReadRestrictionsBase
/// </summary>
internal abstract class ReadRestrictionsBase : IRecord
{
/// <summary>
/// Get the Entities can be retrieved.
/// </summary>
public bool? Readable { get; private set; }
/// <summary>
/// Gets the List of required scopes to invoke an action or function
/// </summary>
public PermissionType Permission { get; private set; }
/// <summary>
/// Gets the Supported or required custom headers.
/// </summary>
public IList<CustomParameter> CustomHeaders { get; private set; }
/// <summary>
/// Gets the Supported or required custom query options.
/// </summary>
public IList<CustomParameter> CustomQueryOptions { get; private set; }
/// <summary>
/// Test the target supports update.
/// </summary>
/// <returns>True/false.</returns>
public bool IsReadable => Readable == null || Readable.Value;
/// <summary>
/// Init the <see cref="ReadRestrictionsBase"/>.
/// </summary>
/// <param name="record">The input record.</param>
public virtual void Initialize(IEdmRecordExpression record)
{
Utils.CheckArgumentNull(record, nameof(record));
// Readable
Readable = record.GetBoolean("Readable");
// Permission
Permission = record.GetRecord<PermissionType>("Permission");
// CustomHeaders
CustomHeaders = record.GetCollection<CustomParameter>("CustomHeaders");
// CustomQueryOptions
CustomQueryOptions = record.GetCollection<CustomParameter>("CustomQueryOptions");
}
}
/// <summary>
/// Complex Type: Org.OData.Capabilities.V1.ReadByKeyRestrictionsType
/// Restrictions for retrieving an entity by key
/// </summary>
internal class ReadByKeyRestrictions : ReadRestrictionsBase
{
// nothing here
}
/// <summary>
/// Complex Type: Org.OData.Capabilities.V1.ReadRestrictionsType
/// </summary>
[Term("Org.OData.Capabilities.V1.ReadRestrictions")]
internal class ReadRestrictionsType : ReadRestrictionsBase
{
/// <summary>
/// Gets the Restrictions for retrieving an entity by key
/// </summary>
public ReadByKeyRestrictions ReadByKeyRestrictions { get; set; }
/// <summary>
/// Init the <see cref="ReadRestrictionsType"/>.
/// </summary>
/// <param name="record">The input record.</param>
public override void Initialize(IEdmRecordExpression record)
{
// Load base
base.Initialize(record);
// ReadByKeyRestrictions
ReadByKeyRestrictions = record.GetRecord<ReadByKeyRestrictions>("ReadByKeyRestrictions");
}
}
}

View file

@ -3,29 +3,17 @@
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
namespace Microsoft.OpenApi.OData.Capabilities
namespace Microsoft.OpenApi.OData.Vocabulary.Capabilities
{
/// <summary>
/// Complex type: Org.OData.Capabilities.V1.ScopeType
/// </summary>
internal class ScopeType
internal class ScopeType : IRecord
{
/// <summary>
/// Initializes a new instance of <see cref="ScopeType"/> class.
/// </summary>
/// <param name="scope">The non-nullable scope name.</param>
/// <param name="restrictedProperties">
/// The non-nullable of the comma-separated string value of all properties
/// that will be included or excluded when using the scope
/// </param>
public ScopeType(string scope, string restrictedProperties)
{
Scope = scope ?? throw Error.ArgumentNull(nameof(scope));
RestrictedProperties = restrictedProperties ?? throw Error.ArgumentNull(nameof(scope));
}
/// <summary>
/// Gets the names of the scope.
/// </summary>
@ -37,5 +25,20 @@ namespace Microsoft.OpenApi.OData.Capabilities
/// Possible string value identifiers when specifying properties are '*', _PropertyName_, '-'_PropertyName_.
/// </summary>
public string RestrictedProperties { get; private set; }
/// <summary>
/// Init the <see cref="ScopeType"/>.
/// </summary>
/// <param name="record">The input record.</param>
public void Initialize(IEdmRecordExpression record)
{
Utils.CheckArgumentNull(record, nameof(record));
// Scope
Scope = record.GetString("Scope");
// RestrictedProperties
RestrictedProperties = record.GetString("RestrictedProperties");
}
}
}

View file

@ -4,11 +4,12 @@
// ------------------------------------------------------------
using System;
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Vocabularies;
using System.Linq;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Edm;
using Microsoft.OpenApi.OData.Common;
namespace Microsoft.OpenApi.OData.Capabilities
namespace Microsoft.OpenApi.OData.Vocabulary.Capabilities
{
/// <summary>
/// Enumerates the search expressions.
@ -48,15 +49,11 @@ namespace Microsoft.OpenApi.OData.Capabilities
}
/// <summary>
/// Org.OData.Capabilities.V1.SearchRestrictions
/// Complex Type: Org.OData.Capabilities.V1.SearchRestrictionsType
/// </summary>
internal class SearchRestrictions : CapabilitiesRestrictions
[Term("Org.OData.Capabilities.V1.SearchRestrictions")]
internal class SearchRestrictionsType : IRecord
{
/// <summary>
/// The Term type kind.
/// </summary>
public override CapabilitesTermKind Kind => CapabilitesTermKind.SearchRestrictions;
/// <summary>
/// Gets the Searchable value.
/// </summary>
@ -93,16 +90,13 @@ namespace Microsoft.OpenApi.OData.Capabilities
return false;
}
protected override bool Initialize(IEdmVocabularyAnnotation annotation)
/// <summary>
/// Init the <see cref="SearchRestrictionsType"/>.
/// </summary>
/// <param name="record">The input record.</param>
public void Initialize(IEdmRecordExpression record)
{
if (annotation == null ||
annotation.Value == null ||
annotation.Value.ExpressionKind != EdmExpressionKind.Record)
{
return false;
}
IEdmRecordExpression record = (IEdmRecordExpression)annotation.Value;
Utils.CheckArgumentNull(record, nameof(record));
// Searchable
Searchable = record.GetBoolean("Searchable");
@ -131,8 +125,6 @@ namespace Microsoft.OpenApi.OData.Capabilities
}
}
}
return true;
}
}
}

View file

@ -3,12 +3,17 @@
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
namespace Microsoft.OpenApi.OData.Capabilities
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
namespace Microsoft.OpenApi.OData.Vocabulary.Capabilities
{
/// <summary>
/// Complex type: Org.OData.Capabilities.V1.SelectSupportType
/// </summary>
internal class SelectSupportType
[Term("Org.OData.Capabilities.V1.SelectSupport")]
internal class SelectSupportType : IRecord
{
/// <summary>
/// Gets the Supports $select.
@ -54,5 +59,41 @@ namespace Microsoft.OpenApi.OData.Capabilities
/// Gets the orderby within $select is supported.
/// </summary>
public bool? Sortable { get; private set; }
/// <summary>
/// Init the <see cref="SelectSupportType"/>.
/// </summary>
/// <param name="record">The input record.</param>
public void Initialize(IEdmRecordExpression record)
{
Utils.CheckArgumentNull(record, nameof(record));
// Supported
Supported = record.GetBoolean("Supported");
// Expandable
Expandable = record.GetBoolean("Expandable");
// Filterable
Filterable = record.GetBoolean("Filterable");
// Searchable
Searchable = record.GetBoolean("Searchable");
// TopSupported
TopSupported = record.GetBoolean("TopSupported");
// SkipSupported
SkipSupported = record.GetBoolean("SkipSupported");
// ComputeSupported
ComputeSupported = record.GetBoolean("ComputeSupported");
// Countable
Countable = record.GetBoolean("Countable");
// Sortable
Sortable = record.GetBoolean("Sortable");
}
}
}

View file

@ -5,21 +5,18 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
namespace Microsoft.OpenApi.OData.Capabilities
namespace Microsoft.OpenApi.OData.Vocabulary.Capabilities
{
/// <summary>
/// Org.OData.Capabilities.V1.SortRestrictions
/// Complex Type: Org.OData.Capabilities.V1.SortRestrictionsType
/// </summary>
internal class SortRestrictions : CapabilitiesRestrictions
[Term("Org.OData.Capabilities.V1.SortRestrictions")]
internal class SortRestrictionsType : IRecord
{
/// <summary>
/// The Term type name.
/// </summary>
public override CapabilitesTermKind Kind => CapabilitesTermKind.SortRestrictions;
/// <summary>
/// Gets the Sortable value.
/// </summary>
@ -75,16 +72,13 @@ namespace Microsoft.OpenApi.OData.Capabilities
return NonSortableProperties != null ? NonSortableProperties.Any(a => a == propertyPath) : false;
}
protected override bool Initialize(IEdmVocabularyAnnotation annotation)
/// <summary>
/// Init the <see cref="SortRestrictionsType"/>.
/// </summary>
/// <param name="record">The input record.</param>
public void Initialize(IEdmRecordExpression record)
{
if (annotation == null ||
annotation.Value == null ||
annotation.Value.ExpressionKind != EdmExpressionKind.Record)
{
return false;
}
IEdmRecordExpression record = (IEdmRecordExpression)annotation.Value;
Utils.CheckArgumentNull(record, nameof(record));
// Sortable
Sortable = record.GetBoolean("Sortable");
@ -97,8 +91,6 @@ namespace Microsoft.OpenApi.OData.Capabilities
// NonSortablePropeties
NonSortableProperties = record.GetCollectionPropertyPath("NonSortableProperties");
return true;
}
}
}

View file

@ -5,21 +5,18 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
namespace Microsoft.OpenApi.OData.Capabilities
namespace Microsoft.OpenApi.OData.Vocabulary.Capabilities
{
/// <summary>
/// Org.OData.Capabilities.V1.UpdateRestrictionsType
/// Complex Type: Org.OData.Capabilities.V1.UpdateRestrictionsType
/// </summary>
internal class UpdateRestrictions : CapabilitiesRestrictions
[Term("Org.OData.Capabilities.V1.UpdateRestrictions")]
internal class UpdateRestrictionsType : IRecord
{
/// <summary>
/// The Term type kind.
/// </summary>
public override CapabilitesTermKind Kind => CapabilitesTermKind.UpdateRestrictions;
/// <summary>
/// Gets the Updatable value, if true, entities can be updated.
/// The default value is true;
@ -35,7 +32,7 @@ namespace Microsoft.OpenApi.OData.Capabilities
/// Gets the maximum number of navigation properties that can be traversed when addressing the collection or entity to update.
/// A value of -1 indicates there is no restriction.
/// </summary>
public int MaxLevels { get; private set; } = -1;
public long? MaxLevels { get; private set; }
/// <summary>
/// Gets/sets the required scopes to perform update.
@ -75,16 +72,13 @@ namespace Microsoft.OpenApi.OData.Capabilities
false;
}
protected override bool Initialize(IEdmVocabularyAnnotation annotation)
/// <summary>
/// Init the <see cref="UpdateRestrictionsType"/>.
/// </summary>
/// <param name="record">The input record.</param>
public void Initialize(IEdmRecordExpression record)
{
if (annotation == null ||
annotation.Value == null ||
annotation.Value.ExpressionKind != EdmExpressionKind.Record)
{
return false;
}
IEdmRecordExpression record = (IEdmRecordExpression)annotation.Value;
Utils.CheckArgumentNull(record, nameof(record));
// Updatable
Updatable = record.GetBoolean("Updatable");
@ -92,7 +86,20 @@ namespace Microsoft.OpenApi.OData.Capabilities
// NonUpdatableNavigationProperties
NonUpdatableNavigationProperties = record.GetCollectionPropertyPath("NonUpdatableNavigationProperties");
return true;
// MaxLevels
MaxLevels = record.GetInteger("MaxLevels");
// Permission
Permission = record.GetRecord<PermissionType>("Permission");
// QueryOptions
QueryOptions = record.GetRecord<ModificationQueryOptionsType>("QueryOptions");
// CustomHeaders
CustomHeaders = record.GetCollection<CustomParameter>("CustomHeaders");
// CustomQueryOptions
CustomQueryOptions = record.GetCollection<CustomParameter>("CustomQueryOptions");
}
}
}

View file

@ -0,0 +1,14 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
namespace Microsoft.OpenApi.OData.Vocabulary.Core
{
/// <summary>
/// Complex type: Org.OData.Core.V1.ComplexExampleValue.
/// </summary>
internal class ComplexExampleValue : ResourceExampleValue
{
}
}

View file

@ -0,0 +1,14 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
namespace Microsoft.OpenApi.OData.Vocabulary.Core
{
/// <summary>
/// Complex type: Org.OData.Core.V1.EntityExampleValue.
/// </summary>
internal class EntityExampleValue : ResourceExampleValue
{
}
}

View file

@ -0,0 +1,34 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
namespace Microsoft.OpenApi.OData.Vocabulary.Core
{
/// <summary>
/// Complex type: Org.OData.Core.V1.ExampleValue.
/// </summary>
internal class ExampleValue : IRecord
{
/// <summary>
/// Gets the description of the example value.
/// </summary>
public string Description { get; private set; }
/// <summary>
/// Init the <see cref="ExampleValue"/>
/// </summary>
/// <param name="record">The input record.</param>
public virtual void Initialize(IEdmRecordExpression record)
{
Utils.CheckArgumentNull(record, nameof(record));
// Description
Description = record.GetString("Description");
}
}
}

View file

@ -6,25 +6,26 @@
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Edm;
namespace Microsoft.OpenApi.OData.Annotations
namespace Microsoft.OpenApi.OData.Vocabulary.Core
{
/// <summary>
/// Complex type Org.OData.Core.V1.ExternalExample
/// Complex type: Org.OData.Core.V1.ExternalExampleValue.
/// </summary>
internal class ExternalExample : Example
internal class ExternalExampleValue : ExampleValue
{
/// <summary>
/// ExternalValue
/// Gets the Url reference to the value in its literal format
/// </summary>
public string ExternalValue { get; set; }
/// <summary>
/// Init the <see cref="ExternalExample"/>.
/// Init the <see cref="ExternalExampleValue"/>
/// </summary>
/// <param name="record">The record.</param>
public override void Init(IEdmRecordExpression record)
/// <param name="record">The input record.</param>
public override void Initialize(IEdmRecordExpression record)
{
base.Init(record);
// Load ExampleValue
base.Initialize(record);
// ExternalValue
ExternalValue = record.GetString("ExternalValue");

View file

@ -0,0 +1,49 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Vocabularies;
using Microsoft.OpenApi.OData.Common;
namespace Microsoft.OpenApi.OData.Vocabulary.Core
{
/// <summary>
/// Complex type: Org.OData.Core.V1.PrimitiveExampleValue.
/// </summary>
internal class PrimitiveExampleValue : ExampleValue
{
/// <summary>
/// Gets the Example value for the custom parameter
/// </summary>
public ODataPrimitiveValue Value { get; private set; }
/// <summary>
/// Init the <see cref="PrimitiveExampleValue"/>
/// </summary>
/// <param name="record">The input record.</param>
public override void Initialize(IEdmRecordExpression record)
{
Utils.CheckArgumentNull(record, nameof(record));
/* Should we throw exception if the input record is not a primitive example value?
* Leave the below codes for further decision.
if (record.DeclaredType == null || record.DeclaredType.FullName() != "Org.OData.Core.V1.PrimitiveExampleValue")
{
throw new OpenApiException();
}
*/
// Load ExampleValue
base.Initialize(record);
// Value of PrimitiveExampleValue
IEdmPropertyConstructor property = record.FindProperty("Value");
if (property != null)
{
Value = property.Value.Convert() as ODataPrimitiveValue;
}
}
}
}

View file

@ -0,0 +1,38 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
using Microsoft.OData.Edm;
using Microsoft.OData.Edm.Vocabularies;
namespace Microsoft.OpenApi.OData.Vocabulary.Core
{
/// <summary>
/// Base class for <see cref="EntityExampleValue"/> and <see cref="ComplexExampleValue"/>.
/// </summary>
internal abstract class ResourceExampleValue : ExampleValue
{
/// <summary>
/// Gets the Example value for the custom parameter
/// </summary>
public ODataResourceValue Value { get; private set; }
/// <summary>
/// Init the <see cref="ResourceExampleValue"/>
/// </summary>
/// <param name="record">The input record.</param>
public override void Initialize(IEdmRecordExpression record)
{
// Load ExampleValue
base.Initialize(record);
// Value of PrimitiveExampleValue
IEdmPropertyConstructor property = record.FindProperty("Value");
if (property != null)
{
Value = property.Value.Convert() as ODataResourceValue;
}
}
}
}

Some files were not shown because too many files have changed in this diff Show more