Skip to content

Commit

Permalink
Merge branch 'main' into elinor/add-kiota-workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
baywet committed Apr 26, 2024
2 parents 58cb7e3 + 4871a37 commit 0b460d4
Show file tree
Hide file tree
Showing 8 changed files with 380 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Updated reserved name providers for Java and Php so that "object" can be escaped.
- Fixes request builder disambiguation when child nodes had different prefixes for different paths with same parameters.[#4448](https://github.com/microsoft/kiota/issues/4448)
- Do not generate CS8603 warnings when enabling backing store in CSharp generation.
- Fixed excluding operation. [#4399](https://github.com/microsoft/kiota/issues/4399)

## [1.13.0] - 2024-04-04

Expand Down
10 changes: 8 additions & 2 deletions src/Kiota.Builder/KiotaBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,14 @@ internal void FilterPathsByPatterns(OpenApiDocument doc)
foreach (var path in doc.Paths.Where(x => !nonOperationIncludePatterns.Any(y => y.IsMatch(x.Key))))
{
var pathString = path.Key;
path.Value.Operations.Keys.Where(x => operationIncludePatterns.Count != 0 && !operationIncludePatterns.Any(y => y.Key.IsMatch(pathString) && y.Value.Contains(x)) ||
operationExcludePatterns.Count != 0 && operationExcludePatterns.Any(y => y.Key.IsMatch(pathString) && y.Value.Contains(x)))
path.Value.Operations.Keys.Where(x => operationIncludePatterns.Count != 0 && !operationIncludePatterns.Any(y => y.Key.IsMatch(pathString) && y.Value.Contains(x)))
.ToList()
.ForEach(x => path.Value.Operations.Remove(x));
}
foreach (var path in doc.Paths)
{
var pathString = path.Key;
path.Value.Operations.Keys.Where(x => operationExcludePatterns.Count != 0 && operationExcludePatterns.Any(y => y.Key.IsMatch(pathString) && y.Value.Contains(x)))
.ToList()
.ForEach(x => path.Value.Operations.Remove(x));
}
Expand Down
290 changes: 290 additions & 0 deletions tests/Kiota.Builder.Tests/KiotaBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7730,4 +7730,294 @@ p.Type is
Name: "EnumValue"
});
}
[Fact]
public void SupportsIncludeFilterAndExcludeWithOperation()
{
var myObjectSchema = new OpenApiSchema
{
Type = "object",
Properties = new Dictionary<string, OpenApiSchema> {
{
"name", new OpenApiSchema {
Type = "string",
}
}
},
Reference = new OpenApiReference
{
Id = "myobject",
Type = ReferenceType.Schema
},
UnresolvedReference = false,
};
var document = new OpenApiDocument
{
Paths = new OpenApiPaths
{
["directory/administrativeUnits"] = new OpenApiPathItem
{
Operations = {
[OperationType.Get] = new OpenApiOperation
{
Responses = new OpenApiResponses
{
["200"] = new OpenApiResponse {
Content = {
["application/json"] = new OpenApiMediaType {
Schema = myObjectSchema
}
}
},
}
},
[OperationType.Post] = new OpenApiOperation
{
RequestBody = new OpenApiRequestBody {
Content = {
["application/json"] = new OpenApiMediaType {
Schema = myObjectSchema
}
}
},
Responses = new OpenApiResponses
{
["201"] = new OpenApiResponse {
Content = {
["application/json"] = new OpenApiMediaType {
Schema = myObjectSchema
}
}
},
}
}
}
},
["directory/administrativeUnits/{id}"] = new OpenApiPathItem
{
Operations = {
[OperationType.Get] = new OpenApiOperation
{
Responses = new OpenApiResponses
{
["200"] = new OpenApiResponse {
Content = {
["application/json"] = new OpenApiMediaType {
Schema = myObjectSchema
}
}
},
}
},
[OperationType.Patch] = new OpenApiOperation
{
RequestBody = new OpenApiRequestBody {
Content = {
["application/json"] = new OpenApiMediaType {
Schema = myObjectSchema
}
}
},
Responses = new OpenApiResponses
{
["204"] = new OpenApiResponse()
}
},
[OperationType.Delete] = new OpenApiOperation
{
Responses = new OpenApiResponses
{
["204"] = new OpenApiResponse()
}
}
}
}
},
Components = new()
{
Schemas = new Dictionary<string, OpenApiSchema> {
{
"myobject", myObjectSchema
}
}
}
};
var mockLogger = new Mock<ILogger<KiotaBuilder>>();
var builder = new KiotaBuilder(mockLogger.Object, new GenerationConfiguration
{
ClientClassName = "TestClient",
ClientNamespaceName = "TestSdk",
ApiRootUrl = "https://localhost",
IncludePatterns = new() {
"directory/administrativeUnits",
"directory/administrativeUnits/**"
},
ExcludePatterns = new()
{
"directory/administrativeUnits/**#DELETE"
}
}, _httpClient);
builder.FilterPathsByPatterns(document);
var node = builder.CreateUriSpace(document);
var codeModel = builder.CreateSourceModel(node);
Assert.Null(codeModel.FindNamespaceByName("TestSdk.groups"));
var administrativeUnitsNS = codeModel.FindNamespaceByName("TestSdk.directory.administrativeUnits");
Assert.NotNull(administrativeUnitsNS);
var administrativeUnitsRS = administrativeUnitsNS.FindChildByName<CodeClass>("AdministrativeUnitsRequestBuilder");
Assert.NotNull(administrativeUnitsRS);
Assert.Single(administrativeUnitsRS.Methods.Where(static x => x.IsOfKind(CodeMethodKind.RequestExecutor) && x.HttpMethod == Builder.CodeDOM.HttpMethod.Post));
Assert.Single(administrativeUnitsRS.Methods.Where(static x => x.IsOfKind(CodeMethodKind.RequestExecutor) && x.HttpMethod == Builder.CodeDOM.HttpMethod.Get));
Assert.Empty(administrativeUnitsRS.Methods.Where(static x => x.IsOfKind(CodeMethodKind.RequestExecutor) && x.HttpMethod == Builder.CodeDOM.HttpMethod.Put));
var administrativeUnitsItemsNS = codeModel.FindNamespaceByName("TestSdk.directory.administrativeUnits.item");
Assert.NotNull(administrativeUnitsItemsNS);
var administrativeUnitItemsRS = administrativeUnitsItemsNS.FindChildByName<CodeClass>("AdministrativeUnitsItemRequestBuilder");
Assert.NotNull(administrativeUnitItemsRS);
Assert.Single(administrativeUnitItemsRS.Methods.Where(static x => x.IsOfKind(CodeMethodKind.RequestExecutor) && x.HttpMethod == Builder.CodeDOM.HttpMethod.Get));
Assert.Single(administrativeUnitItemsRS.Methods.Where(static x => x.IsOfKind(CodeMethodKind.RequestExecutor) && x.HttpMethod == Builder.CodeDOM.HttpMethod.Patch));
Assert.Empty(administrativeUnitItemsRS.Methods.Where(static x => x.IsOfKind(CodeMethodKind.RequestExecutor) && x.HttpMethod == Builder.CodeDOM.HttpMethod.Delete));
}
[Fact]
public void SupportsIncludeFilterAndExcludeWithOperationForSpecificPath()
{
var myObjectSchema = new OpenApiSchema
{
Type = "object",
Properties = new Dictionary<string, OpenApiSchema> {
{
"name", new OpenApiSchema {
Type = "string",
}
}
},
Reference = new OpenApiReference
{
Id = "myobject",
Type = ReferenceType.Schema
},
UnresolvedReference = false,
};
var document = new OpenApiDocument
{
Paths = new OpenApiPaths
{
["directory/administrativeUnits"] = new OpenApiPathItem
{
Operations = {
[OperationType.Get] = new OpenApiOperation
{
Responses = new OpenApiResponses
{
["200"] = new OpenApiResponse {
Content = {
["application/json"] = new OpenApiMediaType {
Schema = myObjectSchema
}
}
},
}
},
[OperationType.Post] = new OpenApiOperation
{
RequestBody = new OpenApiRequestBody {
Content = {
["application/json"] = new OpenApiMediaType {
Schema = myObjectSchema
}
}
},
Responses = new OpenApiResponses
{
["201"] = new OpenApiResponse {
Content = {
["application/json"] = new OpenApiMediaType {
Schema = myObjectSchema
}
}
},
}
}
}
},
["directory/administrativeUnits/{id}"] = new OpenApiPathItem
{
Operations = {
[OperationType.Get] = new OpenApiOperation
{
Responses = new OpenApiResponses
{
["200"] = new OpenApiResponse {
Content = {
["application/json"] = new OpenApiMediaType {
Schema = myObjectSchema
}
}
},
}
},
[OperationType.Patch] = new OpenApiOperation
{
RequestBody = new OpenApiRequestBody {
Content = {
["application/json"] = new OpenApiMediaType {
Schema = myObjectSchema
}
}
},
Responses = new OpenApiResponses
{
["204"] = new OpenApiResponse()
}
},
[OperationType.Delete] = new OpenApiOperation
{
Responses = new OpenApiResponses
{
["204"] = new OpenApiResponse()
}
}
}
}
},
Components = new()
{
Schemas = new Dictionary<string, OpenApiSchema> {
{
"myobject", myObjectSchema
}
}
}
};
var mockLogger = new Mock<ILogger<KiotaBuilder>>();
var builder = new KiotaBuilder(mockLogger.Object, new GenerationConfiguration
{
ClientClassName = "TestClient",
ClientNamespaceName = "TestSdk",
ApiRootUrl = "https://localhost",
IncludePatterns = new() {
"directory/administrativeUnits",
"directory/administrativeUnits/**"
},
ExcludePatterns = new()
{
"directory/administrativeUnits/{id}#DELETE"
}
}, _httpClient);
builder.FilterPathsByPatterns(document);
var node = builder.CreateUriSpace(document);
var codeModel = builder.CreateSourceModel(node);
Assert.Null(codeModel.FindNamespaceByName("TestSdk.groups"));
var administrativeUnitsNS = codeModel.FindNamespaceByName("TestSdk.directory.administrativeUnits");
Assert.NotNull(administrativeUnitsNS);
var administrativeUnitsRS = administrativeUnitsNS.FindChildByName<CodeClass>("AdministrativeUnitsRequestBuilder");
Assert.NotNull(administrativeUnitsRS);
Assert.Single(administrativeUnitsRS.Methods.Where(static x => x.IsOfKind(CodeMethodKind.RequestExecutor) && x.HttpMethod == Builder.CodeDOM.HttpMethod.Post));
Assert.Single(administrativeUnitsRS.Methods.Where(static x => x.IsOfKind(CodeMethodKind.RequestExecutor) && x.HttpMethod == Builder.CodeDOM.HttpMethod.Get));
Assert.Empty(administrativeUnitsRS.Methods.Where(static x => x.IsOfKind(CodeMethodKind.RequestExecutor) && x.HttpMethod == Builder.CodeDOM.HttpMethod.Put));
var administrativeUnitsItemsNS = codeModel.FindNamespaceByName("TestSdk.directory.administrativeUnits.item");
Assert.NotNull(administrativeUnitsItemsNS);
var administrativeUnitItemsRS = administrativeUnitsItemsNS.FindChildByName<CodeClass>("AdministrativeUnitsItemRequestBuilder");
Assert.NotNull(administrativeUnitItemsRS);
Assert.Single(administrativeUnitItemsRS.Methods.Where(static x => x.IsOfKind(CodeMethodKind.RequestExecutor) && x.HttpMethod == Builder.CodeDOM.HttpMethod.Get));
Assert.Single(administrativeUnitItemsRS.Methods.Where(static x => x.IsOfKind(CodeMethodKind.RequestExecutor) && x.HttpMethod == Builder.CodeDOM.HttpMethod.Patch));
Assert.Empty(administrativeUnitItemsRS.Methods.Where(static x => x.IsOfKind(CodeMethodKind.RequestExecutor) && x.HttpMethod == Builder.CodeDOM.HttpMethod.Delete));
}
}
2 changes: 1 addition & 1 deletion vscode/microsoft-kiota/l10n/bundle.l10n.ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"Yes": "نعم",
"No": "لا",
"not found": "لم يتم العثور على شيء",
"error updating the clients {error}": "خطأ في تحديث العملاء {خطأ}",
"error updating the clients {error}": "خطأ في تحديث العملاء {error}",
"updating client with path {path}": "تحديث العميل {path}",
"Kiota Dependencies Information": "معلومات حول تبعيات Kiota",
"Installation commands": "أوامر التثبيت",
Expand Down
42 changes: 42 additions & 0 deletions vscode/microsoft-kiota/l10n/bundle.l10n.cs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"Client will be upgraded from version {0} to {1}, upgrade your dependencies": "Klient bude aktualizován z verze {0} na {1}, aktualizujte své závislosti",
"No description found, select a description first": "Popis nebyl nalezen, nejprve vyberte popis",
"No endpoints selected, select endpoints first": "Zakončení nebylo vybráno, nejprve vyberte zakončení",
"No workspace folder found, open a folder first": "Nebyla nalezena žádná složka pracovního prostoru, nejprve otevřete složku",
"Yes": "Ano",
"No": "Ne",
"not found": "nenalezeno",
"error updating the clients {error}": "chyba při aktualizaci klientů {error}",
"updating client with path {path}": "aktualizace klienta s cestou {path}",
"Kiota Dependencies Information": "Informace o závislostech Kiota",
"Installation commands": "Instalační příkazy",
"Dependencies": "Závislosti",
"No language selected, select a language first": "Žádný jazyk nebyl vybrán, nejprve vyberte jazyk",
"Open an API description": "Otevřít popis API",
"A path or url to an OpenAPI description": "Cesta nebo URL adresa k popisu OpenAPI",
"Search for an API description": "Hledat popis API",
"Enter a search query": "Zadejte hledací dotaz",
"Pick a search result": "Vyberte výsledek hledání",
"Generate an API client": "Vytvořit klienta API",
"Choose a name for the client class": "Vyberte název třídy klienta",
"Choose a name for the client class namespace": "Vyberte název prostoru názvů třídy klienta",
"Enter an output path relative to the root of the project": "Zadejte výstupní cestu relativně k základní složce projektu",
"Pick a language": "Vyberte jazyk",
"Downloading kiota requires an internet connection. Please check your connection and try again.": "Stažení Kiota vyžaduje připojení k internetu. Zkontrolujte své připojení a zkuste to znovu.",
"Kiota download failed. Try closing all Visual Studio Code windows and open only one. Check the extension host logs for more information.": "Stažení Kiota se nezdařilo. Zkuste zavřít všechna okna Visual Studio Code a otevřít pouze jedno. Pro více informací zkontrolujte protokoly hostitele rozšíření.",
"Downloading kiota...": "Stahování Kiota...",
"Generating client...": "Generování klienta...",
"Updating clients...": "Aktualizace klientů...",
"Loading...": "Načítání...",
"Pick a lock file": "Vybrat soubor zámku",
"Open a lock file": "Otevřít soubor zámku",
"Filter the API description": "Filtrovat popis API",
"Enter a filter": "Zadejte filtr",
"Searching...": "Hledání...",
"A path or URL to an API manifest": "Cesta nebo URL adresa k manifestu API",
"Open an API manifest": "Otevřít manifest API",
"Invalid URL, please check the documentation for the supported URLs": "Neplatná URL adresa, zkontrolujte dokumentaci pro podporované URL adresy",
"No content found in the clipboard": "V schránce nebyl nalezen žádný obsah",
"Invalid content found in the clipboard": "V schránce byl nalezen neplatný obsah",
"Select an API manifest key": "Vyberte klíč manifestu API"
}
Loading

0 comments on commit 0b460d4

Please sign in to comment.