本文整理汇总了C#中Swashbuckle.Swagger.SchemaRegistry类的典型用法代码示例。如果您正苦于以下问题:C# SchemaRegistry类的具体用法?C# SchemaRegistry怎么用?C# SchemaRegistry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SchemaRegistry类属于Swashbuckle.Swagger命名空间,在下文中一共展示了SchemaRegistry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateOperation
private Operation CreateOperation(ApiDescription apiDescription, SchemaRegistry schemaRegistry)
{
var parameters = apiDescription.ParameterDescriptions
.Select(paramDesc =>
{
var inPath = apiDescription.RelativePathSansQueryString().Contains("{" + paramDesc.Name + "}");
return CreateParameter(paramDesc, inPath, schemaRegistry);
})
.ToList();
var responses = new Dictionary<string, Response>();
var responseType = apiDescription.ResponseType();
if (responseType == null || responseType == typeof(void))
responses.Add("204", new Response { description = "No Content" });
else
responses.Add("200", new Response { description = "OK", schema = schemaRegistry.GetOrRegister(responseType) });
var operation = new Operation
{
tags = new [] { _options.GroupingKeySelector(apiDescription) },
operationId = apiDescription.FriendlyId(),
produces = apiDescription.Produces().ToList(),
consumes = apiDescription.Consumes().ToList(),
parameters = parameters.Any() ? parameters : null, // parameters can be null but not empty
responses = responses,
deprecated = apiDescription.IsObsolete()
};
foreach (var filter in _options.OperationFilters)
{
filter.Apply(operation, schemaRegistry, apiDescription);
}
return operation;
}
示例2: Apply
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
{
List<SwaggerDefaultValue> listDefine = new List<SwaggerDefaultValue>
{
new SwaggerDefaultValue("Compare", "<", "<,<=,>,>=,="),
//new SwaggerDefaultValue("Model_URI", "@{body(\'besconnector').Results.output2.FullURL}"),
//new SwaggerDefaultValue("Evaluate_Output_Path", "@{body(\'besconnector\').Results.output1.FullURL}")
};
if (operation.parameters == null)
return;
foreach (var param in operation.parameters)
{
var actionParam = apiDescription.ActionDescriptor.GetParameters().First(p => p.ParameterName == param.name);
foreach (SwaggerDefaultValue customAttribute in listDefine)
{
if (customAttribute.ParameterName == param.name)
{
[email protected] = customAttribute.DefaultValue;
string[] listValue = customAttribute.Values.Split(',');
if (listValue != null && listValue.Length > 1)
[email protected] = listValue;
}
}
}
}
示例3: Apply
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
{
if (operation.parameters == null) return;
HandleFromUriArrayParams(operation);
HandleFromUriObjectParams(operation, schemaRegistry, apiDescription);
}
示例4: Apply
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
{
if (operation.operationId == "FileDownload_GetFile")
{
operation.produces = new[] { "application/octet-stream" };
}
}
示例5: Apply
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
{
if (operation == null)
{
throw new ArgumentNullException("operation");
}
if (apiDescription == null)
{
throw new ArgumentNullException("apiDescription");
}
Collection<IFilter> filters = apiDescription.ActionDescriptor.ControllerDescriptor.GetFilters();
IEnumerable<IFilter> mobileAppFilter = filters.Where(f => typeof(MobileAppControllerAttribute).IsAssignableFrom(f.GetType()));
if (mobileAppFilter.Any())
{
if (operation.parameters == null)
{
operation.parameters = new List<Parameter>();
}
operation.parameters.Add(new Parameter
{
name = "ZUMO-API-VERSION",
@in = "header",
type = "string",
required = true,
@default = "2.0.0"
});
}
}
示例6: Apply
public void Apply(SwaggerDocument swaggerDoc, SchemaRegistry schemaRegistry, IApiExplorer apiExplorer)
{
Contract.Assume(swaggerDoc != null);
Contract.Assume(schemaRegistry != null);
Contract.Assume(apiExplorer != null);
var pathItems = swaggerDoc.paths.Values;
var deletes = pathItems.Select(pathItem => pathItem.delete).Where(operation => operation != null);
var gets = pathItems.Select(pathItem => pathItem.get).Where(operation => operation != null);
var heads = pathItems.Select(pathItem => pathItem.head).Where(operation => operation != null);
var patches = pathItems.Select(pathItem => pathItem.patch).Where(operation => operation != null);
var puts = pathItems.Select(pathItem => pathItem.put).Where(operation => operation != null);
var posts = pathItems.Select(pathItem => pathItem.post).Where(operation => operation != null);
var options = pathItems.Select(pathItem => pathItem.options).Where(operation => operation != null);
var allOperations = deletes.ConcatEvenIfNull(gets)
.ConcatEvenIfNull(heads)
.ConcatEvenIfNull(patches)
.ConcatEvenIfNull(puts)
.ConcatEvenIfNull(posts)
.ConcatEvenIfNull(options)
.ToList();
AppendParameterNamesToOperationId(allOperations);
UniquifyOperationId(allOperations);
}
示例7: Apply
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
{
if (!operation.responses.ContainsKey("default") && operation.responses.ContainsKey("200"))
{
operation.responses.Add("default", operation.responses["200"]);
}
}
示例8: Apply
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
{
// Determine if the operation has the Authorize attribute
var authorizeAttributes = apiDescription
.ActionDescriptor.GetCustomAttributes<AuthorizeAttribute>();
if (!authorizeAttributes.Any())
return;
// Correspond each "Authorize" role to an oauth2 scope
var scopes =
authorizeAttributes
.SelectMany(attr => attr.Roles.Split(','))
.Distinct()
.ToList();
// Initialize the operation.security property if it hasn't already been
if (operation.security == null)
operation.security = new List<IDictionary<string, IEnumerable<string>>>();
var oAuthRequirements = new Dictionary<string, IEnumerable<string>>
{
{ "oauth2", scopes }
};
operation.security.Add(oAuthRequirements);
}
示例9: Apply
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
{
if (operation == null)
{
throw new ArgumentNullException("operation");
}
if (apiDescription == null)
{
throw new ArgumentNullException("apiDescription");
}
// Correspond each "Authorize" action to an oauth2 scope
var authorized = apiDescription.ActionDescriptor.GetFilterPipeline()
.Select(filterInfo => filterInfo.Instance)
.OfType<AuthorizeAttribute>()
.Distinct();
if (authorized.Any())
{
if (operation.security == null)
{
operation.security = new List<IDictionary<string, IEnumerable<string>>>();
}
var requirements = new Dictionary<string, IEnumerable<string>>
{
{ this.provider, new string[] { } }
};
operation.security.Add(requirements);
}
}
示例10: Apply
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
{
var hasAuthorizeAttr = apiDescription.ActionDescriptor.GetFilterPipeline()
.Select(filterInfo => filterInfo.Instance)
.Any(filter => filter is IAuthorizationFilter);
var hasAllowAnonymous = apiDescription.ActionDescriptor.GetCustomAttributes<AllowAnonymousAttribute>().Any();
if (hasAuthorizeAttr && !hasAllowAnonymous)
{
if (operation.parameters == null)
{
operation.parameters = new List<Parameter>();
}
operation.parameters.Add(new Parameter()
{
description = "Authorization token. Used for applying content access restrictions. Use one of the OAuth2 grants to auto-populate this value.",
@in = "header",
name = "Authorization",
required = true,
type = "string",
@default = "bearer "
});
}
}
示例11: Apply
/// <summary>
/// Implement the interace of operation filter
/// </summary>
/// <param name="operation"></param>
/// <param name="schemaRegistry"></param>
/// <param name="apiDescription"></param>
public void Apply(Operation operation, SchemaRegistry schemaRegistry, System.Web.Http.Description.ApiDescription apiDescription)
{
if (operation != null && operation.responses != null && operation.responses.ContainsKey("202"))
{
operation.responses["202"].schema = null;
}
}
示例12: Apply
/// <summary>
///
/// </summary>
/// <param name="swaggerDoc"></param>
/// <param name="schemaRegistry"></param>
/// <param name="apiExplorer"></param>
public void Apply(SwaggerDocument swaggerDoc, SchemaRegistry schemaRegistry, IApiExplorer apiExplorer)
{
IList<string> apilist = new List<string>();
if (swaggerDoc != null && swaggerDoc.paths != null)
{
foreach (System.Collections.Generic.KeyValuePair<string, PathItem> pathitem in swaggerDoc.paths)
{
if (pathitem.Key.Contains("OAuth"))
{
apilist.Add(pathitem.Key);
}
}
}
foreach (string pathitem in apilist)
{
swaggerDoc.paths.Remove(pathitem);
}
if (swaggerDoc != null && swaggerDoc.definitions != null)
{
swaggerDoc.definitions.Remove("TokenResult");
swaggerDoc.definitions.Remove("Object");
}
}
示例13: Apply
public void Apply(Operation operation, SchemaRegistry schemaRegistry, System.Web.Http.Description.ApiDescription apiDescription)
{
// stripping the name
string operationName = operation.operationId;
if (!string.IsNullOrEmpty(operationName))
{
// swashbuckle adds controller name, stripping that
int index = operationName.IndexOf("_", 0);
if (index >= 0 && (index + 1) < operationName.Length)
{
operation.operationId = operationName.Substring(index + 1);
}
}
// operation response change
IDictionary<string, Response> responses = operation.responses;
if (responses != null && !responses.ContainsKey(defaultResponseCode))
{
try
{
string successResponseCode = JsonSwaggerGenerator.GetReturnCodeForSuccess(responses.Keys);
Response successResponse = responses[successResponseCode];
Response defaultResponse = new Response();
defaultResponse.description = Resources.DefaultResponseDescription;
defaultResponse.schema = null;
responses.Add(defaultResponseCode, defaultResponse);
}
catch(InvalidOperationException)
{
throw new Exception("No success code found, not adding default response code");
}
}
}
开发者ID:sudarsanan-krishnan,项目名称:DynamicsCRMConnector,代码行数:35,代码来源:OperationNameAndDefaultResponseFilter.cs
示例14: Apply
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
{
var descriptor = apiDescription.ActionDescriptor as ControllerlessActionDescriptor;
operation.summary = descriptor != null
? this.provider.GetDescription(descriptor.MessageType)
: operation.summary;
}
示例15: FixSchemaReference
private static void FixSchemaReference(SchemaRegistry registry, Schema schema, Type referencedType)
{
Contract.Requires([email protected] != null);
var schemaIdSelector = registry.GetInstanceField<Func<Type, string>>("_schemaIdSelector", true);
[email protected] = "#/definitions/" + schemaIdSelector(referencedType);
}