-
Notifications
You must be signed in to change notification settings - Fork 65
Add support for PUT operation on entity sets and navigation properties based on UpdateMethod annotation #166
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
danielmbaluka
merged 10 commits into
master
from
feature/dm/add-support-for-put-operations
Feb 8, 2022
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4e65886
support put operations on entities through update restrictions
danielmbaluka f85f5c6
refactor entity set update (patch and put) operation handler classes to
danielmbaluka 2bf0752
add put operation handler tests
danielmbaluka d442087
add support for put update method on navigation properties
danielmbaluka f3e2835
clean up testing code
danielmbaluka f268dbc
add sample annotations in tripservice csdl for generate PUT update
danielmbaluka 3777266
support put operations on complex properties
danielmbaluka 3d7c2c8
add missing tests for supporting PUT in complex types
danielmbaluka f43a170
add test samples generated with PUT update operation
danielmbaluka 045d631
rebase against master
danielmbaluka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/Microsoft.OpenApi.OData.Reader/Operation/ComplexPropertyPutOperationHandler.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// ------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------ | ||
|
||
using Microsoft.OpenApi.Models; | ||
|
||
namespace Microsoft.OpenApi.OData.Operation; | ||
|
||
internal class ComplexPropertyPutOperationHandler : ComplexPropertyUpdateOperationHandler | ||
{ | ||
/// <inheritdoc /> | ||
public override OperationType OperationType => OperationType.Put; | ||
} |
115 changes: 115 additions & 0 deletions
115
src/Microsoft.OpenApi.OData.Reader/Operation/ComplexPropertyUpdateOperationHandler.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// ------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------ | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Microsoft.OData.Edm; | ||
using Microsoft.OpenApi.Models; | ||
using Microsoft.OpenApi.OData.Common; | ||
using Microsoft.OpenApi.OData.Edm; | ||
using Microsoft.OpenApi.OData.Generator; | ||
using Microsoft.OpenApi.OData.Vocabulary.Capabilities; | ||
|
||
namespace Microsoft.OpenApi.OData.Operation; | ||
|
||
internal abstract class ComplexPropertyUpdateOperationHandler : ComplexPropertyBaseOperationHandler | ||
{ | ||
/// <inheritdoc/> | ||
protected override void SetBasicInfo(OpenApiOperation operation) | ||
{ | ||
// Summary | ||
operation.Summary = $"Update property {ComplexPropertySegment.Property.Name} value."; | ||
|
||
// Description | ||
operation.Description = Context.Model.GetDescriptionAnnotation(ComplexPropertySegment.Property); | ||
|
||
// OperationId | ||
if (Context.Settings.EnableOperationId) | ||
{ | ||
string typeName = ComplexPropertySegment.ComplexType.Name; | ||
operation.OperationId = ComplexPropertySegment.Property.Name + "." + typeName + ".Update" + Utils.UpperFirstChar(typeName); | ||
} | ||
} | ||
|
||
/// <inheritdoc/> | ||
protected override void SetRequestBody(OpenApiOperation operation) | ||
{ | ||
OpenApiSchema schema = ComplexPropertySegment.Property.Type.IsCollection() ? | ||
new OpenApiSchema | ||
{ | ||
Type = "array", | ||
Items = new OpenApiSchema | ||
{ | ||
Reference = new OpenApiReference | ||
{ | ||
Type = ReferenceType.Schema, | ||
Id = ComplexPropertySegment.ComplexType.FullName() | ||
} | ||
} | ||
} | ||
: | ||
new OpenApiSchema | ||
{ | ||
Reference = new OpenApiReference | ||
{ | ||
Type = ReferenceType.Schema, | ||
Id = ComplexPropertySegment.ComplexType.FullName() | ||
} | ||
}; | ||
|
||
operation.RequestBody = new OpenApiRequestBody | ||
{ | ||
Required = true, | ||
Description = "New property values", | ||
Content = new Dictionary<string, OpenApiMediaType> | ||
{ | ||
{ | ||
Constants.ApplicationJsonMediaType, new OpenApiMediaType | ||
{ | ||
Schema = schema | ||
} | ||
} | ||
} | ||
}; | ||
|
||
base.SetRequestBody(operation); | ||
} | ||
|
||
/// <inheritdoc/> | ||
protected override void SetResponses(OpenApiOperation operation) | ||
{ | ||
operation.AddErrorResponses(Context.Settings, true); | ||
base.SetResponses(operation); | ||
} | ||
protected override void SetSecurity(OpenApiOperation operation) | ||
{ | ||
UpdateRestrictionsType update = Context.Model.GetRecord<UpdateRestrictionsType>(ComplexPropertySegment.Property, CapabilitiesConstants.UpdateRestrictions); | ||
if (update == null || update.Permissions == null) | ||
{ | ||
return; | ||
} | ||
|
||
operation.Security = Context.CreateSecurityRequirements(update.Permissions).ToList(); | ||
} | ||
|
||
protected override void AppendCustomParameters(OpenApiOperation operation) | ||
{ | ||
UpdateRestrictionsType update = Context.Model.GetRecord<UpdateRestrictionsType>(ComplexPropertySegment.Property, CapabilitiesConstants.UpdateRestrictions); | ||
if (update == null) | ||
{ | ||
return; | ||
} | ||
|
||
if (update.CustomHeaders != null) | ||
{ | ||
AppendCustomParameters(operation, update.CustomHeaders, ParameterLocation.Header); | ||
} | ||
|
||
if (update.CustomQueryOptions != null) | ||
{ | ||
AppendCustomParameters(operation, update.CustomQueryOptions, ParameterLocation.Query); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.