rswag icon indicating copy to clipboard operation
rswag copied to clipboard

How To Describe Nested Form Data?

Open Petercopter opened this issue 5 years ago • 3 comments

What's the right way to describe nested multipart form data? It looks like it was added back in 2017: https://github.com/domaindrivendev/rswag/pull/54 But has since been removed/simplified.

It seems like I have something that kind of works, but it's not displaying all the values in the generated documentation.

What I've got looks something like this (adjusted to match the example)

parameter name: :blog,
                in: :formData,
                type: :object,
                properties: {
                  title: { type: :string },
                  content: { type: :string },
                  thumbnails: {
                    type: :array,
                    items: { type: :file }
                  }
                }

But it's not displaying all the array values in the generated documentation. I'm not seeing the array items inside the 'thumbnails' array.

Petercopter avatar Apr 19 '19 17:04 Petercopter

parameter name: 'product[name]', in: :formData, type: :string,
                required: true, example: 'Tomato'
parameter name: 'product[description]', in: :formData, type: :string,
                required: true,
                example: 'The tomato is an edible, often red, berry.'
parameter name: 'product[image]', in: :formData, type: :file

Sorry for late reply, but the proper syntax is something like this, or in your example:

parameter name: 'blog[title]', in: :formData, type: :string,
                required: true
parameter name: 'blog[content]', in: :formData, type: :string,
                required: true
parameter name: 'blog[thumbnails][0]', in: :formData, type: :file
parameter name: 'blog[thumbnails][1]', in: :formData, type: :file

If you have worked before with a non-api rails application, you can check the rended html views and see that this is how rails handles arrays in formData.

Kutomore avatar Dec 17 '19 19:12 Kutomore

If you need to send an array of objects with files you can do something like this:

parameter name: 'documents', in: :formData, type: :array, required: true

let(:documents) do
  [
    {
     file: file_1,
     name: '...' 
    },
    {
     file: file_2,
     name: '...'
    }
  ]
end

vladhilko avatar Sep 09 '21 07:09 vladhilko

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If the issue is still relevant to you, please leave a comment stating so to keep the issue from being closed. Thank you for your contributions.

stale[bot] avatar Sep 09 '22 11:09 stale[bot]