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

[Backport 1.x] Fix time type matching and normalize all deprecation versions (#782) #783

Merged
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
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 @@
</Entry.Match>
<Entry.SortBy>
<Kind Is="Member" />
<Name Is="Enter Pattern Here" />
<Name />
</Entry.SortBy>
</Entry>
<Entry DisplayName="Fields">
Expand All @@ -116,7 +116,7 @@
<Entry.SortBy>
<Access />
<Readonly />
<Name Is="Enter Pattern Here" />
<Name />
</Entry.SortBy>
</Entry>
<Entry DisplayName="Constructors">
Expand All @@ -136,7 +136,7 @@
</Entry.Match>
<Entry.SortBy>
<Access />
<Name Is="Enter Pattern Here" />
<Name />
</Entry.SortBy>
</Entry>
<Entry DisplayName="Setup/Teardown Methods" Priority="100">
Expand Down Expand Up @@ -200,7 +200,7 @@
</Entry.Match>
<Entry.SortBy>
<Kind Is="Member" />
<Name Is="Enter Pattern Here" />
<Name />
</Entry.SortBy>
</Entry>
<Entry DisplayName="Fields">
Expand All @@ -215,7 +215,7 @@
<Entry.SortBy>
<Access />
<Readonly />
<Name Is="Enter Pattern Here" />
<Name />
</Entry.SortBy>
</Entry>
<Entry DisplayName="Constructors">
Expand All @@ -235,7 +235,7 @@
</Entry.Match>
<Entry.SortBy>
<Access />
<Name Is="Enter Pattern Here" />
<Name />
</Entry.SortBy>
</Entry>
<Entry DisplayName="Interface Implementations">
Expand All @@ -248,7 +248,7 @@
<Entry.SortBy>
<ImplementsInterface Name="IDisposable" />
<Access />
<Name Is="Enter Pattern Here" />
<Name />
</Entry.SortBy>
</Entry>
<Entry DisplayName="All other members" />
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
Loading