Skip to content

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

Draft
github-actions[bot] wants to merge 2 commits intomasterfrom
repo-assist/test-definition-path-20260410-71f0ca0589b76902
Draft

[Repo Assist] test: add DefinitionPath.Parse unit tests and PreferNullable coverage#370
github-actions[bot] wants to merge 2 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>
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.

0 participants