Skip to content

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

Open
Hardik K (hardikkaurani) wants to merge 8 commits into
microsoft:mainfrom
hardikkaurani:fix/preserve-extensions-in-paths-and-responses-copy-constructors
Open

Hardik K (hardikkaurani) wants to merge 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!

This branch has not been deployed

No deployments
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.

2 participants