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

Improving generation of OAS3.0 requestBody from parameters #723

Open
wants to merge 10 commits into
base: v3
Choose a base branch
from

Conversation

stevegeek
Copy link

Problem / Solution

The handling of path parameters does not currently generate OAS3.0 requestBody correctly in some cases. This PR proposes a refactoring and updates to SwaggerFormatter to improve translation of the DSL defined parameters.

It takes the approach that any parameter defined as in: :body is handled differently to parameters that are in: :formData. A request can only have a single body parameter but can have multiple formData parameters.

It also adds support for translating a :fileparameter to the new OAS3.0 schema and some tests for the http bearer security schema.

I started this as I wanted to specify parameter for multipart requestBody (including file upload with multiple possible content types) and ended up making these changes so far.

This concerns this parts of the OpenAPI Specification:

Note that file upload definitions improved in OAS3.1 but this PR does not yet attempt to support that

The changes I made are compatible with:

  • OAS3
  • OAS3.1

Checklist

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

Thanks so much for all the work on rswag over the years, its great!

# There can only be 1 body parameter in Swagger 2.0, so while in OAS3 we interpret
# body parameters as formData, only consider the first body we encounter.
schema_param = parameters.find { |p| p[:schema] if p[:in] == :body }
parse_body_parameter(endpoint, schema_param, mime_list) if schema_param
Copy link
Member

Choose a reason for hiding this comment

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

@stevegeek, the Swagger 2.0 support is being dropped in this branch.
It seems to me that the parse_body_parameter function can be dropped.

@romanblanco romanblanco added this to the Gem 3.0.0 milestone Jan 29, 2024
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

2 participants