Skip to content
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
11 changes: 8 additions & 3 deletions src/Refitter.Core/InterfaceGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,18 @@ private string GetBaseOperationName(OpenApiOperationInfo op)
.GetOperationName(document, op.Path, op.Verb, op.Operation);
}

private static string TrimImportedNamespaces(string returnTypeParameter) =>
returnTypeParameter.StartsWith("System.Collections.Generic.", StringComparison.OrdinalIgnoreCase)
? returnTypeParameter.Replace("System.Collections.Generic.", string.Empty)
: returnTypeParameter;

private string GetTypeName(OpenApiOperation operation)
{
if (settings.ResponseTypeOverride.TryGetValue(operation.OperationId, out var type))
{
return type is null or "void"
? GetAsyncOperationType(true)
: $"{GetAsyncOperationType(false)}<{WellKnownNamespaces.TrimImportedNamespaces(type)}>";
: $"{GetAsyncOperationType(false)}<{TrimImportedNamespaces(type)}>";
}

if (IsFileStreamResponse(operation))
Expand Down Expand Up @@ -328,8 +333,8 @@ private string GetConfiguredReturnType(string returnTypeParameter)
{
var asyncType = GetAsyncOperationType(false);
return settings.ReturnIApiResponse
? $"{asyncType}<IApiResponse<{WellKnownNamespaces.TrimImportedNamespaces(returnTypeParameter)}>>"
: $"{asyncType}<{WellKnownNamespaces.TrimImportedNamespaces(returnTypeParameter)}>";
? $"{asyncType}<IApiResponse<{TrimImportedNamespaces(returnTypeParameter)}>>"
: $"{asyncType}<{TrimImportedNamespaces(returnTypeParameter)}>";
}

private string GetAsyncOperationType(bool withVoidReturnType)
Expand Down
10 changes: 7 additions & 3 deletions src/Refitter.Core/ParameterShared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,16 @@ public static string FindSupportedType(string typeName)
return typeName;
}

private static string TrimImportedNamespaces(string returnTypeParameter) =>
returnTypeParameter.StartsWith("System.Collections.Generic.", StringComparison.OrdinalIgnoreCase)
? returnTypeParameter.Replace("System.Collections.Generic.", string.Empty)
: returnTypeParameter;

public static string GetParameterType(
ParameterModelBase parameterModel,
RefitGeneratorSettings settings)
{
var type = WellKnownNamespaces
.TrimImportedNamespaces(
var type = TrimImportedNamespaces(
FindSupportedType(
parameterModel.Type));

Expand Down Expand Up @@ -198,7 +202,7 @@ public static string GetQueryParameterType(
public static string GetBodyAttribute(CSharpParameterModel parameter, RefitGeneratorSettings settings)
{
var anyType = settings.CodeGeneratorSettings?.AnyType ?? "object";
var parameterType = WellKnownNamespaces.TrimImportedNamespaces(FindSupportedType(parameter.Type));
var parameterType = TrimImportedNamespaces(FindSupportedType(parameter.Type));

if (parameterType.Equals(anyType, StringComparison.OrdinalIgnoreCase) ||
parameterType.Contains("JsonElement", StringComparison.OrdinalIgnoreCase))
Expand Down
16 changes: 0 additions & 16 deletions src/Refitter.Core/WellKnownNamespaces.cs

This file was deleted.

92 changes: 0 additions & 92 deletions src/Refitter.Tests/FileWriterTests.cs

This file was deleted.

22 changes: 0 additions & 22 deletions src/Refitter/FileWriter.cs

This file was deleted.

10 changes: 8 additions & 2 deletions src/Refitter/GenerationOrchestrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ private static async Task WriteSingleFile(

reporter.ReportSingleFileOutput(fileName, directory, sizeFormatted, lines);

await FileWriter.WriteAsync(planned);
var dir = Path.GetDirectoryName(planned.Path);
if (!string.IsNullOrWhiteSpace(dir) && !Directory.Exists(dir))
Directory.CreateDirectory(dir);
await File.WriteAllTextAsync(planned.Path, planned.Content);
reporter.ReportFileWritten(planned.Path);
}

Expand Down Expand Up @@ -136,7 +139,10 @@ private static async Task WriteMultipleFiles(
totalSize += size;
totalLines += lines;

await FileWriter.WriteAsync(plannedFile);
var plannedDir = Path.GetDirectoryName(plannedFile.Path);
if (!string.IsNullOrWhiteSpace(plannedDir) && !Directory.Exists(plannedDir))
Directory.CreateDirectory(plannedDir);
await File.WriteAllTextAsync(plannedFile.Path, plannedFile.Content);
reporter.ReportFileWritten(plannedFile.Path);
}

Expand Down
Loading