Skip to content

Commit 205cff3

Browse files
[Fix] Updates the format of the request body schema of a collection of complex property (#472)
* Update format of request body schema of collection of complex property * Update test * Update tests * Update Complex props Get tests * Updates release notes --------- Co-authored-by: Millicent Achieng <[email protected]>
1 parent 902025d commit 205cff3

13 files changed

+930
-410
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
<TargetFrameworks>netstandard2.0</TargetFrameworks>
1616
<PackageId>Microsoft.OpenApi.OData</PackageId>
1717
<SignAssembly>true</SignAssembly>
18-
<Version>1.6.0-preview.1</Version>
18+
<Version>1.6.0-preview.2</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>
2424
- Reads annotations on structural properties of stream types for media entity paths #399
25+
- Updates the format of the request body schema of a collection of complex property #423
2526
</PackageReleaseNotes>
2627
<AssemblyName>Microsoft.OpenApi.OData.Reader</AssemblyName>
2728
<AssemblyOriginatorKeyFile>..\..\tool\Microsoft.OpenApi.OData.snk</AssemblyOriginatorKeyFile>

src/Microsoft.OpenApi.OData.Reader/Operation/ComplexPropertyUpdateOperationHandler.cs

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -98,29 +98,37 @@ protected override void AppendCustomParameters(OpenApiOperation operation)
9898

9999
private OpenApiSchema GetOpenApiSchema()
100100
{
101-
return ComplexPropertySegment.Property.Type.IsCollection() ?
102-
new OpenApiSchema
103-
{
104-
Type = "array",
105-
Items = new OpenApiSchema
106-
{
107-
UnresolvedReference = true,
108-
Reference = new OpenApiReference
109-
{
110-
Type = ReferenceType.Schema,
111-
Id = ComplexPropertySegment.ComplexType.FullName()
112-
}
113-
}
114-
}
115-
:
116-
new OpenApiSchema
101+
var schema = new OpenApiSchema
102+
{
103+
UnresolvedReference = true,
104+
Reference = new OpenApiReference
105+
{
106+
Type = ReferenceType.Schema,
107+
Id = ComplexPropertySegment.ComplexType.FullName()
108+
}
109+
};
110+
111+
if (ComplexPropertySegment.Property.Type.IsCollection())
112+
{
113+
return new OpenApiSchema
117114
{
118-
UnresolvedReference = true,
119-
Reference = new OpenApiReference
120-
{
121-
Type = ReferenceType.Schema,
122-
Id = ComplexPropertySegment.ComplexType.FullName()
115+
Type = Constants.ObjectType,
116+
Properties = new Dictionary<string, OpenApiSchema>
117+
{
118+
{
119+
"value",
120+
new OpenApiSchema
121+
{
122+
Type = "array",
123+
Items = schema
124+
}
125+
}
123126
}
124-
};
127+
};
128+
}
129+
else
130+
{
131+
return schema;
132+
}
125133
}
126134
}

test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/ComplexPropertyGetOperationHandlerTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ public void CreateComplexPropertyGetOperationReturnsCorrectOperationForCollectio
8080

8181
// Assert
8282
Assert.NotNull(get);
83-
Assert.Equal("Get AlternativeAddresses property value", get.Summary);
84-
Assert.Equal("The AlternativeAddresses.", get.Description);
83+
Assert.Equal("Get the AlternativeAddresses.", get.Summary);
84+
Assert.Equal("Get the AlternativeAddresses value.", get.Description);
8585

8686
Assert.NotNull(get.Parameters);
8787
Assert.Equal(9, get.Parameters.Count); //id, select, expand, order, top, skip, count, search, filter

test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/ComplexPropertyPutOperationHandlerTests.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
44
// ------------------------------------------------------------
55

6-
using System;
76
using System.Linq;
87
using Microsoft.OData.Edm;
98
using Microsoft.OpenApi.OData.Edm;
@@ -78,7 +77,7 @@ public void CreateComplexPropertyPutOperationReturnsCorrectOperationForCollectio
7877
var model = EntitySetGetOperationHandlerTests.GetEdmModel("");
7978
var entitySet = model.EntityContainer.FindEntitySet("Customers");
8079
var entity = entitySet.EntityType();
81-
var property = entity.FindProperty("BillingAddress");
80+
var property = entity.FindProperty("AlternativeAddresses");
8281
var settings = new OpenApiConvertSettings
8382
{
8483
EnableOperationId = enableOperationId
@@ -91,19 +90,25 @@ public void CreateComplexPropertyPutOperationReturnsCorrectOperationForCollectio
9190

9291
// Assert
9392
Assert.NotNull(put);
94-
Assert.Equal("Update the BillingAddress.", put.Summary);
95-
Assert.Equal("Update the BillingAddress value.", put.Description);
93+
Assert.Equal("Update the AlternativeAddresses.", put.Summary);
94+
Assert.Equal("Update the AlternativeAddresses value.", put.Description);
9695

9796
Assert.NotNull(put.Parameters);
9897
Assert.Single(put.Parameters); //id
9998

10099
Assert.NotNull(put.Responses);
101100
Assert.Equal(2, put.Responses.Count);
102101
Assert.Equal(new[] { "204", "default" }, put.Responses.Select(r => r.Key));
103-
104-
if (enableOperationId)
102+
var schema = put.RequestBody?.Content.FirstOrDefault().Value?.Schema;
103+
104+
Assert.NotNull(schema);
105+
Assert.Equal("object", schema.Type);
106+
Assert.Equal("value", schema.Properties.FirstOrDefault().Key);
107+
Assert.Equal("array", schema.Properties.FirstOrDefault().Value.Type);
108+
109+
if (enableOperationId)
105110
{
106-
Assert.Equal("Customers.UpdateBillingAddress", put.OperationId);
111+
Assert.Equal("Customers.UpdateAlternativeAddresses", put.OperationId);
107112
}
108113
else
109114
{

test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/EntitySetGetOperationHandlerTests.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,18 @@ public static IEdmModel GetEdmModel(string annotation)
356356
</Property>
357357
<Property Name=""MailingAddress"" Type=""NS.Address"" Nullable=""false"" />
358358
<Property Name=""AlternativeAddresses"" Type=""Collection(NS.Address)"" Nullable=""false"">
359-
<Annotation Term=""Org.OData.Core.V1.Description"" String=""The AlternativeAddresses."" />
360-
<Annotation Term=""Org.OData.Core.V1.LongDescription"" String=""The AlternativeAddresses value."" />
359+
<Annotation Term=""Org.OData.Capabilities.V1.ReadRestrictions"">
360+
<Record>
361+
<PropertyValue Property=""Description"" String=""Get the AlternativeAddresses."" />
362+
<PropertyValue Property=""LongDescription"" String=""Get the AlternativeAddresses value."" />
363+
</Record>
364+
</Annotation>
365+
<Annotation Term=""Org.OData.Capabilities.V1.UpdateRestrictions"">
366+
<Record>
367+
<PropertyValue Property=""Description"" String=""Update the AlternativeAddresses."" />
368+
<PropertyValue Property=""LongDescription"" String=""Update the AlternativeAddresses value."" />
369+
</Record>
370+
</Annotation>
361371
</Property>
362372
</EntityType>
363373
<EntityContainer Name =""Default"">

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

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,9 +1078,14 @@
10781078
"description": "New property values",
10791079
"required": true,
10801080
"schema": {
1081-
"type": "array",
1082-
"items": {
1083-
"$ref": "#/definitions/Siterra.Documents.App.DTO.DocumentTagRelDto"
1081+
"type": "object",
1082+
"properties": {
1083+
"value": {
1084+
"type": "array",
1085+
"items": {
1086+
"$ref": "#/definitions/Siterra.Documents.App.DTO.DocumentTagRelDto"
1087+
}
1088+
}
10841089
}
10851090
}
10861091
}
@@ -1811,9 +1816,14 @@
18111816
"description": "New property values",
18121817
"required": true,
18131818
"schema": {
1814-
"type": "array",
1815-
"items": {
1816-
"$ref": "#/definitions/Siterra.Documents.App.DTO.DocumentTagRelDto"
1819+
"type": "object",
1820+
"properties": {
1821+
"value": {
1822+
"type": "array",
1823+
"items": {
1824+
"$ref": "#/definitions/Siterra.Documents.App.DTO.DocumentTagRelDto"
1825+
}
1826+
}
18171827
}
18181828
}
18191829
}
@@ -2776,9 +2786,14 @@
27762786
"description": "New property values",
27772787
"required": true,
27782788
"schema": {
2779-
"type": "array",
2780-
"items": {
2781-
"$ref": "#/definitions/Siterra.Documents.BusinessLogic.Entities.Document.DocumentClass"
2789+
"type": "object",
2790+
"properties": {
2791+
"value": {
2792+
"type": "array",
2793+
"items": {
2794+
"$ref": "#/definitions/Siterra.Documents.BusinessLogic.Entities.Document.DocumentClass"
2795+
}
2796+
}
27822797
}
27832798
}
27842799
}
@@ -3009,9 +3024,14 @@
30093024
"description": "New property values",
30103025
"required": true,
30113026
"schema": {
3012-
"type": "array",
3013-
"items": {
3014-
"$ref": "#/definitions/Siterra.Documents.BusinessLogic.Entities.Document.DocumentTagRel"
3027+
"type": "object",
3028+
"properties": {
3029+
"value": {
3030+
"type": "array",
3031+
"items": {
3032+
"$ref": "#/definitions/Siterra.Documents.BusinessLogic.Entities.Document.DocumentTagRel"
3033+
}
3034+
}
30153035
}
30163036
}
30173037
}
@@ -3914,9 +3934,14 @@
39143934
"description": "New property values",
39153935
"required": true,
39163936
"schema": {
3917-
"type": "array",
3918-
"items": {
3919-
"$ref": "#/definitions/Siterra.Documents.App.DTO.DocumentTagRelDto"
3937+
"type": "object",
3938+
"properties": {
3939+
"value": {
3940+
"type": "array",
3941+
"items": {
3942+
"$ref": "#/definitions/Siterra.Documents.App.DTO.DocumentTagRelDto"
3943+
}
3944+
}
39203945
}
39213946
}
39223947
}

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

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -764,9 +764,12 @@ paths:
764764
description: New property values
765765
required: true
766766
schema:
767-
type: array
768-
items:
769-
$ref: '#/definitions/Siterra.Documents.App.DTO.DocumentTagRelDto'
767+
type: object
768+
properties:
769+
value:
770+
type: array
771+
items:
772+
$ref: '#/definitions/Siterra.Documents.App.DTO.DocumentTagRelDto'
770773
responses:
771774
'204':
772775
description: Success
@@ -1282,9 +1285,12 @@ paths:
12821285
description: New property values
12831286
required: true
12841287
schema:
1285-
type: array
1286-
items:
1287-
$ref: '#/definitions/Siterra.Documents.App.DTO.DocumentTagRelDto'
1288+
type: object
1289+
properties:
1290+
value:
1291+
type: array
1292+
items:
1293+
$ref: '#/definitions/Siterra.Documents.App.DTO.DocumentTagRelDto'
12881294
responses:
12891295
'204':
12901296
description: Success
@@ -1982,9 +1988,12 @@ paths:
19821988
description: New property values
19831989
required: true
19841990
schema:
1985-
type: array
1986-
items:
1987-
$ref: '#/definitions/Siterra.Documents.BusinessLogic.Entities.Document.DocumentClass'
1991+
type: object
1992+
properties:
1993+
value:
1994+
type: array
1995+
items:
1996+
$ref: '#/definitions/Siterra.Documents.BusinessLogic.Entities.Document.DocumentClass'
19881997
responses:
19891998
'204':
19901999
description: Success
@@ -2143,9 +2152,12 @@ paths:
21432152
description: New property values
21442153
required: true
21452154
schema:
2146-
type: array
2147-
items:
2148-
$ref: '#/definitions/Siterra.Documents.BusinessLogic.Entities.Document.DocumentTagRel'
2155+
type: object
2156+
properties:
2157+
value:
2158+
type: array
2159+
items:
2160+
$ref: '#/definitions/Siterra.Documents.BusinessLogic.Entities.Document.DocumentTagRel'
21492161
responses:
21502162
'204':
21512163
description: Success
@@ -2782,9 +2794,12 @@ paths:
27822794
description: New property values
27832795
required: true
27842796
schema:
2785-
type: array
2786-
items:
2787-
$ref: '#/definitions/Siterra.Documents.App.DTO.DocumentTagRelDto'
2797+
type: object
2798+
properties:
2799+
value:
2800+
type: array
2801+
items:
2802+
$ref: '#/definitions/Siterra.Documents.App.DTO.DocumentTagRelDto'
27882803
responses:
27892804
'204':
27902805
description: Success

0 commit comments

Comments
 (0)