Skip to content

Commit 4c9150a

Browse files
Add navigation property extension (#277)
1 parent bc5be6f commit 4c9150a

20 files changed

+183
-69
lines changed

src/Microsoft.OpenApi.OData.Reader/Common/Constants.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ internal static class Constants
9595
/// </summary>
9696
public static string xMsDiscriminatorValue = "x-ms-discriminator-value";
9797

98+
/// <summary>
99+
/// extension for navigation property
100+
/// </summary>
101+
public static string xMsNavigationProperty = "x-ms-navigationProperty";
102+
98103
/// <summary>
99104
/// Name used for the OpenAPI referenced schema for OData Count operations responses.
100105
/// </summary>

src/Microsoft.OpenApi.OData.Reader/Common/Utils.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ internal static bool TryAdd<TKey, TValue>(this IDictionary<TKey, TValue> diction
166166
/// values will be added to.</param>
167167
/// <param name="context">The OData context.</param>
168168
/// <param name="element">The target element.</param>
169-
internal static void AddCustomAtributesToExtensions(this IDictionary<string, IOpenApiExtension> extensions, ODataContext context, IEdmElement element)
169+
internal static void AddCustomAttributesToExtensions(this IDictionary<string, IOpenApiExtension> extensions, ODataContext context, IEdmElement element)
170170
{
171171
if (extensions == null ||
172172
context == null ||
@@ -175,7 +175,7 @@ internal static void AddCustomAtributesToExtensions(this IDictionary<string, IOp
175175
return;
176176
}
177177

178-
Dictionary<string, string> atrributesValueMap = GetCustomXMLAtrributesValueMapping(context.Model, element, context.Settings.CustomXMLAttributesMapping);
178+
Dictionary<string, string> atrributesValueMap = GetCustomXMLAttributesValueMapping(context.Model, element, context.Settings.CustomXMLAttributesMapping);
179179

180180
if (atrributesValueMap?.Any() ?? false)
181181
{
@@ -194,7 +194,7 @@ internal static void AddCustomAtributesToExtensions(this IDictionary<string, IOp
194194
/// <param name="element">The target element.</param>
195195
/// <param name="customXMLAttributesMapping">The dictionary mapping of attribute names and extension names.</param>
196196
/// <returns>A dictionary of extension names mapped to the custom attribute values.</returns>
197-
private static Dictionary<string, string> GetCustomXMLAtrributesValueMapping(IEdmModel model, IEdmElement element, Dictionary<string, string> customXMLAttributesMapping)
197+
private static Dictionary<string, string> GetCustomXMLAttributesValueMapping(IEdmModel model, IEdmElement element, Dictionary<string, string> customXMLAttributesMapping)
198198
{
199199
Dictionary<string, string> atrributesValueMap = new();
200200

src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiSchemaGenerator.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ public static IDictionary<string, OpenApiSchema> CreateStructuredTypePropertiesS
389389
{
390390
OpenApiSchema propertySchema = context.CreatePropertySchema(property);
391391
propertySchema.Description = context.Model.GetDescriptionAnnotation(property);
392-
propertySchema.Extensions.AddCustomAtributesToExtensions(context, property);
392+
propertySchema.Extensions.AddCustomAttributesToExtensions(context, property);
393393
properties.Add(property.Name, propertySchema);
394394
}
395395

@@ -398,7 +398,8 @@ public static IDictionary<string, OpenApiSchema> CreateStructuredTypePropertiesS
398398
{
399399
OpenApiSchema propertySchema = context.CreateEdmTypeSchema(property.Type);
400400
propertySchema.Description = context.Model.GetDescriptionAnnotation(property);
401-
propertySchema.Extensions.AddCustomAtributesToExtensions(context, property);
401+
propertySchema.Extensions.AddCustomAttributesToExtensions(context, property);
402+
propertySchema.Extensions.Add(Constants.xMsNavigationProperty, new OpenApiBoolean(true));
402403
properties.Add(property.Name, propertySchema);
403404
}
404405

src/Microsoft.OpenApi.OData.Reader/PathItem/ComplexPropertyItemHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,6 @@ protected override void Initialize(ODataContext context, ODataPath path)
7070
/// <inheritdoc/>
7171
protected override void SetExtensions(OpenApiPathItem item)
7272
{
73-
item.Extensions.AddCustomAtributesToExtensions(Context, ComplexProperty);
73+
item.Extensions.AddCustomAttributesToExtensions(Context, ComplexProperty);
7474
}
7575
}

src/Microsoft.OpenApi.OData.Reader/PathItem/EntityPathItemHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ protected override void SetOperations(OpenApiPathItem item)
5555
protected override void SetExtensions(OpenApiPathItem pathItem)
5656
{
5757
base.SetExtensions(pathItem);
58-
pathItem.Extensions.AddCustomAtributesToExtensions(Context, EntitySet.EntityType());
58+
pathItem.Extensions.AddCustomAttributesToExtensions(Context, EntitySet.EntityType());
5959
}
6060
}
6161
}

src/Microsoft.OpenApi.OData.Reader/PathItem/EntitySetPathItemHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ protected override void SetBasicInfo(OpenApiPathItem pathItem)
6060
protected override void SetExtensions(OpenApiPathItem pathItem)
6161
{
6262
base.SetExtensions(pathItem);
63-
pathItem.Extensions.AddCustomAtributesToExtensions(Context, EntitySet);
63+
pathItem.Extensions.AddCustomAttributesToExtensions(Context, EntitySet);
6464
}
6565
}
6666
}

src/Microsoft.OpenApi.OData.Reader/PathItem/NavigationPropertyPathItemHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ protected override void SetExtensions(OpenApiPathItem item)
266266
}
267267

268268
base.SetExtensions(item);
269-
item.Extensions.AddCustomAtributesToExtensions(Context, NavigationProperty);
269+
item.Extensions.AddCustomAttributesToExtensions(Context, NavigationProperty);
270270
}
271271
/// <inheritdoc/>
272272
protected override void SetBasicInfo(OpenApiPathItem pathItem)

src/Microsoft.OpenApi.OData.Reader/PathItem/ODataTypeCastPathItemHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ protected override void SetBasicInfo(OpenApiPathItem pathItem)
4545
protected override void SetExtensions(OpenApiPathItem pathItem)
4646
{
4747
base.SetExtensions(pathItem);
48-
pathItem.Extensions.AddCustomAtributesToExtensions(Context, StructuredType);
48+
pathItem.Extensions.AddCustomAttributesToExtensions(Context, StructuredType);
4949
}
5050
}

src/Microsoft.OpenApi.OData.Reader/PathItem/OperationImportPathItemHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ protected override void SetBasicInfo(OpenApiPathItem pathItem)
7171
protected override void SetExtensions(OpenApiPathItem item)
7272
{
7373
base.SetExtensions(item);
74-
item.Extensions.AddCustomAtributesToExtensions(Context, EdmOperationImport);
74+
item.Extensions.AddCustomAttributesToExtensions(Context, EdmOperationImport);
7575
}
7676
}
7777
}

src/Microsoft.OpenApi.OData.Reader/PathItem/OperationPathItemHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ protected override void SetExtensions(OpenApiPathItem item)
9595
}
9696

9797
base.SetExtensions(item);
98-
item.Extensions.AddCustomAtributesToExtensions(Context, EdmOperation);
98+
item.Extensions.AddCustomAttributesToExtensions(Context, EdmOperation);
9999
}
100100

101101
/// <inheritdoc/>

0 commit comments

Comments
 (0)