Skip to content

fix(models): preserve specification extensions in OpenApiPaths and OpenApiResponses copy constructors - #3162

Merged
Vincent Biret (baywet) merged 8 commits into
microsoft:mainfrom
hardikkaurani:fix/preserve-extensions-in-paths-and-responses-copy-constructors
Nov 6, 2026
Merged

Vincent Biret (baywet) merged 8 commits into
microsoft:mainfrom
hardikkaurani:fix/preserve-extensions-in-paths-and-responses-copy-constructors

Conversation

@hardikkaurani

Copy link
Copy Markdown
Contributor

Pull Request

Description

This pull request ensures that specification extensions (Extensions) are preserved when copying OpenApiPaths and OpenApiResponses instances via their copy constructors.

Previously, OpenApiPaths(OpenApiPaths paths) and OpenApiResponses(OpenApiResponses openApiResponses) called base(dictionary: ...) without forwarding the existing instance's Extensions. Because the extensions parameter defaults to null, OpenApiExtensibleDictionary initialized Extensions = [], dropping any specification extensions configured on Paths or Responses.

This also caused OpenApiDocument(OpenApiDocument document) and OpenApiOperation(OpenApiOperation operation) to lose any Paths.Extensions and Responses.Extensions during document or operation cloning.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Other (please describe):

Related Issue(s)

None.

Changes Made

  • Updated OpenApiPaths(OpenApiPaths paths) to pass extensions: paths?.Extensions != null ? new Dictionary<string, IOpenApiExtension>(paths.Extensions) : null to the base constructor.
  • Updated OpenApiResponses(OpenApiResponses openApiResponses) to pass extensions: openApiResponses?.Extensions != null ? new Dictionary<string, IOpenApiExtension>(openApiResponses.Extensions) : null to the base constructor.
  • Updated XML documentation on both copy constructors to clarify that specification extensions are copied into a new dictionary.
  • Added comprehensive unit tests in OpenApiPathsTests and OpenApiResponsesTests covering extensions preservation, dictionary mutation isolation, null parameter handling, and empty extensions handling.
  • Added regression tests in OpenApiDocumentTests and OpenApiOperationTests verifying that cloning an OpenApiDocument preserves Paths.Extensions and cloning an OpenApiOperation preserves Responses.Extensions.

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed
  • All existing tests pass

Local verification:

  • dotnet test test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj -> 1322 passed, 0 failed.
  • dotnet test test/Microsoft.OpenApi.Readers.Tests/Microsoft.OpenApi.Readers.Tests.csproj -> 637 passed, 0 failed.

Checklist

  • My code follows the code style of this project
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Versions applicability

  • My change applies to the version 1.X of the library, if so PR link:
  • My change applies to the version 2.X of the library, if so PR link:
  • My change applies to the version 3.X of the library, if so PR link:
  • I have evaluated the applicability of my change against the other versions above.

See the contributing guidelines for more information about how patches are applied across multiple versions.

Additional Notes

Preserves full backwards compatibility and public API analyzer surface without any breaking changes.

Signed-off-by: Hardik K <hardikkaurani1@gmail.com>
…ions

Signed-off-by: Hardik K <hardikkaurani1@gmail.com>
… extensions

Signed-off-by: Hardik K <hardikkaurani1@gmail.com>
Signed-off-by: Hardik K <hardikkaurani1@gmail.com>
…tensions

Signed-off-by: Hardik K <hardikkaurani1@gmail.com>
…onses extensions

Signed-off-by: Hardik K <hardikkaurani1@gmail.com>
…ths and Responses copy constructors

Signed-off-by: Hardik K <hardikkaurani1@gmail.com>
…ponses copy constructors

Signed-off-by: Hardik K <hardikkaurani1@gmail.com>
@hardikkaurani
Hardik K (hardikkaurani) requested a review from a team as a code owner November 5, 2026 18:25
Copilot AI balanced review requested due to automatic review settings November 5, 2026 18:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@hardikkaurani

Hardik K (hardikkaurani) commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi Vincent Biret (@baywet),

While working with the model copy constructors, I noticed that OpenApiPaths and OpenApiResponses, both deriving from OpenApiExtensibleDictionary<T>, invoked base(dictionary: ...) without passing the existing instance's Extensions.

Since the extensions parameter defaults to null, any specification extensions attached to Paths or Responses were silently dropped during cloning. This also affected copies of parent OpenApiDocument and OpenApiOperation instances.

This PR updates both copy constructors to pass a shallow copy of Extensions to the base class, adds unit and regression tests covering the affected models, and updates the corresponding XML documentation.

Whenever you have a moment, I'd appreciate your review. Thank you!

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified for the changes preserving extensions when copying OpenApiPaths and OpenApiResponses.

No open issues 🎉

Review effort: Balanced

@baywet
Vincent Biret (baywet) merged commit a68f8be into microsoft:main Nov 6, 2026
9 checks passed
Vincent Biret (baywet) added a commit that referenced this pull request Nov 6, 2026
…enApiResponses copy constructors (#3162) (#3163)

* fix(models): preserve extensions in OpenApiPaths copy constructor



* test(models): add unit tests for OpenApiPaths copy constructor extensions



* test(models): verify OpenApiDocument copy constructor preserves Paths extensions



* fix(models): preserve extensions in OpenApiResponses copy constructor



* test(models): add unit tests for OpenApiResponses copy constructor extensions



* test(models): verify OpenApiOperation copy constructor preserves Responses extensions



* test(models): add edge case tests for null and empty extensions in Paths and Responses copy constructors



* docs(models): update XML documentation on OpenApiPaths and OpenApiResponses copy constructors



---------

Signed-off-by: Hardik K <hardikkaurani1@gmail.com>
Co-authored-by: Hardik K <hardikkaurani1@gmail.com>
This was referenced Nov 18, 2026
Roman Bolshakov (rombolshak) pushed a commit to rombolshak/ahlcg that referenced this pull request Nov 19, 2026
Updated
[coverlet.collector](https://github.com/coverlet-coverage/coverlet) from
10.1.0 to 10.1.1.

<details>
<summary>Release notes</summary>

_Sourced from [coverlet.collector's
releases](https://github.com/coverlet-coverage/coverlet/releases)._

## 10.1.1

### Improvements

- Add `IsReachable` to branch points, computed from the method's
control-flow graph, and exclude unreachable branches from
branch-coverage totals and from branch details in Cobertura, LCOV and
OpenCover reports
[#​2056](coverlet-coverage/coverlet#2056) by
@​pcshrosbree
- coverlet.MTP: Narrow Dynamic Exclude Filters for Loaded Assemblies
[#​2069](coverlet-coverage/coverlet#2069)

### Fixed

- Fix Regression Prevent invalid IL from branch trampolines
[#​2067](coverlet-coverage/coverlet#2067)
- Fix Regression coverlet.MTP does not instrument local functions
[#​2046](coverlet-coverage/coverlet#2046)

## Maintenance

- Update NuGet package versions
[#​2050](coverlet-coverage/coverlet#2050)

[Diff between 10.1.0 and
10.1.1](coverlet-coverage/coverlet@v10.1.0...v10.1.1)

Commits viewable in [compare
view](coverlet-coverage/coverlet@v10.1.0...v10.1.1).
</details>

Updated
[JsonPatch.Net](https://github.com/json-everything/json-everything) from
5.0.3 to 5.1.0.

<details>
<summary>Release notes</summary>

_Sourced from [JsonPatch.Net's
releases](https://github.com/json-everything/json-everything/releases)._

No release notes found for this version range.

Commits viewable in [compare
view](https://github.com/json-everything/json-everything/commits).
</details>

Updated
[Meziantou.Analyzer](https://github.com/meziantou/Meziantou.Analyzer)
from 3.0.325 to 3.0.341.

<details>
<summary>Release notes</summary>

_Sourced from [Meziantou.Analyzer's
releases](https://github.com/meziantou/Meziantou.Analyzer/releases)._

## 3.0.341

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.341>

## What's Changed
* MA0036: do not report classes used in a using alias directive by
@​meziantou in meziantou/Meziantou.Analyzer#1822


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.340...3.0.341

## 3.0.340

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.340>

## What's Changed
* MA0182: remove the using directives that reference the removed type by
@​meziantou in meziantou/Meziantou.Analyzer#1817
* MA0038, MA0041: do not report members that use the extension
parameter, nor partial properties by @​meziantou in
meziantou/Meziantou.Analyzer#1819
* MA0190: produce valid code for calls used as statements, method groups
and crefs by @​meziantou in
meziantou/Meziantou.Analyzer#1818


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.339...3.0.340

## 3.0.339

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.339>

## What's Changed
* MA0028, MA0106, MA0124, MA0151, MA0192: do not overflow the stack on
expressions with many operands by @​meziantou in
meziantou/Meziantou.Analyzer#1808
* MA0079: do not report a ConfiguredCancelableAsyncEnumerable created
elsewhere by @​meziantou in
meziantou/Meziantou.Analyzer#1800
* MA0028: do not report the string argument of
StringBuilder.Append(string, int, int) by @​meziantou in
meziantou/Meziantou.Analyzer#1796
* MA0169: do not report comparisons with this by @​meziantou in
meziantou/Meziantou.Analyzer#1784
* MA0004: do not offer a no-op fix for await using with several
declarators by @​meziantou in
meziantou/Meziantou.Analyzer#1807
* MA0040: only look up the values that can provide a token instead of
every name in scope by @​meziantou in
meziantou/Meziantou.Analyzer#1809


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.338...3.0.339

## 3.0.338

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.338>

## What's Changed
* MA0024: report Comparer<string>.Default by @​meziantou in
meziantou/Meziantou.Analyzer#1794
* MA0017: keep the comments of the constructor when making it protected
by @​meziantou in
meziantou/Meziantou.Analyzer#1799


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.337...3.0.338

## 3.0.337

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.337>

## What's Changed
* MA0095: call the explicit IEquatable<T>.Equals implementation when
overriding Equals(object) by @​meziantou in
meziantou/Meziantou.Analyzer#1795


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.336...3.0.337

## 3.0.336

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.336>

## What's Changed
* MA0004: stop the reachability check at the common ancestor statement
by @​meziantou in
meziantou/Meziantou.Analyzer#1791


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.335...3.0.336

## 3.0.335

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.335>

## What's Changed
* MA0061: treat the default value of a type parameter as the default
value of the type argument by @​meziantou in
meziantou/Meziantou.Analyzer#1790


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.334...3.0.335

## 3.0.334

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.334>

## What's Changed
* MA0158: allocate the symbol dictionary lazily and register fewer
actions per operation block by @​meziantou in
meziantou/Meziantou.Analyzer#1798
* MA0190, MA0110: do not suggest a partial property when
GeneratedRegexAttribute cannot be applied to properties by @​meziantou
in meziantou/Meziantou.Analyzer#1801
* MA0004: do not move local functions when fixing await using
declarations by @​meziantou in
meziantou/Meziantou.Analyzer#1803


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.333...3.0.334

## 3.0.333

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.333>

## What's Changed
* MA0036, MA0038, MA0041, MA0053: add the CompilationEnd tag to the
descriptors by @​meziantou in
meziantou/Meziantou.Analyzer#1793
* MA0182: track internal type arguments of public base types and
interfaces by @​meziantou in
meziantou/Meziantou.Analyzer#1792


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.332...3.0.333

## 3.0.332

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.332>

## What's Changed
* MA0004: fix await foreach with a deconstruction by @​meziantou in
meziantou/Meziantou.Analyzer#1797


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.331...3.0.332

## 3.0.331

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.331>

## What's Changed
* MA0002: find the key type of Enumerable methods from their comparer
overload by @​meziantou in
meziantou/Meziantou.Analyzer#1787
* MA0020, MA0030, MA0031, MA0063, MA0098: fix the code fixes of the
static invocation form of LINQ methods by @​meziantou in
meziantou/Meziantou.Analyzer#1788


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.330...3.0.331

## 3.0.330

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.330>

## What's Changed
* MA0004: only count ConfigureAwait(false) as a previous ConfigureAwait
by @​meziantou in
meziantou/Meziantou.Analyzer#1786
* MA0076: do not report interpolated strings converted to IFormattable
by @​meziantou in
meziantou/Meziantou.Analyzer#1783


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.329...3.0.330

## 3.0.329

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.329>

## What's Changed
* Tests: compile with MetadataImportOptions.Public like the command line
compiler by @​meziantou in
meziantou/Meziantou.Analyzer#1810
* MA0102: run the data flow analysis once per member by @​meziantou in
meziantou/Meziantou.Analyzer#1802


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.328...3.0.329

## 3.0.328

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.328>

## What's Changed
* MA0060: report ignored results awaited through ConfigureAwait by
@​meziantou in meziantou/Meziantou.Analyzer#1804
* MA0050: use the method identifier to name the local function of an
explicit interface implementation by @​meziantou in
meziantou/Meziantou.Analyzer#1805
* MA0042: skip the MA0045 analysis when MA0045 is disabled by
@​meziantou in meziantou/Meziantou.Analyzer#1806


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.327...3.0.328

## 3.0.327

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.327>

## What's Changed
* MA0182: do not remove the containing type when fixing a nested enum or
delegate by @​meziantou in
meziantou/Meziantou.Analyzer#1785
* chore(deps): update all dependencies by @​renovate[bot] in
meziantou/Meziantou.Analyzer#1772


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.326...3.0.327

## 3.0.326

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.326>

## What's Changed
* MA0124: replace the reflection on SymbolEqualityComparer with the
public API by @​meziantou in
meziantou/Meziantou.Analyzer#1781


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.325...3.0.326

Commits viewable in [compare
view](meziantou/Meziantou.Analyzer@3.0.325...3.0.341).
</details>

Updated [Microsoft.OpenApi](https://github.com/Microsoft/OpenAPI.NET)
from 2.13.0 to 2.13.1.

<details>
<summary>Release notes</summary>

_Sourced from [Microsoft.OpenApi's
releases](https://github.com/Microsoft/OpenAPI.NET/releases)._

## 2.13.1

##
[2.13.1](microsoft/OpenAPI.NET@v2.13.0...v2.13.1)
(2026-11-16)


### Bug Fixes

* **models:** preserve specification extensions in OpenApiPaths and
OpenApiResponses copy constructors
([#​3162](microsoft/OpenAPI.NET#3162))
([#​3163](microsoft/OpenAPI.NET#3163))
([3301ba7](microsoft/OpenAPI.NET@3301ba7))
* **models:** preserve tag collection types and comparers in copy
constructors
([#​3141](microsoft/OpenAPI.NET#3141))
([#​3145](microsoft/OpenAPI.NET#3145))
([aa5e2b5](microsoft/OpenAPI.NET@aa5e2b5))
* **models:** preserve tag collection types and comparers in
OpenApiDocument copy constructor
([aa5e2b5](microsoft/OpenAPI.NET@aa5e2b5))
* **reader:** backport external reference file loading to v2
([#​3174](microsoft/OpenAPI.NET#3174))
([cb3003a](microsoft/OpenAPI.NET@cb3003a))
* **reader:** backport external reference loading to v2
([cb3003a](microsoft/OpenAPI.NET@cb3003a))
* Support custom tag ordering and null assignment in
OpenApiOperation.Tags
([#​3128](microsoft/OpenAPI.NET#3128))
([#​3133](microsoft/OpenAPI.NET#3133))
([295c89c](microsoft/OpenAPI.NET@295c89c))
* support reinitializing OpenApiOperation.Tags to null and custom
comparers
([#​3116](microsoft/OpenAPI.NET#3116))
([#​3142](microsoft/OpenAPI.NET#3142))
([9cfcdd2](microsoft/OpenAPI.NET@9cfcdd2))
* **v2:** map OpenAPI 2.0 response schema type file to binary format
([#​3150](microsoft/OpenAPI.NET#3150))
([#​3151](microsoft/OpenAPI.NET#3151))
([4cf52e1](microsoft/OpenAPI.NET@4cf52e1))
* **v3:** retain full JSON pointer path on OpenAPI 3.0 schema references
([#​3155](microsoft/OpenAPI.NET#3155))
([#​3170](microsoft/OpenAPI.NET#3170))
([16969bc](microsoft/OpenAPI.NET@16969bc))

Commits viewable in [compare
view](microsoft/OpenAPI.NET@v2.13.0...v2.13.1).
</details>

Updated [Scalar.AspNetCore](https://github.com/scalar/scalar) from
2.20.0 to 2.21.0.

<details>
<summary>Release notes</summary>

_Sourced from [Scalar.AspNetCore's
releases](https://github.com/scalar/scalar/releases)._

No release notes found for this version range.

Commits viewable in [compare
view](https://github.com/scalar/scalar/commits).
</details>

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore <dependency name> major version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's major version (unless you unignore this specific
dependency's major version or upgrade to it yourself)
- `@dependabot ignore <dependency name> minor version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's minor version (unless you unignore this specific
dependency's minor version or upgrade to it yourself)
- `@dependabot ignore <dependency name>` will close this group update PR
and stop Dependabot creating any more for the specific dependency
(unless you unignore this specific dependency or upgrade to it yourself)
- `@dependabot unignore <dependency name>` will remove all of the ignore
conditions of the specified dependency
- `@dependabot unignore <dependency name> <ignore condition>` will
remove the ignore condition of the specified dependency and ignore
conditions


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants