Apipie / apipie-rails

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

Array of Hashes parameters are converted to Arrays of Strings by SwaggerGenerator #735

Closed patsch closed 2 years ago

patsch commented 2 years ago

Thank you for your great work - I love using Apiepie !

I have an API that includes an array of hashes as a parameter:

param :parties, Array, :required => true, :desc => "A set of parties", of: Hash do
      param :role, String, :required => true
      param :guid, String, :required => true
      param :first_name, :required => false
      param :last_name, :required => false
end

However, if I use rake apipie:static_swagger_json using APIPIE 0.5.19 on Ruby 3.0.3 it gets translated to

"parties": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  },
                  "description": "A set of parties"
                },

Am I doing something wrong or is the SwaggerGenerator bundled with Apipie not able to produce a schema for arrays of objects/hashes ?

patsch commented 2 years ago

Not pretty, but it works for what I needed: https://gist.github.com/patsch/0482a8db40b091d82be311baa47db3f1

hikhvar commented 1 year ago

The workaround provided by @patsch didn't fix the issue for me. Could we please reopen this issue?

PanosCodes commented 1 year ago

For context, our swagger generator follows the OpenAPI 2.0 spec.

Can I have an object as a query parameter? This is possible in OpenAPI 3.0, but not in 2.0.

Idealy we would have another generator for the 3.0 spec.

hikhvar commented 1 year ago

I told apipie to generate JSON request bodies instead of the default multipart/form data. This also supports nested objects in Swagger 2.0.

Yes, an OpenAPI v3.0 generator would be cool. It would help me avoid having to translate from Swagger 2.0 to OpenAPI v3.0 with a decated tool. My code generator only supports OpenAPI v3.0.

I test with Foreman for reverence. And the PUT /api/hosts/{hostid} endpoint is the wrongly generated endpoint.