Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
2 changes: 1 addition & 1 deletion InterfaceStubGenerator.Core/InterfaceStubGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Refit.Generator
public class InterfaceStubGenerator
{
static readonly HashSet<string> httpMethodAttributeNames = new HashSet<string>(
new[] { "Get", "Head", "Post", "Put", "Delete", "Patch" }
new[] { "Get", "Head", "Post", "Put", "Delete", "Patch", "Options" }
.SelectMany(x => new[] { "{0}", "{0}Attribute" }.Select(f => string.Format(f, x))));

public InterfaceStubGenerator() : this(null, null) { }
Expand Down
16 changes: 15 additions & 1 deletion Refit.Tests/RequestBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ public interface IRestMethodInfoTests
[Patch("/foo/{id}")]
IObservable<string> PatchSomething(int id, [Body] string someAttribute);

[Options("/foo/{id}")]
Task<string> SendOptions(int id, [Body] string someAttribute);

[Post("/foo/{id}")]
Task<ApiResponse<bool>> PostReturnsApiResponse(int id);

Expand Down Expand Up @@ -383,6 +386,15 @@ public void UsingThePatchAttributeSetsTheCorrectMethod()
Assert.Equal("PATCH", fixture.HttpMethod.Method);
}

[Fact]
public void UsingOptionsAttribute()
{
var input = typeof(IRestMethodInfoTests);
var fixture = new RestMethodInfo(input, input.GetMethods().First(x => x.Name == nameof(IDummyHttpApi.SendOptions)));

Assert.Equal("OPTIONS", fixture.HttpMethod.Method);
}

[Fact]
public void ApiResponseShouldBeSet()
{
Expand Down Expand Up @@ -478,6 +490,9 @@ public interface IDummyHttpApi
[Patch("/foo/bar/{id}")]
IObservable<string> PatchSomething(int id, [Body] string someAttribute);

[Options("/foo/bar/{id}")]
Task<string> SendOptions(int id, [Body] string someAttribute);

[Get("/foo/bar/{id}")]
Task<string> FetchSomeStuffWithQueryFormat([Query(Format = "0.0")] int id);

Expand Down Expand Up @@ -1271,7 +1286,6 @@ public void ICanPostAValueTypeIfIWantYoureNotTheBossOfMe()
var expected = string.Format("\"{0}\"", guid);
var output = factory(new object[] { 7, guid });


Assert.Equal(expected, output.SendContent);
}
}
Expand Down
13 changes: 12 additions & 1 deletion Refit/Attributes.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
Expand Down Expand Up @@ -79,6 +79,17 @@ public override HttpMethod Method
}
}

[AttributeUsage(AttributeTargets.Method)]
public class OptionsAttribute : HttpMethodAttribute
{
public OptionsAttribute(string path) : base(path) { }

public override HttpMethod Method
{
get { return new HttpMethod("OPTIONS"); }
}
}

[AttributeUsage(AttributeTargets.Method)]
public class HeadAttribute : HttpMethodAttribute
{
Expand Down