Skip to content

Commit

Permalink
Fix time type matching and normalize all deprecation versions (opense…
Browse files Browse the repository at this point in the history
…arch-project#782) (opensearch-project#783)

Signed-off-by: Thomas Farr <tsfarr@amazon.com>
(cherry picked from commit 3b526f7)
  • Loading branch information
Xtansia authored Sep 3, 2024
1 parent 65492ae commit c76138e
Show file tree
Hide file tree
Showing 4 changed files with 4,012 additions and 1,141 deletions.
15 changes: 8 additions & 7 deletions OpenSearch.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
&lt;/Entry.Match&gt;&#xD;
&lt;Entry.SortBy&gt;&#xD;
&lt;Kind Is="Member" /&gt;&#xD;
&lt;Name Is="Enter Pattern Here" /&gt;&#xD;
&lt;Name /&gt;&#xD;
&lt;/Entry.SortBy&gt;&#xD;
&lt;/Entry&gt;&#xD;
&lt;Entry DisplayName="Fields"&gt;&#xD;
Expand All @@ -116,7 +116,7 @@
&lt;Entry.SortBy&gt;&#xD;
&lt;Access /&gt;&#xD;
&lt;Readonly /&gt;&#xD;
&lt;Name Is="Enter Pattern Here" /&gt;&#xD;
&lt;Name /&gt;&#xD;
&lt;/Entry.SortBy&gt;&#xD;
&lt;/Entry&gt;&#xD;
&lt;Entry DisplayName="Constructors"&gt;&#xD;
Expand All @@ -136,7 +136,7 @@
&lt;/Entry.Match&gt;&#xD;
&lt;Entry.SortBy&gt;&#xD;
&lt;Access /&gt;&#xD;
&lt;Name Is="Enter Pattern Here" /&gt;&#xD;
&lt;Name /&gt;&#xD;
&lt;/Entry.SortBy&gt;&#xD;
&lt;/Entry&gt;&#xD;
&lt;Entry DisplayName="Setup/Teardown Methods" Priority="100"&gt;&#xD;
Expand Down Expand Up @@ -200,7 +200,7 @@
&lt;/Entry.Match&gt;&#xD;
&lt;Entry.SortBy&gt;&#xD;
&lt;Kind Is="Member" /&gt;&#xD;
&lt;Name Is="Enter Pattern Here" /&gt;&#xD;
&lt;Name /&gt;&#xD;
&lt;/Entry.SortBy&gt;&#xD;
&lt;/Entry&gt;&#xD;
&lt;Entry DisplayName="Fields"&gt;&#xD;
Expand All @@ -215,7 +215,7 @@
&lt;Entry.SortBy&gt;&#xD;
&lt;Access /&gt;&#xD;
&lt;Readonly /&gt;&#xD;
&lt;Name Is="Enter Pattern Here" /&gt;&#xD;
&lt;Name /&gt;&#xD;
&lt;/Entry.SortBy&gt;&#xD;
&lt;/Entry&gt;&#xD;
&lt;Entry DisplayName="Constructors"&gt;&#xD;
Expand All @@ -235,7 +235,7 @@
&lt;/Entry.Match&gt;&#xD;
&lt;Entry.SortBy&gt;&#xD;
&lt;Access /&gt;&#xD;
&lt;Name Is="Enter Pattern Here" /&gt;&#xD;
&lt;Name /&gt;&#xD;
&lt;/Entry.SortBy&gt;&#xD;
&lt;/Entry&gt;&#xD;
&lt;Entry DisplayName="Interface Implementations"&gt;&#xD;
Expand All @@ -248,7 +248,7 @@
&lt;Entry.SortBy&gt;&#xD;
&lt;ImplementsInterface Name="IDisposable" /&gt;&#xD;
&lt;Access /&gt;&#xD;
&lt;Name Is="Enter Pattern Here" /&gt;&#xD;
&lt;Name /&gt;&#xD;
&lt;/Entry.SortBy&gt;&#xD;
&lt;/Entry&gt;&#xD;
&lt;Entry DisplayName="All other members" /&gt;&#xD;
Expand Down Expand Up @@ -501,6 +501,7 @@
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpUseContinuousIndentInsideBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002EMemberReordering_002EMigrations_002ECSharpFileLayoutPatternRemoveIsAttributeUpgrade/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAlwaysTreatStructAsNotReorderableMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/HighlightingManager/HighlightingEnabledByDefault/@EntryValue">False</s:Boolean>
Expand Down
6 changes: 4 additions & 2 deletions src/ApiGenerator/Domain/Specification/Deprecation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,18 @@
* under the License.
*/

using SemanticVersioning;

namespace ApiGenerator.Domain.Specification;

public class Deprecation
{
public string Version { get; set; }
public Version Version { get; set; }

public string Description { get; set; }

public override string ToString() =>
(!string.IsNullOrEmpty(Version), !string.IsNullOrEmpty(Description)) switch
(Version != null, !string.IsNullOrEmpty(Description)) switch
{
(true, true) => $"Deprecated as of: {Version}, reason: {Description}",
(true, false) => $"Deprecated as of: {Version}",
Expand Down
23 changes: 14 additions & 9 deletions src/ApiGenerator/Generator/ApiEndpointFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ private static string GetOpenSearchType(JsonSchema schema, Action<string, bool>
{
JsonObjectType.Integer => "number",
JsonObjectType.Array => "list",
JsonObjectType.String when schema.Pattern == "^([0-9]+)(?:d|h|m|s|ms|micros|nanos)$" => "time",
JsonObjectType.String when schema.Pattern == @"^([0-9\.]+)(?:d|h|m|s|ms|micros|nanos)$" => "time",
var t => t.ToString().ToLowerInvariant()
};
}
Expand Down Expand Up @@ -308,19 +308,24 @@ private static bool XGlobal(this OpenApiParameter parameter) =>
private static string XDeprecationMessage(this IJsonExtensionObject schema) =>
schema.GetExtension("x-deprecation-message") as string;

private static string XVersionDeprecated(this IJsonExtensionObject schema) =>
schema.GetExtension("x-version-deprecated") as string;
private static Version XVersionDeprecated(this IJsonExtensionObject schema) =>
schema.GetExtension("x-version-deprecated") is string s
? CoerceVersion(s)
: null;

private static Version XVersionAdded(this IJsonExtensionObject schema) =>
schema.GetExtension("x-version-added") is string s
? s.Split('.').Length switch
{
1 => new Version($"{s}.0.0"),
2 => new Version($"{s}.0"),
_ => new Version(s),
}
? CoerceVersion(s)
: null;

private static Version CoerceVersion(string s) =>
s.Split('.').Length switch
{
1 => new Version($"{s}.0.0"),
2 => new Version($"{s}.0"),
_ => new Version(s),
};

private static object GetExtension(this IJsonExtensionObject schema, string key) =>
schema.ExtensionData?.TryGetValue(key, out var value) ?? false ? value : null;
}
Expand Down
Loading

0 comments on commit c76138e

Please sign in to comment.