Skip to content

Commit afffecc

Browse files
Add support for Edm.Untyped (#531)
* Add support for Edm.Untyped * Add release notes * Additional test
1 parent bfb0cb7 commit afffecc

File tree

10 files changed

+67
-7
lines changed

10 files changed

+67
-7
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ public static OpenApiSchema CreateEdmTypeSchema(this ODataContext context, IEdmT
7272
case EdmTypeKind.EntityReference:
7373
return context.CreateTypeDefinitionSchema(edmTypeReference.AsTypeDefinition());
7474

75+
case EdmTypeKind.Untyped:
76+
return new OpenApiSchema();
77+
7578
case EdmTypeKind.None:
7679
default:
7780
throw Error.NotSupported(String.Format(SRResource.NotSupportedEdmTypeKind, edmTypeReference.TypeKind()));

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ private static IOpenApiAny GetTypeNameForExample(IEdmTypeReference edmTypeRefere
180180
return GetTypeNameForExample(new EdmPrimitiveTypeReference(typedef.UnderlyingType, edmTypeReference.IsNullable));
181181

182182
case EdmTypeKind.Untyped:
183+
return new OpenApiObject();
184+
183185
case EdmTypeKind.EntityReference:
184186
default:
185187
throw new OpenApiException("Not support for the type kind " + edmTypeReference.TypeKind());

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,8 @@ private static IOpenApiAny GetTypeNameForExample(ODataContext context, IEdmTypeR
700700
return array;
701701

702702
case EdmTypeKind.Untyped:
703+
return new OpenApiObject();
704+
703705
case EdmTypeKind.TypeDefinition:
704706
case EdmTypeKind.EntityReference:
705707
default:

src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
<TargetFrameworks>netstandard2.0</TargetFrameworks>
1616
<PackageId>Microsoft.OpenApi.OData</PackageId>
1717
<SignAssembly>true</SignAssembly>
18-
<Version>1.6.3</Version>
18+
<Version>1.6.4</Version>
1919
<Description>This package contains the codes you need to convert OData CSDL to Open API Document of Model.</Description>
2020
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
2121
<PackageTags>Microsoft OpenApi OData EDM</PackageTags>
2222
<RepositoryUrl>https://github.com/Microsoft/OpenAPI.NET.OData</RepositoryUrl>
2323
<PackageReleaseNotes>
24-
- Add delete operations to media entities #522
24+
- Add support for Edm.Untyped #511
2525
</PackageReleaseNotes>
2626
<AssemblyName>Microsoft.OpenApi.OData.Reader</AssemblyName>
2727
<AssemblyOriginatorKeyFile>..\..\tool\Microsoft.OpenApi.OData.snk</AssemblyOriginatorKeyFile>

test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiSchemaGeneratorTests.cs

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ public void CreatesCollectionResponseSchema(bool enablePagination, bool enableCo
5656
var schemas = context.CreateSchemas();
5757

5858
var stringCollectionResponse = schemas["StringCollectionResponse"];
59-
var flightCollectionResponse = schemas["Microsoft.OData.Service.Sample.TrippinInMemory.Models.FlightCollectionResponse"];
60-
59+
var flightCollectionResponse = schemas["Microsoft.OData.Service.Sample.TrippinInMemory.Models.FlightCollectionResponse"];
60+
6161
if (enablePagination || enableCount)
6262
{
6363
Assert.Collection(stringCollectionResponse.AllOf,
@@ -79,7 +79,7 @@ public void CreatesCollectionResponseSchema(bool enablePagination, bool enableCo
7979
Assert.Equal("array", stringCollectionResponse.Properties["value"].Type);
8080
Assert.Equal("array", flightCollectionResponse.Properties["value"].Type);
8181
Assert.Equal("Microsoft.OData.Service.Sample.TrippinInMemory.Models.Flight", flightCollectionResponse.Properties["value"].Items.Reference.Id);
82-
}
82+
}
8383
}
8484

8585
[Fact]
@@ -903,7 +903,7 @@ public void CreatePropertySchemaForNullableEnumPropertyReturnSchema(OpenApiSpecV
903903
Assert.NotNull(schema);
904904
string json = schema.SerializeAsJson(specVersion);
905905
_output.WriteLine(json);
906-
906+
907907
// Assert
908908
if (specVersion == OpenApiSpecVersion.OpenApi2_0)
909909
{
@@ -956,7 +956,7 @@ public void CreatePropertySchemaWithComputedAnnotationReturnsCorrectSchema(OpenA
956956
""pattern"": ""^-?P([0-9]+D)?(T([0-9]+H)?([0-9]+M)?([0-9]+([.][0-9]+)?S)?)?$"",
957957
""type"": ""string"",
958958
""readOnly"": true
959-
}".ChangeLineBreaks(), json);
959+
}".ChangeLineBreaks(), json);
960960
}
961961
else
962962
{
@@ -1117,5 +1117,31 @@ public void NonNullableDoublePropertyWithDefaultStringWorks()
11171117
""default"": ""3.1415926535897931""
11181118
}".ChangeLineBreaks(), json);
11191119
}
1120+
1121+
1122+
[Fact]
1123+
public void NonNullableUntypedPropertyWorks()
1124+
{
1125+
ODataContext context = new ODataContext(
1126+
EdmModelHelper.BasicEdmModel,
1127+
new OpenApiConvertSettings
1128+
{
1129+
ShowSchemaExamples = true
1130+
});
1131+
EdmEntityType entitType = new EdmEntityType("NS", "Entity");
1132+
IEdmStructuralProperty property = new EdmStructuralProperty(
1133+
entitType, "UntypedProperty", EdmCoreModel.Instance.GetUntyped());
1134+
1135+
// Act
1136+
var schema = context.CreatePropertySchema(property);
1137+
1138+
// Assert
1139+
Assert.NotNull(schema);
1140+
Assert.Null(schema.Type);
1141+
1142+
string json = schema.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0);
1143+
1144+
Assert.Equal("{ }", json);
1145+
}
11201146
}
11211147
}

test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OData.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@
207207
<Property Name="Budget" Type="Edm.Single" Nullable="false" />
208208
<Property Name="Description" Type="Edm.String" />
209209
<Property Name="Tags" Type="Collection(Edm.String)" />
210+
<Property Name="TripData" Type="Edm.Untyped" />
211+
<Property Name="DestinationInfo" Type="Collection(Edm.Untyped)" />
210212
<Property Name="StartsAt" Type="Edm.DateTimeOffset" Nullable="false" />
211213
<Property Name="EndsAt" Type="Edm.DateTimeOffset" Nullable="false" />
212214
<NavigationProperty Name="PlanItems" Type="Collection(Microsoft.OData.Service.Sample.TrippinInMemory.Models.PlanItem)" >

test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.V2.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30590,6 +30590,11 @@
3059030590
"type": "string"
3059130591
}
3059230592
},
30593+
"TripData": { },
30594+
"DestinationInfo": {
30595+
"type": "array",
30596+
"items": { }
30597+
},
3059330598
"StartsAt": {
3059430599
"format": "date-time",
3059530600
"pattern": "^[0-9]{4,}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]{1,12})?(Z|[+-][0-9][0-9]:[0-9][0-9])$",

test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.V2.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20754,6 +20754,10 @@ definitions:
2075420754
type: array
2075520755
items:
2075620756
type: string
20757+
TripData: { }
20758+
DestinationInfo:
20759+
type: array
20760+
items: { }
2075720761
StartsAt:
2075820762
format: date-time
2075920763
pattern: '^[0-9]{4,}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]{1,12})?(Z|[+-][0-9][0-9]:[0-9][0-9])$'

test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34196,6 +34196,11 @@
3419634196
"nullable": true
3419734197
}
3419834198
},
34199+
"TripData": { },
34200+
"DestinationInfo": {
34201+
"type": "array",
34202+
"items": { }
34203+
},
3419934204
"StartsAt": {
3420034205
"pattern": "^[0-9]{4,}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]{1,12})?(Z|[+-][0-9][0-9]:[0-9][0-9])$",
3420134206
"type": "string",
@@ -35296,6 +35301,9 @@
3529635301
"value": {
3529735302
"Budget": 0,
3529835303
"Description": "String",
35304+
"DestinationInfo": [
35305+
{ }
35306+
],
3529935307
"EndsAt": "0001-01-01T00:00:00.0000000+00:00",
3530035308
"Name": "String",
3530135309
"PlanItems": [
@@ -35308,6 +35316,7 @@
3530835316
"Tags": [
3530935317
"String"
3531035318
],
35319+
"TripData": { },
3531135320
"TripId": 0
3531235321
}
3531335322
},

test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23041,6 +23041,10 @@ components:
2304123041
items:
2304223042
type: string
2304323043
nullable: true
23044+
TripData: { }
23045+
DestinationInfo:
23046+
type: array
23047+
items: { }
2304423048
StartsAt:
2304523049
pattern: '^[0-9]{4,}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]{1,12})?(Z|[+-][0-9][0-9]:[0-9][0-9])$'
2304623050
type: string
@@ -23737,6 +23741,8 @@ components:
2373723741
value:
2373823742
Budget: 0
2373923743
Description: String
23744+
DestinationInfo:
23745+
- { }
2374023746
EndsAt: '0001-01-01T00:00:00.0000000+00:00'
2374123747
Name: String
2374223748
PlanItems:
@@ -23745,6 +23751,7 @@ components:
2374523751
StartsAt: '0001-01-01T00:00:00.0000000+00:00'
2374623752
Tags:
2374723753
- String
23754+
TripData: { }
2374823755
TripId: 0
2374923756
Microsoft.OData.Service.Sample.TrippinInMemory.Models.PlanItem:
2375023757
value:

0 commit comments

Comments
 (0)