Skip to content

Add support for Edm.Untyped #531

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -84,7 +84,7 @@
// properties
foreach (var property in structuredType.DeclaredProperties.OrderBy(p => p.Name))
{
// IOpenApiAny item;

Check warning on line 87 in src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiExampleGenerator.cs

View workflow job for this annotation

GitHub Actions / Build

Remove this commented out code. (https://rules.sonarsource.com/csharp/RSPEC-125)
IEdmTypeReference propertyType = property.Type;

IOpenApiAny item = GetTypeNameForExample(propertyType);
Expand Down Expand Up @@ -180,6 +180,8 @@
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 @@ -631,7 +631,7 @@
// properties
foreach (var property in structuredType.Properties())
{
// IOpenApiAny item;

Check warning on line 634 in src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiSchemaGenerator.cs

View workflow job for this annotation

GitHub Actions / Build

Remove this commented out code. (https://rules.sonarsource.com/csharp/RSPEC-125)
IEdmTypeReference propertyType = property.Type;

IOpenApiAny item = GetTypeNameForExample(context, propertyType);
Expand Down Expand Up @@ -700,6 +700,8 @@
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
Loading