Skip to content

[Repo Assist] test: add DefinitionPath.Parse unit tests and PreferNullable coverage#370

Merged
sergey-tihon merged 4 commits intomasterfrom
repo-assist/test-definition-path-20260410-71f0ca0589b76902
Apr 11, 2026
Merged

[Repo Assist] test: add DefinitionPath.Parse unit tests and PreferNullable coverage#370
sergey-tihon merged 4 commits intomasterfrom
repo-assist/test-definition-path-20260410-71f0ca0589b76902

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This is an automated pull request from Repo Assist, an AI assistant.

Summary

Adds 21 new unit tests covering two previously-untested areas:

1. DefinitionPath.Parse (new file: v3/Schema.DefinitionPathTests.fs, 16 tests)

DefinitionPath.Parse is the function that splits a JSON Reference path (e.g. #/components/schemas/My.Namespace.TypeName) into a namespace list, a raw type name, and a PascalCase candidate name. It has zero existing tests. The new tests cover:

  • Simple (un-namespaced) names → empty namespace, identity type name
  • PascalCase candidate via nicePascalName
  • One-level namespace extraction (My.Pet["My"], "Pet")
  • Multi-level namespace extraction (2, 3, and 4 levels deep)
  • Names containing hyphens (non-dot separator — no spurious namespace split)
  • Error cases: definition not starting with #/components/schemas/ prefix, Swagger 2 #/definitions/ path

2. PreferNullable=true type mapping (additions to v3/Schema.TypeMappingTests.fs, 5 tests)

When DefinitionCompiler is constructed with provideNullable=true, optional value-type properties should produce Nullable<T> instead of Option<T>. These tests were entirely missing:

  • optional boolean → Nullable<bool>
  • optional integer → Nullable<int32>
  • optional int64 → Nullable<int64>
  • required integer → int32 (unchanged — nullable wrapping is only for optional)
  • optional string → string (reference types are never wrapped, regardless of mode)

3. compilePropertyTypeWith helper (additions to v3/Schema.TestHelpers.fs)

New helper that mirrors compilePropertyType but exposes the provideNullable flag, enabling the PreferNullable tests above and any future tests that need non-default compiler options.

Rationale

DefinitionPath.Parse is called on every $ref encountered in a schema, making it load-bearing code. Adding regression tests protects against future changes that inadvertently alter its namespace-splitting logic. The PreferNullable tests document and protect a user-facing static parameter.

Test Status

✅ Build: succeeded (dotnet build)
✅ Tests: 316/316 passed, 0 failed — up from 295 (21 new tests)
(dotnet tests/SwaggerProvider.Tests/bin/Release/net10.0/SwaggerProvider.Tests.dll)

Generated by 🌈 Repo Assist, see workflow run. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@7ee2b60744abf71b985bead4599640f165edcd93

Add 21 new unit tests:

- v3/Schema.DefinitionPathTests.fs (16 tests): unit-tests for
  DefinitionPath.Parse covering simple names, one- and multi-level
  namespaces, PascalCase candidate generation, names with hyphens,
  and error cases (wrong prefix). DefinitionPath.Parse had no tests
  at all.

- v3/Schema.TypeMappingTests.fs (+5 tests): PreferNullable mode
  tests verifying that optional value types produce Nullable<T>
  instead of Option<T> when provideNullable=true, and that required
  types and reference types are unaffected.

- v3/Schema.TestHelpers.fs: add compilePropertyTypeWith helper that
  exposes the provideNullable parameter to enable the above tests.

Test count: 295 → 316 (all pass).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@sergey-tihon sergey-tihon marked this pull request as ready for review April 11, 2026 08:03
Copilot AI review requested due to automatic review settings April 11, 2026 08:03
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds new unit tests to improve coverage of OpenAPI v3 schema compilation helpers, specifically around $ref definition-path parsing and PreferNullable=true behavior in type mapping.

Changes:

  • Add a new v3 test module covering DefinitionPath.Parse (prefix handling, namespace splitting, and failure cases).
  • Extend v3 type-mapping tests to cover PreferNullable=true for optional value types (Nullable<T> vs Option<T>).
  • Add a new compilePropertyTypeWith helper to compile schemas under non-default DefinitionCompiler options.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
tests/SwaggerProvider.Tests/v3/Schema.TypeMappingTests.fs Adds PreferNullable=true unit tests for optional value-type property mapping.
tests/SwaggerProvider.Tests/v3/Schema.TestHelpers.fs Introduces compilePropertyTypeWith to compile schemas with configurable provideNullable.
tests/SwaggerProvider.Tests/v3/Schema.DefinitionPathTests.fs New test suite validating DefinitionPath.Parse behavior and error cases.
tests/SwaggerProvider.Tests/SwaggerProvider.Tests.fsproj Includes the new Schema.DefinitionPathTests.fs in the test project compile list.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sergey-tihon
Copy link
Copy Markdown
Member

/repo-assist address inline review comments

@github-actions
Copy link
Copy Markdown
Contributor Author

github-actions bot commented Apr 11, 2026

✗ Repo Assist encountered failed, see workflow run.

@sergey-tihon
Copy link
Copy Markdown
Member

@copilot address inline review comments (don't update pr description)

…able assertions, and comment wording

Agent-Logs-Url: https://github.com/fsprojects/SwaggerProvider/sessions/39b1a730-3011-42c1-84c3-eb4a4ce202c3

Co-authored-by: sergey-tihon <1197905+sergey-tihon@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 11, 2026

@copilot address inline review comments (don't update pr description)

Addressed all three inline review comments in commit 9c88958:

  1. compilePropertyTypeWith diagnostic handling — Added the same readResult.Diagnostic.Errors check used in compileV3Schema, including the same error message format and failwithf pattern, so parse errors/warnings surface consistently.

  2. Nullable type assertions — Replaced all three typedefof<Nullable<_>>.MakeGenericType(...) calls with direct typeof<Nullable<bool>>, typeof<Nullable<int32>>, and typeof<Nullable<int64>>.

  3. Misleading comment — Reworded per the suggestion: "The dot before 'my-type' is in the scanned definition-name segment after the prefix; the hyphen stops the scan, so LastIndexOf('.') finds that dot."

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…ia private core helper

Agent-Logs-Url: https://github.com/fsprojects/SwaggerProvider/sessions/2592f70e-57ed-4977-9913-daaaccdd91e4

Co-authored-by: sergey-tihon <1197905+sergey-tihon@users.noreply.github.com>
@sergey-tihon sergey-tihon merged commit 9adfa27 into master Apr 11, 2026
2 checks passed
@sergey-tihon sergey-tihon deleted the repo-assist/test-definition-path-20260410-71f0ca0589b76902 branch April 11, 2026 09:18
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.

3 participants