Apipie / apipie-rails

Ruby on Rails API documentation tool
Apache License 2.0
2.47k stars 463 forks source link

[Question] How to use Custom Validator? #772

Open Kyokatarz opened 2 years ago

Kyokatarz commented 2 years ago

Hi,

How do I use the defined Custom Validator? For example if I define

class NameValidator < ApiPie::Validator::BaseValidator
  (...defined here)
end

How do I use NameValidator then?

I tried calling in my route controller:

class Api::V2::NameController < Api::V2::ApplicationController
  api :PUT, '/v2/name', 'Get user name'
  param :name, NameValidator, desc: "Name", required: true
  param_group :defaults, Api::V2::ApplicationController
(.......)

I get this error uninitialized constant Api::V2::NameController::NameValidator

Is this written in the code somewhere? Or am I using it wrong?

mathieujobin commented 2 years ago

I use param :useful_id, :number, 'ID/s of something useful' in the controller

and automatically, it loads up Apipie::Validator::NumberValidator