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

fixes incompatibility with new odata primitive format. #5557

Merged
merged 1 commit into from
Oct 8, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Fixed incompatibility with detecting odata primitives after conversion library updates at [OpenAPI.NET.OData#581](https://github.com/microsoft/OpenAPI.NET.OData/issues/581);
- Fixed cyclic dependencies in generated Go code. [#2834](https://github.com/microsoft/kiota/issues/2834)
- Fixed a bug where default output folder is created on plugin edit and generate commands. [#5510](https://github.com/microsoft/kiota/issues/5429)

Expand Down
18 changes: 17 additions & 1 deletion src/Kiota.Builder/Extensions/OpenApiSchemaExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
return schema.MergeIntersectionSchemaEntries(schemasToExclude, true, filter);
}

internal static OpenApiSchema? MergeIntersectionSchemaEntries(this OpenApiSchema? schema, HashSet<OpenApiSchema>? schemasToExclude = default, bool overrideIntersection = false, Func<OpenApiSchema, bool>? filter = default)

Check warning on line 92 in src/Kiota.Builder/Extensions/OpenApiSchemaExtensions.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this method to reduce its Cognitive Complexity from 16 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)

Check warning on line 92 in src/Kiota.Builder/Extensions/OpenApiSchemaExtensions.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this method to reduce its Cognitive Complexity from 16 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)
{
if (schema is null) return null;
if (!schema.IsIntersection() && !overrideIntersection) return schema;
Expand Down Expand Up @@ -132,13 +132,13 @@
"number",
"integer",
};
public static bool IsODataPrimitiveType(this OpenApiSchema schema)
private static bool IsODataPrimitiveTypeBackwardCompatible(this OpenApiSchema schema)
{
return schema.IsExclusiveUnion() &&
schema.OneOf.Count == 3 &&
schema.OneOf.Count(static x => x.Enum?.Any() ?? false) == 1 &&
schema.OneOf.Count(static x => oDataTypes.Contains(x.Type)) == 1 &&
schema.OneOf.Count(static x => "string".Equals(x.Type, StringComparison.OrdinalIgnoreCase)) == 1

Check warning on line 141 in src/Kiota.Builder/Extensions/OpenApiSchemaExtensions.cs

View workflow job for this annotation

GitHub Actions / Build

Define a constant instead of using this literal 'string' 7 times. (https://rules.sonarsource.com/csharp/RSPEC-1192)

Check warning on line 141 in src/Kiota.Builder/Extensions/OpenApiSchemaExtensions.cs

View workflow job for this annotation

GitHub Actions / Build

Define a constant instead of using this literal 'string' 7 times. (https://rules.sonarsource.com/csharp/RSPEC-1192)
||
schema.IsInclusiveUnion() &&
schema.AnyOf.Count == 3 &&
Expand All @@ -146,6 +146,22 @@
schema.AnyOf.Count(static x => oDataTypes.Contains(x.Type)) == 1 &&
schema.AnyOf.Count(static x => "string".Equals(x.Type, StringComparison.OrdinalIgnoreCase)) == 1;
}
public static bool IsODataPrimitiveType(this OpenApiSchema schema)
{
return schema.IsExclusiveUnion() &&
schema.OneOf.Count == 3 &&
schema.OneOf.Count(static x => "string".Equals(x.Type, StringComparison.OrdinalIgnoreCase) && (x.Enum?.Any() ?? false)) == 1 &&
schema.OneOf.Count(static x => oDataTypes.Contains(x.Type)) == 1 &&
schema.OneOf.Count(static x => "string".Equals(x.Type, StringComparison.OrdinalIgnoreCase)) == 2
||
schema.IsInclusiveUnion() &&
schema.AnyOf.Count == 3 &&
schema.AnyOf.Count(static x => "string".Equals(x.Type, StringComparison.OrdinalIgnoreCase) && (x.Enum?.Any() ?? false)) == 1 &&
schema.AnyOf.Count(static x => oDataTypes.Contains(x.Type)) == 1 &&
schema.AnyOf.Count(static x => "string".Equals(x.Type, StringComparison.OrdinalIgnoreCase)) == 2
||
schema.IsODataPrimitiveTypeBackwardCompatible();
}
public static bool IsEnum(this OpenApiSchema schema)
{
if (schema is null) return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -785,4 +785,66 @@ public void IsEnumDoesNotMaskUnions()
};
Assert.False(schema.IsEnum());
}
[Fact]
public void IsOdataPrimitive()
{
var schema = new OpenApiSchema
{
OneOf = new List<OpenApiSchema>
{
new ()
{
Type = "number",
Format = "double",
Nullable = true
},
new ()
{
Type = "string",
Nullable = true
},
new ()
{
Enum = new List<IOpenApiAny>()
{
new OpenApiString("INF"),
new OpenApiString("INF"),
new OpenApiString("NaN"),
},
Type = "string",
Nullable = true
}
}
};
Assert.True(schema.IsODataPrimitiveType());
}
[Fact]
public void IsOdataPrimitiveBackwardCompatible()
{
var schema = new OpenApiSchema
{
OneOf = new List<OpenApiSchema>
{
new ()
{
Type = "number",
Format = "double",
},
new ()
{
Type = "string",
},
new ()
{
Enum = new List<IOpenApiAny>()
{
new OpenApiString("INF"),
new OpenApiString("INF"),
new OpenApiString("NaN"),
}
}
}
};
Assert.True(schema.IsODataPrimitiveType());
}
}
Loading