Skip to content

Commit

Permalink
Merge branch 'main' into fix/php-integration-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
timayabi2020 authored Nov 28, 2024
2 parents 0f05da2 + 6746032 commit aba8d81
Show file tree
Hide file tree
Showing 18 changed files with 620 additions and 152 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/check-translations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Check Translations

on:
workflow_dispatch:
push:
branches: [main]
pull_request:

permissions:
contents: read

jobs:
check-translations:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22.x

- name: Run translation check
run: ./scripts/check-translations.ps1
shell: pwsh

- name: Upload untranslated strings
uses: actions/upload-artifact@v4
with:
name: untranslated-strings
path: ./untranslated_strings.html
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- Fixed python generation in scenarios with opening/closing tags for code comments. [#5636](https://github.com/microsoft/kiota/issues/5636)
- Fixed Python error when a class inherits from a base class and implements an interface. [5637](https://github.com/microsoft/kiota/issues/5637)
- Fix anyOf/oneOf generation in TypeScript. [5353](https://github.com/microsoft/kiota/issues/5353)
- Fixed Python error when a class inherits from a base class and implements an interface. [#5637](https://github.com/microsoft/kiota/issues/5637)
- Fixed a bug where one/any schemas with single schema entries would be missing properties. [#5808](https://github.com/microsoft/kiota/issues/5808)
- Fixed anyOf/oneOf generation in TypeScript. [5353](https://github.com/microsoft/kiota/issues/5353)
- Fixed invalid code in Php caused by "*/*/" in property description. [5635](https://github.com/microsoft/kiota/issues/5635)
- Fixed a bug where discriminator property name lookup could end up in an infinite loop. [#5771](https://github.com/microsoft/kiota/issues/5771)
- Fixed TypeScript generation error when generating usings from shaken serializers. [#5634](https://github.com/microsoft/kiota/issues/5634)
- Multiple fixed and improvements in OpenAPI description generation for plugins. [#5806](https://github.com/microsoft/kiota/issues/5806)

## [1.20.0] - 2024-11-07

Expand Down
6 changes: 3 additions & 3 deletions it/python/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ yapf==0.43.0

zipp==3.21.0 ; python_version >= '3.7'

aiohttp==3.11.7 ; python_version >= '3.6'
aiohttp==3.11.8 ; python_version >= '3.6'

aiosignal==1.3.1 ; python_version >= '3.7'

Expand All @@ -82,7 +82,7 @@ azure-identity==1.19.0

cffi==1.17.1

cryptography==43.0.3 ; python_version >= '3.7'
cryptography==44.0.0 ; python_version >= '3.7'

frozenlist==1.5.0 ; python_version >= '3.7'

Expand Down Expand Up @@ -122,7 +122,7 @@ portalocker==3.0.0 ; python_version >= '3.5' and platform_system == 'Windows'

pycparser==2.22

pyjwt[crypto]==2.10.0 ; python_version >= '3.7'
pyjwt[crypto]==2.10.1 ; python_version >= '3.7'

python-dateutil==2.9.0.post0 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2'

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

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

2 changes: 1 addition & 1 deletion it/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"devDependencies": {
"@es-exec/esbuild-plugin-start": "^0.0.5",
"@stylistic/eslint-plugin-ts": "^2.11.0",
"@types/node": "^22.10.0",
"@types/node": "^22.10.1",
"@typescript-eslint/eslint-plugin": "^8.16.0",
"@typescript-eslint/parser": "^8.16.0",
"esbuild": "^0.24.0",
Expand Down
83 changes: 83 additions & 0 deletions scripts/check-translations.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Step 1: Find all instances of vscode.l10n.t() and extract the strings from .ts and .tsx files
$withParamsPattern = 'vscode\.l10n\.t\(["''`](.+?)["''`],'
Get-ChildItem -Path vscode/microsoft-kiota/src -Recurse -Include *.ts, *.tsx |
Select-String -Pattern $withParamsPattern |
ForEach-Object { $_.Matches.Groups[1].Value } |
Sort-Object |
Get-Unique |
Out-File -FilePath "strings_with_params.txt"

$withoutParamsPattern = 'vscode\.l10n\.t\(["' + "`'" + '`]([^"' + "`'" + '`]+)["' + "`'" + '`]\)'
Get-ChildItem -Path vscode/microsoft-kiota/src -Recurse -Include *.ts, *.tsx |
Select-String -Pattern $withoutParamsPattern |
ForEach-Object { $_.Matches.Groups[1].Value } |
Sort-Object |
Get-Unique |
Out-File -FilePath "strings_without_params.txt"

Get-Content strings_with_params.txt, strings_without_params.txt |
Sort-Object |
Get-Unique |
Out-File -FilePath "strings.txt"

# Step 2: Check translation files in the l10n folder
$results = @()
foreach ($file in Get-ChildItem -Path "vscode/microsoft-kiota/l10n" -Filter bundle.l10n.*.json -Recurse) {
$translations = Get-Content $file.FullName |
Select-String -Pattern '"[^"]+"' |
ForEach-Object { $_.Matches.Groups[0].Value.Trim('"') } |
Sort-Object
$missing = Compare-Object (Get-Content "strings.txt") $translations -PassThru |
Where-Object { $_.SideIndicator -eq "<=" }

if ($missing) {
$untranslatedItems = $missing | ForEach-Object { "<li>$_</li>" }
$results += [PSCustomObject]@{
"LanguageFile" = "$($file.Name)"
"Count" = "$($untranslatedItems.Count) found"
"UntranslatedStrings" = "<ul>$($untranslatedItems -join "`n")</ul>"
}
}
}

# Create the HTML table
$htmlTable = @"
<!DOCTYPE html>
<html>
<head>
<style>
table { width: 100%; border-collapse: collapse; }
th, td { border: 1px solid black; padding: 8px; text-align: left; }
th { background-color: #f2f2f2; }
</style>
</head>
<body>
<h2>Untranslated Strings</h2>
<table>
<tr>
<th>Language File</th>
<th>Untranslated Strings</th>
</tr>
"@
foreach ($result in $results) {
$htmlTable += "<tr><td>$($result.LanguageFile) ($($result.Count))</td><td>$($result.UntranslatedStrings)</td></tr>"
}
$htmlTable += @"
</table>
</body>
</html>
"@
$htmlTable | Out-File -FilePath "untranslated_strings.html"

# Output a summary table to the workflow log
if ($results.Count -gt 0) {
Write-Host "Untranslated strings found. See untranslated_strings.html for details." -ForegroundColor Red
Write-Host "| Language File | Count |"
Write-Host "|----------------------------------------|---------|"
foreach ($result in $results) {
Write-Host "| $($result.LanguageFile) | $($result.Count) |"
}
}
else {
Write-Host "All strings have translations." -ForegroundColor Green
}
38 changes: 34 additions & 4 deletions src/Kiota.Builder/Extensions/OpenApiSchemaExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public static bool HasAnyProperty(this OpenApiSchema? schema)
{
return schema?.Properties is { Count: > 0 };
}
public static bool IsInclusiveUnion(this OpenApiSchema? schema)
public static bool IsInclusiveUnion(this OpenApiSchema? schema, uint exclusiveMinimumNumberOfEntries = 1)
{
return schema?.AnyOf?.Count(static x => IsSemanticallyMeaningful(x, true)) > 1;
return schema?.AnyOf?.Count(static x => IsSemanticallyMeaningful(x, true)) > exclusiveMinimumNumberOfEntries;
// so we don't consider any of object/nullable as a union type
}

Expand All @@ -89,6 +89,36 @@ public static bool IsInherited(this OpenApiSchema? schema)
return schema.MergeIntersectionSchemaEntries(schemasToExclude, true, filter);
}

internal static OpenApiSchema? MergeInclusiveUnionSchemaEntries(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);
}
}
return result;
}

internal static OpenApiSchema? MergeExclusiveUnionSchemaEntries(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)
{
foreach (var property in subSchema.Properties)
{
result.Properties.TryAdd(property.Key, property.Value);
}
}
return result;
}

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;
Expand Down Expand Up @@ -123,9 +153,9 @@ public static bool IsIntersection(this OpenApiSchema? schema)
return meaningfulSchemas?.Count(static x => !string.IsNullOrEmpty(x.Reference?.Id)) > 1 || meaningfulSchemas?.Count(static x => string.IsNullOrEmpty(x.Reference?.Id)) > 1;
}

public static bool IsExclusiveUnion(this OpenApiSchema? schema)
public static bool IsExclusiveUnion(this OpenApiSchema? schema, uint exclusiveMinimumNumberOfEntries = 1)
{
return schema?.OneOf?.Count(static x => IsSemanticallyMeaningful(x, true)) > 1;
return schema?.OneOf?.Count(static x => IsSemanticallyMeaningful(x, true)) > exclusiveMinimumNumberOfEntries;
// so we don't consider one of object/nullable as a union type
}
private static readonly HashSet<string> oDataTypes = new(StringComparer.OrdinalIgnoreCase) {
Expand Down
10 changes: 10 additions & 0 deletions src/Kiota.Builder/KiotaBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1895,6 +1895,16 @@ private CodeElement AddModelDeclarationIfDoesntExist(OpenApiUrlTreeNode currentN
// multiple allOf entries that do not translate to inheritance
return createdClass;
}
else if (schema.MergeInclusiveUnionSchemaEntries() is { } iUMergedSchema &&
AddModelClass(currentNode, iUMergedSchema, declarationName, currentNamespace, currentOperation, inheritsFrom) is CodeClass uICreatedClass)
{
return uICreatedClass;
}
else if (schema.MergeExclusiveUnionSchemaEntries() is { } eUMergedSchema &&
AddModelClass(currentNode, eUMergedSchema, declarationName, currentNamespace, currentOperation, inheritsFrom) is CodeClass uECreatedClass)
{
return uECreatedClass;
}
return AddModelClass(currentNode, schema, declarationName, currentNamespace, currentOperation, inheritsFrom);
}
return existingDeclaration;
Expand Down
Loading

0 comments on commit aba8d81

Please sign in to comment.