Skip to content

[repo-assist] refactor+test: extract compileSingleRefOrNewObject helper; add text/plain body, octet-stream response, path-level param tests (+ [Content truncated due to length]#452

Open
github-actions[bot] wants to merge 3 commits into
masterfrom
repo-assist/improve-defcomp-refactor-test-ops-20260525-8f33b351bcedd951
Open

[repo-assist] refactor+test: extract compileSingleRefOrNewObject helper; add text/plain body, octet-stream response, path-level param tests (+ [Content truncated due to length]#452
github-actions[bot] wants to merge 3 commits into
masterfrom
repo-assist/improve-defcomp-refactor-test-ops-20260525-8f33b351bcedd951

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This PR was created by Repo Assist, an automated AI assistant.

Summary

Two changes in one PR: a targeted refactoring in DefinitionCompiler.fs and 9 new unit tests.

Task 5 — Refactor: extract compileSingleRefOrNewObject helper

compileBySchema contained three match arms for allOf/oneOf/anyOf single-$ref collapse that each had an identical 4-line inner match expression:

match schemas.[0] with
| :? OpenApiSchemaReference as schemaRef when not(isNull schemaRef.Reference) ->
    ns.ReleaseNameReservation tyName
    compileByPath <| getFullPath schemaRef.Reference.Id
| _ -> compileNewObject()

This is now extracted into a local compileSingleRefOrNewObject helper. The guards and semantics are unchanged — each arm still fires under the same conditions as before. The result is ~18 fewer lines of duplicated code and a clearer signal that the three arms share the same collapsing logic.

Task 10 — Tests: three untested OperationCompiler behaviours

Scenario What's tested
text/plain request body Method generates; body param is named textPlain; CT is last
application/octet-stream response Method generates; return type is Task<IO.Stream>; CT is only param
Path-level parameters (on PathItem) userId inherited by both GET and POST operations on the same path

These cover real-world API patterns (file download, plain-text echo, resource-scoped sub-collections) that were previously exercised by integration tests only.

Test Status

Total: 474, Errors: 0, Failed: 0, Skipped: 1, Time: 1.087s

All 474 tests pass (465 before → 474 after). Format check passes (dotnet fantomas --check).

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

To install this agentic workflow, run

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

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

To install this agentic workflow, run

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

…lain body, octet-stream response, path-level param tests (+9 tests, 465→474)

Task 5: Extract the three identical allOf/oneOf/anyOf single-$ref collapse
match arm bodies into a shared compileSingleRefOrNewObject local helper in
DefinitionCompiler.compileBySchema. The semantics are unchanged — each of the
three guards fires under the same conditions as before, but the 4-line inner
match expression is replaced by a single call. This removes ~18 lines of
duplicated code while keeping the guard conditions explicit and separate.

Task 10: Add 9 unit tests covering three previously untested OperationCompiler
behaviours:
- text/plain request body → parameter named "textPlain"
- application/octet-stream response → return type Task<IO.Stream>
- Path-level parameters on PathItem → inherited by all operations on that path

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@sergey-tihon sergey-tihon marked this pull request as ready for review May 25, 2026 20:16
Copilot AI review requested due to automatic review settings May 25, 2026 20:16
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

Refactors three duplicated match arms in DefinitionCompiler.compileBySchema into a single local helper compileSingleRefOrNewObject, and adds nine new unit tests in Schema.OperationCompilationTests.fs covering text/plain request bodies, application/octet-stream responses, and path-level (PathItem-inherited) parameters.

Changes:

  • Extract identical 4-line $ref-collapse logic from allOf/oneOf/anyOf arms into a local helper.
  • Add tests for text/plain request body shape (method, parameter name, CancellationToken position).
  • Add tests for octet-stream response (Task<IO.Stream> return type) and path-level parameter inheritance across GET/POST.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/SwaggerProvider.DesignTime/DefinitionCompiler.fs Introduce compileSingleRefOrNewObject helper and use it in the three single-$ref collapse arms.
tests/SwaggerProvider.Tests/Schema.OperationCompilationTests.fs Add 9 tests covering text/plain bodies, octet-stream responses, and path-level parameters.

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

@sergey-tihon
Copy link
Copy Markdown
Member

@copilot fix the build

Copy link
Copy Markdown
Contributor

Copilot AI commented May 26, 2026

@copilot fix the build

I pushed a build-fix commit e88ebf5 that switches generated property accessors to typed field expressions (Expr.FieldGet/Expr.FieldSet) instead of unchecked variants in DefinitionCompiler. This is now validated locally with format check + 474 unit tests passing, and automated review/CodeQL checks are clean.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • petstore.swagger.io
    • Triggering command: /usr/share/dotnet/dotnet /usr/share/dotnet/dotnet /usr/share/dotnet/sdk/10.0.300/FSharp/fsc.dll @/tmp/MSBuildTempUZB569/tmp6fca80bfc966468a8cd66035ce2fec65.rsp (dns block)
    • Triggering command: /usr/share/dotnet/dotnet /usr/share/dotnet/dotnet /usr/share/dotnet/sdk/10.0.300/FSharp/fsc.dll @/tmp/MSBuildTempU0djT9/tmp6f1fe6f60096479d9eafe70a3941957b.rsp (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested a review from sergey-tihon May 26, 2026 06:12
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