Closed PARAIPAN9 closed 2 months ago
I have a question because I'm a bit confused about what to do after the creation of the wrapper. Should we use the wrapper in place of the extensions from DiagnosticCollector?
I think DiagnosticCollector
's emit
method should become throwing, and then create a new concrete collector implementation that looks something like this:
struct ErrorThrowingDiagnosticCollector: DiagnosticCollector {
var upstream: any DiagnosticCollector
func emit(_ diagnostic: Diagnostic) throws {
upstream.emit(diagnostic)
if diagnostic.severity == .error { throw diagnostic }
}
}
And then use this collector by default, wrapping today's collector.
I think
DiagnosticCollector
'semit
method should become throwing, and then create a new concrete collector implementation that looks something like this:struct ErrorThrowingDiagnosticCollector: DiagnosticCollector { var upstream: any DiagnosticCollector func emit(_ diagnostic: Diagnostic) throws { upstream.emit(diagnostic) if diagnostic.severity == .error { throw diagnostic } } }
And then use this collector by default, wrapping today's collector.
It makes sense, perfect!!
@swift-server-bot test this please
Ok the code looks good, would you be able to add one test that constructs the pipeline with a malformed input and ends up throwing the error? Just to verify that it's really working?
Sure.
@swift-server-bot test this please
Got some build failures on Linux:
/code/Tests/OpenAPIGeneratorTests/Test_GenerateOptions.swift:38:34: error: cannot call value of non-function type 'String'
let arguments = [docPath.path(), "--config", configPath.path]
^ ~~
/code/Tests/OpenAPIGeneratorTests/Test_GenerateOptions.swift:42:94: error: 'nil' requires a contextual type
try await generator.runGenerator(outputDirectory: outputDirectory, pluginSource: nil, isDryRun: false)
You can fix the first one by using docPath.path
(the property) instead. For the second, just pass the "build plugin" plugin source case.
@swift-server-bot test this please
** Running /code/scripts/check-license-headers.sh...
** ERROR: Unsupported file extension for file (exclude or update this script): Tests/OpenAPIGeneratorTests/Resources/Docs/malformed-openapi.yaml
You'll need to add the file to the license check ignore list.
Hmm this actually breaks 5.9.0, because it creates a dependency of a test target on an executable target. https://ci.swiftserver.group/job/swift-openapi-generator-swift590-prb/246/console
To fix this, you'll need to start depending on _OpenAPIGeneratorCore
instead of swift-openapi-generator
, and move _YamlFileDiagnosticsCollector
to _OpenAPIGeneratorCore
, and create a method called e.g. preparedDiagnosticsCollector(...) -> DiagnosticCollector & Sendable
that lives in _OpenAPIGeneratorCore
. Then just test that method, and call the method from the swift-openapi-generator
code.
I don't think we'll be able to make the new dependency work otherwise.
@swift-server-bot test this please
@swift-server-bot test this please
@swift-server-bot test this please
@PARAIPAN9 The CI is happy, but I believe we still need to move the remaining diagnostic collection code into the new prepare...
function, so that it's called from the CLI and also from tests. Right now we're still re-creating the collectors using different code in the CLI vs the tests.
Motivation
Modifications
ErrorThrowingDiagnosticCollector
wrapper collector.Result
ErrorThrowingDiagnosticCollector
throws an error when a diagnostic with severity.error
is emited.Test Plan