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/code reduction generators #804

Merged
merged 6 commits into from
Nov 10, 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [0.9.0] - 2023-11-10

### Added

- Added helper methods to request information to reduce the amount of generated code. [Kiota #3651](https://github.com/microsoft/kiota/issues/3651)

### Changed

- Kiota-Java has moved away from Async/Completable futures, thus Async components are no longer utilized and have been removed. Furthermore, requestAdapter methods no longer use the async suffix. [#175](https://github.com/microsoft/kiota-java/issues/175)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,46 @@ public class RequestInformation {
/** Creates a new instance of the request information class. */
public RequestInformation() { //Default constructor
}
/**
* Creates a new instance of the request information class.
* @param method The HTTP method for the request.
* @param urlTemplate The url template for the request.
* @param pathParameters The path parameters for the request.
*/
public RequestInformation(@Nonnull final HttpMethod method, @Nonnull final String urlTemplate, @Nonnull final Map<String, Object> pathParameters) {
this.httpMethod = Objects.requireNonNull(method);
this.urlTemplate = Objects.requireNonNull(urlTemplate);
this.pathParameters = Objects.requireNonNull(pathParameters);
}
/**
* Configures the request information based on the request configuration and the query parameters getter.
* @param <T> The type of the request configuration.
* @param requestConfiguration The request configuration to apply to the request information.
* @param configurationFactory The factory to create the request configuration from.
*/
public <T extends BaseRequestConfiguration> void configure(@Nullable final java.util.function.Consumer<T> requestConfiguration, @Nonnull final java.util.function.Supplier<T> configurationFactory) {
configure(requestConfiguration, configurationFactory, null);
}
/**
* Configures the request information based on the request configuration and the query parameters getter.
* @param <T> The type of the request configuration.
* @param requestConfiguration The request configuration to apply to the request information.
* @param configurationFactory The factory to create the request configuration from.
* @param queryParametersGetter The function to get the query parameters from the request configuration.
*/
public <T extends BaseRequestConfiguration> void configure(@Nullable final java.util.function.Consumer<T> requestConfiguration, @Nonnull final java.util.function.Supplier<T> configurationFactory, @Nullable final java.util.function.Function<T, Object> queryParametersGetter) {
baywet marked this conversation as resolved.
Show resolved Hide resolved
Objects.requireNonNull(configurationFactory);
if (requestConfiguration == null) {
return;
}
final T requestConfig = configurationFactory.get();
requestConfiguration.accept(requestConfig);
if (queryParametersGetter != null) {
addQueryParameters(queryParametersGetter.apply(requestConfig));
}
headers.putAll(requestConfig.headers);
addRequestOptions(requestConfig.options);
}
/** The url template for the current request */
@Nullable
public String urlTemplate;
Expand Down