Skip to content

Fix namespace imports in controller source generator #1261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 11, 2023
Merged
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
6 changes: 3 additions & 3 deletions src/JsonApiDotNetCore.SourceGenerators/SourceCodeWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public string Write(INamedTypeSymbol resourceType, ITypeSymbol idType, JsonApiEn
WriteNullableEnable();
}

WriteNamespaceImports(loggerFactoryInterface, resourceType);
WriteNamespaceImports(loggerFactoryInterface, resourceType, controllerNamespace);

if (controllerNamespace != null)
{
Expand Down Expand Up @@ -96,15 +96,15 @@ private void WriteNullableEnable()
_sourceBuilder.AppendLine();
}

private void WriteNamespaceImports(INamedTypeSymbol loggerFactoryInterface, INamedTypeSymbol resourceType)
private void WriteNamespaceImports(INamedTypeSymbol loggerFactoryInterface, INamedTypeSymbol resourceType, string? controllerNamespace)
{
_sourceBuilder.AppendLine($@"using {loggerFactoryInterface.ContainingNamespace};");

_sourceBuilder.AppendLine("using JsonApiDotNetCore.Configuration;");
_sourceBuilder.AppendLine("using JsonApiDotNetCore.Controllers;");
_sourceBuilder.AppendLine("using JsonApiDotNetCore.Services;");

if (!resourceType.ContainingNamespace.IsGlobalNamespace)
if (!resourceType.ContainingNamespace.IsGlobalNamespace && resourceType.ContainingNamespace.ToString() != controllerNamespace)
{
_sourceBuilder.AppendLine($"using {resourceType.ContainingNamespace};");
}
Expand Down
Loading