Skip to content

fix: allow the file type in OpenAPI 2.0 response schemas - #3255

Merged
Daryna-del merged 5 commits into
Redocly:mainfrom
HawkForge:fix/oas2-file-response-schema
Oct 19, 2026
Merged

Daryna-del merged 5 commits into
Redocly:mainfrom
HawkForge:fix/oas2-file-response-schema

Conversation

@HawkForge

@HawkForge HawkForge commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

What/Why/How?

The OpenAPI 2.0 spec allows type: file in the schema of a Response Object ("As an extension to the Schema Object, its root type value may also be "file"").
The struct rule rejected it because the OAS 2 Schema node type only allows object, array, string, number, integer, boolean, and null for type.

This adds file to that enum in packages/core/src/types/oas2.ts.
Responses and nested schemas share the same Schema node type, so file is now accepted at any depth, not only at the root of a response schema.
That matches how the enum already accepts null, which OAS 2 does not define either. A separate node type for the response schema root would keep other rules from visiting it as a Schema.

Reference

Fixes #540. Thanks @thejan2009 for the report.

Testing

Added a case to packages/core/src/rules/oas2/__tests__/struct/operation.test.ts with a 200 response whose schema is type: file.
It fails without the change (the type can be one of the following only... error at #/paths/~1download/get/responses/200/schema/type) and passes with it.
npm run unit -- packages/core/src/rules --coverage=false passes (705 tests).

Screenshots (optional)

Check yourself

  • This PR follows the contributing guide
  • All new/updated code is covered by tests
  • Core code changed? - Tested with other Redocly products (internal contributions only)
  • New package installed? - Tested in different environments (browser/node)
  • Documentation update has been considered

Security

  • The security impact of the change has been considered
  • Code follows company security practices and guidelines

Note

Low Risk
Narrow validation-schema change with a regression test; no auth, runtime API, or data-handling impact.

Overview
Fixes false positives from the struct rule on valid Swagger 2.0 specs that declare type: file on a response schema (allowed by the spec for file/binary responses).

The OAS 2 Schema node type in packages/core/src/types/oas2.ts now includes file in the allowed values for type, aligning response schemas with parameter types that already accepted file. A struct test covers a GET /download response with schema.type: file and expects no lint errors. A patch changeset notes the fix for @redocly/openapi-core and @redocly/cli.

Reviewed by Cursor Bugbot for commit 8b95f63. Configure here.

@HawkForge
HawkForge requested review from a team as code owners October 15, 2026 11:27
@changeset-bot

changeset-bot Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: cfc814e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@redocly/openapi-core Patch
@redocly/cli Patch
@redocly/client-generator Patch
@redocly/recheck Patch
@redocly/respect-core Patch
@redocly/reunite-integration Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Comment thread .changeset/swagger-file-response-schema.md Outdated
@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Performance Benchmark (Lower is Faster)

CLI Version Bundle Lint Check Config
latest ▓░░░░░░░░░░ 1.01x ± 0.01 ▓░░░░░░░░░░ 1.01x ± 0.01 ▓░░░░░░░░░░ 1.00x
next ▓░░░░░░░░░░ 1.00x ▓░░░░░░░░░░ 1.00x ▓░░░░░░░░░░ 1.02x ± 0.02

@Daryna-del
Daryna-del merged commit 0ad7b0b into Redocly:main Oct 19, 2026
52 checks passed
@Daryna-del

Copy link
Copy Markdown
Contributor

@HawkForge
Thanks a lot for the contribution!

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.

file shoud be an accepted primitive data type in swagger 2.0 spec

3 participants