Skip to content

Commit

Permalink
Merge branch 'main' into shem/fix_python_anyof_generation
Browse files Browse the repository at this point in the history
  • Loading branch information
shemogumbe authored Jun 4, 2024
2 parents ae8e822 + a031b6d commit ad70695
Show file tree
Hide file tree
Showing 27 changed files with 1,223 additions and 310 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Check out the repo
uses: actions/checkout@v4
- name: Login to GitHub package feed
uses: docker/login-action@v3.1.0
uses: docker/login-action@v3.2.0
with:
username: ${{ secrets.ACR_USERNAME }}
password: ${{ secrets.ACR_PASSWORD }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/project-auto-add.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:

jobs:
track_issue:
if: github.actor != 'dependabot[bot]'
if: github.actor != 'dependabot[bot]' && github.event.pull_request.head.repo.fork == false
runs-on: ubuntu-latest
steps:
- name: Generate token
Expand Down
8 changes: 7 additions & 1 deletion 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
- Added uri-form encoded serialization for PHP. [#2074](https://github.com/microsoft/kiota/issues/2074)
- Added information message with base URL in the CLI experience. [#4635](https://github.com/microsoft/kiota/issues/4635)
- Added optional parameter --disable-ssl-validation for generate, show, and download commands. [#4176](https://github.com/microsoft/kiota/issues/4176)
- For *Debug* builds of kiota, the `--log-level` / `--ll` option is now observed if specified explicitly on the command line. It still defaults to `Debug` for *Debug* builds and `Warning` for *Release* builds. [#4739](https://github.com/microsoft/kiota/pull/4739)

### Changed

Expand Down Expand Up @@ -43,7 +44,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixes a bug where CLI Generation does not handle path parameters of type "string" and format "date", "date-time", "time", etc. [#4615](https://github.com/microsoft/kiota/issues/4615)
- Fixes a bug where request executors would be missing Untyped parameters in dotnet [#4692](https://github.com/microsoft/kiota/issues/4692)
- Fixes a bug where indexers in include/exclude patters were not normalized if the indexer was the last segment without a slash at the end [#4715](https://github.com/microsoft/kiota/issues/4715)
- Fixes a bug where CLI generation doesnot handle parameters of type string array. [#4707](https://github.com/microsoft/kiota/issues/4707)
- Fixes a bug where CLI generation doesn't handle parameters of type string array. [#4707](https://github.com/microsoft/kiota/issues/4707)
- Fixed a bug where models would not be created when a multipart content schema existed with no encoding [#4734](https://github.com/microsoft/kiota/issues/4734)
- Types generated by Kiota are now referenced with their full name to avoid namespace ambiguities [#4475](https://github.com/microsoft/kiota/issues/4475)
- Fixes a bug where warnings about discriminator not being inherited were generated [#4761](https://github.com/microsoft/kiota/issues/4761)
- Fix scalar member composed type serialization in PHP [#2827](https://github.com/microsoft/kiota/issues/2827)
- Trims unused components from output openApi document when generating plugins [#4672](https://github.com/microsoft/kiota/issues/4672)

## [1.14.0] - 2024-05-02

Expand Down
4 changes: 2 additions & 2 deletions it/csharp/dotnet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.11.3" />
<PackageReference Include="Microsoft.Kiota.Abstractions" Version="1.9.1" />
<PackageReference Include="Microsoft.Kiota.Abstractions" Version="1.9.5" />
<PackageReference Include="Microsoft.Kiota.Authentication.Azure" Version="1.1.7" />
<PackageReference Include="Microsoft.Kiota.Http.HttpClientLibrary" Version="1.4.2" />
<PackageReference Include="Microsoft.Kiota.Http.HttpClientLibrary" Version="1.4.3" />
<PackageReference Include="Microsoft.Kiota.Serialization.Form" Version="1.2.4" />
<PackageReference Include="Microsoft.Kiota.Serialization.Json" Version="1.3.3" />
<PackageReference Include="Microsoft.kiota.Serialization.Multipart" Version="1.1.5" />
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 @@ -2,7 +2,7 @@

astroid==3.2.2 ; python_full_version >= '3.7.2'

certifi==2024.2.2 ; python_version >= '3.6'
certifi==2024.6.2 ; python_version >= '3.6'

charset-normalizer==3.3.2 ; python_full_version >= '3.7.0'

Expand Down Expand Up @@ -46,7 +46,7 @@ pytest==8.2.1

pytest-asyncio==0.23.7

requests==2.32.2 ; python_version >= '3.7'
requests==2.32.3 ; python_version >= '3.7'

toml==0.10.2

Expand All @@ -56,15 +56,15 @@ tomli-w==1.0.0 ; python_version >= '3.7'

tomlkit==0.12.5 ; python_version >= '3.7'

typing-extensions==4.12.0 ; python_version >= '3.7'
typing-extensions==4.12.1 ; python_version >= '3.7'

urllib3==2.2.1 ; python_version >= '3.7'

wrapt==1.15.0 ; python_version < '3.11'

yapf==0.40.2

zipp==3.19.0 ; python_version >= '3.7'
zipp==3.19.1 ; python_version >= '3.7'

aiohttp==3.9.5 ; python_version >= '3.6'

Expand Down
16 changes: 8 additions & 8 deletions it/typescript/package-lock.json

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

4 changes: 2 additions & 2 deletions it/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
"prettier": "./.prettierrc.json",
"devDependencies": {
"@es-exec/esbuild-plugin-start": "^0.0.5",
"@types/node": "^20.12.12",
"@types/node": "^20.14.1",
"@typescript-eslint/eslint-plugin": "^7.7.1",
"@typescript-eslint/parser": "^7.8.0",
"esbuild": "^0.21.4",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"minimist": "^1.2.8",
"prettier": "^3.2.5",
"prettier": "^3.3.0",
"typescript": "^4.9.5"
},
"dependencies": {
Expand Down
8 changes: 8 additions & 0 deletions src/Kiota.Builder/CodeDOM/CodeClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ public CodeComposedTypeBase? OriginalComposedType
{
get; set;
}
public string GetComponentSchemaName(CodeNamespace modelsNamespace)
{
if (Kind is not CodeClassKind.Model ||
Parent is not CodeNamespace parentNamespace ||
!parentNamespace.IsChildOf(modelsNamespace))
return string.Empty;
return $"{parentNamespace.Name[(modelsNamespace.Name.Length + 1)..]}.{Name}";
}
public CodeIndexer? Indexer => InnerChildElements.Values.OfType<CodeIndexer>().FirstOrDefault(static x => !x.IsLegacyIndexer);
public void AddIndexer(params CodeIndexer[] indexers)
{
Expand Down
9 changes: 9 additions & 0 deletions src/Kiota.Builder/Extensions/OpenApiOperationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ internal static bool IsMultipartFormDataSchema(this IDictionary<string, OpenApiM
return source.GetValidSchemas(structuredMimeTypes).FirstOrDefault() is OpenApiSchema schema &&
source.GetValidSchemas(multipartMimeTypes).FirstOrDefault() == schema;
}
internal static bool IsMultipartTopMimeType(this IDictionary<string, OpenApiMediaType> source, StructuredMimeTypesCollection structuredMimeTypes)
{
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(structuredMimeTypes);
if (structuredMimeTypes.Count == 0) return false;
if (!source.ContainsKey(multipartMimeTypes.First())) return false;
if (source.Count == 1) return true;
return structuredMimeTypes.First() == multipartMimeTypes.First();
}
internal static IEnumerable<OpenApiSchema> GetValidSchemas(this IDictionary<string, OpenApiMediaType> source, StructuredMimeTypesCollection structuredMimeTypes)
{
ArgumentNullException.ThrowIfNull(source);
Expand Down
35 changes: 26 additions & 9 deletions src/Kiota.Builder/Extensions/OpenApiSchemaExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static IEnumerable<string> GetSchemaNames(this OpenApiSchema schema, bool
internal static IEnumerable<OpenApiSchema> FlattenSchemaIfRequired(this IList<OpenApiSchema> schemas, Func<OpenApiSchema, IList<OpenApiSchema>> subsequentGetter)
{
if (schemas is null) return [];
return schemas.Count == 1 && !schemas[0].HasAnyProperty() ?
return schemas.Count == 1 && !schemas[0].HasAnyProperty() && string.IsNullOrEmpty(schemas[0].Reference?.Id) ?
schemas.FlattenEmptyEntries(subsequentGetter, 1) :
schemas;
}
Expand Down Expand Up @@ -84,19 +84,36 @@ public static bool IsInherited(this OpenApiSchema? schema)
isRootSchemaMeaningful);
}

internal static OpenApiSchema? MergeIntersectionSchemaEntries(this OpenApiSchema? schema, HashSet<OpenApiSchema>? schemasToExclude = default)
internal static OpenApiSchema? MergeAllOfSchemaEntries(this OpenApiSchema? schema, HashSet<OpenApiSchema>? schemasToExclude = default, Func<OpenApiSchema, bool>? filter = default)
{
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)
{
if (schema is null) return null;
if (!schema.IsIntersection()) return schema;
if (!schema.IsIntersection() && !overrideIntersection) return schema;
var result = new OpenApiSchema(schema);
result.AllOf.Clear();
var meaningfulSchemas = schema.AllOf
.Where(static x => x.IsSemanticallyMeaningful() || x.AllOf.Any())
.Select(x => MergeIntersectionSchemaEntries(x, schemasToExclude))
.Where(x => (x.IsSemanticallyMeaningful() || x.AllOf.Any()) && (filter == null || filter(x)))
.Select(x => MergeIntersectionSchemaEntries(x, schemasToExclude, overrideIntersection, filter))
.Where(x => x is not null && (schemasToExclude is null || !schemasToExclude.Contains(x)))
.OfType<OpenApiSchema>()
.ToArray();
meaningfulSchemas.FlattenEmptyEntries(static x => x.AllOf).Union(meaningfulSchemas).SelectMany(static x => x.Properties).ToList().ForEach(x => result.Properties.TryAdd(x.Key, x.Value));
var entriesToMerge = meaningfulSchemas.FlattenEmptyEntries(static x => x.AllOf).Union(meaningfulSchemas).ToArray();
if (entriesToMerge.Select(static x => x.Discriminator).OfType<OpenApiDiscriminator>().FirstOrDefault() is OpenApiDiscriminator discriminator)
if (result.Discriminator is null)
result.Discriminator = discriminator;
else if (string.IsNullOrEmpty(result.Discriminator.PropertyName) && !string.IsNullOrEmpty(discriminator.PropertyName))
result.Discriminator.PropertyName = discriminator.PropertyName;
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.Properties.TryAdd(propertyToMerge.Key, propertyToMerge.Value);
}
return result;
}

Expand Down Expand Up @@ -225,8 +242,8 @@ internal static string GetDiscriminatorPropertyName(this OpenApiSchema schema)
return oneOfDiscriminatorPropertyName;
if (schema.AnyOf.Select(GetDiscriminatorPropertyName).FirstOrDefault(static x => !string.IsNullOrEmpty(x)) is string anyOfDiscriminatorPropertyName)
return anyOfDiscriminatorPropertyName;
if (schema.AllOf.Any())
return GetDiscriminatorPropertyName(schema.AllOf[^1]);
if (schema.AllOf.Select(GetDiscriminatorPropertyName).FirstOrDefault(static x => !string.IsNullOrEmpty(x)) is string allOfDiscriminatorPropertyName)
return allOfDiscriminatorPropertyName;

return string.Empty;
}
Expand Down Expand Up @@ -260,7 +277,7 @@ private static IEnumerable<string> GetAllInheritanceSchemaReferences(string curr
ArgumentNullException.ThrowIfNull(inheritanceIndex);
if (inheritanceIndex.TryGetValue(currentReferenceId, out var dependents))
return dependents.Keys.Union(dependents.Keys.SelectMany(x => GetAllInheritanceSchemaReferences(x, inheritanceIndex))).Distinct(StringComparer.OrdinalIgnoreCase);
return Enumerable.Empty<string>();
return [];
}
}

Loading

0 comments on commit ad70695

Please sign in to comment.