From 4438117f55c4d7e91fcbc1dec7b0cfcaea015dc8 Mon Sep 17 00:00:00 2001 From: RRosio Date: Mon, 24 Feb 2025 23:02:42 -0800 Subject: [PATCH 1/6] initial pass for generated api schema --- jupyter_fsspec/api_schema.yml | 114 ++++++++++++++++++++ jupyter_fsspec/handlers.py | 2 +- jupyter_fsspec/{schemas.py => models.py} | 0 jupyter_fsspec/scripts/update_api_schema.py | 35 ++++++ 4 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 jupyter_fsspec/api_schema.yml rename jupyter_fsspec/{schemas.py => models.py} (100%) create mode 100644 jupyter_fsspec/scripts/update_api_schema.py diff --git a/jupyter_fsspec/api_schema.yml b/jupyter_fsspec/api_schema.yml new file mode 100644 index 0000000..d0c4d90 --- /dev/null +++ b/jupyter_fsspec/api_schema.yml @@ -0,0 +1,114 @@ +components: + schemas: + BaseRequest: + properties: + item_path: + title: Item Path + type: string + key: + title: Key + type: string + required: + - key + - item_path + title: BaseRequest + type: object + DeleteRequest: + properties: + item_path: + title: Item Path + type: string + key: + title: Key + type: string + required: + - key + - item_path + title: DeleteRequest + type: object + Direction: + enum: + - upload + - download + title: Direction + type: string + GetRequest: + properties: + item_path: + title: Item Path + type: string + key: + title: Key + type: string + type: + anyOf: + - $ref: '#/components/schemas/RequestType' + - type: 'null' + default: default + required: + - key + - item_path + title: GetRequest + type: object + PostRequest: + properties: + action: + anyOf: + - $ref: '#/components/schemas/RequestAction' + - type: 'null' + default: null + content: + anyOf: + - type: string + - type: 'null' + default: null + title: Content + item_path: + title: Item Path + type: string + key: + title: Key + type: string + required: + - key + - item_path + title: PostRequest + type: object + RequestAction: + const: move + title: RequestAction + type: string + RequestType: + enum: + - default + - range + title: RequestType + type: string + TransferRequest: + properties: + action: + $ref: '#/components/schemas/Direction' + destination_key: + title: Destination Key + type: string + key: + title: Key + type: string + local_path: + title: Local Path + type: string + remote_path: + title: Remote Path + type: string + required: + - key + - destination_key + - local_path + - remote_path + - action + title: TransferRequest + type: object +info: + title: jupyter-fsspec API + version: 0.4.0 +openapi: 3.1.1 diff --git a/jupyter_fsspec/handlers.py b/jupyter_fsspec/handlers.py index 357fc6b..ed632a1 100644 --- a/jupyter_fsspec/handlers.py +++ b/jupyter_fsspec/handlers.py @@ -1,7 +1,7 @@ from .file_manager import FileSystemManager from jupyter_server.base.handlers import APIHandler from jupyter_server.utils import url_path_join -from .schemas import GetRequest, PostRequest, DeleteRequest, TransferRequest, Direction +from .models import GetRequest, PostRequest, DeleteRequest, TransferRequest, Direction from .utils import parse_range from .exceptions import ConfigFileException from contextlib import contextmanager diff --git a/jupyter_fsspec/schemas.py b/jupyter_fsspec/models.py similarity index 100% rename from jupyter_fsspec/schemas.py rename to jupyter_fsspec/models.py diff --git a/jupyter_fsspec/scripts/update_api_schema.py b/jupyter_fsspec/scripts/update_api_schema.py new file mode 100644 index 0000000..eab1001 --- /dev/null +++ b/jupyter_fsspec/scripts/update_api_schema.py @@ -0,0 +1,35 @@ +from jupyter_fsspec.models import ( + BaseRequest, + GetRequest, + PostRequest, + DeleteRequest, + TransferRequest, +) +from pydantic.json_schema import models_json_schema +import yaml +import os + + +def write_json_schema(models): + _, schemas = models_json_schema( + [(model, "validation") for model in models], + ref_template="#/components/schemas/{model}", + ) + + open_api_schema = { + "openapi": "3.1.1", + "info": {"title": "jupyter-fsspec API", "version": "0.4.0"}, + "components": {"schemas": schemas.get("$defs")}, + } + + cwd = os.getcwd() + schema_file = os.path.join(cwd, "jupyter_fsspec/api_schema.yml") + + with open(schema_file, "w") as f: + yaml.dump(open_api_schema, f) + + +if __name__ == "__main__": + write_json_schema( + [BaseRequest, GetRequest, PostRequest, DeleteRequest, TransferRequest] + ) From 74b63399e3321b828e5e407178f330e2d582af28 Mon Sep 17 00:00:00 2001 From: RRosio Date: Tue, 25 Feb 2025 23:10:57 -0800 Subject: [PATCH 2/6] update descriptions for models --- jupyter_fsspec/api_schema.yml | 83 ++++++++++++++++++++++++++++++----- jupyter_fsspec/models.py | 82 ++++++++++++++++++++++++++++++---- 2 files changed, 144 insertions(+), 21 deletions(-) diff --git a/jupyter_fsspec/api_schema.yml b/jupyter_fsspec/api_schema.yml index d0c4d90..12dfe32 100644 --- a/jupyter_fsspec/api_schema.yml +++ b/jupyter_fsspec/api_schema.yml @@ -1,12 +1,21 @@ components: schemas: BaseRequest: + description: 'The required information for all Filesystem handler endpoints. + + + key: unique + + item_path: destination path for the acting filesystem' properties: item_path: - title: Item Path + description: Acting path in filesystem + title: Path type: string key: - title: Key + description: Unique identifier given as the filesystem 'name' in the config + file + title: Filesystem name type: string required: - key @@ -14,12 +23,19 @@ components: title: BaseRequest type: object DeleteRequest: + description: 'Placeholder model for delete request + + + No additional information is needed than base request' properties: item_path: - title: Item Path + description: Acting path in filesystem + title: Path type: string key: - title: Key + description: Unique identifier given as the filesystem 'name' in the config + file + title: Filesystem name type: string required: - key @@ -33,41 +49,64 @@ components: title: Direction type: string GetRequest: + description: 'GET request specific items. + + + type: option to specify type of GET request' properties: item_path: - title: Item Path + description: Acting path in filesystem + title: Path type: string key: - title: Key + description: Unique identifier given as the filesystem 'name' in the config + file + title: Filesystem name type: string type: anyOf: - $ref: '#/components/schemas/RequestType' - type: 'null' default: default + description: Either a 'range' GET request for file or 'default' for normal + GET + title: Type of GET request required: - key - item_path title: GetRequest type: object PostRequest: + description: 'POST request specific items. + + + content: content to be created upon request + + action: move action specified when calling action handler' properties: action: anyOf: - $ref: '#/components/schemas/RequestAction' - type: 'null' default: null + description: Specify 'move' action when calling action handler, default + treated as copy + title: Move or copy action indicator content: anyOf: - type: string - type: 'null' default: null - title: Content + description: Content to be created upon request + title: File content or file/directory name item_path: - title: Item Path + description: Acting path in filesystem + title: Path type: string key: - title: Key + description: Unique identifier given as the filesystem 'name' in the config + file + title: Filesystem name type: string required: - key @@ -85,14 +124,34 @@ components: title: RequestType type: string TransferRequest: + description: 'Requests made to download, upload and sync. + + + key: unique + + destination_key: unique + + local_path: file/directory path, filesystem root path for sync + + remote_path: file/directory path, filesystem root path for sync + + action: enum option upload or download' properties: action: - $ref: '#/components/schemas/Direction' + allOf: + - $ref: '#/components/schemas/Direction' + description: Can be 'upload' or 'download for local to remote or remote + to local respectively + title: Transfer direction destination_key: - title: Destination Key + description: Unique identifier given as the filesystem 'name' in the config + file + title: Destination filesystem name type: string key: - title: Key + description: Unique identifier given as the filesystem 'name' in the config + file + title: Source filesystem name type: string local_path: title: Local Path diff --git a/jupyter_fsspec/models.py b/jupyter_fsspec/models.py index a212b04..27c2e19 100644 --- a/jupyter_fsspec/models.py +++ b/jupyter_fsspec/models.py @@ -1,4 +1,4 @@ -from pydantic import BaseModel +from pydantic import BaseModel, Field from typing import Optional from enum import Enum @@ -13,20 +13,62 @@ class RequestAction(str, Enum): class BaseRequest(BaseModel): - key: str - item_path: str + """ + The required information for all Filesystem handler endpoints. + + key: unique + item_path: destination path for the acting filesystem + """ + + key: str = Field( + ..., + title="Filesystem name", + description="Unique identifier given as the filesystem 'name' in the config file", + ) + item_path: str = Field(..., title="Path", description="Acting path in filesystem") class GetRequest(BaseRequest): - type: Optional[RequestType] = RequestType.default + """ + GET request specific items. + + type: option to specify type of GET request + """ + + type: Optional[RequestType] = Field( + default=RequestType.default, + title="Type of GET request", + description="Either a 'range' GET request for file or 'default' for normal GET", + ) class PostRequest(BaseRequest): - content: Optional[str] = None - action: Optional[RequestAction] = None + """ + POST request specific items. + + content: content to be created upon request + action: move action specified when calling action handler + """ + + content: Optional[str] = Field( + default=None, + title="File content or file/directory name", + description="Content to be created upon request", + ) + action: Optional[RequestAction] = Field( + default=None, + title="Move or copy action indicator", + description="Specify 'move' action when calling action handler, default treated as copy", + ) class DeleteRequest(BaseRequest): + """ + Placeholder model for delete request + + No additional information is needed than base request + """ + pass @@ -36,8 +78,30 @@ class Direction(str, Enum): class TransferRequest(BaseModel): - key: str - destination_key: str + """ + Requests made to download, upload and sync. + + key: unique + destination_key: unique + local_path: file/directory path, filesystem root path for sync + remote_path: file/directory path, filesystem root path for sync + action: enum option upload or download + """ + + key: str = Field( + ..., + title="Source filesystem name", + description="Unique identifier given as the filesystem 'name' in the config file", + ) + destination_key: str = Field( + ..., + title="Destination filesystem name", + description="Unique identifier given as the filesystem 'name' in the config file", + ) local_path: str remote_path: str - action: Direction + action: Direction = Field( + ..., + title="Transfer direction", + description="Can be 'upload' or 'download for local to remote or remote to local respectively", + ) From 602c4d91297ae42677f9e2dcd414b9dfd865dd67 Mon Sep 17 00:00:00 2001 From: RRosio Date: Tue, 25 Feb 2025 23:49:36 -0800 Subject: [PATCH 3/6] move all models into models.py --- jupyter_fsspec/file_manager.py | 15 +-------------- jupyter_fsspec/models.py | 14 +++++++++++++- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/jupyter_fsspec/file_manager.py b/jupyter_fsspec/file_manager.py index 3f059e9..0964102 100644 --- a/jupyter_fsspec/file_manager.py +++ b/jupyter_fsspec/file_manager.py @@ -1,6 +1,5 @@ from jupyter_core.paths import jupyter_config_dir -from pydantic import BaseModel -from typing import Optional, Dict, List +from .models import Source, Config from fsspec.utils import infer_storage_options from fsspec.implementations.asyn_wrapper import AsyncFileSystemWrapper import fsspec @@ -16,18 +15,6 @@ logger.setLevel(logging.INFO) -class Source(BaseModel): - name: str - path: str - protocol: Optional[str] = None - args: Optional[List] = [] - kwargs: Optional[Dict] = {} - - -class Config(BaseModel): - sources: List[Source] - - class FileSystemManager: def __init__(self, config_file): self.filesystems = {} diff --git a/jupyter_fsspec/models.py b/jupyter_fsspec/models.py index 27c2e19..076d030 100644 --- a/jupyter_fsspec/models.py +++ b/jupyter_fsspec/models.py @@ -1,8 +1,20 @@ from pydantic import BaseModel, Field -from typing import Optional +from typing import Optional, Dict, List from enum import Enum +class Source(BaseModel): + name: str + path: str + protocol: Optional[str] = None + args: Optional[List] = [] + kwargs: Optional[Dict] = {} + + +class Config(BaseModel): + sources: List[Source] + + class RequestType(str, Enum): default = "default" range = "range" From 8d6079bf965c25ba362db74f7fd50c1d7b60fac1 Mon Sep 17 00:00:00 2001 From: RRosio Date: Wed, 26 Feb 2025 01:24:54 -0800 Subject: [PATCH 4/6] update schema, add config endpoint to schema --- jupyter_fsspec/api_schema.yml | 232 ++++++++++++-------- jupyter_fsspec/models.py | 4 + jupyter_fsspec/scripts/config_schema.py | 21 ++ jupyter_fsspec/scripts/update_api_schema.py | 63 ++++-- 4 files changed, 218 insertions(+), 102 deletions(-) create mode 100644 jupyter_fsspec/scripts/config_schema.py diff --git a/jupyter_fsspec/api_schema.yml b/jupyter_fsspec/api_schema.yml index 12dfe32..7e9e32b 100644 --- a/jupyter_fsspec/api_schema.yml +++ b/jupyter_fsspec/api_schema.yml @@ -1,164 +1,167 @@ +openapi: 3.1.0 +info: + title: jupyter-fsspec API + version: 0.4.0 +paths: + /jupyter_fsspec/config: + get: + description: List all source filesystems in configuration file + operationId: listConfigSources + responses: + '200': + description: Retrieved available filesystems from configuration file. + content: + application/json: + schema: + $ref: '#/components/schemas/Config' components: schemas: BaseRequest: - description: 'The required information for all Filesystem handler endpoints. - - - key: unique - - item_path: destination path for the acting filesystem' properties: - item_path: - description: Acting path in filesystem - title: Path - type: string key: + type: string + title: Filesystem name description: Unique identifier given as the filesystem 'name' in the config file - title: Filesystem name + item_path: type: string + title: Path + description: Acting path in filesystem + type: object required: - key - item_path title: BaseRequest - type: object - DeleteRequest: - description: 'Placeholder model for delete request + description: 'The required information for all Filesystem handler endpoints. - No additional information is needed than base request' + key: unique + + item_path: destination path for the acting filesystem' + DeleteRequest: properties: - item_path: - description: Acting path in filesystem - title: Path - type: string key: + type: string + title: Filesystem name description: Unique identifier given as the filesystem 'name' in the config file - title: Filesystem name + item_path: type: string + title: Path + description: Acting path in filesystem + type: object required: - key - item_path title: DeleteRequest - type: object + description: 'Placeholder model for delete request + + + No additional information is needed than base request' Direction: + type: string enum: - upload - download title: Direction - type: string GetRequest: - description: 'GET request specific items. - - - type: option to specify type of GET request' properties: - item_path: - description: Acting path in filesystem - title: Path - type: string key: + type: string + title: Filesystem name description: Unique identifier given as the filesystem 'name' in the config file - title: Filesystem name + item_path: type: string + title: Path + description: Acting path in filesystem type: anyOf: - $ref: '#/components/schemas/RequestType' - type: 'null' - default: default + title: Type of GET request description: Either a 'range' GET request for file or 'default' for normal GET - title: Type of GET request + default: default + type: object required: - key - item_path title: GetRequest - type: object - PostRequest: - description: 'POST request specific items. + description: 'GET request specific items. - content: content to be created upon request - - action: move action specified when calling action handler' + type: option to specify type of GET request' + PostRequest: properties: + key: + type: string + title: Filesystem name + description: Unique identifier given as the filesystem 'name' in the config + file + item_path: + type: string + title: Path + description: Acting path in filesystem + content: + anyOf: + - type: string + - type: 'null' + title: File content or file/directory name + description: Content to be created upon request action: anyOf: - $ref: '#/components/schemas/RequestAction' - type: 'null' - default: null + title: Move or copy action indicator description: Specify 'move' action when calling action handler, default treated as copy - title: Move or copy action indicator - content: - anyOf: - - type: string - - type: 'null' - default: null - description: Content to be created upon request - title: File content or file/directory name - item_path: - description: Acting path in filesystem - title: Path - type: string - key: - description: Unique identifier given as the filesystem 'name' in the config - file - title: Filesystem name - type: string + type: object required: - key - item_path title: PostRequest - type: object + description: 'POST request specific items. + + + content: content to be created upon request + + action: move action specified when calling action handler' RequestAction: + type: string const: move title: RequestAction - type: string RequestType: + type: string enum: - default - range title: RequestType - type: string TransferRequest: - description: 'Requests made to download, upload and sync. - - - key: unique - - destination_key: unique - - local_path: file/directory path, filesystem root path for sync - - remote_path: file/directory path, filesystem root path for sync - - action: enum option upload or download' properties: - action: - allOf: - - $ref: '#/components/schemas/Direction' - description: Can be 'upload' or 'download for local to remote or remote - to local respectively - title: Transfer direction - destination_key: + key: + type: string + title: Source filesystem name description: Unique identifier given as the filesystem 'name' in the config file - title: Destination filesystem name + destination_key: type: string - key: + title: Destination filesystem name description: Unique identifier given as the filesystem 'name' in the config file - title: Source filesystem name - type: string local_path: - title: Local Path type: string + title: Local Path remote_path: - title: Remote Path type: string + title: Remote Path + action: + allOf: + - $ref: '#/components/schemas/Direction' + title: Transfer direction + description: Can be 'upload' or 'download for local to remote or remote + to local respectively + type: object required: - key - destination_key @@ -166,8 +169,59 @@ components: - remote_path - action title: TransferRequest + description: 'Requests made to download, upload and sync. + + + key: unique + + destination_key: unique + + local_path: file/directory path, filesystem root path for sync + + remote_path: file/directory path, filesystem root path for sync + + action: enum option upload or download' + Config: + properties: + sources: + items: + $ref: '#/components/schemas/Source' + type: array + title: Sources type: object -info: - title: jupyter-fsspec API - version: 0.4.0 -openapi: 3.1.1 + required: + - sources + title: Config + description: A list of source filesystem configurations + Source: + properties: + name: + type: string + title: Name + path: + type: string + title: Path + protocol: + anyOf: + - type: string + - type: 'null' + title: Protocol + args: + anyOf: + - items: {} + type: array + - type: 'null' + title: Args + default: [] + kwargs: + anyOf: + - type: object + - type: 'null' + title: Kwargs + default: {} + type: object + required: + - name + - path + title: Source + description: Filesystem configurations passed to fsspec diff --git a/jupyter_fsspec/models.py b/jupyter_fsspec/models.py index 076d030..97c32e3 100644 --- a/jupyter_fsspec/models.py +++ b/jupyter_fsspec/models.py @@ -4,6 +4,8 @@ class Source(BaseModel): + """Filesystem configurations passed to fsspec""" + name: str path: str protocol: Optional[str] = None @@ -12,6 +14,8 @@ class Source(BaseModel): class Config(BaseModel): + """A list of source filesystem configurations""" + sources: List[Source] diff --git a/jupyter_fsspec/scripts/config_schema.py b/jupyter_fsspec/scripts/config_schema.py new file mode 100644 index 0000000..9b7863e --- /dev/null +++ b/jupyter_fsspec/scripts/config_schema.py @@ -0,0 +1,21 @@ +from jupyter_fsspec.models import Config +from pydantic.json_schema import models_json_schema +import yaml + + +def generate_config_schema(): + models = [Config] + _, schemas = models_json_schema( + [(model, "validation") for model in models], + ref_template="#/components/schemas/{model}", + ) + config_schema = { + "info": {"title": "jupyter-fsspec API", "version": "0.4.0"}, + "components": {"schemas": schemas.get("$defs")}, + } + config = yaml.dump(config_schema) + print(config) + + +if __name__ == "__main__": + generate_config_schema() diff --git a/jupyter_fsspec/scripts/update_api_schema.py b/jupyter_fsspec/scripts/update_api_schema.py index eab1001..198f294 100644 --- a/jupyter_fsspec/scripts/update_api_schema.py +++ b/jupyter_fsspec/scripts/update_api_schema.py @@ -1,4 +1,5 @@ from jupyter_fsspec.models import ( + Config, BaseRequest, GetRequest, PostRequest, @@ -6,30 +7,66 @@ TransferRequest, ) from pydantic.json_schema import models_json_schema +from openapi_pydantic.v3 import OpenAPI, Info, PathItem, Operation +from openapi_pydantic.util import PydanticSchema, construct_open_api_with_schema_class import yaml import os -def write_json_schema(models): +def write_json_schema(openapi): + cwd = os.getcwd() + schema_file = os.path.join(cwd, "jupyter_fsspec/api_schema.yml") + + with open(schema_file, "w") as f: + f.write( + yaml.dump( + openapi.model_dump( + by_alias=True, + mode="json", + exclude_none=True, + exclude_unset=True, + ), + sort_keys=False, + ) + ) + + +def base_openapi(models) -> OpenAPI: _, schemas = models_json_schema( [(model, "validation") for model in models], ref_template="#/components/schemas/{model}", ) - open_api_schema = { - "openapi": "3.1.1", - "info": {"title": "jupyter-fsspec API", "version": "0.4.0"}, - "components": {"schemas": schemas.get("$defs")}, - } + return OpenAPI( + openapi="3.1.0", + info=Info(title="jupyter-fsspec API", version="0.4.0"), + components={"schemas": schemas.get("$defs")}, + paths={ + "/jupyter_fsspec/config": PathItem( + get=Operation( + operationId="listConfigSources", + description="List all source filesystems in configuration file", + responses={ + "200": { + "description": "Retrieved available filesystems from configuration file.", + "content": { + "application/json": { + "schema": PydanticSchema(schema_class=Config) + } + }, + } + }, + ) + ), + }, + ) - cwd = os.getcwd() - schema_file = os.path.join(cwd, "jupyter_fsspec/api_schema.yml") - with open(schema_file, "w") as f: - yaml.dump(open_api_schema, f) +open_api = base_openapi( + [BaseRequest, GetRequest, PostRequest, DeleteRequest, TransferRequest] +) +open_api = construct_open_api_with_schema_class(open_api) if __name__ == "__main__": - write_json_schema( - [BaseRequest, GetRequest, PostRequest, DeleteRequest, TransferRequest] - ) + write_json_schema(open_api) From 065712aeecf1776cd8a7c2e4ae52ca746a91906e Mon Sep 17 00:00:00 2001 From: RRosio Date: Wed, 26 Feb 2025 08:13:53 -0800 Subject: [PATCH 5/6] update schema with endpoints --- jupyter_fsspec/api_schema.yml | 82 ++++++++++++- jupyter_fsspec/scripts/update_api_schema.py | 125 +++++++++++++++++++- 2 files changed, 205 insertions(+), 2 deletions(-) diff --git a/jupyter_fsspec/api_schema.yml b/jupyter_fsspec/api_schema.yml index 7e9e32b..a236083 100644 --- a/jupyter_fsspec/api_schema.yml +++ b/jupyter_fsspec/api_schema.yml @@ -6,7 +6,6 @@ paths: /jupyter_fsspec/config: get: description: List all source filesystems in configuration file - operationId: listConfigSources responses: '200': description: Retrieved available filesystems from configuration file. @@ -14,6 +13,87 @@ paths: application/json: schema: $ref: '#/components/schemas/Config' + /jupyter_fsspec/files?{key}: + get: + description: List content at the specified path of the {key} filesystem + parameters: + - description: Unique name identifying the filesystem + required: true + schema: + type: string + name: key + in: query + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/GetRequest' + responses: + '200': + description: Retrieved content from item_path. + put: + description: Update existing file + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/PostRequest' + responses: + '200': + description: Update file at existing item_path + post: + description: Create a file or directory based on provided content + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/PostRequest' + responses: + '200': + description: Created file or directory in source filesystem + delete: + description: Delete the file or directory specified by path + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/DeleteRequest' + responses: + '200': + description: Delete path at item_path. + /jupyter_fsspec/files/action: + post: + description: Move or, by default, copy path to destination + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/PostRequest' + responses: + '200': + description: Copied or moved item_path to destination specified by content. + /jupyter_fsspec/files/rename: + post: + description: Rename path to content provided + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/PostRequest' + responses: + '200': + description: Renamed the specified item_path to content provided. + /jupyter_fsspec/files/transfer: + post: + description: Upload or download file(s) source path to destination path + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/TransferRequest' + responses: + '200': + description: Downloaded or Uploaded from source path to destination path components: schemas: BaseRequest: diff --git a/jupyter_fsspec/scripts/update_api_schema.py b/jupyter_fsspec/scripts/update_api_schema.py index 198f294..f814fb8 100644 --- a/jupyter_fsspec/scripts/update_api_schema.py +++ b/jupyter_fsspec/scripts/update_api_schema.py @@ -44,7 +44,6 @@ def base_openapi(models) -> OpenAPI: paths={ "/jupyter_fsspec/config": PathItem( get=Operation( - operationId="listConfigSources", description="List all source filesystems in configuration file", responses={ "200": { @@ -58,6 +57,130 @@ def base_openapi(models) -> OpenAPI: }, ) ), + "/jupyter_fsspec/files?{key}": PathItem( + get=Operation( + description="List content at the specified path of the {key} filesystem", + parameters=[ + { + "name": "key", + "in": "query", + "description": "Unique name identifying the filesystem", + "required": True, + "schema": { + "type": "string", + }, + }, + ], + requestBody={ + "content": { + "application/json": { + "schema": PydanticSchema(schema_class=GetRequest) + } + } + }, + responses={ + "200": { + "description": "Retrieved content from item_path.", + } + }, + ), + post=Operation( + description="Create a file or directory based on provided content", + requestBody={ + "content": { + "application/json": { + "schema": PydanticSchema(schema_class=PostRequest) + } + } + }, + responses={ + "200": { + "description": "Created file or directory in source filesystem", + } + }, + ), + put=Operation( + description="Update existing file", + requestBody={ + "content": { + "application/json": { + "schema": PydanticSchema(schema_class=PostRequest) + } + } + }, + responses={ + "200": { + "description": "Update file at existing item_path", + } + }, + ), + delete=Operation( + description="Delete the file or directory specified by path", + requestBody={ + "content": { + "application/json": { + "schema": PydanticSchema(schema_class=DeleteRequest) + } + } + }, + responses={ + "200": { + "description": "Delete path at item_path.", + } + }, + ), + ), + "/jupyter_fsspec/files/action": PathItem( + post=Operation( + description="Move or, by default, copy path to destination", + requestBody={ + "content": { + "application/json": { + "schema": PydanticSchema(schema_class=PostRequest) + } + } + }, + responses={ + "200": { + "description": "Copied or moved item_path to destination specified by content.", + } + }, + ), + ), + "/jupyter_fsspec/files/rename": PathItem( + post=Operation( + description="Rename path to content provided", + requestBody={ + "content": { + "application/json": { + "schema": PydanticSchema(schema_class=PostRequest) + } + } + }, + responses={ + "200": { + "description": "Renamed the specified item_path to content provided.", + } + }, + ), + ), + "/jupyter_fsspec/files/transfer": PathItem( + post=Operation( + description="Upload or download file(s) source path to destination path", + requestBody={ + "content": { + "application/json": { + "schema": PydanticSchema(schema_class=TransferRequest) + } + } + }, + responses={ + "200": { + "description": "Downloaded or Uploaded from source path to destination path", + } + }, + ), + ), }, ) From 3e36a7fa280662ccf0cb055f448c997bcaa2f862 Mon Sep 17 00:00:00 2001 From: RRosio Date: Wed, 26 Feb 2025 08:18:27 -0800 Subject: [PATCH 6/6] remove redundant config schema script --- jupyter_fsspec/scripts/config_schema.py | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 jupyter_fsspec/scripts/config_schema.py diff --git a/jupyter_fsspec/scripts/config_schema.py b/jupyter_fsspec/scripts/config_schema.py deleted file mode 100644 index 9b7863e..0000000 --- a/jupyter_fsspec/scripts/config_schema.py +++ /dev/null @@ -1,21 +0,0 @@ -from jupyter_fsspec.models import Config -from pydantic.json_schema import models_json_schema -import yaml - - -def generate_config_schema(): - models = [Config] - _, schemas = models_json_schema( - [(model, "validation") for model in models], - ref_template="#/components/schemas/{model}", - ) - config_schema = { - "info": {"title": "jupyter-fsspec API", "version": "0.4.0"}, - "components": {"schemas": schemas.get("$defs")}, - } - config = yaml.dump(config_schema) - print(config) - - -if __name__ == "__main__": - generate_config_schema()