Skip to content
Open
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
12 changes: 11 additions & 1 deletion src/Microsoft.OpenApi.OData.Reader/OpenApiConvertSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,15 @@ public string? PathPrefix
/// </summary>
public int ComposableFunctionsExpansionDepth { get; set; } = 1;

/// <summary>
/// Gets/sets a value indicating whether to use HTTP PUT method for update operations by default
/// instead of PATCH when no UpdateRestrictions annotation is present in the CSDL.
/// If false (default), PATCH will be used for updates.
/// If true, PUT will be used for updates.
/// This setting is ignored when UpdateRestrictions annotations are present in the CSDL.
/// </summary>
public bool UseHttpPutForUpdate { get; set; } = false;

internal OpenApiConvertSettings Clone()
{
var newSettings = new OpenApiConvertSettings
Expand Down Expand Up @@ -392,7 +401,8 @@ internal OpenApiConvertSettings Clone()
SemVerVersion = this.SemVerVersion,
EnableAliasForOperationSegments = this.EnableAliasForOperationSegments,
UseStringArrayForQueryOptionsSchema = this.UseStringArrayForQueryOptionsSchema,
ComposableFunctionsExpansionDepth = this.ComposableFunctionsExpansionDepth
ComposableFunctionsExpansionDepth = this.ComposableFunctionsExpansionDepth,
UseHttpPutForUpdate = this.UseHttpPutForUpdate
};

return newSettings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,16 @@ public void AddUpdateOperation(OpenApiPathItem item)
}
else
{
AddOperation(item, HttpMethod.Patch);
// When no explicit update method is specified in UpdateRestrictions,
// use the UseHttpPutForUpdate setting to determine the default method
if (Context?.Settings?.UseHttpPutForUpdate == true)
{
AddOperation(item, HttpMethod.Put);
}
else
{
AddOperation(item, HttpMethod.Patch);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,16 @@ protected override void SetOperations(OpenApiPathItem item)
}
else
{
AddOperation(item, HttpMethod.Patch);
// When no explicit update method is specified in UpdateRestrictions,
// use the UseHttpPutForUpdate setting to determine the default method
if (Context?.Settings?.UseHttpPutForUpdate == true)
{
AddOperation(item, HttpMethod.Put);
}
else
{
AddOperation(item, HttpMethod.Patch);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,16 @@ private void AddUpdateOperation(OpenApiPathItem item, UpdateRestrictionsType? up
}
else
{
AddOperation(item, HttpMethod.Patch);
// When no explicit update method is specified in UpdateRestrictions,
// use the UseHttpPutForUpdate setting to determine the default method
if (Context?.Settings?.UseHttpPutForUpdate == true)
{
AddOperation(item, HttpMethod.Put);
}
else
{
AddOperation(item, HttpMethod.Patch);
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/Microsoft.OpenApi.OData.Reader/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ Microsoft.OpenApi.OData.OpenApiConvertSettings.UseStringArrayForQueryOptionsSche
Microsoft.OpenApi.OData.OpenApiConvertSettings.UseStringArrayForQueryOptionsSchema.set -> void
Microsoft.OpenApi.OData.OpenApiConvertSettings.UseSuccessStatusCodeRange.get -> bool
Microsoft.OpenApi.OData.OpenApiConvertSettings.UseSuccessStatusCodeRange.set -> void
Microsoft.OpenApi.OData.OpenApiConvertSettings.UseHttpPutForUpdate.get -> bool
Microsoft.OpenApi.OData.OpenApiConvertSettings.UseHttpPutForUpdate.set -> void
Microsoft.OpenApi.OData.OpenApiConvertSettings.VerifyEdmModel.get -> bool
Microsoft.OpenApi.OData.OpenApiConvertSettings.VerifyEdmModel.set -> void
Microsoft.OpenApi.OData.Vocabulary.Core.LinkRelKey
Expand Down
32 changes: 32 additions & 0 deletions src/OoasUtil/ComLineProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ public ComLineProcessor(string[] args)
/// </summary>
public bool? RequireDerivedTypesConstraint { get; private set; }

/// <summary>
/// Use HTTP PUT method for update operations by default instead of PATCH.
/// </summary>
public bool? UseHttpPutForUpdate { get; private set; }

/// <summary>
/// Process the arguments.
/// </summary>
Expand Down Expand Up @@ -227,6 +232,14 @@ public bool Process()
}
break;

case "--useputforupdate":
case "-put":
if (!ProcessUseHttpPutForUpdate(true))
{
return false;
}
break;

default:
PrintUsage();
return false;
Expand Down Expand Up @@ -285,6 +298,11 @@ public bool Process()
DisableSchemaExamples = false;
}

if (UseHttpPutForUpdate == null)
{
UseHttpPutForUpdate = false;
}

_continue = ValidateArguments();
return _continue;
}
Expand Down Expand Up @@ -419,6 +437,19 @@ private bool ProcessDisableSchemaExamples(bool disableSchemaExamples)
return true;
}

private bool ProcessUseHttpPutForUpdate(bool useHttpPutForUpdate)
{
if (UseHttpPutForUpdate != null)
{
Console.WriteLine("[Error:] Multiple [--useputforupdate|-put] are not allowed.\n");
PrintUsage();
return false;
}

UseHttpPutForUpdate = useHttpPutForUpdate;
return true;
}

private bool ProcessTarget(int version)
{
if (Version != null)
Expand Down Expand Up @@ -484,6 +515,7 @@ public static void PrintUsage()
sb.Append(" --enablepagination|-p\t\t\tSet the output to expose pagination for collections.\n");
sb.Append(" --enableunqualifiedcall|-u\t\t\tSet the output to use unqualified calls for bound operations.\n");
sb.Append(" --disableschemaexamples|-x\t\t\tDisable examples in the schema.\n");
sb.Append(" --useputforupdate|-put\t\t\tUse HTTP PUT method for update operations instead of PATCH by default.\n");
sb.Append(" --json|-j\t\t\tSet the output format as JSON.\n");
sb.Append(" --yaml|-y\t\t\tSet the output format as YAML.\n");
sb.Append(" --specversion|-s IntVersion\tSet the OpenApi Specification version of the output. Only 2 or 3 are supported.\n");
Expand Down
1 change: 1 addition & 0 deletions src/OoasUtil/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ static async System.Threading.Tasks.Task<int> Main(string[] args)
EnableUnqualifiedCall = processor.EnableUnqualifiedCall.Value,
ShowSchemaExamples = !processor.DisableSchemaExamples.Value,
OpenApiSpecVersion = processor.Version.Value,
UseHttpPutForUpdate = processor.UseHttpPutForUpdate.Value,
};

if (processor.IsLocalFile)
Expand Down
2 changes: 1 addition & 1 deletion tool/versioning.props
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
overflows the Int16. The system convert below will throw errors when this happens.
-->
<PropertyGroup>
<VersionStartYear Condition="'$(VersionStartYear)' == ''">2020</VersionStartYear>
<VersionStartYear Condition="'$(VersionStartYear)' == ''">2026</VersionStartYear>

<!-- { Now.Year - 2019 + 1}{MM}{DD} -->
<VersionDateCode>$([System.Convert]::ToInt32('$([MSBuild]::Add(1, $([MSBuild]::Subtract($([System.DateTime]::Now.Year), $(VersionStartYear)))))$([System.DateTime]::Now.ToString("MMdd"))'))</VersionDateCode>
Expand Down
Loading