Skip to content

Conversation

@mdaneri
Copy link
Contributor

@mdaneri mdaneri commented Jan 21, 2026

Pull Request

Description

Introduce a shared abstraction for OpenAPI elements that expose a Content map, enabling generic helpers and reducing duplication across the model surface.

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)

Fixes #2677

Changes Made

  • Added IOpenApiContentElement / IOpenApiReadOnlyContentElement to represent the shared Content capability
  • Updated IOpenApiResponse, IOpenApiRequestBody, IOpenApiParameter, and IOpenApiHeader to inherit the shared interface
  • Updated corresponding model classes to implement the writable interface

Testing

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

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.

Additional Notes

None

@mdaneri mdaneri requested a review from a team as a code owner January 21, 2026 14:39
baywet
baywet previously approved these changes Jan 21, 2026
Copy link
Member

@baywet baywet left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution!
A couple of minor suggestions

@mdaneri
Copy link
Contributor Author

mdaneri commented Jan 21, 2026

@baywet I'm sure that you already know but the tests are failing on Windows due to differences in newline formats, specifically between CRLF and LF

baywet
baywet previously approved these changes Jan 21, 2026
Copy link
Member

@baywet baywet left a comment

Choose a reason for hiding this comment

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

Thank you for making the changes!

@baywet
Copy link
Member

baywet commented Jan 21, 2026

@mdaneri do you mean the unit tests? or a formatting issue with the source code?

@mdaneri
Copy link
Contributor Author

mdaneri commented Jan 21, 2026

@mdaneri do you mean the unit tests? or a formatting issue with the source code?

xunit tests 5 of 6 of them are failing on windows

@mdaneri
Copy link
Contributor Author

mdaneri commented Jan 21, 2026

for example,

Assert.Equal() Failure: Strings differ
                         ↓ (pos 14)
Expected: "swagger: '2.0'\ninfo:\n  version: 1.0.0\npat"···
Actual:   "swagger: '2.0'\r\ninfo:\r\n  version: 1.0.0\r\n"···
                         ↑ (pos 14)
at Microsoft.OpenApi.Tests.Models.OpenApiDocumentTests.SerializeSimpleDocumentWithTopLevelReferencingComponentsAsYamlV2Works() (file:///c%3A/Users/m_dan/Documents/GitHub/kestrun/OpenAPI.NET/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs#L1466,0)

@mdaneri
Copy link
Contributor Author

mdaneri commented Jan 21, 2026

I think it's an issue with my environment I force windows to use \n only not \r\n

baywet
baywet previously approved these changes Jan 21, 2026
@baywet baywet enabled auto-merge (squash) January 21, 2026 15:32
@baywet
Copy link
Member

baywet commented Jan 21, 2026

@mdaneri the public API export needs to be refreshed, would you mind pushing that latest change please?

auto-merge was automatically disabled January 21, 2026 16:16

Head branch was pushed to by a user without write access

@baywet baywet enabled auto-merge (squash) January 21, 2026 16:29
@baywet baywet merged commit 9e13b25 into microsoft:main Jan 21, 2026
16 checks passed
baywet added a commit that referenced this pull request Jan 21, 2026
feat(models): add shared Content interface

* Update src/Microsoft.OpenApi/Models/Interfaces/IOpenApiContentElement.cs

Co-authored-by: Vincent Biret <[email protected]>

* Update src/Microsoft.OpenApi/Models/Interfaces/IOpenApiContentElement.cs

Co-authored-by: Vincent Biret <[email protected]>

* Update src/Microsoft.OpenApi/Models/OpenApiHeader.cs

Co-authored-by: Vincent Biret <[email protected]>

* Update src/Microsoft.OpenApi/Models/OpenApiResponse.cs

Co-authored-by: Vincent Biret <[email protected]>

* Remove inheritance from IOpenApiReadOnlyContentElement

revert commit 7758a81

* Update src/Microsoft.OpenApi/Models/Interfaces/IOpenApiContentElement.cs

Co-authored-by: Vincent Biret <[email protected]>

* test(publicapi): approve content interface surface

---------

Co-authored-by: Vincent Biret <[email protected]>
Signed-off-by: Vincent Biret <[email protected]>
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.

Several OpenAPI model types in **Microsoft.OpenApi** expose a Content property with the same shape:

2 participants