Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 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

### Changed

- TypeScript: import response enum objects for request builders reached through path parameters. [#6884](https://github.com/microsoft/kiota/issues/6884)
- Dart: escape enum options named value or values to avoid conflicts with generated and built-in enum members. [#7807](https://github.com/microsoft/kiota/issues/7807)
- C#: escape Unicode line and paragraph separators in generated string literals so generated clients remain valid C# source.
- External reference allowlist wildcards no longer cross the URI authority boundary, so a wildcard in the scheme or host cannot match text in the path, the user information or the port.
Expand Down
2 changes: 1 addition & 1 deletion src/Kiota.Builder/Refiners/TypeScriptRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1419,7 +1419,7 @@ protected static void AddEnumObject(CodeElement currentElement)
}
protected static void AddEnumObjectUsings(CodeElement currentElement)
{
if (currentElement is CodeProperty codeProperty && codeProperty.Kind is CodePropertyKind.RequestBuilder && codeProperty.Type is CodeType codeType && codeType.TypeDefinition is CodeClass codeClass)
if (currentElement is CodeClass codeClass && codeClass.Kind is CodeClassKind.RequestBuilder)
{
foreach (var propertyMethod in codeClass.Methods)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Threading.Tasks;
using Kiota.Builder.CodeDOM;
using Kiota.Builder.Configuration;
using Kiota.Builder.Refiners;
using Microsoft.Extensions.Logging.Abstractions;
using Xunit;

namespace Kiota.Builder.Tests;

public sealed partial class KiotaBuilderTests
{
[Theory]
[InlineData("/groups", "GroupsRequestBuilder")]
[InlineData("/groups/{group}", "WithGroupItemRequestBuilder")]
public async Task ImportsEnumResponseObjectAsync(string path, string builderName)
{
var description = """
{"openapi":"3.0.3","info":{"title":"Enum response","version":"1.0"},
"paths":{"PATH":{"get":{"responses":{"200":{"description":"Success","content":{
"application/json":{"schema":{"$ref":"#/components/schemas/Status"}}}}}}}},
"components":{"schemas":{"Status":{"type":"string","enum":["active","inactive"]}}}}
""".Replace("PATH", path);
await using var stream = await GetDocumentStreamAsync(description);
var configuration = new GenerationConfiguration { Language = GenerationLanguage.TypeScript };
var builder = new KiotaBuilder(NullLogger<KiotaBuilder>.Instance, configuration, _httpClient);
var document = await builder.CreateOpenApiDocumentAsync(stream, cancellationToken: TestContext.Current.CancellationToken);
var model = builder.CreateSourceModel(builder.CreateUriSpace(document));
await ILanguageRefiner.RefineAsync(configuration, model, TestContext.Current.CancellationToken);
var requestBuilder = model.FindChildByName<CodeInterface>(builderName);
Assert.NotNull(requestBuilder);
var responseEnum = model.FindChildByName<CodeEnum>("Status");
Assert.NotNull(responseEnum);
Assert.NotNull(responseEnum.CodeEnumObject);
Assert.Contains(requestBuilder.Usings, x => x.Declaration?.TypeDefinition == responseEnum.CodeEnumObject && !x.IsErasable);
}
}
Loading