ヘルプページの生成プロセスを拡張できます。 ASP.NET Web APIプロジェクトを作成すると、ヘルプページ関連のコードがソースとしてダウンロードされ、.dll
ではなく、ダウンロードして、必要なカスタムロジックで拡張できます。ここで
は、私がどうなるのかです:
- は
- (例えば
[DynamicQueryParameter("Param1",typeof(string))]
)attribute
クラスを作成し、それに私の特別な方法を飾るだけでなく行動からこれらの属性を照会し、それらを手動で追加するHelPageConfigurationExtensions.cs
を変更モデルのUriParameters
コレクションに移動します。私はおそらくGenerateUriParameters()
メソッドでこれを行うでしょう。
[編集]それは楽しいです、あなたが知っている、ので、私は実際にいくつかの時間を持っていたので、私は解決策に一緒に自分自身を置く:)
のでattribute
を作成します。
public class DynamicUriParameterAttribute : Attribute
{
public string Name { get; set; }
public Type Type { get; set; }
public string Description { get; set; }
}
あなたはこれであなたのアクションメソッドを飾ることができます。
[DynamicUriParameter(Description = "Some description", Name ="Some name", Type =typeof(string))]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
それから私はこのようなHelpPageConfigurationExtensions.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);
// add this part
var attrs = apiDescription.ActionDescriptor.GetCustomAttributes<DynamicUriParameterAttribute>();
foreach (var attr in attrs)
{
apiModel.UriParameters.Add(
new ParameterDescription
{
Name = attr.Name,
Documentation = attr.Description,
TypeDescription = modelGenerator.GetOrCreateModelDescription(attr.Type)
}
);
}
// until here
GenerateRequestModelDescription(apiModel, modelGenerator, sampleGenerator);
GenerateResourceDescription(apiModel, modelGenerator);
GenerateSamples(apiModel, sampleGenerator);
return apiModel;
}