Skip to content

Commit

Permalink
- fixes #635 Renames middlewareoption into requestoption to stay agno…
Browse files Browse the repository at this point in the history
…stic from implementation
  • Loading branch information
baywet committed Oct 1, 2021
1 parent 3243d39 commit b4a9aac
Show file tree
Hide file tree
Showing 42 changed files with 129 additions and 127 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Renames middlewareoption into requestoption to stay agnostic from implementation #635

## [0.0.9] - 2021-10-01

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,25 @@ public void SetUriExtractsQueryParameters()


[Fact]
public void AddsAndRemovesMiddlewareOptions()
public void AddsAndRemovesRequestOptions()
{
// Arrange
var testRequest = new RequestInformation()
{
HttpMethod = HttpMethod.GET,
URI = new Uri("http://localhost")
};
var testMiddleWareOption = new Mock<IMiddlewareOption>().Object;
Assert.Empty(testRequest.MiddlewareOptions);
var testMiddleWareOption = new Mock<IRequestOption>().Object;
Assert.Empty(testRequest.RequestOptions);
// Act
testRequest.AddMiddlewareOptions(testMiddleWareOption);
testRequest.AddRequestOptions(testMiddleWareOption);
// Assert
Assert.NotEmpty(testRequest.MiddlewareOptions);
Assert.Equal(testMiddleWareOption, testRequest.MiddlewareOptions.First());
Assert.NotEmpty(testRequest.RequestOptions);
Assert.Equal(testMiddleWareOption, testRequest.RequestOptions.First());

// Act by removing the option
testRequest.RemoveMiddlewareOptions(testMiddleWareOption);
Assert.Empty(testRequest.MiddlewareOptions);
testRequest.RemoveRequestOptions(testMiddleWareOption);
Assert.Empty(testRequest.RequestOptions);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Microsoft.Kiota.Abstractions
/// <summary>
/// Represents a middleware option.
/// </summary>
public interface IMiddlewareOption
public interface IRequestOption
{
}
}
12 changes: 6 additions & 6 deletions abstractions/dotnet/src/NativeResponseWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ public class NativeResponseWrapper
/// <param name="originalCall">The original request to make</param>
/// <param name="q">The query parameters of the request</param>
/// <param name="h">The request headers of the request</param>
/// <param name="o">Request options for HTTP middlewares</param>
/// <param name="o">Request options</param>
/// <returns></returns>
public static async Task<NativeResponseType> CallAndGetNativeType<ModelType, NativeResponseType, QueryParametersType>(
Func<Action<QueryParametersType>, Action<IDictionary<string, string>>, IEnumerable<IMiddlewareOption>, IResponseHandler, Task<ModelType>> originalCall,
Func<Action<QueryParametersType>, Action<IDictionary<string, string>>, IEnumerable<IRequestOption>, IResponseHandler, Task<ModelType>> originalCall,
Action<QueryParametersType> q = default,
Action<IDictionary<string, string>> h = default,
IEnumerable<IMiddlewareOption> o = default) where NativeResponseType : class
IEnumerable<IRequestOption> o = default) where NativeResponseType : class
{
var responseHandler = new NativeResponseHandler();
await originalCall.Invoke(q, h, o, responseHandler);
Expand All @@ -41,13 +41,13 @@ public static async Task<NativeResponseType> CallAndGetNativeType<ModelType, Nat
/// <param name="requestBody">The request body of the request</param>
/// <param name="q">The query parameters of the request</param>
/// <param name="h">The request headers of the request</param>
/// <param name="o">Request options for HTTP middlewares</param>
/// <param name="o">Request options</param>
public static async Task<NativeResponseType> CallAndGetNativeType<ModelType, NativeResponseType, QueryParametersType, RequestBodyType>(
Func<RequestBodyType, Action<QueryParametersType>, Action<IDictionary<string, string>>, IEnumerable<IMiddlewareOption>, IResponseHandler, Task<ModelType>> originalCall,
Func<RequestBodyType, Action<QueryParametersType>, Action<IDictionary<string, string>>, IEnumerable<IRequestOption>, IResponseHandler, Task<ModelType>> originalCall,
RequestBodyType requestBody,
Action<QueryParametersType> q = default,
Action<IDictionary<string, string>> h = default,
IEnumerable<IMiddlewareOption> o = default) where NativeResponseType : class
IEnumerable<IRequestOption> o = default) where NativeResponseType : class
{
var responseHandler = new NativeResponseHandler();
await originalCall.Invoke(requestBody, q, h, o, responseHandler);
Expand Down
24 changes: 12 additions & 12 deletions abstractions/dotnet/src/RequestInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,31 +60,31 @@ public void SetURI(string currentPath, string pathSegment, bool isRawUrl)
/// The Request Body.
/// </summary>
public Stream Content { get; set; }
private Dictionary<string, IMiddlewareOption> _middlewareOptions = new Dictionary<string, IMiddlewareOption>(StringComparer.OrdinalIgnoreCase);
private Dictionary<string, IRequestOption> _requestOptions = new Dictionary<string, IRequestOption>(StringComparer.OrdinalIgnoreCase);
/// <summary>
/// Gets the middleware options for this request. Options are unique by type. If an option of the same type is added twice, the last one wins.
/// Gets the options for this request. Options are unique by type. If an option of the same type is added twice, the last one wins.
/// </summary>
public IEnumerable<IMiddlewareOption> MiddlewareOptions { get { return _middlewareOptions.Values; } }
public IEnumerable<IRequestOption> RequestOptions { get { return _requestOptions.Values; } }
/// <summary>
/// Adds a middleware option to the request.
/// Adds an option to the request.
/// </summary>
/// <param name="options">The middleware option to add.</param>
public void AddMiddlewareOptions(params IMiddlewareOption[] options)
/// <param name="options">The option to add.</param>
public void AddRequestOptions(params IRequestOption[] options)
{
if(!(options?.Any() ?? false)) return; // it's a no-op if there are no options and this avoid having to check in the code gen.
foreach(var option in options.Where(x => x != null))
if(!_middlewareOptions.TryAdd(option.GetType().FullName, option))
_middlewareOptions[option.GetType().FullName] = option;
if(!_requestOptions.TryAdd(option.GetType().FullName, option))
_requestOptions[option.GetType().FullName] = option;
}
/// <summary>
/// Removes given middleware options from the current request.
/// Removes given options from the current request.
/// </summary>
/// <param name="options">Middleware options to remove.</param>
public void RemoveMiddlewareOptions(params IMiddlewareOption[] options)
/// <param name="options">Options to remove.</param>
public void RemoveRequestOptions(params IRequestOption[] options)
{
if(!options?.Any() ?? false) throw new ArgumentNullException(nameof(options));
foreach(var optionName in options.Where(x => x != null).Select(x => x.GetType().FullName))
_middlewareOptions.Remove(optionName);
_requestOptions.Remove(optionName);
}
private const string BinaryContentType = "application/octet-stream";
private const string ContentTypeHeader = "Content-Type";
Expand Down
2 changes: 1 addition & 1 deletion abstractions/go/middleware_option.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package abstractions

type MiddlewareOption interface {
type RequestOption interface {
}
16 changes: 8 additions & 8 deletions abstractions/go/request_information.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ type RequestInformation struct {
Headers map[string]string
QueryParameters map[string]string
Content []byte
options map[string]MiddlewareOption
options map[string]RequestOption
}

func NewRequestInformation() *RequestInformation {
return &RequestInformation{
URI: u.URL{},
Headers: make(map[string]string),
QueryParameters: make(map[string]string),
options: make(map[string]MiddlewareOption),
options: make(map[string]RequestOption),
}
}

Expand Down Expand Up @@ -63,12 +63,12 @@ func (request *RequestInformation) SetUri(currentPath string, pathSegment string
return nil
}

func (request *RequestInformation) AddMiddlewareOptions(options ...MiddlewareOption) error {
func (request *RequestInformation) AddRequestOptions(options ...RequestOption) error {
if options == nil {
return errors.New("MiddlewareOptions cannot be nil")
return errors.New("RequestOptions cannot be nil")
}
if request.options == nil {
request.options = make(map[string]MiddlewareOption, len(options))
request.options = make(map[string]RequestOption, len(options))
}
for _, option := range options {
tp := reflect.TypeOf(option)
Expand All @@ -78,11 +78,11 @@ func (request *RequestInformation) AddMiddlewareOptions(options ...MiddlewareOpt
return nil
}

func (request *RequestInformation) GetMiddlewareOptions() []MiddlewareOption {
func (request *RequestInformation) GetRequestOptions() []RequestOption {
if request.options == nil {
return []MiddlewareOption{}
return []RequestOption{}
}
result := make([]MiddlewareOption, len(request.options))
result := make([]RequestOption, len(request.options))
for _, option := range request.options {
result = append(result, option)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ public class NativeResponseWrapper {
@SuppressWarnings("unchecked")
@Nonnull
public static <ModelType, NativeResponseType, QueryParametersType> CompletableFuture<NativeResponseType> CallAndGetNativeType(
@Nonnull final QuadFunction<Consumer<QueryParametersType>, Consumer<Map<String,String>>, Collection<MiddlewareOption>, ResponseHandler, CompletableFuture<ModelType>> originalCall,
@Nonnull final QuadFunction<Consumer<QueryParametersType>, Consumer<Map<String,String>>, Collection<RequestOption>, ResponseHandler, CompletableFuture<ModelType>> originalCall,
@Nullable final Consumer<QueryParametersType> q,
@Nullable final Consumer<Map<String,String>> h,
@Nullable final Collection<MiddlewareOption> o) {
@Nullable final Collection<RequestOption> o) {
Objects.requireNonNull(originalCall, "parameter originalCall cannot be null");
final NativeResponseHandler responseHandler = new NativeResponseHandler();
return originalCall.apply(q, h, o, responseHandler).thenApply((val) -> {
Expand All @@ -26,30 +26,30 @@ public static <ModelType, NativeResponseType, QueryParametersType> CompletableFu
}
@Nonnull
public static <ModelType, NativeResponseType, QueryParametersType> CompletableFuture<NativeResponseType> CallAndGetNativeType(
@Nonnull final QuadFunction<Consumer<QueryParametersType>, Consumer<Map<String,String>>, Collection<MiddlewareOption>, ResponseHandler, CompletableFuture<ModelType>> originalCall,
@Nonnull final QuadFunction<Consumer<QueryParametersType>, Consumer<Map<String,String>>, Collection<RequestOption>, ResponseHandler, CompletableFuture<ModelType>> originalCall,
@Nullable final Consumer<QueryParametersType> q,
@Nullable final Consumer<Map<String,String>> h) {
return CallAndGetNativeType(originalCall, q, h, null);
}
@Nonnull
public static <ModelType, NativeResponseType, QueryParametersType> CompletableFuture<NativeResponseType> CallAndGetNativeType(
@Nonnull final QuadFunction<Consumer<QueryParametersType>, Consumer<Map<String,String>>, Collection<MiddlewareOption>, ResponseHandler, CompletableFuture<ModelType>> originalCall,
@Nonnull final QuadFunction<Consumer<QueryParametersType>, Consumer<Map<String,String>>, Collection<RequestOption>, ResponseHandler, CompletableFuture<ModelType>> originalCall,
@Nullable final Consumer<QueryParametersType> q) {
return CallAndGetNativeType(originalCall, q, null, null);
}
@Nonnull
public static <ModelType, NativeResponseType, QueryParametersType> CompletableFuture<NativeResponseType> CallAndGetNativeType(
@Nonnull final QuadFunction<Consumer<QueryParametersType>, Consumer<Map<String,String>>, Collection<MiddlewareOption>, ResponseHandler, CompletableFuture<ModelType>> originalCall) {
@Nonnull final QuadFunction<Consumer<QueryParametersType>, Consumer<Map<String,String>>, Collection<RequestOption>, ResponseHandler, CompletableFuture<ModelType>> originalCall) {
return CallAndGetNativeType(originalCall, null, null, null);
}
@SuppressWarnings("unchecked")
@Nonnull
public static <ModelType, NativeResponseType, QueryParametersType, RequestBodyType> CompletableFuture<NativeResponseType> CallWithBodyAndGetNativeType(
@Nonnull final PentaFunction<RequestBodyType, Consumer<QueryParametersType>, Consumer<Map<String, String>>, Collection<MiddlewareOption>, ResponseHandler, CompletableFuture<ModelType>> originalCall,
@Nonnull final PentaFunction<RequestBodyType, Consumer<QueryParametersType>, Consumer<Map<String, String>>, Collection<RequestOption>, ResponseHandler, CompletableFuture<ModelType>> originalCall,
@Nonnull final RequestBodyType requestBody,
@Nullable final Consumer<QueryParametersType> q,
@Nullable final Consumer<Map<String,String>> h,
@Nullable final Collection<MiddlewareOption> o) {
@Nullable final Collection<RequestOption> o) {
Objects.requireNonNull(originalCall, "parameter originalCall cannot be null");
Objects.requireNonNull(requestBody, "parameter requestBody cannot be null");
final NativeResponseHandler responseHandler = new NativeResponseHandler();
Expand All @@ -59,22 +59,22 @@ public static <ModelType, NativeResponseType, QueryParametersType, RequestBodyTy
}
@Nonnull
public static <ModelType, NativeResponseType, QueryParametersType, RequestBodyType> CompletableFuture<NativeResponseType> CallWithBodyAndGetNativeType(
@Nonnull final PentaFunction<RequestBodyType, Consumer<QueryParametersType>, Consumer<Map<String, String>>, Collection<MiddlewareOption>, ResponseHandler, CompletableFuture<ModelType>> originalCall,
@Nonnull final PentaFunction<RequestBodyType, Consumer<QueryParametersType>, Consumer<Map<String, String>>, Collection<RequestOption>, ResponseHandler, CompletableFuture<ModelType>> originalCall,
@Nonnull final RequestBodyType requestBody,
@Nullable final Consumer<QueryParametersType> q,
@Nullable final Consumer<Map<String,String>> h) {
return CallWithBodyAndGetNativeType(originalCall, requestBody, q, h, null);
}
@Nonnull
public static <ModelType, NativeResponseType, QueryParametersType, RequestBodyType> CompletableFuture<NativeResponseType> CallWithBodyAndGetNativeType(
@Nonnull final PentaFunction<RequestBodyType, Consumer<QueryParametersType>, Consumer<Map<String, String>>, Collection<MiddlewareOption>, ResponseHandler, CompletableFuture<ModelType>> originalCall,
@Nonnull final PentaFunction<RequestBodyType, Consumer<QueryParametersType>, Consumer<Map<String, String>>, Collection<RequestOption>, ResponseHandler, CompletableFuture<ModelType>> originalCall,
@Nonnull final RequestBodyType requestBody,
@Nullable final Consumer<QueryParametersType> q) {
return CallWithBodyAndGetNativeType(originalCall, requestBody, q, null, null);
}
@Nonnull
public static <ModelType, NativeResponseType, QueryParametersType, RequestBodyType> CompletableFuture<NativeResponseType> CallWithBodyAndGetNativeType(
@Nonnull final PentaFunction<RequestBodyType, Consumer<QueryParametersType>, Consumer<Map<String, String>>, Collection<MiddlewareOption>, ResponseHandler, CompletableFuture<ModelType>> originalCall,
@Nonnull final PentaFunction<RequestBodyType, Consumer<QueryParametersType>, Consumer<Map<String, String>>, Collection<RequestOption>, ResponseHandler, CompletableFuture<ModelType>> originalCall,
@Nonnull final RequestBodyType requestBody) {
return CallWithBodyAndGetNativeType(originalCall, requestBody, null, null, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,30 +69,30 @@ private void setUriFromString(final String uriString) {
/** The Request Body. */
@Nullable
public InputStream content;
private HashMap<String, MiddlewareOption> _middlewareOptions = new HashMap<>();
private HashMap<String, RequestOption> _requestOptions = new HashMap<>();
/**
* Gets the middleware options for this request. Options are unique by type. If an option of the same type is added twice, the last one wins.
* @return the middleware options for this request.
*/
public Collection<MiddlewareOption> getMiddlewareOptions() { return _middlewareOptions.values(); }
public Collection<RequestOption> getRequestOptions() { return _requestOptions.values(); }
/**
* Adds a middleware option to this request.
* @param option the middleware option to add.
*/
public void addMiddlewareOptions(@Nullable final MiddlewareOption... options) {
public void addRequestOptions(@Nullable final RequestOption... options) {
if(options == null || options.length == 0) return;
for(final MiddlewareOption option : options) {
_middlewareOptions.put(option.getClass().getCanonicalName(), option);
for(final RequestOption option : options) {
_requestOptions.put(option.getClass().getCanonicalName(), option);
}
}
/**
* Removes a middleware option from this request.
* @param option the middleware option to remove.
*/
public void removeMiddlewareOptions(@Nullable final MiddlewareOption... options) {
public void removeRequestOptions(@Nullable final RequestOption... options) {
if(options == null || options.length == 0) return;
for(final MiddlewareOption option : options) {
_middlewareOptions.remove(option.getClass().getCanonicalName());
for(final RequestOption option : options) {
_requestOptions.remove(option.getClass().getCanonicalName());
}
}
private static String binaryContentType = "application/octet-stream";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.microsoft.kiota;

/** Represents a middleware option. */
public interface MiddlewareOption {
public interface RequestOption {

}
2 changes: 1 addition & 1 deletion abstractions/typescript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ export * from "./nativeResponseWrapper";
export * from './serialization';
export * from './utils';
export * from './store';
export * from './middlewareOption';
export * from './requestOption';
Loading

0 comments on commit b4a9aac

Please sign in to comment.