Skip to content
Draft
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
37 changes: 19 additions & 18 deletions src/HttpGenerator.Core/HttpFileGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,29 +261,30 @@ private static string GenerateRequest(
code);

var url = operationPath.Key.Replace("{", "{{").Replace("}", "}}");
if (url.Contains("{") || url.Contains("}"))

// Handle path parameters - replace placeholders in the URL
foreach (var parameterName in parameterNameMap)
{
foreach (var parameterName in parameterNameMap)
{
url = url.Replace($"{{{{{parameterName.Key}}}}}", $"{{{{{parameterName.Value}}}}}");
}
url = url.Replace($"{{{{{parameterName.Key}}}}}", $"{{{{{parameterName.Value}}}}}");
}
else

// Handle query parameters - append to URL
var queryParameters = operation
.Parameters
.Where(c => c.In == ParameterLocation.Query)
.ToArray();

if (queryParameters.Length > 0)
{
if (parameterNameMap.Count > 0)
{
url += "?";
}

foreach (var parameterName in parameterNameMap)
{
url += $"{parameterName.Key}={{{{{parameterName.Value}}}}}&";
}

if (parameterNameMap.Count > 0)
url += "?";
foreach (var queryParam in queryParameters)
{
url = url.Remove(url.Length - 1);
var variableName = parameterNameMap.TryGetValue(queryParam.Name, out var mappedName)
? mappedName
: queryParam.Name;
url += $"{queryParam.Name}={{{{{variableName}}}}}&";
}
url = url.Remove(url.Length - 1); // Remove trailing &
}

code.AppendLine($"{verb.ToUpperInvariant()} {{{{baseUrl}}}}{url}");
Expand Down
21 changes: 6 additions & 15 deletions src/HttpGenerator.Core/OpenApiDocumentFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,12 @@
/// <returns>The content of the HTTP request.</returns>
private static async Task<string> GetHttpContent(string openApiPath)
{
var httpMessageHandler = new HttpClientHandler();
httpMessageHandler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
httpMessageHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true;
using var http = new HttpClient(httpMessageHandler);
var httpMessageHandler = new HttpClientHandler
{
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate,
ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true

Check failure

Code scanning / SonarCloud

Server certificates should be verified during SSL/TLS connections High

Enable server certificate validation on this SSL/TLS connection See more on SonarQube Cloud
};
using var http = new HttpClient(httpMessageHandler, disposeHandler: true);
var content = await http.GetStringAsync(openApiPath);
return content;
}
Expand All @@ -84,15 +86,4 @@
return path.StartsWith("http://", StringComparison.OrdinalIgnoreCase) ||
path.StartsWith("https://", StringComparison.OrdinalIgnoreCase);
}

/// <summary>
/// Determines whether the specified path is a YAML file.
/// </summary>
/// <param name="path">The path to check.</param>
/// <returns>True if the path is a YAML file, otherwise false.</returns>
private static bool IsYaml(string path)
{
return path.EndsWith(".yaml", StringComparison.OrdinalIgnoreCase) ||
path.EndsWith(".yml", StringComparison.OrdinalIgnoreCase);
}
}
2 changes: 1 addition & 1 deletion src/HttpGenerator/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class Settings : CommandSettings
$"{nameof(OutputType.OneFilePerTag)} generates one .http file per first tag associated with each request.")]
[CommandOption("--output-type <OUTPUT-TYPE>")]
[DefaultValue(OutputType.OneRequestPerFile)]
[AllowedValues(nameof(OutputType.OneRequestPerFile), nameof(OutputType.OneFile))]
[AllowedValues(nameof(OutputType.OneRequestPerFile), nameof(OutputType.OneFile), nameof(OutputType.OneFilePerTag))]
public OutputType OutputType { get; set; } = OutputType.OneRequestPerFile;

[Description("Azure Entra ID Scope to use for retrieving Access Token for Authorization header")]
Expand Down