本文整理汇总了C#中Swashbuckle.Swagger.SchemaRegistry.GetOrRegister方法的典型用法代码示例。如果您正苦于以下问题:C# SchemaRegistry.GetOrRegister方法的具体用法?C# SchemaRegistry.GetOrRegister怎么用?C# SchemaRegistry.GetOrRegister使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Swashbuckle.Swagger.SchemaRegistry
的用法示例。
在下文中一共展示了SchemaRegistry.GetOrRegister方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Apply
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
{
var errorSchema = schemaRegistry.GetOrRegister(typeof(HttpError));
operation.responses.Add("200", new Response
{
description = "Ok",
schema = errorSchema
});
}
示例2: Apply
/// <summary>
/// Apply function
/// </summary>
/// <param name="operation"></param>
/// <param name="schemaRegistry"></param>
/// <param name="apiDescription"></param>
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
{
var errorSchema = schemaRegistry.GetOrRegister(typeof(ErrorModel));
var err = ErrorModel.Create(Guid.NewGuid(), ErrorCode.Unknown,
"A more technical error message", "A more user friendly error message");
err.SetSystem("ApiName");
// appends a error model to each given error code
foreach (var response in operation.responses.Where(response => !response.Key.StartsWith("2")))
{
response.Value.schema = errorSchema;
response.Value.examples = err;
}
}
示例3: Apply
/// <summary>
/// Apply function
/// </summary>
/// <param name="operation"></param>
/// <param name="schemaRegistry"></param>
/// <param name="apiDescription"></param>
public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
{
var attributes =
apiDescription.ActionDescriptor.ControllerDescriptor.GetCustomAttributes<WiboriAuthorizeAttribute>()
.ToList();
var actionAttributes =
apiDescription.ActionDescriptor.GetCustomAttributes<WiboriAuthorizeAttribute>()
.ToList();
var authorizeAttributes =
apiDescription.ActionDescriptor.ControllerDescriptor.GetCustomAttributes<AuthorizeAttribute>()
.ToList();
var authorizeActionAttributes =
apiDescription.ActionDescriptor.GetCustomAttributes<AuthorizeAttribute>()
.ToList();
attributes.AddRange(actionAttributes);
authorizeAttributes.AddRange(authorizeActionAttributes);
if (!attributes.Any() && !authorizeAttributes.Any())
{
return;
}
operation.parameters = operation.parameters ?? new List<Parameter>();
operation.parameters.Add(new Parameter
{
@in = "header",
name = "Authorization",
description = "OAuth2 bearer token",
type = "string",
required = true
});
if (!operation.responses.ContainsKey("401"))
{
var errorSchema = schemaRegistry.GetOrRegister(typeof(ErrorModel));
operation.responses.Add("401", new Response
{
description = "The bearer token in header Authorization is either invalid or has expired.",
schema = errorSchema
});
}
}
示例4: HandleFromUriObjectParams
private void HandleFromUriObjectParams(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
{
var fromUriObjectParams = operation.parameters
.Where(param => [email protected] == "query" && param.type == null)
.ToArray();
foreach (var objectParam in fromUriObjectParams)
{
var type = apiDescription.ParameterDescriptions
.Single(paramDesc => paramDesc.Name == objectParam.name)
.ParameterDescriptor.ParameterType;
var refSchema = schemaRegistry.GetOrRegister(type);
var schema = schemaRegistry.Definitions[[email protected]("#/definitions/", "")];
ExtractAndAddQueryParams(schema, "", objectParam.required, schemaRegistry, operation.parameters);
operation.parameters.Remove(objectParam);
}
}
示例5: RegisterReferencedTypes
private static void RegisterReferencedTypes(SchemaRegistry registry, IEdmModel edmModel, Schema schema)
{
Contract.Requires(registry != null);
Contract.Requires(schema != null);
while (true)
{
Contract.Assume(schema != null);
var referencedType = schema.GetReferencedType();
if (referencedType != null)
{
registry.GetOrRegister(referencedType);
FixSchemaReference(registry, schema, referencedType);
ApplyEdmModelPropertyNamesToSchema(registry, edmModel, referencedType);
return;
}
if (schema.properties != null && schema.properties.Any())
{
foreach (var property in schema.properties)
{
RegisterReferencedTypes(registry, edmModel, property.Value);
}
return;
}
if (schema.items != null)
{
schema = schema.items;
continue;
}
break;
}
}
示例6: CreateParameter
private Parameter CreateParameter(ApiParameterDescription paramDesc, bool inPath, SchemaRegistry schemaRegistry)
{
var @in = (inPath)
? "path"
: (paramDesc.Source == ApiParameterSource.FromUri) ? "query" : "body";
var parameter = new Parameter
{
name = paramDesc.Name,
@in = @in
};
if (paramDesc.ParameterDescriptor == null)
{
parameter.type = "string";
parameter.required = true;
return parameter;
}
parameter.required = !paramDesc.ParameterDescriptor.IsOptional;
var schema = schemaRegistry.GetOrRegister(paramDesc.ParameterDescriptor.ParameterType);
if ([email protected] == "body")
parameter.schema = schema;
else
parameter.PopulateFrom(schema);
return parameter;
}
示例7: 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)
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;
}
示例8: applyResponseSchemas
/// <summary>
/// Ensures that the 200 response message schmea is present with the correct
/// type and that the 202 response message schema is cleared out
/// </summary>
/// <param name="operation">Metadata for the polling operation of a polling trigger</param>
/// <param name="pollingResponseType">Type of the polling response</param>
/// <param name="schemaRegistry">Current registry of schemas used in the metadata</param>
private static void applyResponseSchemas(Operation operation, Type pollingResponseType, SchemaRegistry schemaRegistry)
{
if (operation.responses == null) operation.responses = new Dictionary<string, Response>();
if (!operation.responses.ContainsKey(Constants.HAPPY_POLL_NO_DATA_RESPONSE_CODE))
{
operation.responses.Add(Constants.HAPPY_POLL_NO_DATA_RESPONSE_CODE, new Response()
{
description = "Successful poll, but no data available"
});
}
operation.responses[Constants.HAPPY_POLL_NO_DATA_RESPONSE_CODE].schema = null;
if (!operation.responses.ContainsKey(Constants.HAPPY_POLL_WITH_DATA_RESPONSE_CODE))
{
operation.responses.Add(Constants.HAPPY_POLL_WITH_DATA_RESPONSE_CODE, new Response()
{
description = "Successful poll with data available"
});
}
operation.responses[Constants.HAPPY_POLL_WITH_DATA_RESPONSE_CODE].schema
= pollingResponseType == null ? null : schemaRegistry.GetOrRegister(pollingResponseType);
}
示例9: HandleGenericODataTypeThatShouldBeUnwrapped
private static Schema HandleGenericODataTypeThatShouldBeUnwrapped(SchemaRegistry registry, IEdmModel edmModel, Type type)
{
var genericArguments = type.GetGenericArguments();
Contract.Assume(genericArguments != null);
var schema = registry.GetOrRegister(genericArguments[0]);
ApplyEdmModelPropertyNamesToSchema(registry, edmModel, genericArguments[0]);
return schema;
}
示例10: ApplyEdmModelPropertyNamesToSchema
private static void ApplyEdmModelPropertyNamesToSchema(SchemaRegistry registry, IEdmModel edmModel, Type type)
{
var entityReference = registry.GetOrRegister(type);
if ([email protected] != null)
{
var definitionKey = [email protected]("#/definitions/", string.Empty);
var schemaDefinition = registry.Definitions[definitionKey];
var edmType = edmModel.GetEdmType(type) as IEdmStructuredType;
if (edmType != null)
{
var edmProperties = new Dictionary<string, Schema>();
foreach (var property in schemaDefinition.properties)
{
var currentProperty = type.GetProperty(property.Key, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
var edmPropertyName = GetEdmPropertyName(currentProperty, edmType);
if (edmPropertyName != null)
{
edmProperties.Add(edmPropertyName, property.Value);
}
}
schemaDefinition.properties = edmProperties;
}
}
}
示例11: CreateOperation
private Operation CreateOperation(ApiDescription apiDesc, SchemaRegistry schemaRegistry)
{
var parameters = apiDesc.ParameterDescriptions
.Select(paramDesc =>
{
string location = GetParameterLocation(apiDesc, paramDesc);
return CreateParameter(location, paramDesc, schemaRegistry);
})
.ToList();
var responses = new Dictionary<string, Response>();
var responseType = apiDesc.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(apiDesc) },
operationId = apiDesc.FriendlyId(),
produces = apiDesc.Produces().ToList(),
consumes = apiDesc.Consumes().ToList(),
parameters = parameters.Any() ? parameters : null, // parameters can be null but not empty
responses = responses,
deprecated = apiDesc.IsObsolete()
};
foreach (var filter in _options.OperationFilters)
{
filter.Apply(operation, schemaRegistry, apiDesc);
}
return operation;
}
示例12: CreateParameter
private Parameter CreateParameter(string location, ApiParameterDescription paramDesc, SchemaRegistry schemaRegistry)
{
var parameter = new Parameter
{
@in = location,
name = paramDesc.Name
};
if (paramDesc.ParameterDescriptor == null)
{
parameter.type = "string";
parameter.required = true;
return parameter;
}
parameter.required = location == "path" || !paramDesc.ParameterDescriptor.IsOptional;
[email protected] = paramDesc.ParameterDescriptor.DefaultValue;
var schema = schemaRegistry.GetOrRegister(paramDesc.ParameterDescriptor.ParameterType);
if ([email protected] == "body")
parameter.schema = schema;
else
parameter.PopulateFrom(schema);
return parameter;
}
示例13: CreateParameter
private Parameter CreateParameter(ApiParameterDescription paramDesc, bool inPath, SchemaRegistry schemaRegistry)
{
var @in = (inPath)
? "path"
: (paramDesc.Source == ApiParameterSource.FromUri) ? "query" : "body";
var parameter = new Parameter
{
name = paramDesc.Name,
@in = @in
};
if (paramDesc.ParameterDescriptor == null)
{
parameter.type = "string";
parameter.required = true;
return parameter;
}
parameter.required = inPath || !paramDesc.ParameterDescriptor.IsOptional;
[email protected] = paramDesc.ParameterDescriptor.DefaultValue;
var schema = schemaRegistry.GetOrRegister(paramDesc.ParameterDescriptor.ParameterType);
var reflectedDescriptor = (ReflectedHttpParameterDescriptor)paramDesc.ParameterDescriptor;
foreach (var attribute in reflectedDescriptor.ParameterInfo.GetCustomAttributes(true))
{
SchemaExtensions.SetSchemaDetails(schema, attribute);
}
//if (paramDesc.ParameterDescriptor.ActionDescriptor != null)
//{
// var actionIgnore = paramDesc.ParameterDescriptor.ActionDescriptor.GetCustomAttributes<SwaggerIgnore>();
// if (actionIgnore != null)
// {
// parameter.ignore = true;
// }
//}
if ([email protected] == "body")
parameter.schema = schema;
else
parameter.PopulateFrom(schema);
return parameter;
}