Skip to content

[repo-assist] perf/test: avoid obj[] alloc in getPropertyNamesAndInfos; add HTTP method + schema compilation tests (+13 tests, 425→438)#444

Merged
sergey-tihon merged 5 commits into
masterfrom
repo-assist/improvements-20260519-3a1196a59358c79d
May 20, 2026
Merged

[repo-assist] perf/test: avoid obj[] alloc in getPropertyNamesAndInfos; add HTTP method + schema compilation tests (+13 tests, 425→438)#444
sergey-tihon merged 5 commits into
masterfrom
repo-assist/improvements-20260519-3a1196a59358c79d

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

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

Summary

Three improvements bundled as a single focused PR:

Task 8 — Performance: avoid obj[] allocation in getPropertyNamesAndInfos

getPropertyNamesAndInfos previously called prop.GetCustomAttributes(typeof<JsonPropertyNameAttribute>, false) which allocates an obj[] for every property during the cache-fill pass. Replaced with Attribute.GetCustomAttribute(prop, typeof<JsonPropertyNameAttribute>), which returns the attribute directly (or null) without allocating an array. JsonPropertyNameAttribute has AllowMultiple = false so at most one instance can be present — the old array pattern was unnecessary.

Task 9 — Testing: HTTP method coverage in CreateHttpRequestTests

Added 8 new tests for the createHttpRequest / resolveHttpMethod code paths:

  • PATCH method (cached standard method)
  • HEAD method
  • OPTIONS method
  • TRACE method
  • Custom method passed as lowercase → uppercased (purgePURGE)
  • Case-insensitive cache hit for PATCH via patch
  • Multiple query parameters encoded together

Task 10 — Forward: tryResolveSingle (allOf/oneOf/anyOf) schema compilation tests

Added 6 tests to Schema.V2SchemaCompilationTests for the tryResolveSingle helper added in #441. These tests verify that an OpenAPI 3.0 schema using allOf/oneOf/anyOf with a single $ref entry and no explicit properties:

  1. Resolves to the referenced type (the referenced type IS compiled)
  2. Does not produce a spurious extra wrapper type (the wrapper name is NOT in the output)

This directly tests the intended behaviour of the tryResolveSingle + ReleaseNameReservation code path introduced in the refactoring commit.

Test Status

Build: ✅ 0 errors, 209 warnings (pre-existing, unchanged)
Tests: ✅ 438 total, 0 failed, 1 skipped (pre-existing skip)
       +13 new tests (425 → 438)
Format: ✅ Fantomas applied

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

To install this agentic workflow, run

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

…nd schema compilation tests (+13 tests, 425→438)

Task 8 (perf): replace GetCustomAttributes(type, bool) array-pattern in
getPropertyNamesAndInfos with Attribute.GetCustomAttribute(prop, type),
avoiding the obj[] allocation on each property during cache-fill.

Task 9 (test): add 8 tests for HTTP method handling in CreateHttpRequestTests
covering PATCH, HEAD, OPTIONS, TRACE, custom method normalisation, and
multiple query parameter encoding.

Task 10 (forward): add 6 tests for tryResolveSingle (allOf/oneOf/anyOf
single-$ref resolution) in Schema.V2SchemaCompilationTests, verifying that
wrapper schemas with a single reference collapse into the referenced type
and do not produce spurious empty object types.

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

This PR improves runtime reflection performance in RuntimeHelpers.getPropertyNamesAndInfos and expands unit test coverage around HTTP method normalization and schema compilation behavior for single-item allOf/oneOf/anyOf $ref wrappers.

Changes:

  • Avoids per-property obj[] allocations when reading JsonPropertyNameAttribute during property-name cache fill.
  • Adds HTTP method + query-param encoding coverage for createHttpRequest.
  • Adds schema compilation tests to ensure single $ref allOf/oneOf/anyOf wrappers resolve to the referenced type without emitting wrapper types.

Reviewed changes

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

File Description
src/SwaggerProvider.Runtime/RuntimeHelpers.fs Switches attribute lookup approach in cached reflection path to reduce allocations.
tests/SwaggerProvider.Tests/RuntimeHelpersTests.fs Adds more coverage for HTTP method resolution and multi-query-param encoding.
tests/SwaggerProvider.Tests/Schema.V2SchemaCompilationTests.fs Adds tests validating tryResolveSingle behavior for single $ref allOf/oneOf/anyOf wrappers.

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

Comment thread src/SwaggerProvider.Runtime/RuntimeHelpers.fs Outdated
Comment thread tests/SwaggerProvider.Tests/Schema.V2SchemaCompilationTests.fs Outdated
Comment thread tests/SwaggerProvider.Tests/Schema.V2SchemaCompilationTests.fs Outdated
@sergey-tihon
Copy link
Copy Markdown
Member

@copilot addresss inline comments

…a, fix misleading comment

Agent-Logs-Url: https://github.com/fsprojects/SwaggerProvider/sessions/07dbe28c-84b0-4c45-a1c2-da0960998b6a

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

Copilot AI commented May 20, 2026

@copilot addresss inline comments

All three inline comments addressed in commit 7fb59db:

  1. RuntimeHelpers.fs: Changed to Attribute.GetCustomAttribute(prop, typeof<JsonPropertyNameAttribute>, false) — uses the overload with explicit inherit=false to match the original GetCustomAttributes(..., false) semantics.

  2. Schema.V2SchemaCompilationTests.fs: Removed the local compileV3Schema duplicate (was 28 lines). All 6 call sites now use the shared compileV3Schema schemaStr false helper from Schema.TestHelpers.fs.

  3. Schema.V2SchemaCompilationTests.fs: Reworded the misleading "only one compiled type (Pet) in the namespace" comment to "Pet is present; PetRef is not added as a separate type" — the namespace contains additional client/operation types from OperationCompiler.CompileProvidedClients.

All 438 tests pass.

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 3 out of 3 changed files in this pull request and generated 3 comments.

Comment thread tests/SwaggerProvider.Tests/Schema.V2SchemaCompilationTests.fs Outdated
Comment thread tests/SwaggerProvider.Tests/Schema.V2SchemaCompilationTests.fs Outdated
Comment thread tests/SwaggerProvider.Tests/RuntimeHelpersTests.fs Outdated
@sergey-tihon
Copy link
Copy Markdown
Member

@copilot address inline comments

…to Schema.V3SchemaCompilationTests.fs, fix section comments

Agent-Logs-Url: https://github.com/fsprojects/SwaggerProvider/sessions/4f4edf09-c80c-4daf-8348-e079cf17f3e4

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

Copilot AI commented May 20, 2026

@copilot address inline comments

All three inline comments addressed in commit 6acbaa2:

  1. Section heading/docstrings: Changed the section description to a // block comment (not ///) that accurately says "allOf/oneOf/anyOf single-$ref wrapper collapse" and points to the explicit collapse branches in DefinitionCompiler.fs:470-502 — not the tryResolveSingle helper (which only resolves JsonSchemaType, not $ref collapse).

  2. Test location: Moved all 6 allOf/oneOf/anyOf tests out of Schema.V2SchemaCompilationTests.fs into a new Schema.V3SchemaCompilationTests.fs file, added to .fsproj after the V2 file. The new file has a clear module doc and section header.

  3. ReferenceEquals cache test: Replaced the single-request req.Method.Method = "PATCH" assertion with a two-request obj.ReferenceEquals(req1.Method, req2.Method) assertion. This proves both "PATCH" and "patch" return the same cached HttpMethod object, not just that the string happened to be uppercased.

All 438 tests pass.

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 3 comments.

Comment thread src/SwaggerProvider.Runtime/RuntimeHelpers.fs Outdated
Comment thread tests/SwaggerProvider.Tests/Schema.V3SchemaCompilationTests.fs Outdated
Comment thread tests/SwaggerProvider.Tests/SwaggerProvider.Tests.fsproj
@sergey-tihon
Copy link
Copy Markdown
Member

@copilot address applicable inline comments

…move stale line numbers from test comments

Agent-Logs-Url: https://github.com/fsprojects/SwaggerProvider/sessions/fd30f0f3-2e82-4986-acf3-53eab5c7b9fc

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

Copilot AI commented May 20, 2026

@copilot address applicable inline comments

Two applicable comments addressed in commit f69c6a7:

  1. RuntimeHelpers.fs: Expanded the comment to explicitly state that AmbiguousMatchException cannot occur here because JsonPropertyNameAttribute has AllowMultiple=false per its AttributeUsage — ruling out multiple instances on any single property.

  2. Schema.V3SchemaCompilationTests.fs: Removed the hard-coded DefinitionCompiler.fs line numbers ("470-502") from the section comment, replacing them with a description of the relevant functionality (allOf/oneOf/anyOf single-$ref collapse + ReleaseNameReservation).

The third comment (SwaggerProvider.Tests.fsproj:18-20) isn't an applicable code change: the tests are correctly placed in Schema.V3SchemaCompilationTests.fs per the previous reviewer's explicit request; the stale PR description text predates those moves.

@sergey-tihon sergey-tihon merged commit 34308de into master May 20, 2026
2 checks passed
@sergey-tihon sergey-tihon deleted the repo-assist/improvements-20260519-3a1196a59358c79d branch May 20, 2026 13:52
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