in tools/code/publisher/ApiDiagnostic.cs [135:178]
public static FindApiDiagnosticDto GetFindApiDiagnosticDto(IServiceProvider provider)
{
var serviceDirectory = provider.GetRequiredService<ManagementServiceDirectory>();
var tryGetFileContents = provider.GetRequiredService<TryGetFileContents>();
var configurationJson = provider.GetRequiredService<ConfigurationJson>();
return async (name, apiName, cancellationToken) =>
{
var informationFile = ApiDiagnosticInformationFile.From(name, apiName, serviceDirectory);
var contentsOption = await tryGetFileContents(informationFile.ToFileInfo(), cancellationToken);
return from contents in contentsOption
let dto = contents.ToObjectFromJson<ApiDiagnosticDto>()
select overrideDto(dto, name, apiName);
};
ApiDiagnosticDto overrideDto(ApiDiagnosticDto dto, ApiDiagnosticName name, ApiName apiName)
{
var diagnosticSectionOption =
// Get the apis section from the configuration json
from apis in configurationJson.Value
.TryGetJsonArrayProperty("apis")
.ToOption()
// Get the API with the specified name
from api in apis.PickJsonObjects()
.Where(api => api.TryGetStringProperty("name")
.Where(name => name.Equals(apiName.ToString(), StringComparison.OrdinalIgnoreCase))
.Any())
.HeadOrNone()
// Get the diagnostics section from the API
from diagnostics in api.TryGetJsonArrayProperty("diagnostics")
.ToOption()
// Get the diagnostic with the specified name
from diagnostic in diagnostics.PickJsonObjects()
.Where(diagnostic => diagnostic.TryGetStringProperty("name")
.Where(name => name.Equals(name.ToString(), StringComparison.OrdinalIgnoreCase))
.Any())
.HeadOrNone()
select diagnostic;
return diagnosticSectionOption.Map(json => OverrideDtoFactory.Override(dto, json))
.IfNone(dto);
}
}