Skip to content

Commit

Permalink
Add support for Edm.Untyped (#531)
Browse files Browse the repository at this point in the history
* Add support for Edm.Untyped

* Add release notes

* Additional test
  • Loading branch information
millicentachieng authored May 21, 2024
1 parent bfb0cb7 commit afffecc
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ public static OpenApiSchema CreateEdmTypeSchema(this ODataContext context, IEdmT
case EdmTypeKind.EntityReference:
return context.CreateTypeDefinitionSchema(edmTypeReference.AsTypeDefinition());

case EdmTypeKind.Untyped:
return new OpenApiSchema();

case EdmTypeKind.None:
default:
throw Error.NotSupported(String.Format(SRResource.NotSupportedEdmTypeKind, edmTypeReference.TypeKind()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ private static IOpenApiAny GetTypeNameForExample(IEdmTypeReference edmTypeRefere
return GetTypeNameForExample(new EdmPrimitiveTypeReference(typedef.UnderlyingType, edmTypeReference.IsNullable));

case EdmTypeKind.Untyped:
return new OpenApiObject();

case EdmTypeKind.EntityReference:
default:
throw new OpenApiException("Not support for the type kind " + edmTypeReference.TypeKind());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,8 @@ private static IOpenApiAny GetTypeNameForExample(ODataContext context, IEdmTypeR
return array;

case EdmTypeKind.Untyped:
return new OpenApiObject();

case EdmTypeKind.TypeDefinition:
case EdmTypeKind.EntityReference:
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<PackageId>Microsoft.OpenApi.OData</PackageId>
<SignAssembly>true</SignAssembly>
<Version>1.6.3</Version>
<Version>1.6.4</Version>
<Description>This package contains the codes you need to convert OData CSDL to Open API Document of Model.</Description>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageTags>Microsoft OpenApi OData EDM</PackageTags>
<RepositoryUrl>https://github.com/Microsoft/OpenAPI.NET.OData</RepositoryUrl>
<PackageReleaseNotes>
- Add delete operations to media entities #522
- Add support for Edm.Untyped #511
</PackageReleaseNotes>
<AssemblyName>Microsoft.OpenApi.OData.Reader</AssemblyName>
<AssemblyOriginatorKeyFile>..\..\tool\Microsoft.OpenApi.OData.snk</AssemblyOriginatorKeyFile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public void CreatesCollectionResponseSchema(bool enablePagination, bool enableCo
var schemas = context.CreateSchemas();

var stringCollectionResponse = schemas["StringCollectionResponse"];
var flightCollectionResponse = schemas["Microsoft.OData.Service.Sample.TrippinInMemory.Models.FlightCollectionResponse"];
var flightCollectionResponse = schemas["Microsoft.OData.Service.Sample.TrippinInMemory.Models.FlightCollectionResponse"];

if (enablePagination || enableCount)
{
Assert.Collection(stringCollectionResponse.AllOf,
Expand All @@ -79,7 +79,7 @@ public void CreatesCollectionResponseSchema(bool enablePagination, bool enableCo
Assert.Equal("array", stringCollectionResponse.Properties["value"].Type);
Assert.Equal("array", flightCollectionResponse.Properties["value"].Type);
Assert.Equal("Microsoft.OData.Service.Sample.TrippinInMemory.Models.Flight", flightCollectionResponse.Properties["value"].Items.Reference.Id);
}
}
}

[Fact]
Expand Down Expand Up @@ -903,7 +903,7 @@ public void CreatePropertySchemaForNullableEnumPropertyReturnSchema(OpenApiSpecV
Assert.NotNull(schema);
string json = schema.SerializeAsJson(specVersion);
_output.WriteLine(json);

// Assert
if (specVersion == OpenApiSpecVersion.OpenApi2_0)
{
Expand Down Expand Up @@ -956,7 +956,7 @@ public void CreatePropertySchemaWithComputedAnnotationReturnsCorrectSchema(OpenA
""pattern"": ""^-?P([0-9]+D)?(T([0-9]+H)?([0-9]+M)?([0-9]+([.][0-9]+)?S)?)?$"",
""type"": ""string"",
""readOnly"": true
}".ChangeLineBreaks(), json);
}".ChangeLineBreaks(), json);
}
else
{
Expand Down Expand Up @@ -1117,5 +1117,31 @@ public void NonNullableDoublePropertyWithDefaultStringWorks()
""default"": ""3.1415926535897931""
}".ChangeLineBreaks(), json);
}


[Fact]
public void NonNullableUntypedPropertyWorks()
{
ODataContext context = new ODataContext(
EdmModelHelper.BasicEdmModel,
new OpenApiConvertSettings
{
ShowSchemaExamples = true
});
EdmEntityType entitType = new EdmEntityType("NS", "Entity");
IEdmStructuralProperty property = new EdmStructuralProperty(
entitType, "UntypedProperty", EdmCoreModel.Instance.GetUntyped());

// Act
var schema = context.CreatePropertySchema(property);

// Assert
Assert.NotNull(schema);
Assert.Null(schema.Type);

string json = schema.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0);

Assert.Equal("{ }", json);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@
<Property Name="Budget" Type="Edm.Single" Nullable="false" />
<Property Name="Description" Type="Edm.String" />
<Property Name="Tags" Type="Collection(Edm.String)" />
<Property Name="TripData" Type="Edm.Untyped" />
<Property Name="DestinationInfo" Type="Collection(Edm.Untyped)" />
<Property Name="StartsAt" Type="Edm.DateTimeOffset" Nullable="false" />
<Property Name="EndsAt" Type="Edm.DateTimeOffset" Nullable="false" />
<NavigationProperty Name="PlanItems" Type="Collection(Microsoft.OData.Service.Sample.TrippinInMemory.Models.PlanItem)" >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30590,6 +30590,11 @@
"type": "string"
}
},
"TripData": { },
"DestinationInfo": {
"type": "array",
"items": { }
},
"StartsAt": {
"format": "date-time",
"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])$",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20754,6 +20754,10 @@ definitions:
type: array
items:
type: string
TripData: { }
DestinationInfo:
type: array
items: { }
StartsAt:
format: date-time
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])$'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34196,6 +34196,11 @@
"nullable": true
}
},
"TripData": { },
"DestinationInfo": {
"type": "array",
"items": { }
},
"StartsAt": {
"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])$",
"type": "string",
Expand Down Expand Up @@ -35296,6 +35301,9 @@
"value": {
"Budget": 0,
"Description": "String",
"DestinationInfo": [
{ }
],
"EndsAt": "0001-01-01T00:00:00.0000000+00:00",
"Name": "String",
"PlanItems": [
Expand All @@ -35308,6 +35316,7 @@
"Tags": [
"String"
],
"TripData": { },
"TripId": 0
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23041,6 +23041,10 @@ components:
items:
type: string
nullable: true
TripData: { }
DestinationInfo:
type: array
items: { }
StartsAt:
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])$'
type: string
Expand Down Expand Up @@ -23737,6 +23741,8 @@ components:
value:
Budget: 0
Description: String
DestinationInfo:
- { }
EndsAt: '0001-01-01T00:00:00.0000000+00:00'
Name: String
PlanItems:
Expand All @@ -23745,6 +23751,7 @@ components:
StartsAt: '0001-01-01T00:00:00.0000000+00:00'
Tags:
- String
TripData: { }
TripId: 0
Microsoft.OData.Service.Sample.TrippinInMemory.Models.PlanItem:
value:
Expand Down

0 comments on commit afffecc

Please sign in to comment.