Skip to content

fix(v2): map OpenAPI 2.0 response schema type file to binary format - #3150

Merged
Vincent Biret (baywet) merged 5 commits into
microsoft:mainfrom
hardikkaurani:fix/v2-schema-type-file-binary-format
Oct 27, 2026
Merged

Vincent Biret (baywet) merged 5 commits into
microsoft:mainfrom
hardikkaurani:fix/v2-schema-type-file-binary-format

Conversation

@hardikkaurani

Copy link
Copy Markdown
Contributor

Summary of Changes

Resolves #3149.

In OpenAPI 2.0, the Response Object specifies:

"As an extension to the Schema Object, its root type value may also be "file". This SHOULD be accompanied by a relevant produces mime-type."

While OpenApiParameterDeserializer already maps type: file to Type = JsonSchemaType.String and Format = "binary", OpenApiSchemaDeserializer previously omitted setting Format = "binary" when type: file was encountered. As a result, OpenAPI 2.0 response schemas returning files were deserialized into plain strings without format metadata.

This PR adds:

  1. Format = "binary" assignment when type equals "file" (case-insensitive) in OpenApiSchemaDeserializer, matching OpenApiParameterDeserializer.
  2. Unit tests in OpenApiSchemaTests.cs verifying both direct schema parsing and response object schema resolution for type: file.

Verification

  • Tested schema deserialization mapping type: file -> JsonSchemaType.String with Format = "binary".
  • Tested response object deserialization ensuring content schema format is "binary".

@hardikkaurani
Hardik K (hardikkaurani) requested a review from a team as a code owner October 27, 2026 08:47
Copilot AI balanced review requested due to automatic review settings October 27, 2026 08:47

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.

@hardikkaurani

Copy link
Copy Markdown
Contributor Author

Hi Vincent Biret (@baywet),

This PR addresses #3149 by bringing schema deserialization in OpenAPI 2.0 into alignment with parameter deserialization:

  1. OpenAPI 2.0 Response Schema type: file: Per the OpenAPI 2.0 Response Object specification, the schema root type may be "file". In OpenApiParameterDeserializer, type: file was already mapped to type: string with format: "binary", but OpenApiSchemaDeserializer previously omitted setting Format = "binary".
  2. Parity: Added the case-insensitive "file" check in OpenApiSchemaDeserializer to set Format = "binary".
  3. Tests: Added unit tests in OpenApiSchemaTests.cs validating direct schema parsing as well as end-to-end response schema loading (IOpenApiResponse).

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.

🟡 Changes recommended

The new response test bypasses media-type processing, leaving Content null and causing its assertion to fail.

1 open issue

Review effort: Balanced

Comment thread test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiSchemaTests.cs Outdated
Copilot AI balanced review requested due to automatic review settings October 27, 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.

@hardikkaurani

Copy link
Copy Markdown
Contributor Author

Hi Vincent Biret (@baywet),

I've pushed an update addressing the failing response schema test in CI.

In OpenAPI 2.0, response content media types are synthesized during operation- or document-level parsing via ProcessProduces matching against produces. The previous integration test was invoking LoadResponse in isolation, leaving response.Content unpopulated. The test now parses an enclosing operation with an explicit produces: ["application/octet-stream"], validating that ProcessProduces correctly populates response.Content and assigns Type = JsonSchemaType.String with Format = "binary".

Ready for your review when you have a moment.

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 change preserving binary format metadata in OpenAPI 2.0 file response schemas.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@baywet
Vincent Biret (baywet) merged commit e41f0e8 into microsoft:main Oct 27, 2026
9 checks passed
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.

OpenAPI 2.0 response schema type: file is read as a plain string (format: binary is set only for parameters)

3 participants