in src/Microsoft.Azure.WebJobs.Extensions.OpenApi.Core/Visitors/NullableObjectTypeVisitor.cs [36:87]
public override void Visit(IAcceptor acceptor, KeyValuePair<string, Type> type, NamingStrategy namingStrategy, params Attribute[] attributes)
{
var instance = acceptor as OpenApiSchemaAcceptor;
if (instance.IsNullOrDefault())
{
return;
}
// Gets the schema for the underlying type.
var underlyingType = type.Value.GetUnderlyingType();
var types = new Dictionary<string, Type>()
{
{ type.Key, underlyingType }
};
var schemas = new Dictionary<string, OpenApiSchema>();
var subAcceptor = new OpenApiSchemaAcceptor()
{
Types = types,
Schemas = schemas,
};
subAcceptor.Accept(this.VisitorCollection, namingStrategy);
// Adds the schema for the underlying type.
var name = subAcceptor.Schemas.First().Key;
var schema = subAcceptor.Schemas.First().Value;
schema.Nullable = true;
// Adds the extra properties.
if (attributes.Any())
{
Attribute attr = attributes.OfType<OpenApiPropertyAttribute>().SingleOrDefault();
if (!attr.IsNullOrDefault())
{
schema.Nullable = this.GetOpenApiPropertyNullable(attr as OpenApiPropertyAttribute);
schema.Default = this.GetOpenApiPropertyDefault(attr as OpenApiPropertyAttribute);
schema.Description = this.GetOpenApiPropertyDescription(attr as OpenApiPropertyAttribute);
schema.Deprecated = this.GetOpenApiPropertyDeprecated(attr as OpenApiPropertyAttribute);
}
attr = attributes.OfType<OpenApiSchemaVisibilityAttribute>().SingleOrDefault();
if (!attr.IsNullOrDefault())
{
var extension = new OpenApiString((attr as OpenApiSchemaVisibilityAttribute).Visibility.ToDisplayName());
schema.Extensions.Add("x-ms-visibility", extension);
}
schema.ApplyValidationAttributes(attributes.OfType<ValidationAttribute>());
}
instance.Schemas.Add(name, schema);
}