From 8c63cb8c219320b3dfe4fc93d53436fae9b169e4 Mon Sep 17 00:00:00 2001 From: Wlad Date: Sat, 24 Oct 2020 17:16:36 +0200 Subject: [PATCH] WIP: File API --- TODO.md | 6 +- .../components/requestBodies/FileCommand.yaml | 77 +++++++++++++++++++ openapi/components/responses/FileCommand.yaml | 28 +++++++ openapi/components/schemas/Position.yaml | 6 ++ .../paths/files/{location}/{path}-post.yaml | 14 ++++ 5 files changed, 128 insertions(+), 3 deletions(-) create mode 100644 openapi/components/requestBodies/FileCommand.yaml create mode 100644 openapi/components/responses/FileCommand.yaml create mode 100644 openapi/components/schemas/Position.yaml create mode 100644 openapi/paths/files/{location}/{path}-post.yaml diff --git a/TODO.md b/TODO.md index 4df6659..bae0260 100644 --- a/TODO.md +++ b/TODO.md @@ -11,14 +11,14 @@ - [x] Current User - [x] Version - [x] Connection Handling -- [ ] File Operations [link](https://docs.octoprint.org/en/master/api/files.html) +- [x] File Operations [link](https://docs.octoprint.org/en/master/api/files.html) - [x] Retrieve all files - [x] Retrieve files from specific location - [x] Upload file or create folder - [x] Retrieve a specific file’s or folder’s information - - [ ] Issue a file command + - [x] Issue a file command - [x] Delete file - - [ ] Model: Upload response + - [x] Model: Upload response - [x] Model: Retrieve response - [ ] Job operations [link](https://docs.octoprint.org/en/master/api/job.html) - [ ] Issue a job command diff --git a/openapi/components/requestBodies/FileCommand.yaml b/openapi/components/requestBodies/FileCommand.yaml new file mode 100644 index 0000000..13a45db --- /dev/null +++ b/openapi/components/requestBodies/FileCommand.yaml @@ -0,0 +1,77 @@ +content: + application/json: + schema: + oneOf: + - type: object + description: Selects a file for printing + properties: + command: + type: string + enum: + - select + print: + description: >- + Optional, if set to true the file will start printing directly after selection. If the printer is not operational when this parameter is present and set to true, the request will fail with a response of 409 Conflict. + type: boolean + - type: object + description: >- + Slices an STL file into GCODE. Note that this is an asynchronous operation that will take place in the background after the response has been sent back to the client. + properties: + command: + type: string + enum: + - slice + slice: + description: >- + The slicing engine to use, defaults to cura if not set, which is also the only supported slicer right now. + type: string + gcode: + description: >- + Name of the GCODE file to generated, in the same location as the STL file. Defaults to the STL file name with extension .gco if not set. + type: string + position: + description: >- + Position of the object-to-slice’s center on the print bed. A dictionary containing both x and y coordinate in mm is expected + $ref: ../schemas/Position.yaml + printerProfile: + description: >- + Name of the printer profile to use, if not set the default printer profile will be used. + type: string + profile: + oneOf: + - type: string + - type: object + select: + type: boolean + description: >- + Optional, if set to true the file be selected for printing right after the slicing has finished. If the printer is not operational or already printing when this parameter is present and set to true, the request will fail with a response of 409 Conflict + print: + type: boolean + description: >- + Optional, if set to true the file be selected and start printing right after the slicing has finished. If the printer is not operational or already printing when this parameter is present and set to true, the request will fail with a response of 409 Conflict. Note that if this parameter is set, the parameter select does not need to be set, it is automatically assumed to be true too, otherwise no printing would be possible. + - type: object + description: >- + Copies the file or folder to a new destination on the same location + properties: + command: + type: string + enum: + - copy + destination: + type: string + format: uri + description: >- + The path of the parent folder to which to copy the file or folder. It must already exist. + - type: object + description: >- + Moves the file or folder to a new destination on the same location + properties: + command: + type: string + enum: + - move + destination: + type: string + format: uri + description: >- + The path of the parent folder to which to copy the file or folder. It must already exist. diff --git a/openapi/components/responses/FileCommand.yaml b/openapi/components/responses/FileCommand.yaml new file mode 100644 index 0000000..92f5121 --- /dev/null +++ b/openapi/components/responses/FileCommand.yaml @@ -0,0 +1,28 @@ +"200": + description: No error for a select command. +"201": + content: + application/json: + schema: + $ref: ../schemas/files/File.yaml + description: >- + No error for copy command. +"202": + content: + application/json: + schema: + $ref: ../schemas/files/File.yaml + description: >- + No error for a slice command. +"400": + description: >- + If the command is unknown or the request is otherwise invalid +"404": + description: >- + If location is neither local nor sdcard or the requested file was not found +"409": + description: >- + If a selected file is supposed to start printing directly but the printer is not operational or if a file is to be selected but the printer is already printing or if a file to be sliced is supposed to be selected or start printing directly but the printer is not operational or already printing. +"415": + description: >- + If a slice command was issued against something other than an STL file. diff --git a/openapi/components/schemas/Position.yaml b/openapi/components/schemas/Position.yaml new file mode 100644 index 0000000..b6b75d5 --- /dev/null +++ b/openapi/components/schemas/Position.yaml @@ -0,0 +1,6 @@ +type: object +properties: + x: + type: number + y: + type: number diff --git a/openapi/paths/files/{location}/{path}-post.yaml b/openapi/paths/files/{location}/{path}-post.yaml new file mode 100644 index 0000000..16227e8 --- /dev/null +++ b/openapi/paths/files/{location}/{path}-post.yaml @@ -0,0 +1,14 @@ +summary: Issue a file command +operationId: sendFileCommand +description: Issue a file command to an existing file. +parameters: + - $ref: ../../../components/parameters/fileLocation.yaml + - $ref: ../../../components/parameters/filePath.yaml + - $ref: ../../../components/parameters/fileRecursive.yaml +responses: + "200": + description: Returns a Retrieve Response + content: + application/json: + schema: + $ref: ../../../components/schemas/files/RetrieveResponse.yaml