def add_file_transfer_paths()

in tasks/tools/open_api_tool.py [0:0]


    def add_file_transfer_paths(spec_paths: Paths):
        """
        file transfer routes for upload and download are served via special routes exposed in SocaServer.
        needs separate handling for these routes as the Http Methods are different from all other IDEA APIs.
        """

        response_json = Schema(
            type='object',
            properties={
                'error_code': Schema(
                    type='string'
                ),
                'success': Schema(
                    type='boolean'
                ),
                'message': Schema(
                    type='string'
                )
            }
        )

        # file upload
        spec_paths['/FileBrowser.UploadFile'] = PathItem(
            put=Operation(
                tags=['FileBrowser'],
                operationId='FileBrowser.UploadFile',
                security=[{
                    'BearerToken': []
                }],
                parameters=[
                    Parameter(
                        name='cwd',
                        description='Current Working Directory',
                        required=True,
                        param_in='query',
                        param_schema=Schema(type='string')
                    )
                ],
                requestBody=RequestBody(
                    content={
                        'multipart/form-data': MediaType(
                            media_type_schema=Schema(
                                type='object',
                                properties={
                                    'files[]': Schema(
                                        type='array',
                                        items=Schema(
                                            type='string',
                                            schema_format='binary'
                                        )
                                    )
                                }
                            )
                        )
                    }
                ),
                responses={
                    '200': Response(
                        description='UploadFile Response',
                        content={
                            'application/json': MediaType(
                                media_type_schema=response_json
                            )
                        }
                    )
                }
            )
        )

        # file download
        spec_paths['/FileBrowser.DownloadFile'] = PathItem(
            get=Operation(
                tags=['FileBrowser'],
                operationId='FileBrowser.DownloadFile',
                security=[{
                    'BearerToken': []
                }],
                parameters=[
                    Parameter(
                        name='file',
                        description='Path of the file to download',
                        required=True,
                        param_in='query',
                        param_schema=Schema(type='string')
                    )
                ],
                responses={
                    '200': Response(
                        description='DownloadFile Response',
                        content={
                            'application/json': MediaType(
                                media_type_schema=response_json
                            ),
                            'text/plain': MediaType(
                                media_type_schema=Schema(
                                    type='string'
                                )
                            ),
                            'application/xml': MediaType(
                                media_type_schema=Schema(
                                    type='string'
                                )
                            ),
                            'image/*': MediaType(
                                media_type_schema=Schema(
                                    type='string',
                                    schema_format='binary'
                                )
                            ),
                            '*/*': MediaType(
                                media_type_schema=Schema(
                                    type='string',
                                    schema_format='binary'
                                )
                            )
                        }
                    )
                }
            )
        )