Skip to content
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

Feature: http language support #5778

Merged
merged 90 commits into from
Jan 22, 2025
Merged
Changes from 1 commit
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
8dd143d
initial http genertion support
koros Oct 9, 2024
c7e352a
add http language generation
koros Oct 22, 2024
c2c7443
remove unused code elements from the DOM
koros Nov 13, 2024
3a25dab
merge if statements
koros Nov 14, 2024
9bcac7d
Merge branch 'main' into feature/http-language-support
koros Nov 14, 2024
5154280
remove unused code in the refiner
koros Nov 14, 2024
80d771c
Merge branch 'main' into feature/http-language-support
koros Nov 14, 2024
bac834f
write all properties including ones in the base class
koros Nov 14, 2024
31c3c53
Remove unused code and enhance JSON request body output
koros Nov 15, 2024
0ec5815
decode the parameter names before writing to http snippet files
koros Nov 18, 2024
f033a45
Merge branch 'main' into feature/http-language-support
koros Nov 18, 2024
f2f1c8e
write all the path parameter variables
koros Nov 18, 2024
ec4aea7
Exclude the generic pathParameters variable from being written to the…
koros Nov 18, 2024
da3bf05
add comments and documentation info. to Writers/HTTP/CodeClassDeclara…
koros Nov 18, 2024
69ba9ac
Merge branch 'main' into feature/http-language-support
koros Nov 19, 2024
3852185
Use URL Template to write actual urls
koros Nov 19, 2024
7508ebd
use double curly braces for all variables
koros Nov 21, 2024
0c7e0ee
Merge branch 'main' into feature/http-language-support
koros Nov 21, 2024
41345d5
add unit tests for HttpPathSegmenter
koros Nov 21, 2024
cfabf37
unit tests for CodeEnum writer
koros Nov 21, 2024
cfbbefe
format code
koros Nov 22, 2024
ff4caed
Merge branch 'main' into feature/http-language-support
koros Nov 22, 2024
d9f7584
remove more unnecessary code from the HttpConventionService
koros Nov 25, 2024
69bac1f
rename http namespace to use proper casing
koros Nov 25, 2024
fc39c89
remove unused method
koros Nov 25, 2024
6900e7e
Merge branch 'main' into feature/http-language-support
koros Nov 25, 2024
2ade0bd
Update HTTP Reserved Names Provider with Additional Reserved Keywords
koros Nov 26, 2024
0343d2a
Merge branch 'main' into feature/http-language-support
koros Nov 26, 2024
0fa1c0d
remove reserved names provider; add more unit tests
koros Nov 27, 2024
106cbae
format code
koros Nov 27, 2024
4f2bda2
Merge branch 'main' into feature/http-language-support
koros Nov 27, 2024
41dbd77
reset .vscode/launch.json
koros Nov 27, 2024
7d30713
add more unit tests
koros Nov 27, 2024
4ccc263
address pr comments
koros Dec 3, 2024
d9da636
address pr comments
koros Dec 3, 2024
ef519d1
address pr comments
koros Dec 3, 2024
51c6e25
format code
koros Dec 4, 2024
cfb3024
Merge branch 'main' into feature/http-language-support
koros Dec 4, 2024
fdfabb7
restore formating for nested json objects
koros Dec 4, 2024
407f61a
address pr comments
koros Dec 5, 2024
54c3d8f
Merge branch 'main' into feature/http-language-support
Onokaev Dec 9, 2024
c2d0635
Merge branch 'main' into feature/http-language-support
andrueastman Jan 9, 2025
7b9b16d
Remove no-op writers
Onokaev Jan 13, 2025
5738cb9
Merge branch 'feature/http-language-support' of https://github.com/mi…
Onokaev Jan 13, 2025
c505b92
Move path parameter addition to refiner
Onokaev Jan 13, 2025
6ff322a
Add launch config for Http
Onokaev Jan 14, 2025
5d42a53
Merge branch 'main' into feature/http-language-support
Onokaev Jan 14, 2025
78b2c1d
Update launch config
Jan 14, 2025
2daae83
Update refiner
Jan 14, 2025
a99c4a8
Fix circular reference
Jan 14, 2025
a96a7e8
Settings file scafolding
Jan 15, 2025
958c5c3
Add security schemes to code DOM
Jan 16, 2025
2d54897
Fix enum comparison
Onokaev Jan 16, 2025
3155aa5
Trim settings management service
Onokaev Jan 16, 2025
b531fc7
Update settings file or write a new one
Onokaev Jan 16, 2025
b97613a
Rename symbol
Onokaev Jan 16, 2025
2103872
Fix formatting
Onokaev Jan 16, 2025
37d2e6e
Add test
Onokaev Jan 16, 2025
f316a5c
Update write path
Onokaev Jan 16, 2025
e6a542c
Move Authentication enum to constants
Onokaev Jan 16, 2025
926759e
Add JsonProperty names for setting file vars
Onokaev Jan 16, 2025
5b8c189
Update tests to remove assertions for baseUrl in code files
Jan 17, 2025
7693fcf
Refactor GetDirectoryContainingSettingsFile
Jan 17, 2025
5c6db56
Merge branch 'main' into feature/http-language-support
Onokaev Jan 17, 2025
58a31e2
Update test
Jan 17, 2025
8713ba8
Merge branch 'feature/http-language-support' of https://github.com/mi…
Jan 17, 2025
e89c51f
Use Path.Combine to add to path
Jan 17, 2025
33d06ae
Refactor default values for security values
Jan 17, 2025
2441aee
Merge branch 'main' into feature/http-language-support
Onokaev Jan 17, 2025
05d9097
Add settings file generation to generation steps
Jan 20, 2025
0651a90
Merge branch 'feature/http-language-support' of https://github.com/mi…
Jan 20, 2025
0f84d3b
Refactor VsCodeSettings manager
Onokaev Jan 20, 2025
2380019
Fix formatting
Onokaev Jan 20, 2025
4a8b5b5
Use generic writer for no-op writing operations
Onokaev Jan 20, 2025
b7c87d1
Refactor generic writers
Onokaev Jan 20, 2025
97965ef
Merge branch 'main' into feature/http-language-support
Onokaev Jan 20, 2025
d8a0ff6
Refactor constants
Onokaev Jan 20, 2025
e15ae0b
Merge branch 'main' into feature/http-language-support
Onokaev Jan 20, 2025
673e08c
Merge branch 'feature/http-language-support' of https://github.com/mi…
Onokaev Jan 20, 2025
759a7ad
- Refactor constsnts
Jan 20, 2025
d446cb9
Pass ISettingsManagementService as a constructor param
Jan 20, 2025
55ae3c8
Fix formatting
Jan 20, 2025
f453306
Use arrays to improve memory efficiency
Jan 21, 2025
0e2dae7
chore: applies trivial suggestions
baywet Jan 21, 2025
e110e82
Merge branch 'main' into feature/http-language-support
baywet Jan 21, 2025
fcd5cfc
fix: reduces complexity of query parameters properties listing
baywet Jan 21, 2025
a6edc30
chore: refactor custom parameters handling in HttpRefiner
baywet Jan 21, 2025
326ad1a
chore: formatting
baywet Jan 21, 2025
b3646b4
Remove unused method
Onokaev Jan 22, 2025
0b40ad4
Update src/Kiota.Builder/Writers/HTTP/CodeClassDeclarationWriter.cs
Onokaev Jan 22, 2025
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
Prev Previous commit
Next Next commit
Use arrays to improve memory efficiency
Evans Aboge (from Dev Box) committed Jan 21, 2025
commit f453306b50c26e3d7ea4398352274edb3e626814
84 changes: 50 additions & 34 deletions src/Kiota.Builder/Writers/HTTP/CodeClassDeclarationWriter.cs
Original file line number Diff line number Diff line change
@@ -62,27 +62,34 @@ protected override void WriteTypeDeclaration(ClassDeclaration codeElement, Langu
/// Retrieves all the query parameters for the given request builder class.
/// </summary>
/// <param name="requestBuilderClass">The request builder class containing the query parameters.</param>
/// <returns>A list of all query parameters.</returns>
private static List<CodeProperty> GetAllQueryParameters(CodeClass requestBuilderClass)
/// <returns>An array of all query parameters.</returns>
private static CodeProperty[] GetAllQueryParameters(CodeClass requestBuilderClass)
{
var queryParameters = new List<CodeProperty>();

// Retrieve all the query parameter classes
var queryParameterClasses = requestBuilderClass
.GetChildElements(true)
.OfType<CodeClass>()
.Where(static element => element.IsOfKind(CodeClassKind.QueryParameters))
.ToList();
.ToArray();

// Collect all query parameter properties into the aggregated list
queryParameterClasses.ForEach(paramCodeClass =>
{
var queryParams = paramCodeClass
.Properties
.SelectMany(static property => property.IsOfKind(CodePropertyKind.QueryParameter) ? [property] : Array.Empty<CodeProperty>());
// Calculate the total number of query parameters
int totalQueryParameters = queryParameterClasses
.Sum(paramCodeClass => paramCodeClass.Properties
.Count(static property => property.IsOfKind(CodePropertyKind.QueryParameter)));

// Create an array to hold all query parameters
var queryParameters = new CodeProperty[totalQueryParameters];
int index = 0;

queryParameters.AddRange(queryParams);
});
// Populate the array with query parameters
foreach (var paramCodeClass in queryParameterClasses)
{
foreach (var property in paramCodeClass.Properties
.Where(static property => property.IsOfKind(CodePropertyKind.QueryParameter)))
{
queryParameters[index++] = property;
}
}

return queryParameters;
}
@@ -91,15 +98,15 @@ private static List<CodeProperty> GetAllQueryParameters(CodeClass requestBuilder
/// Retrieves all the path parameters for the given request builder class.
/// </summary>
/// <param name="requestBuilderClass">The request builder class containing the path parameters.</param>
/// <returns>A list of all path parameters, or an empty list if none are found.</returns>
private static List<CodeProperty> GetPathParameters(CodeClass requestBuilderClass)
/// <returns>An array of all path parameters, or an empty array if none are found.</returns>
private static CodeProperty[] GetPathParameters(CodeClass requestBuilderClass)
{
// Retrieve all the path variables except the generic path parameter named "pathParameters"
var pathParameters = requestBuilderClass
.GetChildElements(true)
.OfType<CodeProperty>()
.Where(property => property.IsOfKind(CodePropertyKind.PathParameters) && !property.Name.Equals(Constants.PathParameters, StringComparison.OrdinalIgnoreCase))
.ToList();
.ToArray();

return pathParameters;
}
@@ -150,23 +157,33 @@ private static void WriteUrlTemplate(CodeProperty urlTemplateProperty, LanguageW
/// <summary>
/// Writes the path parameters for the given request builder class to the writer.
/// </summary>
/// <param name="pathParameters">The list of path parameters to write.</param>
/// <param name="pathParameters">The array of path parameters to write.</param>
/// <param name="writer">The language writer to write the path parameters to.</param>
private static void WritePathParameters(List<CodeProperty> pathParameters, LanguageWriter writer)
private static void WritePathParameters(CodeProperty[] pathParameters, LanguageWriter writer)
{
if (pathParameters is null) return;

// Write each path parameter property
pathParameters?.ForEach(prop => WriteHttpParameterProperty(prop, writer));
foreach (var pathParameter in pathParameters)
{
WriteHttpParameterProperty(pathParameter, writer);
}
}

/// <summary>
/// Writes the query parameters for the given request builder class to the writer.
/// </summary>
/// <param name="queryParameters">The list of query parameters to write.</param>
/// <param name="queryParameters">The array of query parameters to write.</param>
/// <param name="writer">The language writer to write the query parameters to.</param>
private static void WriteQueryParameters(List<CodeProperty> queryParameters, LanguageWriter writer)
private static void WriteQueryParameters(CodeProperty[] queryParameters, LanguageWriter writer)
{
if (queryParameters is null) return;

// Write each query parameter property
queryParameters.ForEach(prop => WriteHttpParameterProperty(prop, writer));
foreach (var queryParameter in queryParameters)
{
WriteHttpParameterProperty(queryParameter, writer);
}
}

/// <summary>
@@ -194,22 +211,22 @@ private static void WriteHttpParameterProperty(CodeProperty property, LanguageWr
/// </summary>
/// <param name="requestBuilderClass">The request builder class containing the HTTP methods.</param>
/// <param name="writer">The language writer to write the HTTP methods to.</param>
/// <param name="queryParameters">The list of query parameters.</param>
/// <param name="pathParameters">The list of path parameters.</param>
/// <param name="queryParameters">The array of query parameters.</param>
/// <param name="pathParameters">The array of path parameters.</param>
/// <param name="urlTemplateProperty">The URL template property containing the URL template.</param>
/// <param name="baseUrl">The base URL.</param>
private static void WriteHttpMethods(
CodeClass requestBuilderClass,
LanguageWriter writer,
List<CodeProperty> queryParameters,
List<CodeProperty> pathParameters,
CodeProperty[] queryParameters,
CodeProperty[] pathParameters,
CodeProperty urlTemplateProperty,
string? baseUrl)
{
// Retrieve all the HTTP methods of kind RequestExecutor
var httpMethods = GetHttpMethods(requestBuilderClass);

var methodCount = httpMethods.Count;
var methodCount = httpMethods.Length;
var currentIndex = 0;

foreach (var method in httpMethods)
@@ -232,7 +249,7 @@ private static void WriteHttpMethods(
.Properties
.FirstOrDefault(static prop => prop.IsOfKind(CodePropertyKind.Headers));

if (authenticationMethod != null
if (authenticationMethod != null
&& Enum.TryParse(typeof(SecuritySchemeType), authenticationMethod.Type.Name, true, out var schemeTypeObj)
&& schemeTypeObj is SecuritySchemeType schemeType
&& Constants.SchemeTypeMapping.TryGetValue(schemeType.ToString().ToLowerInvariant(), out var mappedSchemeType))
@@ -257,14 +274,13 @@ private static void WriteHttpMethods(
/// Retrieves all the HTTP methods of kind RequestExecutor for the given request builder class.
/// </summary>
/// <param name="requestBuilderClass">The request builder class containing the HTTP methods.</param>
/// <returns>A list of HTTP methods of kind RequestExecutor.</returns>
private static List<CodeMethod> GetHttpMethods(CodeClass requestBuilderClass)
/// <returns>An array of HTTP methods of kind RequestExecutor.</returns>
private static CodeMethod[] GetHttpMethods(CodeClass requestBuilderClass)
{
return requestBuilderClass
return [.. requestBuilderClass
.GetChildElements(true)
.OfType<CodeMethod>()
.Where(static element => element.IsOfKind(CodeMethodKind.RequestExecutor))
.ToList();
.Where(static element => element.IsOfKind(CodeMethodKind.RequestExecutor))];
}

/// <summary>
@@ -349,7 +365,7 @@ private static void WriteProperties(CodeClass requestBodyClass, LanguageWriter w
}
}

private static string BuildUrlStringFromTemplate(string urlTemplateString, List<CodeProperty> queryParameters, List<CodeProperty> pathParameters, string? baseUrl)
private static string BuildUrlStringFromTemplate(string urlTemplateString, CodeProperty[] queryParameters, CodeProperty[] pathParameters, string? baseUrl)
{
// Use the provided baseUrl or default to "http://localhost/"
baseUrl ??= Constants.LocalHostUrl;