feathersjs-ecosystem / feathers-swagger

Add documentation to your FeatherJS services and feed them to Swagger UI.
MIT License
226 stars 63 forks source link

feat: allow a service to be marked as multipart #258

Closed AshotN closed 6 months ago

AshotN commented 7 months ago

Summary

For services that accept file uploads, JSON is not the correct content type. This will allow the user to mark a service as a multipart service.

Mairu commented 7 months ago

Hi, thanks for the merge request.

But I don't know if this should be part of the library.

There are different ways to handle file uploads, the file could also be uploaded directly as described at OpenAPI File Uploads page.

Also, how you implemented, it would be an all-or-nothing setting. (all methods that support a request body and just another hard-coded content type)

It is a quite rare use case and if supported, there should also be support for file downloads and other content types.

I would prefer if there is documentation on how to handle such cases, but they should be defined manually.

docs: createSwaggerServiceOptions({
    schemas: { messageDataSchema, messageQuerySchema, messageSchema },
    docs: { 
      operations: {
        create: {
          'requestBody.content': {
            'multipart/form-data': {
              schema: {
                filename: {
                  type: 'string',
                  format: 'binary'
                }
              }
            }
          }
        }
      }
    }
  })