cancel
Showing results for 
Search instead for 
Did you mean: 

Validation incoming parameters (in: :body) in rswag specs (Rails)

devpull
Visitor

Validation incoming parameters (in: :body) in rswag specs (Rails)

Hello all!  I have spent a lot of time trying to emplement ability of validation incoming params is rswag specs, my code:

 

# incoming-parameter
params = {
  login: 'www',
  id: 15
}

# test rswag-spec
path '/controller/hello' do
  post('Say Hello!') do
    tags 'users'
      consumes 'application/json'
      produces 'application/json'

      parameter name: :my_params, in: :body, schema: {
        type: :object,
        required: %i[id name],
        properties: {
        id: { type: :string },
        name: { type: :string }
        }
      }  

      response(200, 'successful') do
        # schema '$ref' => '#/components/schemas/UserRegistrationResponse'

        describe 'new user with valid reg_params' do
          let(:my_params) { params }

          run_test! do |response|
            data = JSON.parse(response.body)
            puts "data = #{data}"
          end
        end
     end
  end
end

 

You expecting that incoming params won't pass validation, because id - is an integer, and name field is absent. But that's doesn't matter and test is compliting with success.

 

Can you say what's wrong with my code an why don't work validation of incoming parameters those declarated in rswag docs?

Tags (2)
1 REPLY 1
HKosova
Moderator

Re: Validation incoming parameters (in: :body) in rswag specs (Rails)

Hi @devpull,

rswag is not one of our projects and we don't know it well enough to provide support for it.

Try asking in the rswag issue tracker, hopefully they can help you:

https://github.com/rswag/rswag/issues


Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
New Here?
Join us and watch the welcome video: