[Repo Assist] fix: helpful error when Swagger 2.0 schema used with OpenApiClientProvider#350
Closed
github-actions[bot] wants to merge 2 commits intomasterfrom
Closed
Conversation
…vider When a user accidentally uses a Swagger 2.0 (OpenAPI v2) schema URL with OpenApiClientProvider, the error was a generic or confusing parse message. This commit detects the v2 specification version via diagnostic.SpecificationVersion and emits a clear, actionable message pointing to SwaggerClientProvider. Closes #231 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Member
|
we plan to drop swaggerprovider and OpenApiClientProvider will be the only one supported, so we don't want to break usage of V2 schemas is they work with OpenApiClientProvider |
github-actions bot
added a commit
that referenced
this pull request
Apr 1, 2026
…ests Task 9: Add Schema.ArrayAndMapTypeMappingTests.fs covering - required/optional array<T> property type mapping - optional arrays are not wrapped in Option (reference type) - additionalProperties maps to Map<string, T> - array of $ref object types Task 10: Add Schema.V2SchemaCompilationTests.fs verifying that Swagger 2.0 schemas can be parsed and compiled by the v3 DefinitionCompiler/OperationCompiler pipeline via Microsoft.OpenApi. Documents the intended behaviour that OpenApiClientProvider should support both v2 and v3 schemas (per maintainer comment on PR #350). Total: 256 tests pass (was 241 before these additions). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Apr 1, 2026
sergey-tihon
added a commit
that referenced
this pull request
Apr 4, 2026
… compilation tests (#351) * test: add v3 array/map type-mapping tests and v2 schema compilation tests Task 9: Add Schema.ArrayAndMapTypeMappingTests.fs covering - required/optional array<T> property type mapping - optional arrays are not wrapped in Option (reference type) - additionalProperties maps to Map<string, T> - array of $ref object types Task 10: Add Schema.V2SchemaCompilationTests.fs verifying that Swagger 2.0 schemas can be parsed and compiled by the v3 DefinitionCompiler/OperationCompiler pipeline via Microsoft.OpenApi. Documents the intended behaviour that OpenApiClientProvider should support both v2 and v3 schemas (per maintainer comment on PR #350). Total: 256 tests pass (was 241 before these additions). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * ci: trigger checks * fix: review comments --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Sergey Tihon <sergey.tihon@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This PR was created by Repo Assist, an automated AI assistant.
Summary
When a user accidentally uses a Swagger 2.0 (OpenAPI v2) schema URL with
OpenApiClientProvider, the error message was confusing (a generic parse error or an IDE-level "error parsing doc comment" tooltip). This PR adds an explicit, actionable check.Closes #231
Root Cause
Microsoft.OpenApican parse both v2 and v3 schemas. After parsing,OpenApiDiagnostic.SpecificationVersionis set toOpenApiSpecVersion.OpenApi2_0when the schema is Swagger 2.0. Previously, there was no check on this value, so the provider would either produce a confusing parse error or generate an empty/broken type.Fix
Added a guard immediately after schema parsing in
Provider.OpenApiClient.fs:The new error message is clear and tells users exactly what to do.
Trade-offs
OpenApiClientProviderwith v2 schemas (even if it accidentally worked in some cases) will now get a compile-time error. However, those cases were never supported and the behaviour was undefined.OpenApiSpecVersionwhich is already part of theMicrosoft.OpenApipackage.Test Status
dotnet build SwaggerProvider.sln -c Release— 0 errors, 207 warnings (pre-existing)dotnet tests/SwaggerProvider.Tests/bin/Release/net10.0/SwaggerProvider.Tests.dlldotnet fantomas --checkpasses