Skip to content

Commit

Permalink
[Fix] DELETE methods should always return response status code 204 (
Browse files Browse the repository at this point in the history
#367)

* Delete responses always return 204

* Update tests

* Update release note
  • Loading branch information
irvinesunday authored Apr 5, 2023
1 parent 01c3c6c commit ef33618
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,13 @@
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<PackageId>Microsoft.OpenApi.OData</PackageId>
<SignAssembly>true</SignAssembly>
<Version>1.3.0</Version>
<Version>1.4.0-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>
- Update key path parameter descriptions #309
- Skips adding a $count path if a similar count() function path exists #347
- Checks whether path exists before adding it to the paths dictionary #343
- Strips namespace prefix from operation segments and aliases type cast segments #348
- Return response status code 2XX for PUT operations of stream properties when UseSuccessStatusCodeRange is enabled #310
- Adds $value segment to paths with entity types with base types with HasStream=true #314
- Uses SemVerVersion in place of Version to Get or Set the metadata version in the OpenAPI document #346
- Resolves operationId and tag names for OData cast paths #324
- DELETE methods should always return response status code 204
</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 @@ -81,7 +81,11 @@ protected override void SetParameters(OpenApiOperation operation)
/// <inheritdoc/>
protected override void SetResponses(OpenApiOperation operation)
{
operation.AddErrorResponses(Context.Settings, true);
// Response for Delete methods should be 204 No Content
OpenApiConvertSettings settings = Context.Settings.Clone();
settings.UseSuccessStatusCodeRange = false;

operation.AddErrorResponses(settings, true);
base.SetResponses(operation);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ protected override void SetSecurity(OpenApiOperation operation)
/// <inheritdoc/>
protected override void SetResponses(OpenApiOperation operation)
{
operation.AddErrorResponses(Context.Settings, true);
// Response for Delete methods should be 204 No Content
OpenApiConvertSettings settings = Context.Settings.Clone();
settings.UseSuccessStatusCodeRange = false;

operation.AddErrorResponses(settings, true);
base.SetResponses(operation);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ protected override void SetSecurity(OpenApiOperation operation)
/// <inheritdoc/>
protected override void SetResponses(OpenApiOperation operation)
{
operation.AddErrorResponses(Context.Settings, true);
// Response for Delete methods should be 204 No Content
OpenApiConvertSettings settings = Context.Settings.Clone();
settings.UseSuccessStatusCodeRange = false;

operation.AddErrorResponses(settings, true);
base.SetResponses(operation);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@ public class NavigationPropertyDeleteOperationHandlerTests
private NavigationPropertyDeleteOperationHandler _operationHandler = new NavigationPropertyDeleteOperationHandler();

[Theory]
[InlineData(true)]
[InlineData(false)]
public void CreateNavigationDeleteOperationReturnsCorrectOperation(bool enableOperationId)
[InlineData(true, false)]
[InlineData(false, false)]
[InlineData(true, true)]
[InlineData(false, true)]
public void CreateNavigationDeleteOperationReturnsCorrectOperation(bool enableOperationId, bool useSuccessStatusCodeRange)
{
// Arrange
IEdmModel model = EdmModelHelper.TripServiceModel;
OpenApiConvertSettings settings = new OpenApiConvertSettings
{
EnableOperationId = enableOperationId
EnableOperationId = enableOperationId,
UseSuccessStatusCodeRange = useSuccessStatusCodeRange
};
ODataContext context = new ODataContext(model, settings);
IEdmEntitySet people = model.EntityContainer.FindEntitySet("People");
Expand Down

0 comments on commit ef33618

Please sign in to comment.