Merged in feature/download-pdf (pull request #216)
retrieve document by id and tests * working * missing files
This commit is contained in:
@@ -1730,6 +1730,9 @@ type ClientInterface interface {
|
||||
// GetDocument request
|
||||
GetDocument(ctx context.Context, id DocumentID, params *GetDocumentParams, reqEditors ...RequestEditorFn) (*http.Response, error)
|
||||
|
||||
// DownloadDocument request
|
||||
DownloadDocument(ctx context.Context, id DocumentID, reqEditors ...RequestEditorFn) (*http.Response, error)
|
||||
|
||||
// GetDocumentLabels request
|
||||
GetDocumentLabels(ctx context.Context, documentId openapi_types.UUID, reqEditors ...RequestEditorFn) (*http.Response, error)
|
||||
|
||||
@@ -2301,6 +2304,18 @@ func (c *Client) GetDocument(ctx context.Context, id DocumentID, params *GetDocu
|
||||
return c.Client.Do(req)
|
||||
}
|
||||
|
||||
func (c *Client) DownloadDocument(ctx context.Context, id DocumentID, reqEditors ...RequestEditorFn) (*http.Response, error) {
|
||||
req, err := NewDownloadDocumentRequest(c.Server, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req = req.WithContext(ctx)
|
||||
if err := c.applyEditors(ctx, req, reqEditors); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return c.Client.Do(req)
|
||||
}
|
||||
|
||||
func (c *Client) GetDocumentLabels(ctx context.Context, documentId openapi_types.UUID, reqEditors ...RequestEditorFn) (*http.Response, error) {
|
||||
req, err := NewGetDocumentLabelsRequest(c.Server, documentId)
|
||||
if err != nil {
|
||||
@@ -4268,6 +4283,40 @@ func NewGetDocumentRequest(server string, id DocumentID, params *GetDocumentPara
|
||||
return req, nil
|
||||
}
|
||||
|
||||
// NewDownloadDocumentRequest generates requests for DownloadDocument
|
||||
func NewDownloadDocumentRequest(server string, id DocumentID) (*http.Request, error) {
|
||||
var err error
|
||||
|
||||
var pathParam0 string
|
||||
|
||||
pathParam0, err = runtime.StyleParamWithLocation("simple", false, "id", runtime.ParamLocationPath, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
serverURL, err := url.Parse(server)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
operationPath := fmt.Sprintf("/document/%s/download", pathParam0)
|
||||
if operationPath[0] == '/' {
|
||||
operationPath = "." + operationPath
|
||||
}
|
||||
|
||||
queryURL, err := serverURL.Parse(operationPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("GET", queryURL.String(), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return req, nil
|
||||
}
|
||||
|
||||
// NewGetDocumentLabelsRequest generates requests for GetDocumentLabels
|
||||
func NewGetDocumentLabelsRequest(server string, documentId openapi_types.UUID) (*http.Request, error) {
|
||||
var err error
|
||||
@@ -5476,6 +5525,9 @@ type ClientWithResponsesInterface interface {
|
||||
// GetDocumentWithResponse request
|
||||
GetDocumentWithResponse(ctx context.Context, id DocumentID, params *GetDocumentParams, reqEditors ...RequestEditorFn) (*GetDocumentResponse, error)
|
||||
|
||||
// DownloadDocumentWithResponse request
|
||||
DownloadDocumentWithResponse(ctx context.Context, id DocumentID, reqEditors ...RequestEditorFn) (*DownloadDocumentResponse, error)
|
||||
|
||||
// GetDocumentLabelsWithResponse request
|
||||
GetDocumentLabelsWithResponse(ctx context.Context, documentId openapi_types.UUID, reqEditors ...RequestEditorFn) (*GetDocumentLabelsResponse, error)
|
||||
|
||||
@@ -6430,6 +6482,32 @@ func (r GetDocumentResponse) StatusCode() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
type DownloadDocumentResponse struct {
|
||||
Body []byte
|
||||
HTTPResponse *http.Response
|
||||
JSON400 *InvalidRequest
|
||||
JSON401 *Unauthorized
|
||||
JSON404 *NotFound
|
||||
JSON429 *TooManyRequests
|
||||
JSON500 *InternalError
|
||||
}
|
||||
|
||||
// Status returns HTTPResponse.Status
|
||||
func (r DownloadDocumentResponse) Status() string {
|
||||
if r.HTTPResponse != nil {
|
||||
return r.HTTPResponse.Status
|
||||
}
|
||||
return http.StatusText(0)
|
||||
}
|
||||
|
||||
// StatusCode returns HTTPResponse.StatusCode
|
||||
func (r DownloadDocumentResponse) StatusCode() int {
|
||||
if r.HTTPResponse != nil {
|
||||
return r.HTTPResponse.StatusCode
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type GetDocumentLabelsResponse struct {
|
||||
Body []byte
|
||||
HTTPResponse *http.Response
|
||||
@@ -7479,6 +7557,15 @@ func (c *ClientWithResponses) GetDocumentWithResponse(ctx context.Context, id Do
|
||||
return ParseGetDocumentResponse(rsp)
|
||||
}
|
||||
|
||||
// DownloadDocumentWithResponse request returning *DownloadDocumentResponse
|
||||
func (c *ClientWithResponses) DownloadDocumentWithResponse(ctx context.Context, id DocumentID, reqEditors ...RequestEditorFn) (*DownloadDocumentResponse, error) {
|
||||
rsp, err := c.DownloadDocument(ctx, id, reqEditors...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ParseDownloadDocumentResponse(rsp)
|
||||
}
|
||||
|
||||
// GetDocumentLabelsWithResponse request returning *GetDocumentLabelsResponse
|
||||
func (c *ClientWithResponses) GetDocumentLabelsWithResponse(ctx context.Context, documentId openapi_types.UUID, reqEditors ...RequestEditorFn) (*GetDocumentLabelsResponse, error) {
|
||||
rsp, err := c.GetDocumentLabels(ctx, documentId, reqEditors...)
|
||||
@@ -9706,6 +9793,60 @@ func ParseGetDocumentResponse(rsp *http.Response) (*GetDocumentResponse, error)
|
||||
return response, nil
|
||||
}
|
||||
|
||||
// ParseDownloadDocumentResponse parses an HTTP response from a DownloadDocumentWithResponse call
|
||||
func ParseDownloadDocumentResponse(rsp *http.Response) (*DownloadDocumentResponse, error) {
|
||||
bodyBytes, err := io.ReadAll(rsp.Body)
|
||||
defer func() { _ = rsp.Body.Close() }()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
response := &DownloadDocumentResponse{
|
||||
Body: bodyBytes,
|
||||
HTTPResponse: rsp,
|
||||
}
|
||||
|
||||
switch {
|
||||
case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400:
|
||||
var dest InvalidRequest
|
||||
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response.JSON400 = &dest
|
||||
|
||||
case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401:
|
||||
var dest Unauthorized
|
||||
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response.JSON401 = &dest
|
||||
|
||||
case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404:
|
||||
var dest NotFound
|
||||
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response.JSON404 = &dest
|
||||
|
||||
case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 429:
|
||||
var dest TooManyRequests
|
||||
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response.JSON429 = &dest
|
||||
|
||||
case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500:
|
||||
var dest InternalError
|
||||
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response.JSON500 = &dest
|
||||
|
||||
}
|
||||
|
||||
return response, nil
|
||||
}
|
||||
|
||||
// ParseGetDocumentLabelsResponse parses an HTTP response from a GetDocumentLabelsWithResponse call
|
||||
func ParseGetDocumentLabelsResponse(rsp *http.Response) (*GetDocumentLabelsResponse, error) {
|
||||
bodyBytes, err := io.ReadAll(rsp.Body)
|
||||
|
||||
Reference in New Issue
Block a user