本文整理汇总了C#中System.Web.Http.HttpConfiguration.GetHelpPageSampleGenerator方法的典型用法代码示例。如果您正苦于以下问题:C# HttpConfiguration.GetHelpPageSampleGenerator方法的具体用法?C# HttpConfiguration.GetHelpPageSampleGenerator怎么用?C# HttpConfiguration.GetHelpPageSampleGenerator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Http.HttpConfiguration
的用法示例。
在下文中一共展示了HttpConfiguration.GetHelpPageSampleGenerator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Register
public static void Register(HttpConfiguration config)
{
//// Uncomment the following to use the documentation from XML documentation file.
config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/bin/myDoc.xml")));
//config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/bin/myDoc.xml")));
//// Uncomment the following to use "sample string" as the sample for all actions that have string as the body parameter or return type.
//// Also, the string arrays will be used for IEnumerable<string>. The sample objects will be serialized into different media type
//// formats by the available formatters.
//config.SetSampleObjects(new Dictionary<Type, object>
//{
// {typeof(CityResult), "sample string"},
// {typeof(IEnumerable<CityResult>), new string[]{"sample 1", "sample 2"}}
//});
// Extend the following to provide factories for types not handled automatically (those lacking parameterless
// constructors) or for which you prefer to use non-default property values. Line below provides a fallback
// since automatic handling will fail and GeneratePageResult handles only a single type.
#if Handle_PageResultOfT
config.GetHelpPageSampleGenerator().SampleObjectFactories.Add(GeneratePageResult);
#endif
// Extend the following to use a preset object directly as the sample for all actions that support a media
// type, regardless of the body parameter or return type. The lines below avoid display of binary content.
// The BsonMediaTypeFormatter (if available) is not used to serialize the TextSample object.
//config.SetSampleForMediaType(
// new TextSample("Binary JSON content. See http://bsonspec.org for details."),
// new MediaTypeHeaderValue("application/bson"));
//// Uncomment the following to use "[0]=foo&[1]=bar" directly as the sample for all actions that support form URL encoded format
//// and have IEnumerable<string> as the body parameter or return type.
config.SetSampleForType("[0]=foo&[1]=bar&[2]=bar", new MediaTypeHeaderValue("application/x-www-form-urlencoded"), typeof(IEnumerable<string>)); //william uncomment
//// Uncomment the following to use "1234" directly as the request sample for media type "text/plain" on the controller named "Values"
//// and action named "Put".
//config.SetSampleRequest("1234", new MediaTypeHeaderValue("text/plain"), "Values", "Put");
//// Uncomment the following to use the image on "../images/aspNetHome.png" directly as the response sample for media type "image/png"
//// on the controller named "Values" and action named "Get" with parameter "id".
//config.SetSampleResponse(new ImageSample("../images/aspNetHome.png"), new MediaTypeHeaderValue("image/png"), "Values", "Get", "id");
//// Uncomment the following to correct the sample request when the action expects an HttpRequestMessage with ObjectContent<string>.
//// The sample will be generated as if the controller named "Values" and action named "Get" were having string as the body parameter.
// config.SetActualRequestType(typeof(string), "City", "Get");
//// Uncomment the following to correct the sample response when the action returns an HttpResponseMessage with ObjectContent<string>.
//// The sample will be generated as if the controller named "Values" and action named "Post" were returning a string.
//config.SetActualResponseType(typeof(string), "Values", "Post");
//config.SetActualResponseType(typeof(City), "City", "Get");
//config.SetActualResponseType(typeof(CityList), "City", "Get");
//config.SetActualResponseType(typeof(RamResource), "Resource", "Get");
//config.SetActualResponseType(typeof(Search_Result), "Search", "Get");
//config.SetActualResponseType(typeof(ProvinceList), "Province", "Get");
//config.SetActualResponseType(typeof(SubCategoryResult), "SubCategory", "Get");
//config.SetActualResponseType(typeof(TopCategoryList), "TopCategory", "Get");
//config.SetActualResponseType(typeof(TopCategory_Result), "TopCategory", "Get");
//config.SetActualResponseType(typeof(SuggestionWords), "Search", "Get");
}
示例2: Register
public static void Register(HttpConfiguration config)
{
//// Uncomment the following to use the documentation from XML documentation file.
config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/XmlDocument.xml")));
//// Uncomment the following to use "sample string" as the sample for all actions that have string as the body parameter or return type.
//// Also, the string arrays will be used for IEnumerable<string>. The sample objects will be serialized into different media type
//// formats by the available formatters.
config.SetSampleObjects(new Dictionary<Type, object>
{
{typeof(string), "{'status':'Succeeded','result':[{'localUrl':'http://localhost/ImagesDownloader/Images/ximnobo2.vqo/c9aef841-7cd2-47e3-be25-436c091101c5.gif','remoteUrl':'https://cdn0.vox-cdn.com/images/verge/default-avatar.v9899025.gif','width':0,'height':0,'size':2926,'contentType':'image/gif'}]}"},
{typeof(IEnumerable<string>), new string[]{"sample 1", "sample 2"}}
});
// Extend the following to provide factories for types not handled automatically (those lacking parameterless
// constructors) or for which you prefer to use non-default property values. Line below provides a fallback
// since automatic handling will fail and GeneratePageResult handles only a single type.
#if Handle_PageResultOfT
config.GetHelpPageSampleGenerator().SampleObjectFactories.Add(GeneratePageResult);
#endif
// Extend the following to use a preset object directly as the sample for all actions that support a media
// type, regardless of the body parameter or return type. The lines below avoid display of binary content.
// The BsonMediaTypeFormatter (if available) is not used to serialize the TextSample object.
/*config.SetSampleForMediaType(
new TextSample("Binary JSON content. See http://bsonspec.org for details."),
new MediaTypeHeaderValue("application/bson"));*/
//// Uncomment the following to use "[0]=foo&[1]=bar" directly as the sample for all actions that support form URL encoded format
//// and have IEnumerable<string> as the body parameter or return type.
//config.SetSampleForType("[0]=foo&[1]=bar", new MediaTypeHeaderValue("application/x-www-form-urlencoded"), typeof(IEnumerable<string>));
//// Uncomment the following to use "1234" directly as the request sample for media type "text/plain" on the controller named "Values"
//// and action named "Put".
//config.SetSampleRequest("1234", new MediaTypeHeaderValue("text/plain"), "Jobs", "Get");
config.SetSampleRequest("{'value': 'http://www.theverge.com'}}", new MediaTypeHeaderValue("application/json"), "Jobs", "Post");
//// Uncomment the following to use "1234" directly as the request sample for media type "text/plain" on the controller named "Values"
//// and action named "Put".
//config.SetSampleRequest("1234", new MediaTypeHeaderValue("text/plain"), "Values", "Put");
//// Uncomment the following to use the image on "../images/aspNetHome.png" directly as the response sample for media type "image/png"
//// on the controller named "Values" and action named "Get" with parameter "id".
//config.SetSampleResponse(new ImageSample("../images/aspNetHome.png"), new MediaTypeHeaderValue("image/png"), "Values", "Get", "id");
//// Uncomment the following to correct the sample request when the action expects an HttpRequestMessage with ObjectContent<string>.
//// The sample will be generated as if the controller named "Values" and action named "Get" were having string as the body parameter.
//config.SetActualRequestType(typeof(string), "Jobs", "Get");
//// Uncomment the following to correct the sample response when the action returns an HttpResponseMessage with ObjectContent<string>.
//// The sample will be generated as if the controller named "Values" and action named "Post" were returning a string.
config.SetActualResponseType(typeof(string), "Jobs", "GetById");
}
示例3: Register
public static void Register(HttpConfiguration config)
{
//// Uncomment the following to use the documentation from XML documentation file.
config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/SearchApi.xml")));
//// Uncomment the following to use "sample string" as the sample for all actions that have string as the body parameter or return type.
//// Also, the string arrays will be used for IEnumerable<string>. The sample objects will be serialized into different media type
//// formats by the available formatters.
config.SetSampleObjects(new Dictionary<Type, object>
{
{typeof(FarmLocationDto), new FarmLocationDto{Name = "Pierrafortscha's Farm", Latitude=46.786415, Longitude =7.185928}},
{typeof(IEnumerable<FarmLocationDto>),new []
{
new FarmLocationDto{Name = "Pierrafortscha's Farm", Latitude=46.786415, Longitude =7.185928},
new FarmLocationDto{Name = "Tentlingen's Farm House", Latitude=46.769621, Longitude =7.186067},
}}
});
// Extend the following to provide factories for types not handled automatically (those lacking parameterless
// constructors) or for which you prefer to use non-default property values. Line below provides a fallback
// since automatic handling will fail and GeneratePageResult handles only a single type.
#if Handle_PageResultOfT
config.GetHelpPageSampleGenerator().SampleObjectFactories.Add(GeneratePageResult);
#endif
// Extend the following to use a preset object directly as the sample for all actions that support a media
// type, regardless of the body parameter or return type. The lines below avoid display of binary content.
// The BsonMediaTypeFormatter (if available) is not used to serialize the TextSample object.
config.SetSampleForMediaType(
new TextSample("Binary JSON content. See http://bsonspec.org for details."),
new MediaTypeHeaderValue("application/bson"));
//// Uncomment the following to use "[0]=foo&[1]=bar" directly as the sample for all actions that support form URL encoded format
//// and have IEnumerable<string> as the body parameter or return type.
//config.SetSampleForType("[0]=foo&[1]=bar", new MediaTypeHeaderValue("application/x-www-form-urlencoded"), typeof(IEnumerable<string>));
//// Uncomment the following to use "1234" directly as the request sample for media type "text/plain" on the controller named "Values"
//// and action named "Put".
//config.SetSampleRequest("1234", new MediaTypeHeaderValue("text/plain"), "Values", "Put");
//// Uncomment the following to use the image on "../images/aspNetHome.png" directly as the response sample for media type "image/png"
//// on the controller named "Values" and action named "Get" with parameter "id".
//config.SetSampleResponse(new ImageSample("../images/aspNetHome.png"), new MediaTypeHeaderValue("image/png"), "Values", "Get", "id");
//// Uncomment the following to correct the sample request when the action expects an HttpRequestMessage with ObjectContent<string>.
//// The sample will be generated as if the controller named "Values" and action named "Get" were having string as the body parameter.
//config.SetActualRequestType(typeof(string), "Values", "Get");
//// Uncomment the following to correct the sample response when the action returns an HttpResponseMessage with ObjectContent<string>.
//// The sample will be generated as if the controller named "Values" and action named "Post" were returning a string.
config.SetActualResponseType(typeof(IEnumerable<FarmLocationDto>), "Search", "GetFarms");
}
示例4: Register
public static void Register(HttpConfiguration config)
{
//// Uncomment the following to use the documentation from XML documentation file.
config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/XmlDocumentation.xml")));
// Uncomment the following to use "sample string" as the sample for all actions that have string as the body parameter or return type.
// Also, the string arrays will be used for IEnumerable<string>. The sample objects will be serialized into different media type
// formats by the available formatters.
config.SetSampleObjects(new Dictionary<Type, object>
{
{typeof(string), "exempel"},
{typeof(IEnumerable<string>), new string[]{"exempel 1", "exempel 2"}}
});
// Extend the following to provide factories for types not handled automatically (those lacking parameterless
// constructors) or for which you prefer to use non-default property values. Line below provides a fallback
// since automatic handling will fail and GeneratePageResult handles only a single type.
#if Handle_PageResultOfT
config.GetHelpPageSampleGenerator().SampleObjectFactories.Add(GeneratePageResult);
#endif
// Extend the following to use a preset object directly as the sample for all actions that support a media
// type, regardless of the body parameter or return type. The lines below avoid display of binary content.
// The BsonMediaTypeFormatter (if available) is not used to serialize the TextSample object.
config.SetSampleForMediaType(
new TextSample("Binary JSON content. See http://bsonspec.org for details."),
new MediaTypeHeaderValue("application/bson"));
// Uncomment the following to use "[0]=foo&[1]=bar" directly as the sample for all actions that support form URL encoded format
// and have IEnumerable<string> as the body parameter or return type.
config.SetSampleForType("FirstName=sample1&LastName=sample2&BossId=sampleBoss&[email protected] &AdTitle=sample3&OwnTitle=sample4&Seat=sample5&UserName=sample6&Phone=1234&Mobile=1234&Office=sample7 &Company=sample8&PersonalInfo=sample9&Active=true&CostCentre=15", new MediaTypeHeaderValue("application/x-www-form-urlencoded"), typeof(SimpleUser));
//// Uncomment the following to use "1234" directly as the request sample for media type "text/plain" on the controller named "Values"
//// and action named "Put".
//config.SetSampleRequest("1234", new MediaTypeHeaderValue("text/plain"), "Values", "Put");
//// Uncomment the following to use the image on "../images/aspNetHome.png" directly as the response sample for media type "image/png"
//// on the controller named "Values" and action named "Get" with parameter "id".
//config.SetSampleResponse(new ImageSample("../images/aspNetHome.png"), new MediaTypeHeaderValue("image/png"), "Values", "Get", "id");
//// Uncomment the following to correct the sample request when the action expects an HttpRequestMessage with ObjectContent<string>.
//// The sample will be generated as if the controller named "Values" and action named "Get" were having string as the body parameter.
//config.SetActualRequestType(typeof(string), "Values", "Get");
//// Uncomment the following to correct the sample response when the action returns an HttpResponseMessage with ObjectContent<string>.
//// The sample will be generated as if the controller named "Values" and action named "Post" were returning a string.
//config.SetActualResponseType(typeof(string), "Values", "Post");
}
示例5: SetSample
private static void SetSample(HttpConfiguration config, object sample)
{
var json = JsonConvert.SerializeObject(sample, Formatting.Indented);
var xml = CreateXml(sample);
var sampleType = sample.GetType();
var gen = config.GetHelpPageSampleGenerator();
var mimeTypes = new List<MediaTypeHeaderValue>
{
new MediaTypeHeaderValue("application/json"),
new MediaTypeHeaderValue("text/json"),
new MediaTypeHeaderValue("text/html"),
new MediaTypeHeaderValue("text/plain")
};
foreach (var mediaType in mimeTypes)
{
var smpl = gen.ActionSamples.FirstOrDefault(x =>
Equals(x.Key, new HelpPageSampleKey(mediaType, sampleType)));
if (smpl.Value != null)
gen.ActionSamples[smpl.Key] = json;
else config.SetSampleForType(json, mediaType, sampleType);
}
mimeTypes = new List<MediaTypeHeaderValue>
{
new MediaTypeHeaderValue("text/xml"),
new MediaTypeHeaderValue("application/xml")
};
foreach (var mediaType in mimeTypes)
{
var smpl = gen.ActionSamples.FirstOrDefault(x =>
Equals(x.Key, new HelpPageSampleKey(mediaType, sampleType)));
if (smpl.Value != null)
gen.ActionSamples[smpl.Key] = xml;
else config.SetSampleForType(xml, mediaType, sampleType);
}
}
示例6: TryGetResourceParameter
private static bool TryGetResourceParameter(ApiDescription apiDescription, HttpConfiguration config, out ApiParameterDescription parameterDescription, out Type resourceType)
{
parameterDescription = apiDescription.ParameterDescriptions.FirstOrDefault(
p => p.Source == ApiParameterSource.FromBody ||
(p.ParameterDescriptor != null && p.ParameterDescriptor.ParameterType == typeof(HttpRequestMessage)));
if (parameterDescription == null)
{
resourceType = null;
return false;
}
resourceType = parameterDescription.ParameterDescriptor.ParameterType;
if (resourceType == typeof(HttpRequestMessage))
{
HelpPageSampleGenerator sampleGenerator = config.GetHelpPageSampleGenerator();
resourceType = sampleGenerator.ResolveHttpRequestMessageType(apiDescription);
}
if (resourceType == null)
{
parameterDescription = null;
return false;
}
return true;
}
示例7: GenerateApiModel
private static HelpPageApiModel GenerateApiModel(ApiDescription apiDescription, HttpConfiguration config)
{
HelpPageApiModel apiModel = new HelpPageApiModel()
{
ApiDescription = apiDescription,
};
ModelDescriptionGenerator modelGenerator = config.GetModelDescriptionGenerator();
HelpPageSampleGenerator sampleGenerator = config.GetHelpPageSampleGenerator();
GenerateUriParameters(apiModel, modelGenerator);
GenerateRequestModelDescription(apiModel, modelGenerator, sampleGenerator);
GenerateResourceDescription(apiModel, modelGenerator);
GenerateSamples(apiModel, sampleGenerator);
return apiModel;
}
示例8: GenerateApiModel
private static HelpPageApiModel GenerateApiModel(ApiDescription apiDescription, HttpConfiguration config)
{
var apiModel = new HelpPageApiModel()
{
ApiDescription = apiDescription,
};
var modelGenerator = config.GetModelDescriptionGenerator();
var sampleGenerator = config.GetHelpPageSampleGenerator();
apiModel.UriParameters = apiModel.ApiDescription.GenerateUriParameters(modelGenerator);
apiModel.RequestModelDescription = apiModel.ApiDescription.GenerateRequestModelDescription(modelGenerator, sampleGenerator);
apiModel.ResourceDescription = apiModel.ApiDescription.GenerateResponseDescription(modelGenerator);
GenerateSamples(apiModel, sampleGenerator);
return apiModel;
}
示例9: SetHelpPageSampleGenerator_ChangesTheDefault
public void SetHelpPageSampleGenerator_ChangesTheDefault()
{
HttpConfiguration config = new HttpConfiguration();
Mock<HelpPageSampleGenerator> helpPageSampleGenerator = new Mock<HelpPageSampleGenerator>();
config.SetHelpPageSampleGenerator(helpPageSampleGenerator.Object);
Assert.Same(helpPageSampleGenerator.Object, config.GetHelpPageSampleGenerator());
}
示例10: GetHelpPageSampleGenerator_ReturnsDefaultValue
public void GetHelpPageSampleGenerator_ReturnsDefaultValue()
{
HttpConfiguration config = new HttpConfiguration();
HelpPageSampleGenerator helpPageSampleGenerator = config.GetHelpPageSampleGenerator();
Assert.NotNull(helpPageSampleGenerator);
Assert.Same(helpPageSampleGenerator, config.GetHelpPageSampleGenerator());
}
示例11: GenerateApiModel
private static HelpPageApiModel GenerateApiModel(ApiDescription apiDescription, HttpConfiguration config)
{
HelpPageApiModel apiModel = new HelpPageApiModel()
{
ApiDescription = apiDescription,
};
if (apiDescription.ActionDescriptor.GetFilterPipeline().Any(x => x.Instance is IAuthorizationFilter))
apiModel.RequiresAuthorization = true;
if (apiDescription.ActionDescriptor.GetFilterPipeline().Any(x => x.Instance is CachedAttribute))
apiModel.IsCached = true;
ModelDescriptionGenerator modelGenerator = config.GetModelDescriptionGenerator();
HelpPageSampleGenerator sampleGenerator = config.GetHelpPageSampleGenerator();
GenerateUriParameters(apiModel, modelGenerator);
GenerateRequestModelDescription(apiModel, modelGenerator, sampleGenerator);
GenerateResourceDescription(apiModel, modelGenerator);
GenerateSamples(apiModel, sampleGenerator);
return apiModel;
}
示例12: GenerateApiModel
private static HelpPageApiModel GenerateApiModel(ApiDescription apiDescription, HttpConfiguration config)
{
HelpPageApiModel apiModel = new HelpPageApiModel
{
ApiDescription = apiDescription
};
var isAnonymous = apiDescription.ActionDescriptor.GetCustomAttributes<AllowAnonymousAttribute>().Any()
||
apiDescription.ActionDescriptor.ControllerDescriptor
.GetCustomAttributes<AllowAnonymousAttribute>().Any();
if (!isAnonymous && apiDescription.ActionDescriptor.GetFilterPipeline().Any(f => f.Instance is IAuthorizationFilter))
apiModel.RequiresAuthorization = true;
//var attr = apiDescription.ActionDescriptor.GetCustomAttributes<MetaDataAttribute>().ToList();
//apiModel.AddedDate = attr.Any() ? attr.First().AddedDate : new DateTime(2014);
ModelDescriptionGenerator modelGenerator = config.GetModelDescriptionGenerator();
HelpPageSampleGenerator sampleGenerator = config.GetHelpPageSampleGenerator();
GenerateUriParameters(apiModel, modelGenerator);
GenerateRequestModelDescription(apiModel, modelGenerator, sampleGenerator);
GenerateResourceDescription(apiModel, modelGenerator);
GenerateSamples(apiModel, sampleGenerator);
return apiModel;
}
示例13: Register
public static void Register(HttpConfiguration config)
{
//// Uncomment the following to use the documentation from XML documentation file.
config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/XmlDocument.xml")));
//// Uncomment the following to use "sample string" as the sample for all actions that have string as the body parameter or return type.
//// Also, the string arrays will be used for IEnumerable<string>. The sample objects will be serialized into different media type
//// formats by the available formatters.
//config.SetSampleObjects(new Dictionary<Type, object>
//{
// {typeof(string), "sample string"},
// {typeof(IEnumerable<string>), new string[]{"sample 1", "sample 2"}}
//});
// Extend the following to provide factories for types not handled automatically (those lacking parameterless
// constructors) or for which you prefer to use non-default property values. Line below provides a fallback
// since automatic handling will fail and GeneratePageResult handles only a single type.
#if Handle_PageResultOfT
config.GetHelpPageSampleGenerator().SampleObjectFactories.Add(GeneratePageResult);
#endif
// Extend the following to use a preset object directly as the sample for all actions that support a media
// type, regardless of the body parameter or return type. The lines below avoid display of binary content.
// The BsonMediaTypeFormatter (if available) is not used to serialize the TextSample object.
config.SetSampleForMediaType(
new TextSample("Binary JSON content. See http://bsonspec.org for details."),
new MediaTypeHeaderValue("application/bson"));
//// Uncomment the following to use "[0]=foo&[1]=bar" directly as the sample for all actions that support form URL encoded format
//// and have IEnumerable<string> as the body parameter or return type.
//config.SetSampleForType("[0]=foo&[1]=bar", new MediaTypeHeaderValue("application/x-www-form-urlencoded"), typeof(IEnumerable<string>));
//config.SetSampleForType("[0]=alias&[1]=description&[2]=path&[3]=title&[4]=version", new MediaTypeHeaderValue("application/x-www-form-urlencoded"), typeof(Bug));
//// Uncomment the following to use "1234" directly as the request sample for media type "text/plain" on the controller named "Values"
//// and action named "Put".
//config.SetSampleRequest("1234", new MediaTypeHeaderValue("text/plain"), "Values", "Put");
config.SetSampleResponse("1.0.0.0", new MediaTypeHeaderValue("application/json"), "Messages", "Version");
config.SetSampleResponse("1.0.0.0", new MediaTypeHeaderValue("text/json"), "Messages", "Version");
config.SetSampleResponse("1.0.0.0", new MediaTypeHeaderValue("text/html"), "Messages", "Version");
config.SetSampleResponse("<string xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/\">1.0.0.0</string>", new MediaTypeHeaderValue("application/xml"), "Messages", "Version");
config.SetSampleResponse("<string xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/\">1.0.0.0</string>", new MediaTypeHeaderValue("text/xml"), "Messages", "Version");
//// Uncomment the following to use the image on "../images/aspNetHome.png" directly as the response sample for media type "image/png"
//// on the controller named "Values" and action named "Get" with parameter "id".
//config.SetSampleResponse(new ImageSample("../images/aspNetHome.png"), new MediaTypeHeaderValue("image/png"), "Values", "Get", "id");
//// Uncomment the following to correct the sample request when the action expects an HttpRequestMessage with ObjectContent<string>.
//// The sample will be generated as if the controller named "Values" and action named "Get" were having string as the body parameter.
//config.SetActualRequestType(typeof(string), "Values", "Get");
//// Uncomment the following to correct the sample response when the action returns an HttpResponseMessage with ObjectContent<string>.
//// The sample will be generated as if the controller named "Values" and action named "Post" were returning a string.
// MessageController
config.SetActualResponseType(typeof(string), "Messages", "Welcome");
config.SetActualResponseType(typeof(string), "Messages", "Daily");
config.SetActualResponseType(typeof(string), "Messages", "Version");
// PeerDiscoveryController
config.SetActualResponseType(typeof(PeerVersionResult), "PeerDiscovery", "IsVersionDisabled");
}
示例14: Register
public static void Register(HttpConfiguration config)
{
//// Uncomment the following to use the documentation from XML documentation file.
//config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/XmlDocument.xml")));
config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/bin/DemoProject.API.XML")));
//// Uncomment the following to use "sample string" as the sample for all actions that have string as the body parameter or return type.
//// Also, the string arrays will be used for IEnumerable<string>. The sample objects will be serialized into different media type
//// formats by the available formatters.
//config.SetSampleObjects(new Dictionary<Type, object>
//{
// {typeof(string), "sample string"},
// {typeof(IEnumerable<string>), new string[]{"sample 1", "sample 2"}}
//});
// Extend the following to provide factories for types not handled automatically (those lacking parameterless
// constructors) or for which you prefer to use non-default property values. Line below provides a fallback
// since automatic handling will fail and GeneratePageResult handles only a single type.
#if Handle_PageResultOfT
config.GetHelpPageSampleGenerator().SampleObjectFactories.Add(GeneratePageResult);
#endif
// Extend the following to use a preset object directly as the sample for all actions that support a media
// type, regardless of the body parameter or return type. The lines below avoid display of binary content.
// The BsonMediaTypeFormatter (if available) is not used to serialize the TextSample object.
config.SetSampleForMediaType(
new TextSample("Binary JSON content. See http://bsonspec.org for details."),
new MediaTypeHeaderValue("application/bson"));
//// Uncomment the following to use "[0]=foo&[1]=bar" directly as the sample for all actions that support form URL encoded format
//// and have IEnumerable<string> as the body parameter or return type.
//config.SetSampleForType("[0]=foo&[1]=bar", new MediaTypeHeaderValue("application/x-www-form-urlencoded"), typeof(IEnumerable<string>));
//// Uncomment the following to use "1234" directly as the request sample for media type "text/plain" on the controller named "Values"
//// and action named "Put".
//config.SetSampleRequest("1234", new MediaTypeHeaderValue("text/plain"), "Values", "Put");
config.SetSampleRequest(@"POST http://localhost/api/upload HTTP/1.1
Content-Type: multipart/form-data; boundary=-------------------------acebdf13572468
User-Agent: Fiddler
Host: localhost
Content-Length: 462
---------------------------acebdf13572468
Content-Disposition: form-data; name=""fieldNameHere""; filename=""TestFile.txt""
Content-Type: text/plain
line1
line 2 - namespace DemoProject
line3
line4
line 5 - 555555555555555555555555555555555555
line 6 - 666666666666 666666666666 666666666666 666666666666 666666666666 666666666666 666666666666 666666666666 666666666666 666666666666 666666666666 666666666666
---------------------------acebdf13572468--
", new MediaTypeHeaderValue("text/plain"), "Upload", "Post");
//// Uncomment the following to use the image on "../images/aspNetHome.png" directly as the response sample for media type "image/png"
//// on the controller named "Values" and action named "Get" with parameter "id".
//config.SetSampleResponse(new ImageSample("../images/aspNetHome.png"), new MediaTypeHeaderValue("image/png"), "Values", "Get", "id");
//// Uncomment the following to correct the sample request when the action expects an HttpRequestMessage with ObjectContent<string>.
//// The sample will be generated as if the controller named "Values" and action named "Get" were having string as the body parameter.
//config.SetActualRequestType(typeof(string), "Values", "Get");
//// Uncomment the following to correct the sample response when the action returns an HttpResponseMessage with ObjectContent<string>.
//// The sample will be generated as if the controller named "Values" and action named "Post" were returning a string.
//config.SetActualResponseType(typeof(string), "Values", "Post");
config.SetActualResponseType(typeof(IEnumerable<DemoProject.API.Models.MetadataInfo>), "Metadata", "Get");
config.SetActualResponseType(typeof(DemoProject.API.Models.MetadataInfo), "Metadata", "Get", "id");
config.SetActualResponseType(typeof(IEnumerable<DemoProject.API.Models.MetadataInfo>), "Upload", "Post");
}
示例15: Register
public static void Register( HttpConfiguration config )
{
// Uncomment the following to use the documentation from XML documentation file.
config.SetDocumentationProvider( new XmlDocumentationProvider( HttpContext.Current.Server.MapPath( "~/App_Data/chrisparkeronline.XML" ) ) );
// Uncomment the following to use "sample string" as the sample for all actions that have string as the body parameter or return type.
// Also, the string arrays will be used for IEnumerable<string>. The sample objects will be serialized into different media type
// formats by the available formatters.
config.SetSampleObjects( new Dictionary<Type, object>
{
{typeof(string), "sample string"},
{typeof(IEnumerable<string>), new string[]{"sample 1", "sample 2"}}
} );
// Extend the following to provide factories for types not handled automatically (those lacking parameterless
// constructors) or for which you prefer to use non-default property values. Line below provides a fallback
// since automatic handling will fail and GeneratePageResult handles only a single type.
#if Handle_PageResultOfT
config.GetHelpPageSampleGenerator().SampleObjectFactories.Add(GeneratePageResult);
#endif
//var types = Assembly.GetAssembly( typeof( HelpPageConfig ) ).GetTypes()
// .Where( type => type.IsClass && !type.IsAbstract )
// .Where( type => typeof( IWebApiV1 ).IsAssignableFrom( type ) );
//var sampleObjectDictionary = types.Select( type => ( ( IWebApiV1 )Activator.CreateInstance( type ) )
// .CreateSampleObjectsEntry() ).ToDictionary( entry => entry.Key, entry => entry.Value );
//config.SetSampleObjects( sampleObjectDictionary );
// Extend the following to use a preset object directly as the sample for all actions that support a media
// type, regardless of the body parameter or return type. The lines below avoid display of binary content.
// The BsonMediaTypeFormatter (if available) is not used to serialize the TextSample object.
//config.SetSampleForMediaType(
// new TextSample( "Binary JSON content. See http://bsonspec.org for details." ),
// new MediaTypeHeaderValue( "application/bson" ) );
//config.SetSampleForMediaType(
// null,
// new MediaTypeHeaderValue( "application/json" ) );
// Uncomment the following to use "[0]=foo&[1]=bar" directly as the sample for all actions that support form URL encoded format
// and have IEnumerable<string> as the body parameter or return type.
//config.SetSampleForType( "[0]=foo&[1]=bar", new MediaTypeHeaderValue( "application/x-www-form-urlencoded" ), typeof( FoodBankDto ) );
// Uncomment the following to use "1234" directly as the request sample for media type "text/plain" on the controller named "Values"
// and action named "Put".
config.SetSampleRequest( "1234", new MediaTypeHeaderValue( "text/plain" ), "Values", "Put" );
// Uncomment the following to use the image on "../images/aspNetHome.png" directly as the response sample for media type "image/png"
// on the controller named "Values" and action named "Get" with parameter "id".
config.SetSampleResponse( new ImageSample( "../images/aspNetHome.png" ), new MediaTypeHeaderValue( "image/png" ), "Values", "Get", "id" );
//// Uncomment the following to correct the sample request when the action expects an HttpRequestMessage with ObjectContent<string>.
//// The sample will be generated as if the controller named "Values" and action named "Get" were having string as the body parameter.
//config.SetActualRequestType(typeof(string), "Values", "Get");
//// Uncomment the following to correct the sample response when the action returns an HttpResponseMessage with ObjectContent<string>.
//// The sample will be generated as if the controller named "Values" and action named "Post" were returning a string.
//config.SetActualResponseType(typeof(string), "Values", "Post");
}