diff --git a/Makefile b/Makefile index 85dcdf4b..12e00186 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ install: .PHONY: test test: install go test ./... - npm install -g @fern-api/seed-cli@0.15.11-5-gc8d919536 + npm install -g @fern-api/seed-cli@0.16.25-2-g32eebe2b seed test --workspace sdk --fixture enum-query-params seed test --workspace sdk --fixture response-property seed test --workspace sdk --fixture file-upload diff --git a/README.md b/README.md index 90be286e..bfbd5cd9 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@
- header + header
diff --git a/internal/generator/generator.go b/internal/generator/generator.go index 4c4cb5e3..700bf237 100644 --- a/internal/generator/generator.go +++ b/internal/generator/generator.go @@ -893,10 +893,7 @@ func shouldSkipRequestType(irEndpoint *fernir.HttpEndpoint) bool { // This endpoint doesn't have any in-lined request types that need to be generated. return true } - if irEndpoint.RequestBody != nil && irEndpoint.RequestBody.FileUpload != nil { - return !fileUploadHasBodyProperties(irEndpoint.RequestBody.FileUpload) - } - return false + return !needsRequestParameter(irEndpoint) } // fileUploadHasBodyProperties returns true if the file upload request has at least diff --git a/internal/generator/sdk.go b/internal/generator/sdk.go index c0de055a..0417b51b 100644 --- a/internal/generator/sdk.go +++ b/internal/generator/sdk.go @@ -1683,6 +1683,9 @@ func needsRequestParameter(endpoint *ir.HttpEndpoint) bool { if endpoint.SdkRequest == nil { return false } + if len(endpoint.QueryParameters) > 0 { + return true + } if endpoint.RequestBody != nil { return endpoint.RequestBody.FileUpload == nil || fileUploadHasBodyProperties(endpoint.RequestBody.FileUpload) } diff --git a/seed/sdk/file-upload/service.go b/seed/sdk/file-upload/service.go index 34b79f08..375f6134 100644 --- a/seed/sdk/file-upload/service.go +++ b/seed/sdk/file-upload/service.go @@ -8,6 +8,14 @@ import ( core "github.com/file-upload/fern/core" ) +type JustFileWithQueryParamsRequet struct { + MaybeString *string `json:"-"` + Integer int `json:"-"` + MaybeInteger *int `json:"-"` + ListOfStrings []string `json:"-"` + OptionalListOfStrings []*string `json:"-"` +} + type MyRequest struct { MaybeString *string `json:"maybeString,omitempty"` Integer int `json:"integer"` diff --git a/seed/sdk/file-upload/service/client.go b/seed/sdk/file-upload/service/client.go index f6cd1da6..20390360 100644 --- a/seed/sdk/file-upload/service/client.go +++ b/seed/sdk/file-upload/service/client.go @@ -11,6 +11,7 @@ import ( io "io" multipart "mime/multipart" http "net/http" + url "net/url" ) type Client struct { @@ -169,3 +170,60 @@ func (c *Client) JustFile(ctx context.Context, file io.Reader) error { } return nil } + +func (c *Client) JustFileWithQueryParams(ctx context.Context, file io.Reader, request *fern.JustFileWithQueryParamsRequet) error { + baseURL := "" + if c.baseURL != "" { + baseURL = c.baseURL + } + endpointURL := baseURL + "/" + "just-file-with-query-params" + + queryParams := make(url.Values) + if request.MaybeString != nil { + queryParams.Add("maybeString", fmt.Sprintf("%v", *request.MaybeString)) + } + queryParams.Add("integer", fmt.Sprintf("%v", request.Integer)) + if request.MaybeInteger != nil { + queryParams.Add("maybeInteger", fmt.Sprintf("%v", *request.MaybeInteger)) + } + for _, value := range request.ListOfStrings { + queryParams.Add("listOfStrings", fmt.Sprintf("%v", value)) + } + for _, value := range request.OptionalListOfStrings { + queryParams.Add("optionalListOfStrings", fmt.Sprintf("%v", *value)) + } + if len(queryParams) > 0 { + endpointURL += "?" + queryParams.Encode() + } + + requestBuffer := bytes.NewBuffer(nil) + writer := multipart.NewWriter(requestBuffer) + fileFilename := "file_filename" + if named, ok := file.(interface{ Name() string }); ok { + fileFilename = named.Name() + } + filePart, err := writer.CreateFormFile("file", fileFilename) + if err != nil { + return err + } + if _, err := io.Copy(filePart, file); err != nil { + return err + } + if err := writer.Close(); err != nil { + return err + } + c.header.Set("Content-Type", writer.FormDataContentType()) + + if err := c.caller.Call( + ctx, + &core.CallParams{ + URL: endpointURL, + Method: http.MethodPost, + Headers: c.header, + Request: requestBuffer, + }, + ); err != nil { + return err + } + return nil +} diff --git a/static/images/fern-logo.png b/static/images/fern-logo.png new file mode 100644 index 00000000..7d23a660 Binary files /dev/null and b/static/images/fern-logo.png differ diff --git a/static/images/fern.png b/static/images/fern.png deleted file mode 100644 index 57fe8a9b..00000000 Binary files a/static/images/fern.png and /dev/null differ