Skip to content
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

[Fix] Updates the format of the request body schema of a collection of complex property #472

Merged
merged 5 commits into from
Jan 16, 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 @@ -15,13 +15,14 @@
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<PackageId>Microsoft.OpenApi.OData</PackageId>
<SignAssembly>true</SignAssembly>
<Version>1.6.0-preview.1</Version>
<Version>1.6.0-preview.2</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>
- Reads annotations on structural properties of stream types for media entity paths #399
- Updates the format of the request body schema of a collection of complex property #423
</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 @@ -98,29 +98,37 @@ protected override void AppendCustomParameters(OpenApiOperation operation)

private OpenApiSchema GetOpenApiSchema()
{
return ComplexPropertySegment.Property.Type.IsCollection() ?
new OpenApiSchema
{
Type = "array",
Items = new OpenApiSchema
{
UnresolvedReference = true,
Reference = new OpenApiReference
{
Type = ReferenceType.Schema,
Id = ComplexPropertySegment.ComplexType.FullName()
}
}
}
:
new OpenApiSchema
var schema = new OpenApiSchema
{
UnresolvedReference = true,
Reference = new OpenApiReference
{
Type = ReferenceType.Schema,
Id = ComplexPropertySegment.ComplexType.FullName()
}
};

if (ComplexPropertySegment.Property.Type.IsCollection())
{
return new OpenApiSchema
{
UnresolvedReference = true,
Reference = new OpenApiReference
{
Type = ReferenceType.Schema,
Id = ComplexPropertySegment.ComplexType.FullName()
Type = Constants.ObjectType,
Properties = new Dictionary<string, OpenApiSchema>
{
{
"value",
new OpenApiSchema
{
Type = "array",
Items = schema
}
}
}
};
};
}
else
{
return schema;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ public void CreateComplexPropertyGetOperationReturnsCorrectOperationForCollectio

// Assert
Assert.NotNull(get);
Assert.Equal("Get AlternativeAddresses property value", get.Summary);
Assert.Equal("The AlternativeAddresses.", get.Description);
Assert.Equal("Get the AlternativeAddresses.", get.Summary);
Assert.Equal("Get the AlternativeAddresses value.", get.Description);

Assert.NotNull(get.Parameters);
Assert.Equal(9, get.Parameters.Count); //id, select, expand, order, top, skip, count, search, filter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------

using System;
using System.Linq;
using Microsoft.OData.Edm;
using Microsoft.OpenApi.OData.Edm;
Expand Down Expand Up @@ -78,7 +77,7 @@ public void CreateComplexPropertyPutOperationReturnsCorrectOperationForCollectio
var model = EntitySetGetOperationHandlerTests.GetEdmModel("");
var entitySet = model.EntityContainer.FindEntitySet("Customers");
var entity = entitySet.EntityType();
var property = entity.FindProperty("BillingAddress");
var property = entity.FindProperty("AlternativeAddresses");
var settings = new OpenApiConvertSettings
{
EnableOperationId = enableOperationId
Expand All @@ -91,19 +90,25 @@ public void CreateComplexPropertyPutOperationReturnsCorrectOperationForCollectio

// Assert
Assert.NotNull(put);
Assert.Equal("Update the BillingAddress.", put.Summary);
Assert.Equal("Update the BillingAddress value.", put.Description);
Assert.Equal("Update the AlternativeAddresses.", put.Summary);
Assert.Equal("Update the AlternativeAddresses value.", put.Description);

Assert.NotNull(put.Parameters);
Assert.Single(put.Parameters); //id

Assert.NotNull(put.Responses);
Assert.Equal(2, put.Responses.Count);
Assert.Equal(new[] { "204", "default" }, put.Responses.Select(r => r.Key));

if (enableOperationId)
var schema = put.RequestBody?.Content.FirstOrDefault().Value?.Schema;

Assert.NotNull(schema);
Assert.Equal("object", schema.Type);
Assert.Equal("value", schema.Properties.FirstOrDefault().Key);
Assert.Equal("array", schema.Properties.FirstOrDefault().Value.Type);

if (enableOperationId)
{
Assert.Equal("Customers.UpdateBillingAddress", put.OperationId);
Assert.Equal("Customers.UpdateAlternativeAddresses", put.OperationId);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,18 @@ public static IEdmModel GetEdmModel(string annotation)
</Property>
<Property Name=""MailingAddress"" Type=""NS.Address"" Nullable=""false"" />
<Property Name=""AlternativeAddresses"" Type=""Collection(NS.Address)"" Nullable=""false"">
<Annotation Term=""Org.OData.Core.V1.Description"" String=""The AlternativeAddresses."" />
<Annotation Term=""Org.OData.Core.V1.LongDescription"" String=""The AlternativeAddresses value."" />
<Annotation Term=""Org.OData.Capabilities.V1.ReadRestrictions"">
<Record>
<PropertyValue Property=""Description"" String=""Get the AlternativeAddresses."" />
<PropertyValue Property=""LongDescription"" String=""Get the AlternativeAddresses value."" />
</Record>
</Annotation>
<Annotation Term=""Org.OData.Capabilities.V1.UpdateRestrictions"">
<Record>
<PropertyValue Property=""Description"" String=""Update the AlternativeAddresses."" />
<PropertyValue Property=""LongDescription"" String=""Update the AlternativeAddresses value."" />
</Record>
</Annotation>
</Property>
</EntityType>
<EntityContainer Name =""Default"">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1078,9 +1078,14 @@
"description": "New property values",
"required": true,
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Siterra.Documents.App.DTO.DocumentTagRelDto"
"type": "object",
"properties": {
"value": {
"type": "array",
"items": {
"$ref": "#/definitions/Siterra.Documents.App.DTO.DocumentTagRelDto"
}
}
}
}
}
Expand Down Expand Up @@ -1811,9 +1816,14 @@
"description": "New property values",
"required": true,
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Siterra.Documents.App.DTO.DocumentTagRelDto"
"type": "object",
"properties": {
"value": {
"type": "array",
"items": {
"$ref": "#/definitions/Siterra.Documents.App.DTO.DocumentTagRelDto"
}
}
}
}
}
Expand Down Expand Up @@ -2776,9 +2786,14 @@
"description": "New property values",
"required": true,
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Siterra.Documents.BusinessLogic.Entities.Document.DocumentClass"
"type": "object",
"properties": {
"value": {
"type": "array",
"items": {
"$ref": "#/definitions/Siterra.Documents.BusinessLogic.Entities.Document.DocumentClass"
}
}
}
}
}
Expand Down Expand Up @@ -3009,9 +3024,14 @@
"description": "New property values",
"required": true,
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Siterra.Documents.BusinessLogic.Entities.Document.DocumentTagRel"
"type": "object",
"properties": {
"value": {
"type": "array",
"items": {
"$ref": "#/definitions/Siterra.Documents.BusinessLogic.Entities.Document.DocumentTagRel"
}
}
}
}
}
Expand Down Expand Up @@ -3914,9 +3934,14 @@
"description": "New property values",
"required": true,
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Siterra.Documents.App.DTO.DocumentTagRelDto"
"type": "object",
"properties": {
"value": {
"type": "array",
"items": {
"$ref": "#/definitions/Siterra.Documents.App.DTO.DocumentTagRelDto"
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -764,9 +764,12 @@ paths:
description: New property values
required: true
schema:
type: array
items:
$ref: '#/definitions/Siterra.Documents.App.DTO.DocumentTagRelDto'
type: object
properties:
value:
type: array
items:
$ref: '#/definitions/Siterra.Documents.App.DTO.DocumentTagRelDto'
responses:
'204':
description: Success
Expand Down Expand Up @@ -1282,9 +1285,12 @@ paths:
description: New property values
required: true
schema:
type: array
items:
$ref: '#/definitions/Siterra.Documents.App.DTO.DocumentTagRelDto'
type: object
properties:
value:
type: array
items:
$ref: '#/definitions/Siterra.Documents.App.DTO.DocumentTagRelDto'
responses:
'204':
description: Success
Expand Down Expand Up @@ -1982,9 +1988,12 @@ paths:
description: New property values
required: true
schema:
type: array
items:
$ref: '#/definitions/Siterra.Documents.BusinessLogic.Entities.Document.DocumentClass'
type: object
properties:
value:
type: array
items:
$ref: '#/definitions/Siterra.Documents.BusinessLogic.Entities.Document.DocumentClass'
responses:
'204':
description: Success
Expand Down Expand Up @@ -2143,9 +2152,12 @@ paths:
description: New property values
required: true
schema:
type: array
items:
$ref: '#/definitions/Siterra.Documents.BusinessLogic.Entities.Document.DocumentTagRel'
type: object
properties:
value:
type: array
items:
$ref: '#/definitions/Siterra.Documents.BusinessLogic.Entities.Document.DocumentTagRel'
responses:
'204':
description: Success
Expand Down Expand Up @@ -2782,9 +2794,12 @@ paths:
description: New property values
required: true
schema:
type: array
items:
$ref: '#/definitions/Siterra.Documents.App.DTO.DocumentTagRelDto'
type: object
properties:
value:
type: array
items:
$ref: '#/definitions/Siterra.Documents.App.DTO.DocumentTagRelDto'
responses:
'204':
description: Success
Expand Down
Loading
Loading