Rswag: 'Try it out' example does not use the body params

Created on 22 Nov 2019  路  5Comments  路  Source: rswag/rswag

Swaggerizing and running the specs are all fine. But when I go to the Swagger UI, click into the example and click Try it out, hitting execute does not use the body params that have been specified:

image

RSpec:

require 'swagger_helper'

describe 'Users API' do
  path '/api/v1/users' do
    post 'Creates a User' do
      tags 'Users'
      consumes 'application/json'
      produces 'application/json'

      parameter name: :user, in: :body, required: true, schema: {
        type: :object,
        properties: {
          user: {
            type: :object,
            properties: {
              email: { type: :string },
              password: { type: :string }
            },
            required: ['email', 'password']
          }
        },
      }

      response '201', 'User created' do
        let(:user) { { user: { email: '[email protected]', password: 'skylarplease' } } }
        run_test!
      end
    end
  end
end
bug

Most helpful comment

I think this happens because the generated swagger_helper.rb file defaults to OpenAPI 3, and that version replaced the body parameter with requestBody (See: https://swagger.io/docs/specification/describing-request-body/) - At least it was what happened in my case.

I replaced

 openapi: '3.0.1',

with:

swagger: '2.0',

in my swagger_helper.rb and got swagger ui to send the data with the request.

All 5 comments

I think this happens because the generated swagger_helper.rb file defaults to OpenAPI 3, and that version replaced the body parameter with requestBody (See: https://swagger.io/docs/specification/describing-request-body/) - At least it was what happened in my case.

I replaced

 openapi: '3.0.1',

with:

swagger: '2.0',

in my swagger_helper.rb and got swagger ui to send the data with the request.

@idoqo It works for me too. thanks!

I think this happens because the generated swagger_helper.rb file defaults to OpenAPI 3

Yep this was a recent change in prep for me finishing off the OpenAPI 3 changes. Seems I was a bit hasty on that one.

@idoqo thanks you!!. you save me. I did spend time above a weeks for not generate curl and body parameters....

thank you @idoqo! Have been struggling with this for 1/2 a day now. rswag should update their generator so that the default swagger_helper.rb file does not default to openapi: '3.0.1' if they don't fully support it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

anjum-ahmed picture anjum-ahmed  路  6Comments

richthedev picture richthedev  路  5Comments

eric-hemasystems picture eric-hemasystems  路  3Comments

abevoelker picture abevoelker  路  4Comments

PhilippeChab picture PhilippeChab  路  4Comments