Skip to content

Commit 9255901

Browse files
committed
- fixes a bug where not implemented exceptions could be thrown by some descriptions
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
1 parent e647a1b commit 9255901

14 files changed

+91
-55
lines changed

src/Microsoft.OpenApi.OData.Reader/Edm/ODataComplexPropertySegment.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ public ODataComplexPropertySegment(IEdmStructuralProperty property)
2020
Property = property ?? throw Error.ArgumentNull(nameof(property));
2121
}
2222

23+
/// <inheritdoc />
24+
public override IEdmEntityType EntityType => null;
25+
2326
/// <inheritdoc />
2427
public override ODataSegmentKind Kind => ODataSegmentKind.ComplexProperty;
2528

src/Microsoft.OpenApi.OData.Reader/Edm/ODataDollarCountSegment.cs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,35 @@
55

66
using System.Collections.Generic;
77
using System.Linq;
8+
using Microsoft.OData.Edm;
89
using Microsoft.OData.Edm.Vocabularies;
910

10-
namespace Microsoft.OpenApi.OData.Edm
11+
namespace Microsoft.OpenApi.OData.Edm;
12+
/// <summary>
13+
/// The $count segment.
14+
/// </summary>
15+
public class ODataDollarCountSegment : ODataSegment
1116
{
1217
/// <summary>
13-
/// The $count segment.
18+
/// Get the static instance of $count segment.
1419
/// </summary>
15-
public class ODataDollarCountSegment : ODataSegment
16-
{
17-
/// <summary>
18-
/// Get the static instance of $count segment.
19-
/// </summary>
20-
internal static ODataDollarCountSegment Instance = new();
20+
internal static ODataDollarCountSegment Instance = new();
2121

22-
/// <inheritdoc />
23-
public override ODataSegmentKind Kind => ODataSegmentKind.DollarCount;
22+
/// <inheritdoc />
23+
public override IEdmEntityType EntityType => null;
2424

25-
/// <inheritdoc />
26-
public override string Identifier => "$count";
25+
/// <inheritdoc />
26+
public override ODataSegmentKind Kind => ODataSegmentKind.DollarCount;
2727

28-
/// <inheritdoc />
29-
public override IEnumerable<IEdmVocabularyAnnotatable> GetAnnotables()
30-
{
31-
return Enumerable.Empty<IEdmVocabularyAnnotatable>();
32-
}
28+
/// <inheritdoc />
29+
public override string Identifier => "$count";
3330

34-
/// <inheritdoc />
35-
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters) => "$count";
31+
/// <inheritdoc />
32+
public override IEnumerable<IEdmVocabularyAnnotatable> GetAnnotables()
33+
{
34+
return Enumerable.Empty<IEdmVocabularyAnnotatable>();
3635
}
36+
37+
/// <inheritdoc />
38+
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters) => "$count";
3739
}

src/Microsoft.OpenApi.OData.Reader/Edm/ODataMetadataSegment.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
using System.Collections.Generic;
77
using System.Linq;
8+
using Microsoft.OData.Edm;
89
using Microsoft.OData.Edm.Vocabularies;
910

1011
namespace Microsoft.OpenApi.OData.Edm
@@ -14,6 +15,8 @@ namespace Microsoft.OpenApi.OData.Edm
1415
/// </summary>
1516
public class ODataMetadataSegment : ODataSegment
1617
{
18+
/// <inheritdoc />
19+
public override IEdmEntityType EntityType => null;
1720
/// <inheritdoc />
1821
public override ODataSegmentKind Kind => ODataSegmentKind.Metadata;
1922

src/Microsoft.OpenApi.OData.Reader/Edm/ODataOperationImportSegment.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ public ODataOperationImportSegment(IEdmOperationImport operationImport, IDiction
4848
/// </summary>
4949
public IEdmOperationImport OperationImport { get; }
5050

51+
/// <inheritdoc />
52+
public override IEdmEntityType EntityType => null;
53+
5154
/// <inheritdoc />
5255
public override ODataSegmentKind Kind => ODataSegmentKind.OperationImport;
5356

src/Microsoft.OpenApi.OData.Reader/Edm/ODataOperationSegment.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ public ODataOperationSegment(IEdmOperation operation, IDictionary<string, string
7070
/// <inheritdoc />
7171
public override string Identifier { get => Operation.Name; }
7272

73+
/// <inheritdoc />
74+
public override IEdmEntityType EntityType => null;
75+
7376
/// <inheritdoc />
7477
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters)
7578
{

src/Microsoft.OpenApi.OData.Reader/Edm/ODataRefSegment.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
using System.Collections.Generic;
77
using System.Linq;
8+
using Microsoft.OData.Edm;
89
using Microsoft.OData.Edm.Vocabularies;
910

1011
namespace Microsoft.OpenApi.OData.Edm
@@ -26,6 +27,9 @@ private ODataRefSegment()
2627
{
2728
}
2829

30+
/// <inheritdoc />
31+
public override IEdmEntityType EntityType => null;
32+
2933
/// <inheritdoc />
3034
public override ODataSegmentKind Kind => ODataSegmentKind.Ref;
3135

src/Microsoft.OpenApi.OData.Reader/Edm/ODataStreamContentSegment.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
using System.Collections.Generic;
77
using System.Linq;
8+
using Microsoft.OData.Edm;
89
using Microsoft.OData.Edm.Vocabularies;
910

1011
namespace Microsoft.OpenApi.OData.Edm
@@ -14,6 +15,8 @@ namespace Microsoft.OpenApi.OData.Edm
1415
/// </summary>
1516
public class ODataStreamContentSegment : ODataSegment
1617
{
18+
/// <inheritdoc />
19+
public override IEdmEntityType EntityType => null;
1720
/// <inheritdoc />
1821
public override ODataSegmentKind Kind => ODataSegmentKind.StreamContent;
1922

src/Microsoft.OpenApi.OData.Reader/Edm/ODataStreamPropertySegment.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System.Collections.Generic;
66
using System.Linq;
7+
using Microsoft.OData.Edm;
78
using Microsoft.OData.Edm.Vocabularies;
89
using Microsoft.OpenApi.OData.Common;
910

@@ -24,6 +25,9 @@ public ODataStreamPropertySegment(string streamPropertyName)
2425
_streamPropertyName = streamPropertyName ?? throw Error.ArgumentNull(nameof(streamPropertyName));
2526
}
2627

28+
/// <inheritdoc />
29+
public override IEdmEntityType EntityType => null;
30+
2731
/// <inheritdoc />
2832
public override ODataSegmentKind Kind => ODataSegmentKind.StreamProperty;
2933

src/Microsoft.OpenApi.OData.Reader/Edm/ODataTypeCastSegment.cs

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,41 @@
88
using Microsoft.OData.Edm.Vocabularies;
99
using Microsoft.OpenApi.OData.Common;
1010

11-
namespace Microsoft.OpenApi.OData.Edm
11+
namespace Microsoft.OpenApi.OData.Edm;
12+
/// <summary>
13+
/// Type cast segment.
14+
/// </summary>
15+
public class ODataTypeCastSegment : ODataSegment
1216
{
1317
/// <summary>
14-
/// Type cast segment.
18+
/// Initializes a new instance of <see cref="ODataTypeCastSegment"/> class.
1519
/// </summary>
16-
public class ODataTypeCastSegment : ODataSegment
20+
/// <param name="structuredType">The target type cast type.</param>
21+
public ODataTypeCastSegment(IEdmStructuredType structuredType)
1722
{
18-
/// <summary>
19-
/// Initializes a new instance of <see cref="ODataTypeCastSegment"/> class.
20-
/// </summary>
21-
/// <param name="structuredType">The target type cast type.</param>
22-
public ODataTypeCastSegment(IEdmStructuredType structuredType)
23-
{
24-
StructuredType = structuredType ?? throw Error.ArgumentNull(nameof(structuredType));
25-
}
26-
/// <inheritdoc />
27-
public override ODataSegmentKind Kind => ODataSegmentKind.TypeCast;
28-
29-
/// <inheritdoc />
30-
public override string Identifier { get => StructuredType.FullTypeName(); }
31-
32-
/// <summary>
33-
/// Gets the target type cast type.
34-
/// </summary>
35-
public IEdmStructuredType StructuredType { get; private set; }
36-
37-
/// <inheritdoc />
38-
public override IEnumerable<IEdmVocabularyAnnotatable> GetAnnotables()
39-
{
40-
return new IEdmVocabularyAnnotatable[] { StructuredType as IEdmVocabularyAnnotatable };
41-
}
42-
43-
/// <inheritdoc />
44-
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters) => StructuredType.FullTypeName();
23+
StructuredType = structuredType ?? throw Error.ArgumentNull(nameof(structuredType));
4524
}
25+
26+
/// <inheritdoc />
27+
public override IEdmEntityType EntityType => null;
28+
29+
/// <inheritdoc />
30+
public override ODataSegmentKind Kind => ODataSegmentKind.TypeCast;
31+
32+
/// <inheritdoc />
33+
public override string Identifier { get => StructuredType.FullTypeName(); }
34+
35+
/// <summary>
36+
/// Gets the target type cast type.
37+
/// </summary>
38+
public IEdmStructuredType StructuredType { get; private set; }
39+
40+
/// <inheritdoc />
41+
public override IEnumerable<IEdmVocabularyAnnotatable> GetAnnotables()
42+
{
43+
return new IEdmVocabularyAnnotatable[] { StructuredType as IEdmVocabularyAnnotatable };
44+
}
45+
46+
/// <inheritdoc />
47+
public override string GetPathItemName(OpenApiConvertSettings settings, HashSet<string> parameters) => StructuredType.FullTypeName();
4648
}

src/Microsoft.OpenApi.OData.Reader/PublicAPI.Unshipped.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ Microsoft.OpenApi.OData.Edm.ODataTypeCastSegment.ODataTypeCastSegment(Microsoft.
9595
Microsoft.OpenApi.OData.Edm.ODataComplexPropertySegment
9696
Microsoft.OpenApi.OData.Edm.ODataComplexPropertySegment.ODataComplexPropertySegment(Microsoft.OData.Edm.IEdmStructuralProperty property) -> void
9797
Microsoft.OpenApi.OData.Edm.ODataComplexPropertySegment.Property.get -> Microsoft.OData.Edm.IEdmStructuralProperty
98+
override Microsoft.OpenApi.OData.Edm.ODataComplexPropertySegment.EntityType.get -> Microsoft.OData.Edm.IEdmEntityType
9899
override Microsoft.OpenApi.OData.Edm.ODataComplexPropertySegment.Kind.get -> Microsoft.OpenApi.OData.Edm.ODataSegmentKind
99100
override Microsoft.OpenApi.OData.Edm.ODataComplexPropertySegment.Identifier.get -> string
100101
Microsoft.OpenApi.OData.Edm.ODataComplexPropertySegment.ComplexType.get -> Microsoft.OData.Edm.IEdmComplexType
@@ -180,6 +181,7 @@ Microsoft.OpenApi.OData.OpenApiConvertSettings.EnableDeprecationInformation.get
180181
Microsoft.OpenApi.OData.OpenApiConvertSettings.EnableDeprecationInformation.set -> void
181182
override Microsoft.OpenApi.OData.Edm.ODataDollarCountSegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet<string> parameters) -> string
182183
override Microsoft.OpenApi.OData.Edm.ODataDollarCountSegment.Identifier.get -> string
184+
override Microsoft.OpenApi.OData.Edm.ODataDollarCountSegment.EntityType.get -> Microsoft.OData.Edm.IEdmEntityType
183185
override Microsoft.OpenApi.OData.Edm.ODataDollarCountSegment.Kind.get -> Microsoft.OpenApi.OData.Edm.ODataSegmentKind
184186
override Microsoft.OpenApi.OData.Edm.ODataDollarCountSegment.GetAnnotables() -> System.Collections.Generic.IEnumerable<Microsoft.OData.Edm.Vocabularies.IEdmVocabularyAnnotatable>
185187
override Microsoft.OpenApi.OData.Edm.ODataKeySegment.EntityType.get -> Microsoft.OData.Edm.IEdmEntityType
@@ -189,6 +191,7 @@ override Microsoft.OpenApi.OData.Edm.ODataKeySegment.Kind.get -> Microsoft.OpenA
189191
override Microsoft.OpenApi.OData.Edm.ODataKeySegment.GetAnnotables() -> System.Collections.Generic.IEnumerable<Microsoft.OData.Edm.Vocabularies.IEdmVocabularyAnnotatable>
190192
override Microsoft.OpenApi.OData.Edm.ODataMetadataSegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet<string> parameters) -> string
191193
override Microsoft.OpenApi.OData.Edm.ODataMetadataSegment.Identifier.get -> string
194+
override Microsoft.OpenApi.OData.Edm.ODataMetadataSegment.EntityType.get -> Microsoft.OData.Edm.IEdmEntityType
192195
override Microsoft.OpenApi.OData.Edm.ODataMetadataSegment.Kind.get -> Microsoft.OpenApi.OData.Edm.ODataSegmentKind
193196
override Microsoft.OpenApi.OData.Edm.ODataMetadataSegment.GetAnnotables() -> System.Collections.Generic.IEnumerable<Microsoft.OData.Edm.Vocabularies.IEdmVocabularyAnnotatable>
194197
override Microsoft.OpenApi.OData.Edm.ODataNavigationPropertySegment.EntityType.get -> Microsoft.OData.Edm.IEdmEntityType
@@ -203,28 +206,34 @@ override Microsoft.OpenApi.OData.Edm.ODataNavigationSourceSegment.Kind.get -> Mi
203206
override Microsoft.OpenApi.OData.Edm.ODataNavigationSourceSegment.GetAnnotables() -> System.Collections.Generic.IEnumerable<Microsoft.OData.Edm.Vocabularies.IEdmVocabularyAnnotatable>
204207
override Microsoft.OpenApi.OData.Edm.ODataOperationImportSegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet<string> parameters) -> string
205208
override Microsoft.OpenApi.OData.Edm.ODataOperationImportSegment.Identifier.get -> string
209+
override Microsoft.OpenApi.OData.Edm.ODataOperationImportSegment.EntityType.get -> Microsoft.OData.Edm.IEdmEntityType
206210
override Microsoft.OpenApi.OData.Edm.ODataOperationImportSegment.Kind.get -> Microsoft.OpenApi.OData.Edm.ODataSegmentKind
207211
override Microsoft.OpenApi.OData.Edm.ODataOperationImportSegment.GetAnnotables() -> System.Collections.Generic.IEnumerable<Microsoft.OData.Edm.Vocabularies.IEdmVocabularyAnnotatable>
208212
override Microsoft.OpenApi.OData.Edm.ODataOperationSegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet<string> parameters) -> string
209213
override Microsoft.OpenApi.OData.Edm.ODataOperationSegment.Identifier.get -> string
214+
override Microsoft.OpenApi.OData.Edm.ODataOperationSegment.EntityType.get -> Microsoft.OData.Edm.IEdmEntityType
210215
override Microsoft.OpenApi.OData.Edm.ODataOperationSegment.Kind.get -> Microsoft.OpenApi.OData.Edm.ODataSegmentKind
211216
override Microsoft.OpenApi.OData.Edm.ODataOperationSegment.GetAnnotables() -> System.Collections.Generic.IEnumerable<Microsoft.OData.Edm.Vocabularies.IEdmVocabularyAnnotatable>
212217
override Microsoft.OpenApi.OData.Edm.ODataPath.ToString() -> string
213218
override Microsoft.OpenApi.OData.Edm.ODataRefSegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet<string> parameters) -> string
214219
override Microsoft.OpenApi.OData.Edm.ODataRefSegment.Identifier.get -> string
220+
override Microsoft.OpenApi.OData.Edm.ODataRefSegment.EntityType.get -> Microsoft.OData.Edm.IEdmEntityType
215221
override Microsoft.OpenApi.OData.Edm.ODataRefSegment.Kind.get -> Microsoft.OpenApi.OData.Edm.ODataSegmentKind
216222
override Microsoft.OpenApi.OData.Edm.ODataRefSegment.GetAnnotables() -> System.Collections.Generic.IEnumerable<Microsoft.OData.Edm.Vocabularies.IEdmVocabularyAnnotatable>
217223
override Microsoft.OpenApi.OData.Edm.ODataStreamContentSegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet<string> parameters) -> string
218224
override Microsoft.OpenApi.OData.Edm.ODataStreamContentSegment.Identifier.get -> string
225+
override Microsoft.OpenApi.OData.Edm.ODataStreamContentSegment.EntityType.get -> Microsoft.OData.Edm.IEdmEntityType
219226
override Microsoft.OpenApi.OData.Edm.ODataStreamContentSegment.Kind.get -> Microsoft.OpenApi.OData.Edm.ODataSegmentKind
220227
override Microsoft.OpenApi.OData.Edm.ODataStreamContentSegment.GetAnnotables() -> System.Collections.Generic.IEnumerable<Microsoft.OData.Edm.Vocabularies.IEdmVocabularyAnnotatable>
221228
override Microsoft.OpenApi.OData.Edm.ODataStreamPropertySegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet<string> parameters) -> string
222229
override Microsoft.OpenApi.OData.Edm.ODataStreamPropertySegment.Identifier.get -> string
230+
override Microsoft.OpenApi.OData.Edm.ODataStreamPropertySegment.EntityType.get -> Microsoft.OData.Edm.IEdmEntityType
223231
override Microsoft.OpenApi.OData.Edm.ODataStreamPropertySegment.Kind.get -> Microsoft.OpenApi.OData.Edm.ODataSegmentKind
224232
override Microsoft.OpenApi.OData.Edm.ODataStreamPropertySegment.GetAnnotables() -> System.Collections.Generic.IEnumerable<Microsoft.OData.Edm.Vocabularies.IEdmVocabularyAnnotatable>
225233
Microsoft.OpenApi.OData.Edm.ODataTypeCastSegment.StructuredType.get -> Microsoft.OData.Edm.IEdmStructuredType
226234
override Microsoft.OpenApi.OData.Edm.ODataTypeCastSegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet<string> parameters) -> string
227235
override Microsoft.OpenApi.OData.Edm.ODataTypeCastSegment.Identifier.get -> string
236+
override Microsoft.OpenApi.OData.Edm.ODataTypeCastSegment.EntityType.get -> Microsoft.OData.Edm.IEdmEntityType
228237
override Microsoft.OpenApi.OData.Edm.ODataTypeCastSegment.Kind.get -> Microsoft.OpenApi.OData.Edm.ODataSegmentKind
229238
override Microsoft.OpenApi.OData.Edm.ODataTypeCastSegment.GetAnnotables() -> System.Collections.Generic.IEnumerable<Microsoft.OData.Edm.Vocabularies.IEdmVocabularyAnnotatable>
230239
static Microsoft.OpenApi.OData.Common.Utils.GetTermQualifiedName<T>() -> string

test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataComplexPropertySegmentTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void ComplexTypeReturnsPropertyComplexType()
3636
var segment = new ODataComplexPropertySegment(_addressProperty);
3737

3838
// Assert
39-
Assert.Throws<NotImplementedException>(() => segment.EntityType);
39+
Assert.Null(segment.EntityType);
4040
Assert.Same(_addressComplexType, segment.ComplexType);
4141
}
4242

test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataOperationImportSegmentTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ public void CtorSetOperationImportProperty()
4444
}
4545

4646
[Fact]
47-
public void GetEntityTypeThrowsNotImplementedException()
47+
public void GetEntityTypeReturnsNull()
4848
{
4949
// Arrange & Act
5050
var segment = new ODataOperationImportSegment(_actionImport);
5151

5252
// Assert
53-
Assert.Throws<NotImplementedException>(() => segment.EntityType);
53+
Assert.Null(segment.EntityType);
5454
}
5555

5656
[Fact]

test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataOperationSegmentTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ public void CtorSetOperationProperty()
3131
}
3232

3333
[Fact]
34-
public void GetEntityTypeThrowsNotImplementedException()
34+
public void GetEntityTypeReturnsNull()
3535
{
3636
// Arrange & Act
3737
IEdmOperation operation = new EdmAction("NS", "MyAction", null);
3838
var segment = new ODataOperationSegment(operation);
3939

4040
// Assert
41-
Assert.Throws<NotImplementedException>(() => segment.EntityType);
41+
Assert.Null(segment.EntityType);
4242
}
4343

4444
[Fact]

test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataTypeCastSegmentTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public void TypeCastSegmentEntityTypePropertyReturnsSameEntityType()
3232
var segment = new ODataTypeCastSegment(_person);
3333

3434
// Assert
35-
Assert.Throws<NotImplementedException>(() => segment.EntityType);
35+
Assert.Null(segment.EntityType);
3636
Assert.Same(_person, segment.StructuredType);
3737
}
3838

0 commit comments

Comments
 (0)