Skip to content

Commit

Permalink
- fixes an issue where inline response types would collide
Browse files Browse the repository at this point in the history
  • Loading branch information
baywet committed Jul 18, 2023
1 parent faad10d commit 9b8025f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/Kiota.Builder/KiotaBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1101,11 +1101,11 @@ codeType.TypeDefinition is CodeClass codeClass &&
}
}
}
private CodeTypeBase? GetExecutorMethodReturnType(OpenApiUrlTreeNode currentNode, OpenApiSchema? schema, OpenApiOperation operation, CodeClass parentClass)
private CodeTypeBase? GetExecutorMethodReturnType(OpenApiUrlTreeNode currentNode, OpenApiSchema? schema, OpenApiOperation operation, CodeClass parentClass, OperationType operationType)
{
if (schema != null)
{
return CreateModelDeclarations(currentNode, schema, operation, parentClass, "Response");
return CreateModelDeclarations(currentNode, schema, operation, parentClass, $"{operationType}Response");
}
else
{
Expand Down Expand Up @@ -1152,7 +1152,7 @@ private void CreateOperationMethods(OpenApiUrlTreeNode currentNode, OperationTyp
operation.Summary)
.CleanupDescription(),
},
ReturnType = GetExecutorMethodReturnType(currentNode, schema, operation, parentClass) ?? throw new InvalidSchemaException(),
ReturnType = GetExecutorMethodReturnType(currentNode, schema, operation, parentClass, operationType) ?? throw new InvalidSchemaException(),
Deprecation = deprecationInformation,
};

Expand Down
18 changes: 9 additions & 9 deletions tests/Kiota.Builder.Tests/KiotaBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ public void Object_Arrays_are_supported()
var codeModel = builder.CreateSourceModel(node);
var userClass = codeModel.FindNamespaceByName("ApiSdk.models").FindChildByName<CodeClass>("user");
Assert.NotNull(userClass);
var userResponseClass = codeModel.FindNamespaceByName("ApiSdk.users.item").FindChildByName<CodeClass>("UsersResponse", false);
var userResponseClass = codeModel.FindNamespaceByName("ApiSdk.users.item").FindChildByName<CodeClass>("UsersGetResponse", false);
Assert.NotNull(userResponseClass);
var valueProp = userResponseClass.FindChildByName<CodeProperty>("value", false);
Assert.NotNull(valueProp);
Expand Down Expand Up @@ -1433,9 +1433,9 @@ public void Inline_Property_Inheritance_Is_Supported()
var codeModel = builder.CreateSourceModel(node);
var resourceClass = codeModel.FindNamespaceByName("ApiSdk.models").FindChildByName<CodeClass>("resource");
var itemsNS = codeModel.FindNamespaceByName("ApiSdk.resource.item");
var responseClass = itemsNS.FindChildByName<CodeClass>("ResourceResponse");
var derivedResourceClass = itemsNS.FindChildByName<CodeClass>("ResourceResponse_derivedResource");
var derivedResourceInfoClass = itemsNS.FindChildByName<CodeClass>("ResourceResponse_derivedResource_info");
var responseClass = itemsNS.FindChildByName<CodeClass>("ResourceGetResponse");
var derivedResourceClass = itemsNS.FindChildByName<CodeClass>("ResourceGetResponse_derivedResource");
var derivedResourceInfoClass = itemsNS.FindChildByName<CodeClass>("ResourceGetResponse_derivedResource_info");


Assert.NotNull(resourceClass);
Expand Down Expand Up @@ -3128,7 +3128,7 @@ public void UnionOfInlineSchemasWorks()
Assert.Equal(2, executorReturnType.Types.Count());
var typeNames = executorReturnType.Types.Select(x => x.Name).ToHashSet(StringComparer.OrdinalIgnoreCase);
Assert.Contains("simpleObject", typeNames);
Assert.Contains("unionTypeResponseMember1", typeNames);
Assert.Contains("unionTypeGetResponseMember1", typeNames);
}
[Fact]
public void IntersectionOfPrimitiveTypesWorks()
Expand Down Expand Up @@ -3287,7 +3287,7 @@ public void IntersectionOfInlineSchemasWorks()
Assert.Equal(2, executorReturnType.Types.Count());
var typeNames = executorReturnType.Types.Select(x => x.Name).ToHashSet(StringComparer.OrdinalIgnoreCase);
Assert.Contains("simpleObject", typeNames);
Assert.Contains("unionTypeResponseMember1", typeNames);
Assert.Contains("unionTypeGetResponseMember1", typeNames);
}
[Fact]
public void InheritedTypeWithInlineSchemaWorks()
Expand Down Expand Up @@ -5822,7 +5822,7 @@ await File.WriteAllTextAsync(tempFilePath, @$"openapi: 3.0.1
var codeModel = builder.CreateSourceModel(node);
var rootNS = codeModel.FindNamespaceByName("ApiSdk");
Assert.NotNull(rootNS);
var inlineType = rootNS.FindChildByName<CodeClass>($"enumerationResponse_{expected}", true);
var inlineType = rootNS.FindChildByName<CodeClass>($"enumerationGetResponse_{expected}", true);
Assert.NotNull(inlineType);
}
[Fact]
Expand Down Expand Up @@ -5970,7 +5970,7 @@ public async Task MergesIntersectionTypes()
var document = await builder.CreateOpenApiDocumentAsync(fs);
var node = builder.CreateUriSpace(document);
var codeModel = builder.CreateSourceModel(node);
var resultClass = codeModel.FindChildByName<CodeClass>("DirectoryObjectResponse");
var resultClass = codeModel.FindChildByName<CodeClass>("DirectoryObjectGetResponse");
Assert.NotNull(resultClass);
Assert.Equal(4, resultClass.Properties.Where(static x => x.IsOfKind(CodePropertyKind.Custom)).Count());
}
Expand Down Expand Up @@ -6010,7 +6010,7 @@ public async Task SkipsInvalidItemsProperties()
var document = await builder.CreateOpenApiDocumentAsync(fs);
var node = builder.CreateUriSpace(document);
var codeModel = builder.CreateSourceModel(node);
var resultClass = codeModel.FindChildByName<CodeClass>("DirectoryObjectResponse");
var resultClass = codeModel.FindChildByName<CodeClass>("DirectoryObjectGetResponse");
Assert.NotNull(resultClass);
var keysToCheck = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "datasets", "datakeys", "datainfo" };
Assert.Empty(resultClass.Properties.Where(x => x.IsOfKind(CodePropertyKind.Custom) && keysToCheck.Contains(x.Name)));
Expand Down

0 comments on commit 9b8025f

Please sign in to comment.