Skip to content

Commit

Permalink
fixes root url parsing issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Omondi committed Sep 6, 2024
1 parent 4183ab8 commit 0ac7b3c
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Fixed a when generating a plugin when only an operation is selected in the root node in the extension. [#5300](https://github.com/microsoft/kiota/issues/5300)

## [1.18.0] - 2024-09-05

### Added
Expand Down
3 changes: 3 additions & 0 deletions src/Kiota.Builder/Plugins/PluginsGenerationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ private OpenApiDocument GetDocumentWithTrimmedComponentsAndResponses(OpenApiDocu
requestUrls[key] = path.Value.Operations.Keys.Select(static key => key.ToString().ToUpperInvariant()).ToList();
}

if (requestUrls.Count == 0)
throw new InvalidOperationException("No operations found in the OpenAPI document.");

var predicate = OpenApiFilterService.CreatePredicate(requestUrls: requestUrls, source: doc);
return OpenApiFilterService.CreateFilteredDocument(doc, predicate);
}
Expand Down
67 changes: 67 additions & 0 deletions tests/Kiota.Builder.Tests/KiotaBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5994,6 +5994,73 @@ public void SetsReadonlyProperties(bool isReadonly)
var nameProperty = objectClass.Properties.First(static x => "name".Equals(x.Name, StringComparison.OrdinalIgnoreCase));
Assert.Equal(isReadonly, nameProperty.ReadOnly);
}
[Theory]
[InlineData("#GET", 0)]
[InlineData("/#GET", 1)]
public void SupportsIncludeFilterOnRootPath(string inputPattern, int expectedPathsCount)
{
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
{
["/"] = new OpenApiPathItem
{
Operations = {
[OperationType.Get] = new OpenApiOperation
{
Responses = new OpenApiResponses
{
["200"] = new OpenApiResponse {
Content = {
["application/json"] = new OpenApiMediaType {
Schema = myObjectSchema
}
}
},
}
}
}
},
},
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() {
inputPattern
}
}, _httpClient);
builder.FilterPathsByPatterns(document);
Assert.Equal(expectedPathsCount, document.Paths.Count);
}
[Fact]
public void SupportsIncludeFilter()
{
Expand Down
6 changes: 5 additions & 1 deletion vscode/microsoft-kiota/src/openApiTreeProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,11 @@ export class OpenApiTreeProvider implements vscode.TreeDataProvider<OpenApiTreeN
if ((currentNode.isOperation || false) && this.rawRootNode) {
const parent = this.findApiNode(getPathSegments(trimOperation(currentNode.path)), this.rawRootNode);
if (parent && !parent.selected) {
result.push(currentNode.path.replace(/\\/g, pathSeparator));
let operationPath = currentNode.path.replace(/\\/g, pathSeparator);
if(operationPath.startsWith('#')) {//its a operation at the root it needs a leading slash
operationPath = `${pathSeparator}${operationPath}`

Check warning on line 272 in vscode/microsoft-kiota/src/openApiTreeProvider.ts

View workflow job for this annotation

GitHub Actions / build_extension

Missing semicolon
}
result.push(operationPath);
}
} else {
result.push(currentNode.path.replace(/\\/g, pathSeparator));
Expand Down

0 comments on commit 0ac7b3c

Please sign in to comment.