forked from loafle/openapi-generator-original
[Go] File Download Fix Return Type (#14046)
* Changes manually cherry-picked (for the most part) from https://github.com/OpenAPITools/openapi-generator/pull/12685/files * Examples updated post changes * Missed a change in the mustache template * Update examples after last fix * Missed dereference for required files * Update unit tests * Missed another test case update * `f := *f` isn't quite the same as `*f, err = ...`
This commit is contained in:
parent
cbbe243bde
commit
63629ad51c
@ -121,9 +121,9 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
|||||||
typeMapping.put("date", "string");
|
typeMapping.put("date", "string");
|
||||||
typeMapping.put("DateTime", "time.Time");
|
typeMapping.put("DateTime", "time.Time");
|
||||||
typeMapping.put("password", "string");
|
typeMapping.put("password", "string");
|
||||||
typeMapping.put("File", "*os.File");
|
typeMapping.put("File", "os.File");
|
||||||
typeMapping.put("file", "*os.File");
|
typeMapping.put("file", "os.File");
|
||||||
typeMapping.put("binary", "*os.File");
|
typeMapping.put("binary", "os.File");
|
||||||
typeMapping.put("ByteArray", "string");
|
typeMapping.put("ByteArray", "string");
|
||||||
typeMapping.put("null", "nil");
|
typeMapping.put("null", "nil");
|
||||||
// A 'type: object' OAS schema without any declared property is
|
// A 'type: object' OAS schema without any declared property is
|
||||||
@ -505,13 +505,13 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
|||||||
boolean addedReflectImport = false;
|
boolean addedReflectImport = false;
|
||||||
for (CodegenOperation operation : operations) {
|
for (CodegenOperation operation : operations) {
|
||||||
// import "os" if the operation uses files
|
// import "os" if the operation uses files
|
||||||
if (!addedOSImport && "*os.File".equals(operation.returnType)) {
|
if (!addedOSImport && "os.File".equals(operation.returnType)) {
|
||||||
imports.add(createMapping("import", "os"));
|
imports.add(createMapping("import", "os"));
|
||||||
addedOSImport = true;
|
addedOSImport = true;
|
||||||
}
|
}
|
||||||
for (CodegenParameter param : operation.allParams) {
|
for (CodegenParameter param : operation.allParams) {
|
||||||
// import "os" if the operation uses files
|
// import "os" if the operation uses files
|
||||||
if (!addedOSImport && "*os.File".equals(param.dataType)) {
|
if (!addedOSImport && "os.File".equals(param.dataType)) {
|
||||||
imports.add(createMapping("import", "os"));
|
imports.add(createMapping("import", "os"));
|
||||||
addedOSImport = true;
|
addedOSImport = true;
|
||||||
}
|
}
|
||||||
@ -665,8 +665,8 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
|||||||
imports.add(createMapping("import", "time"));
|
imports.add(createMapping("import", "time"));
|
||||||
addedTimeImport = true;
|
addedTimeImport = true;
|
||||||
}
|
}
|
||||||
if (!addedOSImport && ("*os.File".equals(cp.dataType) ||
|
if (!addedOSImport && ("os.File".equals(cp.dataType) ||
|
||||||
(cp.items != null && "*os.File".equals(cp.items.dataType)))) {
|
(cp.items != null && "os.File".equals(cp.items.dataType)))) {
|
||||||
imports.add(createMapping("import", "os"));
|
imports.add(createMapping("import", "os"));
|
||||||
addedOSImport = true;
|
addedOSImport = true;
|
||||||
}
|
}
|
||||||
|
@ -305,7 +305,7 @@ public class GoServerCodegen extends AbstractGoCodegen {
|
|||||||
for (CodegenOperation operation : operations) {
|
for (CodegenOperation operation : operations) {
|
||||||
for (CodegenParameter param : operation.allParams) {
|
for (CodegenParameter param : operation.allParams) {
|
||||||
// import "os" if the operation uses files
|
// import "os" if the operation uses files
|
||||||
if (!addedOSImport && ("*os.File".equals(param.dataType) || ("[]*os.File".equals(param.dataType)))) {
|
if (!addedOSImport && ("os.File".equals(param.dataType) || ("[]os.File".equals(param.dataType)))) {
|
||||||
imports.add(createMapping("import", "os"));
|
imports.add(createMapping("import", "os"));
|
||||||
addedOSImport = true;
|
addedOSImport = true;
|
||||||
}
|
}
|
||||||
|
@ -112,22 +112,22 @@ func EncodeJSONResponse(i interface{}, status *int,{{#addResponseHeaders}} heade
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ReadFormFileToTempFile reads file data from a request form and writes it to a temporary file
|
// ReadFormFileToTempFile reads file data from a request form and writes it to a temporary file
|
||||||
func ReadFormFileToTempFile(r *http.Request, key string) (*os.File, error) {
|
func ReadFormFileToTempFile(r *http.Request, key string) (os.File, error) {
|
||||||
_, fileHeader, err := r.FormFile(key)
|
_, fileHeader, err := r.FormFile(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return os.File{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return readFileHeaderToTempFile(fileHeader)
|
return readFileHeaderToTempFile(fileHeader)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadFormFilesToTempFiles reads files array data from a request form and writes it to a temporary files
|
// ReadFormFilesToTempFiles reads files array data from a request form and writes it to a temporary files
|
||||||
func ReadFormFilesToTempFiles(r *http.Request, key string) ([]*os.File, error) {
|
func ReadFormFilesToTempFiles(r *http.Request, key string) ([]os.File, error) {
|
||||||
if err := r.ParseMultipartForm(32 << 20); err != nil {
|
if err := r.ParseMultipartForm(32 << 20); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
files := make([]*os.File, 0, len(r.MultipartForm.File[key]))
|
files := make([]os.File, 0, len(r.MultipartForm.File[key]))
|
||||||
|
|
||||||
for _, fileHeader := range r.MultipartForm.File[key] {
|
for _, fileHeader := range r.MultipartForm.File[key] {
|
||||||
file, err := readFileHeaderToTempFile(fileHeader)
|
file, err := readFileHeaderToTempFile(fileHeader)
|
||||||
@ -142,29 +142,29 @@ func ReadFormFilesToTempFiles(r *http.Request, key string) ([]*os.File, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// readFileHeaderToTempFile reads multipart.FileHeader and writes it to a temporary file
|
// readFileHeaderToTempFile reads multipart.FileHeader and writes it to a temporary file
|
||||||
func readFileHeaderToTempFile(fileHeader *multipart.FileHeader) (*os.File, error) {
|
func readFileHeaderToTempFile(fileHeader *multipart.FileHeader) (os.File, error) {
|
||||||
formFile, err := fileHeader.Open()
|
formFile, err := fileHeader.Open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return os.File{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer formFile.Close()
|
defer formFile.Close()
|
||||||
|
|
||||||
fileBytes, err := ioutil.ReadAll(formFile)
|
fileBytes, err := ioutil.ReadAll(formFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return os.File{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
file, err := ioutil.TempFile("", fileHeader.Filename)
|
file, err := ioutil.TempFile("", fileHeader.Filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return os.File{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
file.Write(fileBytes)
|
file.Write(fileBytes)
|
||||||
|
|
||||||
return file, nil
|
return *file, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseInt64Parameter parses a string parameter to an int64.
|
// parseInt64Parameter parses a string parameter to an int64.
|
||||||
|
@ -259,20 +259,25 @@ func (a *{{{classname}}}Service) {{nickname}}Execute(r {{#structPrefix}}{{&class
|
|||||||
{{paramName}}LocalVarFormFileName = "{{baseName}}"
|
{{paramName}}LocalVarFormFileName = "{{baseName}}"
|
||||||
|
|
||||||
{{#required}}
|
{{#required}}
|
||||||
{{paramName}}LocalVarFile := *r.{{paramName}}
|
{{paramName}}LocalVarFile := r.{{paramName}}
|
||||||
{{/required}}
|
{{/required}}
|
||||||
{{^required}}
|
{{^required}}
|
||||||
var {{paramName}}LocalVarFile {{dataType}}
|
var {{paramName}}LocalVarFile *{{dataType}}
|
||||||
if r.{{paramName}} != nil {
|
if r.{{paramName}} != nil {
|
||||||
{{paramName}}LocalVarFile = *r.{{paramName}}
|
{{paramName}}LocalVarFile = r.{{paramName}}
|
||||||
}
|
}
|
||||||
{{/required}}
|
|
||||||
if {{paramName}}LocalVarFile != nil {
|
if {{paramName}}LocalVarFile != nil {
|
||||||
fbs, _ := ioutil.ReadAll({{paramName}}LocalVarFile)
|
fbs, _ := ioutil.ReadAll({{paramName}}LocalVarFile)
|
||||||
|
{{/required}}
|
||||||
|
{{#required}}
|
||||||
|
fbs, _ := ioutil.ReadAll({{paramName}}LocalVarFile)
|
||||||
|
{{/required}}
|
||||||
{{paramName}}LocalVarFileBytes = fbs
|
{{paramName}}LocalVarFileBytes = fbs
|
||||||
{{paramName}}LocalVarFileName = {{paramName}}LocalVarFile.Name()
|
{{paramName}}LocalVarFileName = {{paramName}}LocalVarFile.Name()
|
||||||
{{paramName}}LocalVarFile.Close()
|
{{paramName}}LocalVarFile.Close()
|
||||||
}
|
{{^required}}
|
||||||
|
}
|
||||||
|
{{/required}}
|
||||||
formFiles = append(formFiles, formFile{fileBytes: {{paramName}}LocalVarFileBytes, fileName: {{paramName}}LocalVarFileName, formFileName: {{paramName}}LocalVarFormFileName})
|
formFiles = append(formFiles, formFile{fileBytes: {{paramName}}LocalVarFileBytes, fileName: {{paramName}}LocalVarFileName, formFileName: {{paramName}}LocalVarFormFileName})
|
||||||
{{/isFile}}
|
{{/isFile}}
|
||||||
{{^isFile}}
|
{{^isFile}}
|
||||||
|
@ -507,8 +507,20 @@ func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err err
|
|||||||
*s = string(b)
|
*s = string(b)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
if f, ok := v.(*os.File); ok {
|
||||||
|
f, err = ioutil.TempFile("", "HttpClientFile")
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_, err = f.Write(b)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_, err = f.Seek(0, io.SeekStart)
|
||||||
|
return
|
||||||
|
}
|
||||||
if f, ok := v.(**os.File); ok {
|
if f, ok := v.(**os.File); ok {
|
||||||
*f, err = ioutil.TempFile("", "HttpClientFile")
|
*f, err = ioutil.TempFile("", "HttpClientFile")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -582,8 +594,8 @@ func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err e
|
|||||||
|
|
||||||
if reader, ok := body.(io.Reader); ok {
|
if reader, ok := body.(io.Reader); ok {
|
||||||
_, err = bodyBuf.ReadFrom(reader)
|
_, err = bodyBuf.ReadFrom(reader)
|
||||||
} else if fp, ok := body.(**os.File); ok {
|
} else if fp, ok := body.(*os.File); ok {
|
||||||
_, err = bodyBuf.ReadFrom(*fp)
|
_, err = bodyBuf.ReadFrom(fp)
|
||||||
} else if b, ok := body.([]byte); ok {
|
} else if b, ok := body.([]byte); ok {
|
||||||
_, err = bodyBuf.Write(b)
|
_, err = bodyBuf.Write(b)
|
||||||
} else if s, ok := body.(string); ok {
|
} else if s, ok := body.(string); ok {
|
||||||
|
@ -262,8 +262,8 @@ public class GoModelTest {
|
|||||||
public void filePropertyTest() {
|
public void filePropertyTest() {
|
||||||
final DefaultCodegen codegen = new GoClientCodegen();
|
final DefaultCodegen codegen = new GoClientCodegen();
|
||||||
final Schema model1 = new Schema().type("file");
|
final Schema model1 = new Schema().type("file");
|
||||||
Assert.assertEquals(codegen.getSchemaType(model1), "*os.File");
|
Assert.assertEquals(codegen.getSchemaType(model1), "os.File");
|
||||||
Assert.assertEquals(codegen.getTypeDeclaration(model1), "*os.File");
|
Assert.assertEquals(codegen.getTypeDeclaration(model1), "os.File");
|
||||||
|
|
||||||
final Schema model2 = new Schema().$ref("#/definitions/File");
|
final Schema model2 = new Schema().$ref("#/definitions/File");
|
||||||
Assert.assertEquals(codegen.getSchemaType(model2), "File");
|
Assert.assertEquals(codegen.getSchemaType(model2), "File");
|
||||||
|
@ -1073,7 +1073,7 @@ type ApiTestEndpointParametersRequest struct {
|
|||||||
int64_ *int64
|
int64_ *int64
|
||||||
float *float32
|
float *float32
|
||||||
string_ *string
|
string_ *string
|
||||||
binary **os.File
|
binary *os.File
|
||||||
date *string
|
date *string
|
||||||
dateTime *time.Time
|
dateTime *time.Time
|
||||||
password *string
|
password *string
|
||||||
@ -1135,7 +1135,7 @@ func (r ApiTestEndpointParametersRequest) String_(string_ string) ApiTestEndpoin
|
|||||||
}
|
}
|
||||||
|
|
||||||
// None
|
// None
|
||||||
func (r ApiTestEndpointParametersRequest) Binary(binary *os.File) ApiTestEndpointParametersRequest {
|
func (r ApiTestEndpointParametersRequest) Binary(binary os.File) ApiTestEndpointParametersRequest {
|
||||||
r.binary = &binary
|
r.binary = &binary
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
@ -1273,14 +1273,14 @@ func (a *FakeApiService) TestEndpointParametersExecute(r ApiTestEndpointParamete
|
|||||||
|
|
||||||
var binaryLocalVarFile *os.File
|
var binaryLocalVarFile *os.File
|
||||||
if r.binary != nil {
|
if r.binary != nil {
|
||||||
binaryLocalVarFile = *r.binary
|
binaryLocalVarFile = r.binary
|
||||||
}
|
}
|
||||||
if binaryLocalVarFile != nil {
|
if binaryLocalVarFile != nil {
|
||||||
fbs, _ := ioutil.ReadAll(binaryLocalVarFile)
|
fbs, _ := ioutil.ReadAll(binaryLocalVarFile)
|
||||||
binaryLocalVarFileBytes = fbs
|
binaryLocalVarFileBytes = fbs
|
||||||
binaryLocalVarFileName = binaryLocalVarFile.Name()
|
binaryLocalVarFileName = binaryLocalVarFile.Name()
|
||||||
binaryLocalVarFile.Close()
|
binaryLocalVarFile.Close()
|
||||||
}
|
}
|
||||||
formFiles = append(formFiles, formFile{fileBytes: binaryLocalVarFileBytes, fileName: binaryLocalVarFileName, formFileName: binaryLocalVarFormFileName})
|
formFiles = append(formFiles, formFile{fileBytes: binaryLocalVarFileBytes, fileName: binaryLocalVarFileName, formFileName: binaryLocalVarFormFileName})
|
||||||
if r.date != nil {
|
if r.date != nil {
|
||||||
parameterAddToQuery(localVarFormParams, "date", r.date, "")
|
parameterAddToQuery(localVarFormParams, "date", r.date, "")
|
||||||
|
@ -895,7 +895,7 @@ type ApiUploadFileRequest struct {
|
|||||||
ApiService PetApi
|
ApiService PetApi
|
||||||
petId int64
|
petId int64
|
||||||
additionalMetadata *string
|
additionalMetadata *string
|
||||||
file **os.File
|
file *os.File
|
||||||
}
|
}
|
||||||
|
|
||||||
// Additional data to pass to server
|
// Additional data to pass to server
|
||||||
@ -905,7 +905,7 @@ func (r ApiUploadFileRequest) AdditionalMetadata(additionalMetadata string) ApiU
|
|||||||
}
|
}
|
||||||
|
|
||||||
// file to upload
|
// file to upload
|
||||||
func (r ApiUploadFileRequest) File(file *os.File) ApiUploadFileRequest {
|
func (r ApiUploadFileRequest) File(file os.File) ApiUploadFileRequest {
|
||||||
r.file = &file
|
r.file = &file
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
@ -979,14 +979,14 @@ func (a *PetApiService) UploadFileExecute(r ApiUploadFileRequest) (*ApiResponse,
|
|||||||
|
|
||||||
var fileLocalVarFile *os.File
|
var fileLocalVarFile *os.File
|
||||||
if r.file != nil {
|
if r.file != nil {
|
||||||
fileLocalVarFile = *r.file
|
fileLocalVarFile = r.file
|
||||||
}
|
}
|
||||||
if fileLocalVarFile != nil {
|
if fileLocalVarFile != nil {
|
||||||
fbs, _ := ioutil.ReadAll(fileLocalVarFile)
|
fbs, _ := ioutil.ReadAll(fileLocalVarFile)
|
||||||
fileLocalVarFileBytes = fbs
|
fileLocalVarFileBytes = fbs
|
||||||
fileLocalVarFileName = fileLocalVarFile.Name()
|
fileLocalVarFileName = fileLocalVarFile.Name()
|
||||||
fileLocalVarFile.Close()
|
fileLocalVarFile.Close()
|
||||||
}
|
}
|
||||||
formFiles = append(formFiles, formFile{fileBytes: fileLocalVarFileBytes, fileName: fileLocalVarFileName, formFileName: fileLocalVarFormFileName})
|
formFiles = append(formFiles, formFile{fileBytes: fileLocalVarFileBytes, fileName: fileLocalVarFileName, formFileName: fileLocalVarFormFileName})
|
||||||
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
|
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -1029,12 +1029,12 @@ type ApiUploadFileWithRequiredFileRequest struct {
|
|||||||
ctx context.Context
|
ctx context.Context
|
||||||
ApiService PetApi
|
ApiService PetApi
|
||||||
petId int64
|
petId int64
|
||||||
requiredFile **os.File
|
requiredFile *os.File
|
||||||
additionalMetadata *string
|
additionalMetadata *string
|
||||||
}
|
}
|
||||||
|
|
||||||
// file to upload
|
// file to upload
|
||||||
func (r ApiUploadFileWithRequiredFileRequest) RequiredFile(requiredFile *os.File) ApiUploadFileWithRequiredFileRequest {
|
func (r ApiUploadFileWithRequiredFileRequest) RequiredFile(requiredFile os.File) ApiUploadFileWithRequiredFileRequest {
|
||||||
r.requiredFile = &requiredFile
|
r.requiredFile = &requiredFile
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
@ -1115,13 +1115,11 @@ func (a *PetApiService) UploadFileWithRequiredFileExecute(r ApiUploadFileWithReq
|
|||||||
|
|
||||||
requiredFileLocalVarFormFileName = "requiredFile"
|
requiredFileLocalVarFormFileName = "requiredFile"
|
||||||
|
|
||||||
requiredFileLocalVarFile := *r.requiredFile
|
requiredFileLocalVarFile := r.requiredFile
|
||||||
if requiredFileLocalVarFile != nil {
|
fbs, _ := ioutil.ReadAll(requiredFileLocalVarFile)
|
||||||
fbs, _ := ioutil.ReadAll(requiredFileLocalVarFile)
|
|
||||||
requiredFileLocalVarFileBytes = fbs
|
requiredFileLocalVarFileBytes = fbs
|
||||||
requiredFileLocalVarFileName = requiredFileLocalVarFile.Name()
|
requiredFileLocalVarFileName = requiredFileLocalVarFile.Name()
|
||||||
requiredFileLocalVarFile.Close()
|
requiredFileLocalVarFile.Close()
|
||||||
}
|
|
||||||
formFiles = append(formFiles, formFile{fileBytes: requiredFileLocalVarFileBytes, fileName: requiredFileLocalVarFileName, formFileName: requiredFileLocalVarFormFileName})
|
formFiles = append(formFiles, formFile{fileBytes: requiredFileLocalVarFileBytes, fileName: requiredFileLocalVarFileName, formFileName: requiredFileLocalVarFormFileName})
|
||||||
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
|
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -454,8 +454,20 @@ func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err err
|
|||||||
*s = string(b)
|
*s = string(b)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
if f, ok := v.(*os.File); ok {
|
||||||
|
f, err = ioutil.TempFile("", "HttpClientFile")
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_, err = f.Write(b)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_, err = f.Seek(0, io.SeekStart)
|
||||||
|
return
|
||||||
|
}
|
||||||
if f, ok := v.(**os.File); ok {
|
if f, ok := v.(**os.File); ok {
|
||||||
*f, err = ioutil.TempFile("", "HttpClientFile")
|
*f, err = ioutil.TempFile("", "HttpClientFile")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -529,8 +541,8 @@ func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err e
|
|||||||
|
|
||||||
if reader, ok := body.(io.Reader); ok {
|
if reader, ok := body.(io.Reader); ok {
|
||||||
_, err = bodyBuf.ReadFrom(reader)
|
_, err = bodyBuf.ReadFrom(reader)
|
||||||
} else if fp, ok := body.(**os.File); ok {
|
} else if fp, ok := body.(*os.File); ok {
|
||||||
_, err = bodyBuf.ReadFrom(*fp)
|
_, err = bodyBuf.ReadFrom(fp)
|
||||||
} else if b, ok := body.([]byte); ok {
|
} else if b, ok := body.([]byte); ok {
|
||||||
_, err = bodyBuf.Write(b)
|
_, err = bodyBuf.Write(b)
|
||||||
} else if s, ok := body.(string); ok {
|
} else if s, ok := body.(string); ok {
|
||||||
|
@ -574,7 +574,7 @@ func main() {
|
|||||||
int64_ := int64(789) // int64 | None (optional)
|
int64_ := int64(789) // int64 | None (optional)
|
||||||
float := float32(3.4) // float32 | None (optional)
|
float := float32(3.4) // float32 | None (optional)
|
||||||
string_ := "string__example" // string | None (optional)
|
string_ := "string__example" // string | None (optional)
|
||||||
binary := os.NewFile(1234, "some_file") // *os.File | None (optional)
|
binary := os.NewFile(1234, "some_file") // os.File | None (optional)
|
||||||
date := time.Now() // string | None (optional)
|
date := time.Now() // string | None (optional)
|
||||||
dateTime := time.Now() // time.Time | None (optional)
|
dateTime := time.Now() // time.Time | None (optional)
|
||||||
password := "password_example" // string | None (optional)
|
password := "password_example" // string | None (optional)
|
||||||
@ -610,7 +610,7 @@ Name | Type | Description | Notes
|
|||||||
**int64_** | **int64** | None |
|
**int64_** | **int64** | None |
|
||||||
**float** | **float32** | None |
|
**float** | **float32** | None |
|
||||||
**string_** | **string** | None |
|
**string_** | **string** | None |
|
||||||
**binary** | ***os.File** | None |
|
**binary** | **os.File** | None |
|
||||||
**date** | **string** | None |
|
**date** | **string** | None |
|
||||||
**dateTime** | **time.Time** | None |
|
**dateTime** | **time.Time** | None |
|
||||||
**password** | **string** | None |
|
**password** | **string** | None |
|
||||||
|
@ -12,7 +12,7 @@ Name | Type | Description | Notes
|
|||||||
**Double** | Pointer to **float64** | | [optional]
|
**Double** | Pointer to **float64** | | [optional]
|
||||||
**String** | Pointer to **string** | | [optional]
|
**String** | Pointer to **string** | | [optional]
|
||||||
**Byte** | **string** | |
|
**Byte** | **string** | |
|
||||||
**Binary** | Pointer to ***os.File** | | [optional]
|
**Binary** | Pointer to **os.File** | | [optional]
|
||||||
**Date** | **string** | |
|
**Date** | **string** | |
|
||||||
**DateTime** | Pointer to **time.Time** | | [optional]
|
**DateTime** | Pointer to **time.Time** | | [optional]
|
||||||
**Uuid** | Pointer to **string** | | [optional]
|
**Uuid** | Pointer to **string** | | [optional]
|
||||||
@ -230,20 +230,20 @@ SetByte sets Byte field to given value.
|
|||||||
|
|
||||||
### GetBinary
|
### GetBinary
|
||||||
|
|
||||||
`func (o *FormatTest) GetBinary() *os.File`
|
`func (o *FormatTest) GetBinary() os.File`
|
||||||
|
|
||||||
GetBinary returns the Binary field if non-nil, zero value otherwise.
|
GetBinary returns the Binary field if non-nil, zero value otherwise.
|
||||||
|
|
||||||
### GetBinaryOk
|
### GetBinaryOk
|
||||||
|
|
||||||
`func (o *FormatTest) GetBinaryOk() (**os.File, bool)`
|
`func (o *FormatTest) GetBinaryOk() (*os.File, bool)`
|
||||||
|
|
||||||
GetBinaryOk returns a tuple with the Binary field if it's non-nil, zero value otherwise
|
GetBinaryOk returns a tuple with the Binary field if it's non-nil, zero value otherwise
|
||||||
and a boolean to check if the value has been set.
|
and a boolean to check if the value has been set.
|
||||||
|
|
||||||
### SetBinary
|
### SetBinary
|
||||||
|
|
||||||
`func (o *FormatTest) SetBinary(v *os.File)`
|
`func (o *FormatTest) SetBinary(v os.File)`
|
||||||
|
|
||||||
SetBinary sets Binary field to given value.
|
SetBinary sets Binary field to given value.
|
||||||
|
|
||||||
|
@ -501,7 +501,7 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
petId := int64(789) // int64 | ID of pet to update
|
petId := int64(789) // int64 | ID of pet to update
|
||||||
additionalMetadata := "additionalMetadata_example" // string | Additional data to pass to server (optional)
|
additionalMetadata := "additionalMetadata_example" // string | Additional data to pass to server (optional)
|
||||||
file := os.NewFile(1234, "some_file") // *os.File | file to upload (optional)
|
file := os.NewFile(1234, "some_file") // os.File | file to upload (optional)
|
||||||
|
|
||||||
configuration := openapiclient.NewConfiguration()
|
configuration := openapiclient.NewConfiguration()
|
||||||
apiClient := openapiclient.NewAPIClient(configuration)
|
apiClient := openapiclient.NewAPIClient(configuration)
|
||||||
@ -532,7 +532,7 @@ Name | Type | Description | Notes
|
|||||||
------------- | ------------- | ------------- | -------------
|
------------- | ------------- | ------------- | -------------
|
||||||
|
|
||||||
**additionalMetadata** | **string** | Additional data to pass to server |
|
**additionalMetadata** | **string** | Additional data to pass to server |
|
||||||
**file** | ***os.File** | file to upload |
|
**file** | **os.File** | file to upload |
|
||||||
|
|
||||||
### Return type
|
### Return type
|
||||||
|
|
||||||
@ -572,7 +572,7 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
petId := int64(789) // int64 | ID of pet to update
|
petId := int64(789) // int64 | ID of pet to update
|
||||||
requiredFile := os.NewFile(1234, "some_file") // *os.File | file to upload
|
requiredFile := os.NewFile(1234, "some_file") // os.File | file to upload
|
||||||
additionalMetadata := "additionalMetadata_example" // string | Additional data to pass to server (optional)
|
additionalMetadata := "additionalMetadata_example" // string | Additional data to pass to server (optional)
|
||||||
|
|
||||||
configuration := openapiclient.NewConfiguration()
|
configuration := openapiclient.NewConfiguration()
|
||||||
@ -603,7 +603,7 @@ Other parameters are passed through a pointer to a apiUploadFileWithRequiredFile
|
|||||||
Name | Type | Description | Notes
|
Name | Type | Description | Notes
|
||||||
------------- | ------------- | ------------- | -------------
|
------------- | ------------- | ------------- | -------------
|
||||||
|
|
||||||
**requiredFile** | ***os.File** | file to upload |
|
**requiredFile** | **os.File** | file to upload |
|
||||||
**additionalMetadata** | **string** | Additional data to pass to server |
|
**additionalMetadata** | **string** | Additional data to pass to server |
|
||||||
|
|
||||||
### Return type
|
### Return type
|
||||||
|
@ -29,7 +29,7 @@ type FormatTest struct {
|
|||||||
Double *float64 `json:"double,omitempty"`
|
Double *float64 `json:"double,omitempty"`
|
||||||
String *string `json:"string,omitempty"`
|
String *string `json:"string,omitempty"`
|
||||||
Byte string `json:"byte"`
|
Byte string `json:"byte"`
|
||||||
Binary **os.File `json:"binary,omitempty"`
|
Binary *os.File `json:"binary,omitempty"`
|
||||||
Date string `json:"date"`
|
Date string `json:"date"`
|
||||||
DateTime *time.Time `json:"dateTime,omitempty"`
|
DateTime *time.Time `json:"dateTime,omitempty"`
|
||||||
Uuid *string `json:"uuid,omitempty"`
|
Uuid *string `json:"uuid,omitempty"`
|
||||||
@ -299,9 +299,9 @@ func (o *FormatTest) SetByte(v string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetBinary returns the Binary field value if set, zero value otherwise.
|
// GetBinary returns the Binary field value if set, zero value otherwise.
|
||||||
func (o *FormatTest) GetBinary() *os.File {
|
func (o *FormatTest) GetBinary() os.File {
|
||||||
if o == nil || isNil(o.Binary) {
|
if o == nil || isNil(o.Binary) {
|
||||||
var ret *os.File
|
var ret os.File
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
return *o.Binary
|
return *o.Binary
|
||||||
@ -309,7 +309,7 @@ func (o *FormatTest) GetBinary() *os.File {
|
|||||||
|
|
||||||
// GetBinaryOk returns a tuple with the Binary field value if set, nil otherwise
|
// GetBinaryOk returns a tuple with the Binary field value if set, nil otherwise
|
||||||
// and a boolean to check if the value has been set.
|
// and a boolean to check if the value has been set.
|
||||||
func (o *FormatTest) GetBinaryOk() (**os.File, bool) {
|
func (o *FormatTest) GetBinaryOk() (*os.File, bool) {
|
||||||
if o == nil || isNil(o.Binary) {
|
if o == nil || isNil(o.Binary) {
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
@ -325,8 +325,8 @@ func (o *FormatTest) HasBinary() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetBinary gets a reference to the given *os.File and assigns it to the Binary field.
|
// SetBinary gets a reference to the given os.File and assigns it to the Binary field.
|
||||||
func (o *FormatTest) SetBinary(v *os.File) {
|
func (o *FormatTest) SetBinary(v os.File) {
|
||||||
o.Binary = &v
|
o.Binary = &v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,7 +154,7 @@ func TestUploadFile(t *testing.T) {
|
|||||||
t.Fatalf("Error opening file: %v", err1)
|
t.Fatalf("Error opening file: %v", err1)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, r, err := client.PetApi.UploadFile(context.Background(), 12830).AdditionalMetadata("golang").File(file).Execute()
|
_, r, err := client.PetApi.UploadFile(context.Background(), 12830).AdditionalMetadata("golang").File(*file).Execute()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Error while uploading file: %v", err)
|
t.Fatalf("Error while uploading file: %v", err)
|
||||||
@ -172,7 +172,7 @@ func TestUploadFileRequired(t *testing.T) {
|
|||||||
t.Fatalf("Error opening file: %v", err1)
|
t.Fatalf("Error opening file: %v", err1)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, r, err := client.PetApi.UploadFileWithRequiredFile(context.Background(), 12830).RequiredFile(file).AdditionalMetadata("golang").Execute()
|
_, r, err := client.PetApi.UploadFileWithRequiredFile(context.Background(), 12830).RequiredFile(*file).AdditionalMetadata("golang").Execute()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Error while uploading file: %v", err)
|
t.Fatalf("Error while uploading file: %v", err)
|
||||||
|
@ -422,8 +422,20 @@ func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err err
|
|||||||
*s = string(b)
|
*s = string(b)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
if f, ok := v.(*os.File); ok {
|
||||||
|
f, err = ioutil.TempFile("", "HttpClientFile")
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_, err = f.Write(b)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_, err = f.Seek(0, io.SeekStart)
|
||||||
|
return
|
||||||
|
}
|
||||||
if f, ok := v.(**os.File); ok {
|
if f, ok := v.(**os.File); ok {
|
||||||
*f, err = ioutil.TempFile("", "HttpClientFile")
|
*f, err = ioutil.TempFile("", "HttpClientFile")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -497,8 +509,8 @@ func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err e
|
|||||||
|
|
||||||
if reader, ok := body.(io.Reader); ok {
|
if reader, ok := body.(io.Reader); ok {
|
||||||
_, err = bodyBuf.ReadFrom(reader)
|
_, err = bodyBuf.ReadFrom(reader)
|
||||||
} else if fp, ok := body.(**os.File); ok {
|
} else if fp, ok := body.(*os.File); ok {
|
||||||
_, err = bodyBuf.ReadFrom(*fp)
|
_, err = bodyBuf.ReadFrom(fp)
|
||||||
} else if b, ok := body.([]byte); ok {
|
} else if b, ok := body.([]byte); ok {
|
||||||
_, err = bodyBuf.Write(b)
|
_, err = bodyBuf.Write(b)
|
||||||
} else if s, ok := body.(string); ok {
|
} else if s, ok := body.(string); ok {
|
||||||
|
@ -1099,7 +1099,7 @@ type ApiTestEndpointParametersRequest struct {
|
|||||||
int64_ *int64
|
int64_ *int64
|
||||||
float *float32
|
float *float32
|
||||||
string_ *string
|
string_ *string
|
||||||
binary **os.File
|
binary *os.File
|
||||||
date *string
|
date *string
|
||||||
dateTime *time.Time
|
dateTime *time.Time
|
||||||
password *string
|
password *string
|
||||||
@ -1161,7 +1161,7 @@ func (r ApiTestEndpointParametersRequest) String_(string_ string) ApiTestEndpoin
|
|||||||
}
|
}
|
||||||
|
|
||||||
// None
|
// None
|
||||||
func (r ApiTestEndpointParametersRequest) Binary(binary *os.File) ApiTestEndpointParametersRequest {
|
func (r ApiTestEndpointParametersRequest) Binary(binary os.File) ApiTestEndpointParametersRequest {
|
||||||
r.binary = &binary
|
r.binary = &binary
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
@ -1300,14 +1300,14 @@ func (a *FakeApiService) TestEndpointParametersExecute(r ApiTestEndpointParamete
|
|||||||
|
|
||||||
var binaryLocalVarFile *os.File
|
var binaryLocalVarFile *os.File
|
||||||
if r.binary != nil {
|
if r.binary != nil {
|
||||||
binaryLocalVarFile = *r.binary
|
binaryLocalVarFile = r.binary
|
||||||
}
|
}
|
||||||
if binaryLocalVarFile != nil {
|
if binaryLocalVarFile != nil {
|
||||||
fbs, _ := ioutil.ReadAll(binaryLocalVarFile)
|
fbs, _ := ioutil.ReadAll(binaryLocalVarFile)
|
||||||
binaryLocalVarFileBytes = fbs
|
binaryLocalVarFileBytes = fbs
|
||||||
binaryLocalVarFileName = binaryLocalVarFile.Name()
|
binaryLocalVarFileName = binaryLocalVarFile.Name()
|
||||||
binaryLocalVarFile.Close()
|
binaryLocalVarFile.Close()
|
||||||
}
|
}
|
||||||
formFiles = append(formFiles, formFile{fileBytes: binaryLocalVarFileBytes, fileName: binaryLocalVarFileName, formFileName: binaryLocalVarFormFileName})
|
formFiles = append(formFiles, formFile{fileBytes: binaryLocalVarFileBytes, fileName: binaryLocalVarFileName, formFileName: binaryLocalVarFormFileName})
|
||||||
if r.date != nil {
|
if r.date != nil {
|
||||||
parameterAddToQuery(localVarFormParams, "date", r.date, "")
|
parameterAddToQuery(localVarFormParams, "date", r.date, "")
|
||||||
|
@ -916,7 +916,7 @@ type ApiUploadFileRequest struct {
|
|||||||
ApiService PetApi
|
ApiService PetApi
|
||||||
petId int64
|
petId int64
|
||||||
additionalMetadata *string
|
additionalMetadata *string
|
||||||
file **os.File
|
file *os.File
|
||||||
}
|
}
|
||||||
|
|
||||||
// Additional data to pass to server
|
// Additional data to pass to server
|
||||||
@ -926,7 +926,7 @@ func (r ApiUploadFileRequest) AdditionalMetadata(additionalMetadata string) ApiU
|
|||||||
}
|
}
|
||||||
|
|
||||||
// file to upload
|
// file to upload
|
||||||
func (r ApiUploadFileRequest) File(file *os.File) ApiUploadFileRequest {
|
func (r ApiUploadFileRequest) File(file os.File) ApiUploadFileRequest {
|
||||||
r.file = &file
|
r.file = &file
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
@ -1002,14 +1002,14 @@ func (a *PetApiService) UploadFileExecute(r ApiUploadFileRequest) (*ApiResponse,
|
|||||||
|
|
||||||
var fileLocalVarFile *os.File
|
var fileLocalVarFile *os.File
|
||||||
if r.file != nil {
|
if r.file != nil {
|
||||||
fileLocalVarFile = *r.file
|
fileLocalVarFile = r.file
|
||||||
}
|
}
|
||||||
if fileLocalVarFile != nil {
|
if fileLocalVarFile != nil {
|
||||||
fbs, _ := ioutil.ReadAll(fileLocalVarFile)
|
fbs, _ := ioutil.ReadAll(fileLocalVarFile)
|
||||||
fileLocalVarFileBytes = fbs
|
fileLocalVarFileBytes = fbs
|
||||||
fileLocalVarFileName = fileLocalVarFile.Name()
|
fileLocalVarFileName = fileLocalVarFile.Name()
|
||||||
fileLocalVarFile.Close()
|
fileLocalVarFile.Close()
|
||||||
}
|
}
|
||||||
formFiles = append(formFiles, formFile{fileBytes: fileLocalVarFileBytes, fileName: fileLocalVarFileName, formFileName: fileLocalVarFormFileName})
|
formFiles = append(formFiles, formFile{fileBytes: fileLocalVarFileBytes, fileName: fileLocalVarFileName, formFileName: fileLocalVarFormFileName})
|
||||||
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
|
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -1052,12 +1052,12 @@ type ApiUploadFileWithRequiredFileRequest struct {
|
|||||||
ctx context.Context
|
ctx context.Context
|
||||||
ApiService PetApi
|
ApiService PetApi
|
||||||
petId int64
|
petId int64
|
||||||
requiredFile **os.File
|
requiredFile *os.File
|
||||||
additionalMetadata *string
|
additionalMetadata *string
|
||||||
}
|
}
|
||||||
|
|
||||||
// file to upload
|
// file to upload
|
||||||
func (r ApiUploadFileWithRequiredFileRequest) RequiredFile(requiredFile *os.File) ApiUploadFileWithRequiredFileRequest {
|
func (r ApiUploadFileWithRequiredFileRequest) RequiredFile(requiredFile os.File) ApiUploadFileWithRequiredFileRequest {
|
||||||
r.requiredFile = &requiredFile
|
r.requiredFile = &requiredFile
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
@ -1140,13 +1140,11 @@ func (a *PetApiService) UploadFileWithRequiredFileExecute(r ApiUploadFileWithReq
|
|||||||
|
|
||||||
requiredFileLocalVarFormFileName = "requiredFile"
|
requiredFileLocalVarFormFileName = "requiredFile"
|
||||||
|
|
||||||
requiredFileLocalVarFile := *r.requiredFile
|
requiredFileLocalVarFile := r.requiredFile
|
||||||
if requiredFileLocalVarFile != nil {
|
fbs, _ := ioutil.ReadAll(requiredFileLocalVarFile)
|
||||||
fbs, _ := ioutil.ReadAll(requiredFileLocalVarFile)
|
|
||||||
requiredFileLocalVarFileBytes = fbs
|
requiredFileLocalVarFileBytes = fbs
|
||||||
requiredFileLocalVarFileName = requiredFileLocalVarFile.Name()
|
requiredFileLocalVarFileName = requiredFileLocalVarFile.Name()
|
||||||
requiredFileLocalVarFile.Close()
|
requiredFileLocalVarFile.Close()
|
||||||
}
|
|
||||||
formFiles = append(formFiles, formFile{fileBytes: requiredFileLocalVarFileBytes, fileName: requiredFileLocalVarFileName, formFileName: requiredFileLocalVarFormFileName})
|
formFiles = append(formFiles, formFile{fileBytes: requiredFileLocalVarFileBytes, fileName: requiredFileLocalVarFileName, formFileName: requiredFileLocalVarFormFileName})
|
||||||
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
|
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -472,8 +472,20 @@ func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err err
|
|||||||
*s = string(b)
|
*s = string(b)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
if f, ok := v.(*os.File); ok {
|
||||||
|
f, err = ioutil.TempFile("", "HttpClientFile")
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_, err = f.Write(b)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_, err = f.Seek(0, io.SeekStart)
|
||||||
|
return
|
||||||
|
}
|
||||||
if f, ok := v.(**os.File); ok {
|
if f, ok := v.(**os.File); ok {
|
||||||
*f, err = ioutil.TempFile("", "HttpClientFile")
|
*f, err = ioutil.TempFile("", "HttpClientFile")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -547,8 +559,8 @@ func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err e
|
|||||||
|
|
||||||
if reader, ok := body.(io.Reader); ok {
|
if reader, ok := body.(io.Reader); ok {
|
||||||
_, err = bodyBuf.ReadFrom(reader)
|
_, err = bodyBuf.ReadFrom(reader)
|
||||||
} else if fp, ok := body.(**os.File); ok {
|
} else if fp, ok := body.(*os.File); ok {
|
||||||
_, err = bodyBuf.ReadFrom(*fp)
|
_, err = bodyBuf.ReadFrom(fp)
|
||||||
} else if b, ok := body.([]byte); ok {
|
} else if b, ok := body.([]byte); ok {
|
||||||
_, err = bodyBuf.Write(b)
|
_, err = bodyBuf.Write(b)
|
||||||
} else if s, ok := body.(string); ok {
|
} else if s, ok := body.(string); ok {
|
||||||
|
@ -571,7 +571,7 @@ func main() {
|
|||||||
int64_ := int64(789) // int64 | None (optional)
|
int64_ := int64(789) // int64 | None (optional)
|
||||||
float := float32(3.4) // float32 | None (optional)
|
float := float32(3.4) // float32 | None (optional)
|
||||||
string_ := "string__example" // string | None (optional)
|
string_ := "string__example" // string | None (optional)
|
||||||
binary := os.NewFile(1234, "some_file") // *os.File | None (optional)
|
binary := os.NewFile(1234, "some_file") // os.File | None (optional)
|
||||||
date := time.Now() // string | None (optional)
|
date := time.Now() // string | None (optional)
|
||||||
dateTime := time.Now() // time.Time | None (optional)
|
dateTime := time.Now() // time.Time | None (optional)
|
||||||
password := "password_example" // string | None (optional)
|
password := "password_example" // string | None (optional)
|
||||||
@ -607,7 +607,7 @@ Name | Type | Description | Notes
|
|||||||
**int64_** | **int64** | None |
|
**int64_** | **int64** | None |
|
||||||
**float** | **float32** | None |
|
**float** | **float32** | None |
|
||||||
**string_** | **string** | None |
|
**string_** | **string** | None |
|
||||||
**binary** | ***os.File** | None |
|
**binary** | **os.File** | None |
|
||||||
**date** | **string** | None |
|
**date** | **string** | None |
|
||||||
**dateTime** | **time.Time** | None |
|
**dateTime** | **time.Time** | None |
|
||||||
**password** | **string** | None |
|
**password** | **string** | None |
|
||||||
|
@ -12,7 +12,7 @@ Name | Type | Description | Notes
|
|||||||
**Double** | Pointer to **float64** | | [optional]
|
**Double** | Pointer to **float64** | | [optional]
|
||||||
**String** | Pointer to **string** | | [optional]
|
**String** | Pointer to **string** | | [optional]
|
||||||
**Byte** | **string** | |
|
**Byte** | **string** | |
|
||||||
**Binary** | Pointer to ***os.File** | | [optional]
|
**Binary** | Pointer to **os.File** | | [optional]
|
||||||
**Date** | **string** | |
|
**Date** | **string** | |
|
||||||
**DateTime** | Pointer to **time.Time** | | [optional]
|
**DateTime** | Pointer to **time.Time** | | [optional]
|
||||||
**Uuid** | Pointer to **string** | | [optional]
|
**Uuid** | Pointer to **string** | | [optional]
|
||||||
@ -231,20 +231,20 @@ SetByte sets Byte field to given value.
|
|||||||
|
|
||||||
### GetBinary
|
### GetBinary
|
||||||
|
|
||||||
`func (o *FormatTest) GetBinary() *os.File`
|
`func (o *FormatTest) GetBinary() os.File`
|
||||||
|
|
||||||
GetBinary returns the Binary field if non-nil, zero value otherwise.
|
GetBinary returns the Binary field if non-nil, zero value otherwise.
|
||||||
|
|
||||||
### GetBinaryOk
|
### GetBinaryOk
|
||||||
|
|
||||||
`func (o *FormatTest) GetBinaryOk() (**os.File, bool)`
|
`func (o *FormatTest) GetBinaryOk() (*os.File, bool)`
|
||||||
|
|
||||||
GetBinaryOk returns a tuple with the Binary field if it's non-nil, zero value otherwise
|
GetBinaryOk returns a tuple with the Binary field if it's non-nil, zero value otherwise
|
||||||
and a boolean to check if the value has been set.
|
and a boolean to check if the value has been set.
|
||||||
|
|
||||||
### SetBinary
|
### SetBinary
|
||||||
|
|
||||||
`func (o *FormatTest) SetBinary(v *os.File)`
|
`func (o *FormatTest) SetBinary(v os.File)`
|
||||||
|
|
||||||
SetBinary sets Binary field to given value.
|
SetBinary sets Binary field to given value.
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
Name | Type | Description | Notes
|
Name | Type | Description | Notes
|
||||||
------------ | ------------- | ------------- | -------------
|
------------ | ------------- | ------------- | -------------
|
||||||
**PropTest** | Pointer to **map[string]*os.File** | a property to test map of file | [optional]
|
**PropTest** | Pointer to **map[string]os.File** | a property to test map of file | [optional]
|
||||||
|
|
||||||
## Methods
|
## Methods
|
||||||
|
|
||||||
@ -27,20 +27,20 @@ but it doesn't guarantee that properties required by API are set
|
|||||||
|
|
||||||
### GetPropTest
|
### GetPropTest
|
||||||
|
|
||||||
`func (o *MapOfFileTest) GetPropTest() map[string]*os.File`
|
`func (o *MapOfFileTest) GetPropTest() map[string]os.File`
|
||||||
|
|
||||||
GetPropTest returns the PropTest field if non-nil, zero value otherwise.
|
GetPropTest returns the PropTest field if non-nil, zero value otherwise.
|
||||||
|
|
||||||
### GetPropTestOk
|
### GetPropTestOk
|
||||||
|
|
||||||
`func (o *MapOfFileTest) GetPropTestOk() (*map[string]*os.File, bool)`
|
`func (o *MapOfFileTest) GetPropTestOk() (*map[string]os.File, bool)`
|
||||||
|
|
||||||
GetPropTestOk returns a tuple with the PropTest field if it's non-nil, zero value otherwise
|
GetPropTestOk returns a tuple with the PropTest field if it's non-nil, zero value otherwise
|
||||||
and a boolean to check if the value has been set.
|
and a boolean to check if the value has been set.
|
||||||
|
|
||||||
### SetPropTest
|
### SetPropTest
|
||||||
|
|
||||||
`func (o *MapOfFileTest) SetPropTest(v map[string]*os.File)`
|
`func (o *MapOfFileTest) SetPropTest(v map[string]os.File)`
|
||||||
|
|
||||||
SetPropTest sets PropTest field to given value.
|
SetPropTest sets PropTest field to given value.
|
||||||
|
|
||||||
|
@ -511,7 +511,7 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
petId := int64(789) // int64 | ID of pet to update
|
petId := int64(789) // int64 | ID of pet to update
|
||||||
additionalMetadata := "additionalMetadata_example" // string | Additional data to pass to server (optional)
|
additionalMetadata := "additionalMetadata_example" // string | Additional data to pass to server (optional)
|
||||||
file := os.NewFile(1234, "some_file") // *os.File | file to upload (optional)
|
file := os.NewFile(1234, "some_file") // os.File | file to upload (optional)
|
||||||
|
|
||||||
configuration := openapiclient.NewConfiguration()
|
configuration := openapiclient.NewConfiguration()
|
||||||
apiClient := openapiclient.NewAPIClient(configuration)
|
apiClient := openapiclient.NewAPIClient(configuration)
|
||||||
@ -542,7 +542,7 @@ Name | Type | Description | Notes
|
|||||||
------------- | ------------- | ------------- | -------------
|
------------- | ------------- | ------------- | -------------
|
||||||
|
|
||||||
**additionalMetadata** | **string** | Additional data to pass to server |
|
**additionalMetadata** | **string** | Additional data to pass to server |
|
||||||
**file** | ***os.File** | file to upload |
|
**file** | **os.File** | file to upload |
|
||||||
|
|
||||||
### Return type
|
### Return type
|
||||||
|
|
||||||
@ -584,7 +584,7 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
petId := int64(789) // int64 | ID of pet to update
|
petId := int64(789) // int64 | ID of pet to update
|
||||||
requiredFile := os.NewFile(1234, "some_file") // *os.File | file to upload
|
requiredFile := os.NewFile(1234, "some_file") // os.File | file to upload
|
||||||
additionalMetadata := "additionalMetadata_example" // string | Additional data to pass to server (optional)
|
additionalMetadata := "additionalMetadata_example" // string | Additional data to pass to server (optional)
|
||||||
|
|
||||||
configuration := openapiclient.NewConfiguration()
|
configuration := openapiclient.NewConfiguration()
|
||||||
@ -615,7 +615,7 @@ Other parameters are passed through a pointer to a apiUploadFileWithRequiredFile
|
|||||||
Name | Type | Description | Notes
|
Name | Type | Description | Notes
|
||||||
------------- | ------------- | ------------- | -------------
|
------------- | ------------- | ------------- | -------------
|
||||||
|
|
||||||
**requiredFile** | ***os.File** | file to upload |
|
**requiredFile** | **os.File** | file to upload |
|
||||||
**additionalMetadata** | **string** | Additional data to pass to server |
|
**additionalMetadata** | **string** | Additional data to pass to server |
|
||||||
|
|
||||||
### Return type
|
### Return type
|
||||||
|
@ -29,7 +29,7 @@ type FormatTest struct {
|
|||||||
Double *float64 `json:"double,omitempty"`
|
Double *float64 `json:"double,omitempty"`
|
||||||
String *string `json:"string,omitempty"`
|
String *string `json:"string,omitempty"`
|
||||||
Byte string `json:"byte"`
|
Byte string `json:"byte"`
|
||||||
Binary **os.File `json:"binary,omitempty"`
|
Binary *os.File `json:"binary,omitempty"`
|
||||||
Date string `json:"date"`
|
Date string `json:"date"`
|
||||||
DateTime *time.Time `json:"dateTime,omitempty"`
|
DateTime *time.Time `json:"dateTime,omitempty"`
|
||||||
Uuid *string `json:"uuid,omitempty"`
|
Uuid *string `json:"uuid,omitempty"`
|
||||||
@ -305,9 +305,9 @@ func (o *FormatTest) SetByte(v string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetBinary returns the Binary field value if set, zero value otherwise.
|
// GetBinary returns the Binary field value if set, zero value otherwise.
|
||||||
func (o *FormatTest) GetBinary() *os.File {
|
func (o *FormatTest) GetBinary() os.File {
|
||||||
if o == nil || isNil(o.Binary) {
|
if o == nil || isNil(o.Binary) {
|
||||||
var ret *os.File
|
var ret os.File
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
return *o.Binary
|
return *o.Binary
|
||||||
@ -315,7 +315,7 @@ func (o *FormatTest) GetBinary() *os.File {
|
|||||||
|
|
||||||
// GetBinaryOk returns a tuple with the Binary field value if set, nil otherwise
|
// GetBinaryOk returns a tuple with the Binary field value if set, nil otherwise
|
||||||
// and a boolean to check if the value has been set.
|
// and a boolean to check if the value has been set.
|
||||||
func (o *FormatTest) GetBinaryOk() (**os.File, bool) {
|
func (o *FormatTest) GetBinaryOk() (*os.File, bool) {
|
||||||
if o == nil || isNil(o.Binary) {
|
if o == nil || isNil(o.Binary) {
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
@ -331,8 +331,8 @@ func (o *FormatTest) HasBinary() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetBinary gets a reference to the given *os.File and assigns it to the Binary field.
|
// SetBinary gets a reference to the given os.File and assigns it to the Binary field.
|
||||||
func (o *FormatTest) SetBinary(v *os.File) {
|
func (o *FormatTest) SetBinary(v os.File) {
|
||||||
o.Binary = &v
|
o.Binary = &v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ var _ MappedNullable = &MapOfFileTest{}
|
|||||||
// MapOfFileTest test map of file in a property
|
// MapOfFileTest test map of file in a property
|
||||||
type MapOfFileTest struct {
|
type MapOfFileTest struct {
|
||||||
// a property to test map of file
|
// a property to test map of file
|
||||||
PropTest *map[string]*os.File `json:"prop_test,omitempty"`
|
PropTest *map[string]os.File `json:"prop_test,omitempty"`
|
||||||
AdditionalProperties map[string]interface{}
|
AdditionalProperties map[string]interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,9 +45,9 @@ func NewMapOfFileTestWithDefaults() *MapOfFileTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetPropTest returns the PropTest field value if set, zero value otherwise.
|
// GetPropTest returns the PropTest field value if set, zero value otherwise.
|
||||||
func (o *MapOfFileTest) GetPropTest() map[string]*os.File {
|
func (o *MapOfFileTest) GetPropTest() map[string]os.File {
|
||||||
if o == nil || isNil(o.PropTest) {
|
if o == nil || isNil(o.PropTest) {
|
||||||
var ret map[string]*os.File
|
var ret map[string]os.File
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
return *o.PropTest
|
return *o.PropTest
|
||||||
@ -55,7 +55,7 @@ func (o *MapOfFileTest) GetPropTest() map[string]*os.File {
|
|||||||
|
|
||||||
// GetPropTestOk returns a tuple with the PropTest field value if set, nil otherwise
|
// GetPropTestOk returns a tuple with the PropTest field value if set, nil otherwise
|
||||||
// and a boolean to check if the value has been set.
|
// and a boolean to check if the value has been set.
|
||||||
func (o *MapOfFileTest) GetPropTestOk() (*map[string]*os.File, bool) {
|
func (o *MapOfFileTest) GetPropTestOk() (*map[string]os.File, bool) {
|
||||||
if o == nil || isNil(o.PropTest) {
|
if o == nil || isNil(o.PropTest) {
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
@ -71,8 +71,8 @@ func (o *MapOfFileTest) HasPropTest() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetPropTest gets a reference to the given map[string]*os.File and assigns it to the PropTest field.
|
// SetPropTest gets a reference to the given map[string]os.File and assigns it to the PropTest field.
|
||||||
func (o *MapOfFileTest) SetPropTest(v map[string]*os.File) {
|
func (o *MapOfFileTest) SetPropTest(v map[string]os.File) {
|
||||||
o.PropTest = &v
|
o.PropTest = &v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ func TestUploadFile(t *testing.T) {
|
|||||||
t.Fatalf("Error opening file: %v", err1)
|
t.Fatalf("Error opening file: %v", err1)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, r, err := client.PetApi.UploadFile(context.Background(), 12830).AdditionalMetadata("golang").File(file).Execute()
|
_, r, err := client.PetApi.UploadFile(context.Background(), 12830).AdditionalMetadata("golang").File(*file).Execute()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Error while uploading file: %v", err)
|
t.Fatalf("Error while uploading file: %v", err)
|
||||||
@ -162,7 +162,7 @@ func TestUploadFileRequired(t *testing.T) {
|
|||||||
t.Fatalf("Error opening file: %v", err1)
|
t.Fatalf("Error opening file: %v", err1)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, r, err := client.PetApi.UploadFileWithRequiredFile(context.Background(), 12830).RequiredFile(file).AdditionalMetadata("golang").Execute()
|
_, r, err := client.PetApi.UploadFileWithRequiredFile(context.Background(), 12830).RequiredFile(*file).AdditionalMetadata("golang").Execute()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Error while uploading file: %v", err)
|
t.Fatalf("Error while uploading file: %v", err)
|
||||||
|
@ -68,7 +68,7 @@ type PetApiServicer interface {
|
|||||||
GetPetById(context.Context, int64) (ImplResponse, error)
|
GetPetById(context.Context, int64) (ImplResponse, error)
|
||||||
UpdatePet(context.Context, Pet) (ImplResponse, error)
|
UpdatePet(context.Context, Pet) (ImplResponse, error)
|
||||||
UpdatePetWithForm(context.Context, int64, string, string) (ImplResponse, error)
|
UpdatePetWithForm(context.Context, int64, string, string) (ImplResponse, error)
|
||||||
UploadFile(context.Context, int64, string, *os.File) (ImplResponse, error)
|
UploadFile(context.Context, int64, string, os.File) (ImplResponse, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -130,7 +130,7 @@ func (s *PetApiService) UpdatePetWithForm(ctx context.Context, petId int64, name
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UploadFile - uploads an image
|
// UploadFile - uploads an image
|
||||||
func (s *PetApiService) UploadFile(ctx context.Context, petId int64, additionalMetadata string, file *os.File) (ImplResponse, error) {
|
func (s *PetApiService) UploadFile(ctx context.Context, petId int64, additionalMetadata string, file os.File) (ImplResponse, error) {
|
||||||
// TODO - update UploadFile with the required logic for this service method.
|
// TODO - update UploadFile with the required logic for this service method.
|
||||||
// Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
|
// Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
|
||||||
|
|
||||||
|
@ -80,22 +80,22 @@ func EncodeJSONResponse(i interface{}, status *int, headers map[string][]string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ReadFormFileToTempFile reads file data from a request form and writes it to a temporary file
|
// ReadFormFileToTempFile reads file data from a request form and writes it to a temporary file
|
||||||
func ReadFormFileToTempFile(r *http.Request, key string) (*os.File, error) {
|
func ReadFormFileToTempFile(r *http.Request, key string) (os.File, error) {
|
||||||
_, fileHeader, err := r.FormFile(key)
|
_, fileHeader, err := r.FormFile(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return os.File{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return readFileHeaderToTempFile(fileHeader)
|
return readFileHeaderToTempFile(fileHeader)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadFormFilesToTempFiles reads files array data from a request form and writes it to a temporary files
|
// ReadFormFilesToTempFiles reads files array data from a request form and writes it to a temporary files
|
||||||
func ReadFormFilesToTempFiles(r *http.Request, key string) ([]*os.File, error) {
|
func ReadFormFilesToTempFiles(r *http.Request, key string) ([]os.File, error) {
|
||||||
if err := r.ParseMultipartForm(32 << 20); err != nil {
|
if err := r.ParseMultipartForm(32 << 20); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
files := make([]*os.File, 0, len(r.MultipartForm.File[key]))
|
files := make([]os.File, 0, len(r.MultipartForm.File[key]))
|
||||||
|
|
||||||
for _, fileHeader := range r.MultipartForm.File[key] {
|
for _, fileHeader := range r.MultipartForm.File[key] {
|
||||||
file, err := readFileHeaderToTempFile(fileHeader)
|
file, err := readFileHeaderToTempFile(fileHeader)
|
||||||
@ -110,29 +110,29 @@ func ReadFormFilesToTempFiles(r *http.Request, key string) ([]*os.File, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// readFileHeaderToTempFile reads multipart.FileHeader and writes it to a temporary file
|
// readFileHeaderToTempFile reads multipart.FileHeader and writes it to a temporary file
|
||||||
func readFileHeaderToTempFile(fileHeader *multipart.FileHeader) (*os.File, error) {
|
func readFileHeaderToTempFile(fileHeader *multipart.FileHeader) (os.File, error) {
|
||||||
formFile, err := fileHeader.Open()
|
formFile, err := fileHeader.Open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return os.File{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer formFile.Close()
|
defer formFile.Close()
|
||||||
|
|
||||||
fileBytes, err := ioutil.ReadAll(formFile)
|
fileBytes, err := ioutil.ReadAll(formFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return os.File{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
file, err := ioutil.TempFile("", fileHeader.Filename)
|
file, err := ioutil.TempFile("", fileHeader.Filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return os.File{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
file.Write(fileBytes)
|
file.Write(fileBytes)
|
||||||
|
|
||||||
return file, nil
|
return *file, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseInt64Parameter parses a string parameter to an int64.
|
// parseInt64Parameter parses a string parameter to an int64.
|
||||||
|
@ -68,7 +68,7 @@ type PetApiServicer interface {
|
|||||||
GetPetById(context.Context, int64) (ImplResponse, error)
|
GetPetById(context.Context, int64) (ImplResponse, error)
|
||||||
UpdatePet(context.Context, Pet) (ImplResponse, error)
|
UpdatePet(context.Context, Pet) (ImplResponse, error)
|
||||||
UpdatePetWithForm(context.Context, int64, string, string) (ImplResponse, error)
|
UpdatePetWithForm(context.Context, int64, string, string) (ImplResponse, error)
|
||||||
UploadFile(context.Context, int64, string, *os.File) (ImplResponse, error)
|
UploadFile(context.Context, int64, string, os.File) (ImplResponse, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -130,7 +130,7 @@ func (s *PetApiService) UpdatePetWithForm(ctx context.Context, petId int64, name
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UploadFile - uploads an image
|
// UploadFile - uploads an image
|
||||||
func (s *PetApiService) UploadFile(ctx context.Context, petId int64, additionalMetadata string, file *os.File) (ImplResponse, error) {
|
func (s *PetApiService) UploadFile(ctx context.Context, petId int64, additionalMetadata string, file os.File) (ImplResponse, error) {
|
||||||
// TODO - update UploadFile with the required logic for this service method.
|
// TODO - update UploadFile with the required logic for this service method.
|
||||||
// Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
|
// Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
|
||||||
|
|
||||||
|
@ -76,22 +76,22 @@ func EncodeJSONResponse(i interface{}, status *int, headers map[string][]string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ReadFormFileToTempFile reads file data from a request form and writes it to a temporary file
|
// ReadFormFileToTempFile reads file data from a request form and writes it to a temporary file
|
||||||
func ReadFormFileToTempFile(r *http.Request, key string) (*os.File, error) {
|
func ReadFormFileToTempFile(r *http.Request, key string) (os.File, error) {
|
||||||
_, fileHeader, err := r.FormFile(key)
|
_, fileHeader, err := r.FormFile(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return os.File{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return readFileHeaderToTempFile(fileHeader)
|
return readFileHeaderToTempFile(fileHeader)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadFormFilesToTempFiles reads files array data from a request form and writes it to a temporary files
|
// ReadFormFilesToTempFiles reads files array data from a request form and writes it to a temporary files
|
||||||
func ReadFormFilesToTempFiles(r *http.Request, key string) ([]*os.File, error) {
|
func ReadFormFilesToTempFiles(r *http.Request, key string) ([]os.File, error) {
|
||||||
if err := r.ParseMultipartForm(32 << 20); err != nil {
|
if err := r.ParseMultipartForm(32 << 20); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
files := make([]*os.File, 0, len(r.MultipartForm.File[key]))
|
files := make([]os.File, 0, len(r.MultipartForm.File[key]))
|
||||||
|
|
||||||
for _, fileHeader := range r.MultipartForm.File[key] {
|
for _, fileHeader := range r.MultipartForm.File[key] {
|
||||||
file, err := readFileHeaderToTempFile(fileHeader)
|
file, err := readFileHeaderToTempFile(fileHeader)
|
||||||
@ -106,29 +106,29 @@ func ReadFormFilesToTempFiles(r *http.Request, key string) ([]*os.File, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// readFileHeaderToTempFile reads multipart.FileHeader and writes it to a temporary file
|
// readFileHeaderToTempFile reads multipart.FileHeader and writes it to a temporary file
|
||||||
func readFileHeaderToTempFile(fileHeader *multipart.FileHeader) (*os.File, error) {
|
func readFileHeaderToTempFile(fileHeader *multipart.FileHeader) (os.File, error) {
|
||||||
formFile, err := fileHeader.Open()
|
formFile, err := fileHeader.Open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return os.File{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer formFile.Close()
|
defer formFile.Close()
|
||||||
|
|
||||||
fileBytes, err := ioutil.ReadAll(formFile)
|
fileBytes, err := ioutil.ReadAll(formFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return os.File{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
file, err := ioutil.TempFile("", fileHeader.Filename)
|
file, err := ioutil.TempFile("", fileHeader.Filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return os.File{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
file.Write(fileBytes)
|
file.Write(fileBytes)
|
||||||
|
|
||||||
return file, nil
|
return *file, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseInt64Parameter parses a string parameter to an int64.
|
// parseInt64Parameter parses a string parameter to an int64.
|
||||||
|
@ -68,7 +68,7 @@ type PetApiServicer interface {
|
|||||||
GetPetById(context.Context, int64) (ImplResponse, error)
|
GetPetById(context.Context, int64) (ImplResponse, error)
|
||||||
UpdatePet(context.Context, Pet) (ImplResponse, error)
|
UpdatePet(context.Context, Pet) (ImplResponse, error)
|
||||||
UpdatePetWithForm(context.Context, int64, string, string) (ImplResponse, error)
|
UpdatePetWithForm(context.Context, int64, string, string) (ImplResponse, error)
|
||||||
UploadFile(context.Context, int64, string, *os.File) (ImplResponse, error)
|
UploadFile(context.Context, int64, string, os.File) (ImplResponse, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -130,7 +130,7 @@ func (s *PetApiService) UpdatePetWithForm(ctx context.Context, petId int64, name
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UploadFile - uploads an image
|
// UploadFile - uploads an image
|
||||||
func (s *PetApiService) UploadFile(ctx context.Context, petId int64, additionalMetadata string, file *os.File) (ImplResponse, error) {
|
func (s *PetApiService) UploadFile(ctx context.Context, petId int64, additionalMetadata string, file os.File) (ImplResponse, error) {
|
||||||
// TODO - update UploadFile with the required logic for this service method.
|
// TODO - update UploadFile with the required logic for this service method.
|
||||||
// Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
|
// Add api_pet_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
|
||||||
|
|
||||||
|
@ -76,22 +76,22 @@ func EncodeJSONResponse(i interface{}, status *int, headers map[string][]string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ReadFormFileToTempFile reads file data from a request form and writes it to a temporary file
|
// ReadFormFileToTempFile reads file data from a request form and writes it to a temporary file
|
||||||
func ReadFormFileToTempFile(r *http.Request, key string) (*os.File, error) {
|
func ReadFormFileToTempFile(r *http.Request, key string) (os.File, error) {
|
||||||
_, fileHeader, err := r.FormFile(key)
|
_, fileHeader, err := r.FormFile(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return os.File{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return readFileHeaderToTempFile(fileHeader)
|
return readFileHeaderToTempFile(fileHeader)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadFormFilesToTempFiles reads files array data from a request form and writes it to a temporary files
|
// ReadFormFilesToTempFiles reads files array data from a request form and writes it to a temporary files
|
||||||
func ReadFormFilesToTempFiles(r *http.Request, key string) ([]*os.File, error) {
|
func ReadFormFilesToTempFiles(r *http.Request, key string) ([]os.File, error) {
|
||||||
if err := r.ParseMultipartForm(32 << 20); err != nil {
|
if err := r.ParseMultipartForm(32 << 20); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
files := make([]*os.File, 0, len(r.MultipartForm.File[key]))
|
files := make([]os.File, 0, len(r.MultipartForm.File[key]))
|
||||||
|
|
||||||
for _, fileHeader := range r.MultipartForm.File[key] {
|
for _, fileHeader := range r.MultipartForm.File[key] {
|
||||||
file, err := readFileHeaderToTempFile(fileHeader)
|
file, err := readFileHeaderToTempFile(fileHeader)
|
||||||
@ -106,29 +106,29 @@ func ReadFormFilesToTempFiles(r *http.Request, key string) ([]*os.File, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// readFileHeaderToTempFile reads multipart.FileHeader and writes it to a temporary file
|
// readFileHeaderToTempFile reads multipart.FileHeader and writes it to a temporary file
|
||||||
func readFileHeaderToTempFile(fileHeader *multipart.FileHeader) (*os.File, error) {
|
func readFileHeaderToTempFile(fileHeader *multipart.FileHeader) (os.File, error) {
|
||||||
formFile, err := fileHeader.Open()
|
formFile, err := fileHeader.Open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return os.File{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer formFile.Close()
|
defer formFile.Close()
|
||||||
|
|
||||||
fileBytes, err := ioutil.ReadAll(formFile)
|
fileBytes, err := ioutil.ReadAll(formFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return os.File{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
file, err := ioutil.TempFile("", fileHeader.Filename)
|
file, err := ioutil.TempFile("", fileHeader.Filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return os.File{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
file.Write(fileBytes)
|
file.Write(fileBytes)
|
||||||
|
|
||||||
return file, nil
|
return *file, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseInt64Parameter parses a string parameter to an int64.
|
// parseInt64Parameter parses a string parameter to an int64.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user