From 3963aa9653831d7eb786851940c8c110af79be4b Mon Sep 17 00:00:00 2001 From: Tit Petric Date: Mon, 5 Nov 2018 15:09:54 +0100 Subject: [PATCH] fix(sam): spec for attachments --- sam/docs/README.md | 2 ++ sam/docs/src/spec.json | 22 ++++++++++++++++++++-- sam/docs/src/spec/attachment.json | 21 +++++++++++++++++++-- sam/rest/request/attachment.go | 4 ++++ 4 files changed, 45 insertions(+), 4 deletions(-) diff --git a/sam/docs/README.md b/sam/docs/README.md index a627919da..5e76a2c1e 100644 --- a/sam/docs/README.md +++ b/sam/docs/README.md @@ -13,6 +13,7 @@ | Parameter | Type | Method | Description | Default | Required? | | --------- | ---- | ------ | ----------- | ------- | --------- | | download | bool | GET | Force file download | N/A | NO | +| name | string | PATH | File name | N/A | YES | | attachmentID | uint64 | PATH | Attachment ID | N/A | YES | ## Serves preview of an attached file @@ -27,6 +28,7 @@ | Parameter | Type | Method | Description | Default | Required? | | --------- | ---- | ------ | ----------- | ------- | --------- | +| ext | string | PATH | Preview extension/format | N/A | YES | | attachmentID | uint64 | PATH | Attachment ID | N/A | YES | diff --git a/sam/docs/src/spec.json b/sam/docs/src/spec.json index 793bdfc68..5997632a2 100644 --- a/sam/docs/src/spec.json +++ b/sam/docs/src/spec.json @@ -526,7 +526,15 @@ "method": "GET", "title": "Serves attached file", "parameters": { - "GET": [ + "path": [ + { + "name": "name", + "type": "string", + "required": true, + "title": "File name" + } + ], + "get": [ { "type": "bool", "name": "download", @@ -540,7 +548,17 @@ "name": "preview", "path": "/preview.{ext}", "method": "GET", - "title": "Serves preview of an attached file" + "title": "Serves preview of an attached file", + "parameters": { + "path": [ + { + "name": "ext", + "type": "string", + "required": true, + "title": "Preview extension/format" + } + ] + } } ] }, diff --git a/sam/docs/src/spec/attachment.json b/sam/docs/src/spec/attachment.json index 6029d7491..eed54b339 100644 --- a/sam/docs/src/spec/attachment.json +++ b/sam/docs/src/spec/attachment.json @@ -26,13 +26,21 @@ "Title": "Serves attached file", "Path": "/original/{name}", "Parameters": { - "GET": [ + "get": [ { "name": "download", "required": false, "title": "Force file download", "type": "bool" } + ], + "path": [ + { + "name": "name", + "required": true, + "title": "File name", + "type": "string" + } ] } }, @@ -41,7 +49,16 @@ "Method": "GET", "Title": "Serves preview of an attached file", "Path": "/preview.{ext}", - "Parameters": null + "Parameters": { + "path": [ + { + "name": "ext", + "required": true, + "title": "Preview extension/format", + "type": "string" + } + ] + } } ] } \ No newline at end of file diff --git a/sam/rest/request/attachment.go b/sam/rest/request/attachment.go index ee554a762..337f815d0 100644 --- a/sam/rest/request/attachment.go +++ b/sam/rest/request/attachment.go @@ -33,6 +33,7 @@ var _ = multipart.FileHeader{} // Attachment original request parameters type AttachmentOriginal struct { Download bool + Name string AttachmentID uint64 `json:",string"` } @@ -71,6 +72,7 @@ func (a *AttachmentOriginal) Fill(r *http.Request) (err error) { a.Download = parseBool(val) } + a.Name = chi.URLParam(r, "name") a.AttachmentID = parseUInt64(chi.URLParam(r, "attachmentID")) return err @@ -80,6 +82,7 @@ var _ RequestFiller = NewAttachmentOriginal() // Attachment preview request parameters type AttachmentPreview struct { + Ext string AttachmentID uint64 `json:",string"` } @@ -114,6 +117,7 @@ func (a *AttachmentPreview) Fill(r *http.Request) (err error) { post[name] = string(param[0]) } + a.Ext = chi.URLParam(r, "ext") a.AttachmentID = parseUInt64(chi.URLParam(r, "attachmentID")) return err