Skip to content

[Repo Assist] fix: helpful error when Swagger 2.0 schema used with OpenApiClientProvider#350

Closed
github-actions[bot] wants to merge 2 commits intomasterfrom
repo-assist/fix-issue-231-v2-schema-helpful-error-8cce270d3c196b5d
Closed

[Repo Assist] fix: helpful error when Swagger 2.0 schema used with OpenApiClientProvider#350
github-actions[bot] wants to merge 2 commits intomasterfrom
repo-assist/fix-issue-231-v2-schema-helpful-error-8cce270d3c196b5d

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 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.OpenApi can parse both v2 and v3 schemas. After parsing, OpenApiDiagnostic.SpecificationVersion is set to OpenApiSpecVersion.OpenApi2_0 when 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:

if diagnostic.SpecificationVersion = Microsoft.OpenApi.OpenApiSpecVersion.OpenApi2_0 then
    failwithf
        "The schema '%s' is a Swagger 2.0 (OpenAPI v2) specification. \
OpenApiClientProvider supports OpenAPI v3 schemas only. \
For Swagger 2.0 schemas, use SwaggerClientProvider instead:\n    \
type Api = SwaggerClientProvider<\"%s\">"
        schemaPathRaw
        schemaPathRaw

The new error message is clear and tells users exactly what to do.

Trade-offs

  • Breaking: Users who relied on OpenApiClientProvider with 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.
  • No new dependencies: uses OpenApiSpecVersion which is already part of the Microsoft.OpenApi package.

Test Status

  • ✅ Build succeeded: dotnet build SwaggerProvider.sln -c Release — 0 errors, 207 warnings (pre-existing)
  • ✅ All 241 unit tests pass: dotnet tests/SwaggerProvider.Tests/bin/Release/net10.0/SwaggerProvider.Tests.dll
  • ✅ Code formatting verified: dotnet fantomas --check passes

Generated by 🌈 Repo Assist at {run-started}. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@1f672aef974f4246124860fc532f82fe8a93a57e

…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>
@sergey-tihon
Copy link
Copy Markdown
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>
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

An error occurred when parsing the doc comment - cannot parse petstore? seems odd

1 participant