The AdditionalTextsProvider filter matches any .yaml/.yml/.json file marked as AdditionalFiles in the consuming project, not just OpenAPI specs:
var provider = context.AdditionalTextsProvider
.Where(file => file.Path.EndsWith(".yaml", StringComparison.OrdinalIgnoreCase) ||
file.Path.EndsWith(".yml", StringComparison.OrdinalIgnoreCase) ||
file.Path.EndsWith(".json", StringComparison.OrdinalIgnoreCase))
.Collect();
Combined with OpenApiDocumentProcessor.ProcessDocument:
return (document.Components?.Schemas ?? throw new InvalidOperationException("Document has no schemas"))
Any unrelated JSON/YAML additional file (e.g. appsettings.json) picked up by a consumer will throw and surface as a generator-crash diagnostic (CS8785), breaking their build.
Suggested fix:
- Require an explicit opt-in (filename convention, e.g.
*.openapi.yaml, or MSBuild item metadata) instead of matching by extension alone.
- Replace thrown exceptions with
context.ReportDiagnostic(...) using a proper DiagnosticDescriptor so a single bad/unrelated file doesn't take down the whole build.
The
AdditionalTextsProviderfilter matches any.yaml/.yml/.jsonfile marked asAdditionalFilesin the consuming project, not just OpenAPI specs:Combined with
OpenApiDocumentProcessor.ProcessDocument:Any unrelated JSON/YAML additional file (e.g.
appsettings.json) picked up by a consumer will throw and surface as a generator-crash diagnostic (CS8785), breaking their build.Suggested fix:
*.openapi.yaml, or MSBuild item metadata) instead of matching by extension alone.context.ReportDiagnostic(...)using a properDiagnosticDescriptorso a single bad/unrelated file doesn't take down the whole build.