Skip to content

Commit

Permalink
Merge branch 'main' into feat/OAI-3-1
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Biret <[email protected]>
  • Loading branch information
baywet committed Jan 2, 2025
2 parents 7a7ca1a + 796e96a commit 55015ff
Show file tree
Hide file tree
Showing 14 changed files with 1,058 additions and 133 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Fixed a bug in generation when a referenced schema in an allOf was a primitive [#5701](https://github.com/microsoft/kiota/issues/5701).
- Fixed a bug where inherited error models would be missing interface declarations. [#5888](https://github.com/microsoft/kiota/issues/5888)
- Fixed a bug where oneOf/anyOf schemas with single references to inheritance or intersections would be missing properties. [#5921](https://github.com/microsoft/kiota/issues/5921)

## [1.21.0] - 2024-12-05

Expand Down
8 changes: 4 additions & 4 deletions it/python/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ astroid==3.3.8 ; python_full_version >= '3.7.2'

certifi==2024.12.14 ; python_version >= '3.6'

charset-normalizer==3.4.0 ; python_full_version >= '3.7.0'
charset-normalizer==3.4.1 ; python_full_version >= '3.7.0'

colorama==0.4.6 ; sys_platform == 'win32'

Expand All @@ -30,7 +30,7 @@ lazy-object-proxy==1.10.0 ; python_version >= '3.7'

mccabe==0.7.0 ; python_version >= '3.6'

mypy==1.14.0
mypy==1.14.1

mypy-extensions==1.0.0 ; python_version >= '3.5'

Expand All @@ -44,7 +44,7 @@ pylint==3.3.3

pytest==8.3.4

pytest-asyncio==0.25.0
pytest-asyncio==0.25.1

requests==2.32.3 ; python_version >= '3.7'

Expand Down Expand Up @@ -118,7 +118,7 @@ msal-extensions==1.2.0

multidict==6.1.0 ; python_version >= '3.7'

portalocker==3.0.0 ; python_version >= '3.5' and platform_system == 'Windows'
portalocker==3.1.1 ; python_version >= '3.5' and platform_system == 'Windows'

pycparser==2.22

Expand Down
96 changes: 48 additions & 48 deletions it/typescript/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions it/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
"devDependencies": {
"@es-exec/esbuild-plugin-start": "^0.0.5",
"@stylistic/eslint-plugin-ts": "^2.12.1",
"@types/node": "^22.10.2",
"@typescript-eslint/eslint-plugin": "^8.18.2",
"@typescript-eslint/parser": "^8.18.2",
"@types/node": "^22.10.3",
"@typescript-eslint/eslint-plugin": "^8.19.0",
"@typescript-eslint/parser": "^8.19.0",
"esbuild": "^0.24.2",
"eslint": "^9.17.0",
"eslint-config-prettier": "^9.1.0",
Expand Down
29 changes: 29 additions & 0 deletions src/Kiota.Builder/Extensions/IListExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Collections.Generic;

namespace Kiota.Builder.Extensions;

public static class IListExtensions
{
/// <summary>
/// Returns the only element of this list when it has count of exactly <c>1</c>
/// </summary>
/// <typeparam name="T">The contained item type.</typeparam>
/// <param name="items">The items.</param>
/// <returns>The only element or null.</returns>
internal static T? OnlyOneOrDefault<T>(this IList<T> items) =>
items.Count == 1 ? items[0] : default;

/// <summary>
/// Adds the provided <paramref name="values"/> to this list.
/// </summary>
/// <typeparam name="T">The contained item type.</typeparam>
/// <param name="items">The items.</param>
/// <param name="values">The values to add.</param>
internal static void AddRange<T>(this IList<T> items, IEnumerable<T> values)
{
foreach (var item in values)
{
items.Add(item);
}
}
}
60 changes: 44 additions & 16 deletions src/Kiota.Builder/Extensions/OpenApiSchemaExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,7 @@ public static bool IsInherited(this OpenApiSchema? schema)
if (schema is null || !schema.IsInclusiveUnion(0)) return null;
var result = new OpenApiSchema(schema);
result.AnyOf.Clear();
foreach (var subSchema in schema.AnyOf)
{
foreach (var property in subSchema.Properties)
{
result.Properties.TryAdd(property.Key, property.Value);
}
}
result.TryAddProperties(schema.AnyOf.SelectMany(static x => x.Properties));
return result;
}

Expand All @@ -113,14 +107,42 @@ public static bool IsInherited(this OpenApiSchema? schema)
if (schema is null || !schema.IsExclusiveUnion(0)) return null;
var result = new OpenApiSchema(schema);
result.OneOf.Clear();
foreach (var subSchema in schema.OneOf)
result.TryAddProperties(schema.OneOf.SelectMany(static x => x.Properties));
return result;
}

internal static OpenApiSchema? MergeSingleInclusiveUnionInheritanceOrIntersectionSchemaEntries(this OpenApiSchema? schema)
{
if (schema is not null
&& schema.IsInclusiveUnion(0)
&& schema.AnyOf.OnlyOneOrDefault() is OpenApiSchema subSchema
&& (subSchema.IsInherited() || subSchema.IsIntersection()))
{
foreach (var property in subSchema.Properties)
{
result.Properties.TryAdd(property.Key, property.Value);
}
var result = new OpenApiSchema(schema);
result.AnyOf.Clear();
result.TryAddProperties(subSchema.Properties);
result.AllOf.AddRange(subSchema.AllOf);
return result;
}
return result;

return null;
}

internal static OpenApiSchema? MergeSingleExclusiveUnionInheritanceOrIntersectionSchemaEntries(this OpenApiSchema? schema)
{
if (schema is not null
&& schema.IsExclusiveUnion(0)
&& schema.OneOf.OnlyOneOrDefault() is OpenApiSchema subSchema
&& (subSchema.IsInherited() || subSchema.IsIntersection()))
{
var result = new OpenApiSchema(schema);
result.OneOf.Clear();
result.TryAddProperties(subSchema.Properties);
result.AllOf.AddRange(subSchema.AllOf);
return result;
}

return null;
}

internal static OpenApiSchema? MergeIntersectionSchemaEntries(this OpenApiSchema? schema, HashSet<OpenApiSchema>? schemasToExclude = default, bool overrideIntersection = false, Func<OpenApiSchema, bool>? filter = default)
Expand All @@ -144,11 +166,17 @@ public static bool IsInherited(this OpenApiSchema? schema)
else if (discriminator.Mapping?.Any() ?? false)
result.Discriminator.Mapping = discriminator.Mapping.ToDictionary(static x => x.Key, static x => x.Value);

foreach (var propertyToMerge in entriesToMerge.SelectMany(static x => x.Properties))
result.TryAddProperties(entriesToMerge.SelectMany(static x => x.Properties));

return result;
}

internal static void TryAddProperties(this OpenApiSchema schema, IEnumerable<KeyValuePair<string, OpenApiSchema>> properties)
{
foreach (var property in properties)
{
result.Properties.TryAdd(propertyToMerge.Key, propertyToMerge.Value);
schema.Properties.TryAdd(property.Key, property.Value);
}
return result;
}

public static bool IsIntersection(this OpenApiSchema? schema)
Expand Down
Loading

0 comments on commit 55015ff

Please sign in to comment.