[Repo Assist] fix: preserve declared properties when schema has both properties and additionalProperties#383
Merged
sergey-tihon merged 2 commits intomasterfrom Apr 16, 2026
Conversation
…alProperties When a schema object defines both `properties` and `additionalProperties`, the compiler previously treated the type as a plain dictionary (Map<string, T>) and silently discarded all the explicitly declared properties. The fix adds a guard so that the Map path only fires when the schema object has NO explicitly declared properties. When both are present the type falls through to compileNewObject(), which produces a proper provided type with all declared properties. This is a better approximation than losing the named properties entirely; the additionalProperties typing is not captured (as before), which is an acceptable trade-off given the current architecture. A regression test is added to Schema.ArrayAndMapTypeMappingTests.fs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes an OpenAPI schema compilation bug where type: object schemas that define both properties and additionalProperties were incorrectly compiled as Map<string, T>, dropping explicitly declared properties.
Changes:
- Tightened the “dictionary/Map” guard in
DefinitionCompiler.fsto only apply when no explicitpropertiesare declared. - Added a regression test ensuring mixed
properties+additionalPropertiesschemas compile to an object type and preserve declared properties.
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 |
Prevents the dictionary compilation path when properties are present, preserving named fields. |
tests/SwaggerProvider.Tests/Schema.ArrayAndMapTypeMappingTests.fs |
Adds regression coverage for the mixed object schema case to avoid future regressions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
7 tasks
github-actions Bot
added a commit
that referenced
this pull request
Apr 18, 2026
Capture the 9 PRs merged since beta01 (April 14 – April 18): - fix: preserve properties+additionalProperties (#383) - refactor: CallAsync returns HttpResponseMessage (#385) - eng: remove stale YamlDotNet dependency (#386) - test: +18 OperationCompiler tests (#380, #386) - docs: README and VitePress site updates (#379, #382) - ci: Dependabot action bumps (#387-#390) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
sergey-tihon
pushed a commit
that referenced
this pull request
Apr 19, 2026
* docs: add 4.0.0-beta02 release notes entry Capture the 9 PRs merged since beta01 (April 14 – April 18): - fix: preserve properties+additionalProperties (#383) - refactor: CallAsync returns HttpResponseMessage (#385) - eng: remove stale YamlDotNet dependency (#386) - test: +18 OperationCompiler tests (#380, #386) - docs: README and VitePress site updates (#379, #382) - ci: Dependabot action bumps (#387-#390) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * ci: trigger checks --------- 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This PR was created by Repo Assist, an automated AI assistant.
Summary
Fixes a bug where an OpenAPI schema object defining both
propertiesandadditionalPropertieswas compiled as a plainMap<string, T>, silently discarding all the explicitly declared named properties.Root Cause
In
DefinitionCompiler.fs, the guard for the dictionary path was:This condition fired whenever
additionalPropertieswas present, regardless of whether the schema also had explicitproperties. As a result, a schema like:would produce
Map<string, int>and theNameproperty would be inaccessible.Fix
Added
&& (schemaObj.Properties |> isNull || schemaObj.Properties.Count = 0)to the guard, so the Map path is only taken when no explicit properties are declared. When both are present, the type falls through tocompileNewObject(), which correctly produces a provided type with all declared properties.This matches the pattern already used for the
allOf/oneOf/anyOfsingle-reference cases (which also guard onProperties.Count = 0).Trade-offs
The
additionalPropertiestyping is not surfaced for the mixed case (same as before, and a known limitation of the current architecture). The named properties are now accessible via the generated type, which is the more useful outcome.Test Status
SwaggerProvider.Tests)object with properties and additionalProperties compiles to object type not Mapdotnet fantomas --check