Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove invalid fields when generating oas 3 docs #686

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Eddayy
Copy link

@Eddayy Eddayy commented Oct 20, 2023

Problem

Rswag::Specs::SwaggerFormatter supports default content type when you defined consumes or produces in swagger_doc but this only works for OAS 2 as it adds field that are incompatible with OAS 3

Solution

Remove invalid root fields when generating for OAS 3

This concerns this parts of the OpenAPI Specification:

I remove fields that do not belong in https://spec.openapis.org/oas/v3.1.0#fixed-fields

The changes I made are compatible with:

  • OAS2
  • OAS3
  • OAS3.1

Related Issues

Links to any related issues.

Checklist

  • Added tests
  • Changelog updated
  • Added documentation to README.md
  • Added example of using the enhancement into test-app

Steps to Test or Reproduce

Add produces: or any key in the swagger_docs config, will remove any invalid fields if openapi is version 3

@romanblanco romanblanco added this to the OAS 3.0 compatibility milestone Nov 13, 2023
@joshraker
Copy link

joshraker commented May 17, 2024

For those looking for a workaround in the meantime, I've had success with adding an after(:spec) block to the swagger_helper config

RSpec.configure do |config|
  ...
  config.after(:suite) do
    spec.delete(:consumes)
    spec.delete(:produces)
  end
end

Edit: The suggestion above broke the OpenAPI spec generation. No requestBody blocks were generated.

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.

None yet

3 participants