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

Swagger JSON cannot parse Array of Hash in params #895

Open
RIstiaque opened this issue Sep 26, 2023 · 4 comments
Open

Swagger JSON cannot parse Array of Hash in params #895

RIstiaque opened this issue Sep 26, 2023 · 4 comments

Comments

@RIstiaque
Copy link

RIstiaque commented Sep 26, 2023

When inputting the following code for a method:

  param :param_1, Array, of: Hash, desc: 'Array of Objects', required: true do
    param :param_2, String, required: true
    param :param_3, String, required: false
  end

It outputs the following after running this command: rails apipie:static_swagger_json:
image

However in the response, there is the array_of property which allows me to make an array_of: Hash:

  returns code: 200 do
    property :array_1, array_of: Hash, desc: 'Array of Objects', required: true do
      property :prop_1, String
      property :prop_2, String
    end
  end

Which results in the following:
image

Is there a reason that the array_of is only limited to responses?

After forking and cloning APIPie locally, I uncommented this line:

raise "an ':array_of =>' validator is allowed exclusively on response-only fields" unless @response_only

And was able to get the first piece of code working after refactoring to array_of: Hash.

@mathieujobin
Copy link
Collaborator

Interesting. Could a config option resolve the problem ?

@wrobbins
Copy link

Also experiencing this issue.

@mathieujobin
Copy link
Collaborator

And was able to get the first piece of code working after refactoring to array_of: Hash.

@RIstiaque Are you planning to open a pull request with the fix you found?

any reason to keep that raise given some setting options ? or we should just allow it as you are using it?

@jaynetics
Copy link

quickfix without forking to allow param :foo, array_of: Hash do ...:

# config/initializers/apipie.rb

Apipie::ParamDescription.prepend(Module.new do
  POINTLESS_ERROR = "an ':array_of =>' validator is allowed exclusively on response-only fields"

  def raise(arg1, ...)
    super unless arg1 == POINTLESS_ERROR
  end
end)

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

No branches or pull requests

4 participants