Skip to content

Commit

Permalink
Merge pull request #7 from fern-api/main
Browse files Browse the repository at this point in the history
Fork Sync: Update from parent repository
  • Loading branch information
davidkonigsberg authored Jan 18, 2024
2 parents d492dfe + 59637b3 commit 7ac98b3
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<br/>
<div align="center">
<a href="https://www.buildwithfern.com/?utm_source=github&utm_medium=readme&utm_campaign=fern-go&utm_content=logo">
<img src="static/images/fern.png" height="120" align="center" alt="header" />
<img src="static/images/fern-logo.png" height="50" align="center" alt="header" />
</a>

<br/>
Expand Down
5 changes: 1 addition & 4 deletions internal/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions internal/generator/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
8 changes: 8 additions & 0 deletions seed/sdk/file-upload/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
58 changes: 58 additions & 0 deletions seed/sdk/file-upload/service/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
io "io"
multipart "mime/multipart"
http "net/http"
url "net/url"
)

type Client struct {
Expand Down Expand Up @@ -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
}
Binary file added static/images/fern-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed static/images/fern.png
Binary file not shown.

0 comments on commit 7ac98b3

Please sign in to comment.