diff --git a/src/HttpGenerator.Core/HttpFileGenerator.cs b/src/HttpGenerator.Core/HttpFileGenerator.cs
index 56a4bba..959fab1 100644
--- a/src/HttpGenerator.Core/HttpFileGenerator.cs
+++ b/src/HttpGenerator.Core/HttpFileGenerator.cs
@@ -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}");
diff --git a/src/HttpGenerator.Core/OpenApiDocumentFactory.cs b/src/HttpGenerator.Core/OpenApiDocumentFactory.cs
index bba2ca1..49a6fc1 100644
--- a/src/HttpGenerator.Core/OpenApiDocumentFactory.cs
+++ b/src/HttpGenerator.Core/OpenApiDocumentFactory.cs
@@ -66,10 +66,12 @@ private static string DowngradeOpenApi31To30(string content)
/// The content of the HTTP request.
private static async Task 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
+ };
+ using var http = new HttpClient(httpMessageHandler, disposeHandler: true);
var content = await http.GetStringAsync(openApiPath);
return content;
}
@@ -84,15 +86,4 @@ private static bool IsHttp(string path)
return path.StartsWith("http://", StringComparison.OrdinalIgnoreCase) ||
path.StartsWith("https://", StringComparison.OrdinalIgnoreCase);
}
-
- ///
- /// Determines whether the specified path is a YAML file.
- ///
- /// The path to check.
- /// True if the path is a YAML file, otherwise false.
- private static bool IsYaml(string path)
- {
- return path.EndsWith(".yaml", StringComparison.OrdinalIgnoreCase) ||
- path.EndsWith(".yml", StringComparison.OrdinalIgnoreCase);
- }
}
\ No newline at end of file
diff --git a/src/HttpGenerator/Settings.cs b/src/HttpGenerator/Settings.cs
index 9e2c61b..0b53562 100644
--- a/src/HttpGenerator/Settings.cs
+++ b/src/HttpGenerator/Settings.cs
@@ -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 ")]
[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")]