in src/Microsoft.Azure.WebJobs.Extensions.OpenApi.Core/Visitors/ListObjectTypeVisitor.cs [35:115]
public override void Visit(IAcceptor acceptor, KeyValuePair<string, Type> type, NamingStrategy namingStrategy, params Attribute[] attributes)
{
var name = this.Visit(acceptor, name: type.Key, title: null, dataType: "array", dataFormat: null, attributes: attributes);
if (name.IsNullOrWhiteSpace())
{
return;
}
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>()
{
{ underlyingType.GetOpenApiReferenceId(underlyingType.IsOpenApiDictionary(), underlyingType.IsOpenApiArray(), namingStrategy), underlyingType }
};
var schemas = new Dictionary<string, OpenApiSchema>();
OpenApiSchemaAcceptor subAcceptor;
if (!this.visitedTypes.ContainsKey(underlyingType))
{
subAcceptor = new OpenApiSchemaAcceptor()
{
Types = types, RootSchemas = instance.RootSchemas, Schemas = schemas,
};
this.visitedTypes.Add(underlyingType, subAcceptor);
subAcceptor.Accept(this.VisitorCollection, namingStrategy);
}
else
{
subAcceptor = this.visitedTypes[underlyingType];
}
var items = subAcceptor.Schemas.First().Value;
// Forces to remove the title value from the items attribute.
items.Title = null;
// Adds the reference to the schema for the underlying type.
if (this.IsReferential(underlyingType))
{
var reference = new OpenApiReference()
{
Type = ReferenceType.Schema,
Id = underlyingType.GetOpenApiReferenceId(underlyingType.IsOpenApiDictionary(), underlyingType.IsOpenApiArray(), namingStrategy)
};
items.Reference = reference;
}
instance.Schemas[name].Items = items;
// Adds schemas to the root.
var schemasToBeAdded = subAcceptor.Schemas
.Where(p => p.Value.IsOpenApiSchemaObject()
|| p.Value.IsOpenApiSchemaArray()
|| p.Value.IsOpenApiSchemaDictionary()
)
.ToDictionary(p => p.Key, p => p.Value);
if (!schemasToBeAdded.Any())
{
return;
}
foreach (var schema in schemasToBeAdded)
{
if (instance.RootSchemas.ContainsKey(schema.Key))
{
continue;
}
instance.RootSchemas.Add(schema.Key, schema.Value);
}
}