Skip to content

Commit

Permalink
Include correct list of discriminator information (#222)
Browse files Browse the repository at this point in the history
* Retrieve list of derived types for structured types

* Update tests for creating structured type schema with discriminator

* Simplify how mapping property of dicriminator object is computed

* Update release notes

Co-authored-by: Irvine Sunday <[email protected]>
  • Loading branch information
millicentachieng and irvinesunday authored May 30, 2022
1 parent 04422bf commit 816d30f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -436,23 +436,21 @@ private static OpenApiSchema CreateStructuredTypeSchema(this ODataContext contex
// The discriminator object is added to structured types which have derived types.
OpenApiDiscriminator discriminator = null;
if (context.Settings.EnableDiscriminatorValue && derivedTypes.Any() && structuredType.BaseType != null)
{
string v3RefIdentifier = new OpenApiSchema
{
Reference = new OpenApiReference
{
Dictionary<string, string> mapping = derivedTypes
.ToDictionary(x => $"#{x.FullTypeName()}", x => new OpenApiSchema
{
Type = ReferenceType.Schema,
Id = structuredType.FullTypeName()
}
}.Reference.ReferenceV3;
Reference = new OpenApiReference
{
Type = ReferenceType.Schema,
Id = x.FullTypeName()
}
}.Reference.ReferenceV3);

discriminator = new OpenApiDiscriminator
{
PropertyName = "@odata.type",
Mapping = new Dictionary<string, string>
{
{"#" + structuredType.FullTypeName(), v3RefIdentifier }
}
Mapping = mapping
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,14 @@
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<PackageId>Microsoft.OpenApi.OData</PackageId>
<SignAssembly>true</SignAssembly>
<Version>1.0.10</Version>
<Version>1.0.11-preview1</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>
- Adds support for reading custom attributes #192
- Adds support for OpenApiLinks for actions and functions #74
- Maps operation summaries to operation descriptions and CSDL description annotations to operation LongDescription #206
- Fixes the response type of functions returning Edm.Stream to use application/octet-stream #200
- Fixes the generation of ODataTypeCast paths #199
- Adds path items for properties of complex type. #176, #15
- Describes errors on error response codes instead of default. #172, #165, #193
- Fixes a bug where reference objects are not created correctly. #171
- Adds support for enum values descriptions. #164
- Declares path parameters on path item instead of operation. #159
- Multiple fixes on navigation properties path items expansion. #151, #123
- Multiple fixes for descriptions. #154
- Fixes a bug where URL templates would be missing quotes for string parameters. #140
- Fixes description of operations of primitive types. #126
- Adds support for OData cast segments in path items generation. #123
- Fixes the response descriptions for functions that return a collection. #122
- Fixes structured and collection-valued parameters of functions. #203
- Adds support for discriminator property in inheritance. #118
- Sets deprecated for operations that are generated from deprecated types/singletons/entitysets/properties in the model. #113
- Aligns target version to netframework2.0. #139
</PackageReleaseNotes>
- Adds list of all derived types for discriminator mapping #219
</PackageReleaseNotes>
<AssemblyName>Microsoft.OpenApi.OData.Reader</AssemblyName>
<AssemblyOriginatorKeyFile>..\..\tool\Microsoft.OpenApi.OData.snk</AssemblyOriginatorKeyFile>
<OutputPath Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">..\..\bin\Debug\</OutputPath>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,23 @@ public void CreateStructuredTypeSchemaWithDiscriminatorValueEnabledReturnsCorrec
""discriminator"": {
""propertyName"": ""@odata.type"",
""mapping"": {
""#microsoft.graph.directoryObject"": ""#/components/schemas/microsoft.graph.directoryObject""
""#microsoft.graph.user"": ""#/components/schemas/microsoft.graph.user"",
""#microsoft.graph.group"": ""#/components/schemas/microsoft.graph.group"",
""#microsoft.graph.device"": ""#/components/schemas/microsoft.graph.device"",
""#microsoft.graph.application"": ""#/components/schemas/microsoft.graph.application"",
""#microsoft.graph.servicePrincipal"": ""#/components/schemas/microsoft.graph.servicePrincipal"",
""#microsoft.graph.policyBase"": ""#/components/schemas/microsoft.graph.policyBase"",
""#microsoft.graph.extensionProperty"": ""#/components/schemas/microsoft.graph.extensionProperty"",
""#microsoft.graph.endpoint"": ""#/components/schemas/microsoft.graph.endpoint"",
""#microsoft.graph.resourceSpecificPermissionGrant"": ""#/components/schemas/microsoft.graph.resourceSpecificPermissionGrant"",
""#microsoft.graph.administrativeUnit"": ""#/components/schemas/microsoft.graph.administrativeUnit"",
""#microsoft.graph.contract"": ""#/components/schemas/microsoft.graph.contract"",
""#microsoft.graph.directoryObjectPartnerReference"": ""#/components/schemas/microsoft.graph.directoryObjectPartnerReference"",
""#microsoft.graph.directoryRole"": ""#/components/schemas/microsoft.graph.directoryRole"",
""#microsoft.graph.directoryRoleTemplate"": ""#/components/schemas/microsoft.graph.directoryRoleTemplate"",
""#microsoft.graph.directorySettingTemplate"": ""#/components/schemas/microsoft.graph.directorySettingTemplate"",
""#microsoft.graph.organization"": ""#/components/schemas/microsoft.graph.organization"",
""#microsoft.graph.orgContact"": ""#/components/schemas/microsoft.graph.orgContact""
}
}
}
Expand Down

0 comments on commit 816d30f

Please sign in to comment.